@Override public void write(NullWritable key, VertexWritable value) throws IOException, InterruptedException { // TODO tolerate possibility that concurrent OLTP activity has deleted the vertex? maybe configurable... Object vertexID = value.get().id(); Vertex vertex = tx.vertices(vertexID).next(); Iterator<VertexProperty<Object>> vpIter = value.get().properties(); while (vpIter.hasNext()) { VertexProperty<Object> vp = vpIter.next(); if (!persistableKeys.isEmpty() && !persistableKeys.contains(vp.key())) { log.debug("[vid {}] skipping key {}", vertexID, vp.key()); continue; } vertex.property(vp.key(), vp.value()); log.debug("[vid {}] set {}={}", vertexID, vp.key(), vp.value()); } }
/** * {@inheritDoc} */ @Override public default String label() { return this.key(); }
@Override public String apply(final Element element) { return ((VertexProperty) element).key(); } },
@Override public String key() { return this.baseVertexProperty.key(); }
private static Map<String, List<VertexProperty>> indexedVertexProperties(final Vertex v) { final Map<String,List<VertexProperty>> index = new HashMap<>(); v.properties().forEachRemaining(vp -> { if (!index.containsKey(vp.key())) { index.put(vp.key(), new ArrayList<>()); } index.get(vp.key()).add(vp); }); return index; }
public static Map<String, List<VertexProperty>> vertexPropertyMap(final Vertex vertex, final String... propertyKeys) { final Map<String, List<VertexProperty>> propertyMap = new HashMap<>(); vertex.properties(propertyKeys).forEachRemaining(property -> { if (propertyMap.containsKey(property.key())) propertyMap.get(property.key()).add(property); else { final List<VertexProperty> list = new ArrayList<>(); list.add(property); propertyMap.put(property.key(), list); } }); return propertyMap; }
@Override public String key() { return this.getBaseVertexProperty().key(); }
public static Map<String, List> vertexPropertyValueMap(final Vertex vertex, final String... propertyKeys) { final Map<String, List> valueMap = new HashMap<>(); vertex.properties(propertyKeys).forEachRemaining(property -> { if (valueMap.containsKey(property.key())) valueMap.get(property.key()).add(property.value()); else { final List list = new ArrayList(); list.add(property.value()); valueMap.put(property.key(), list); } }); return valueMap; }
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(baseVertexProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) return Optional.of(vertexProperty); } return Optional.empty(); }
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) return Optional.of(vertexProperty); } } return Optional.empty(); }
private void addPropertiesToOriginalGraph() { TinkerHelper.dropGraphComputerView(this.graph); this.computeProperties.forEach((element, properties) -> { properties.forEach((key, vertexProperties) -> { vertexProperties.forEach(vertexProperty -> { final VertexProperty<?> newVertexProperty = ((Vertex) element).property(VertexProperty.Cardinality.list, vertexProperty.key(), vertexProperty.value(), T.id, vertexProperty.id()); vertexProperty.properties().forEachRemaining(property -> { newVertexProperty.property(property.key(), property.value()); }); }); }); }); this.computeProperties.clear(); }
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } };
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } };
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(baseVertexProperty.id()) ? vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) : vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value()); baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); return vertexProperty; } throw new IllegalStateException("Could not find vertex to create the attachable vertex property on"); }
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertThat(oldValue, instanceOf(KeyedVertexProperty.class)); assertEquals("new", oldValue.key()); assertEquals("dah", setValue); triggered.set(true); } };
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(DetachedVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } };
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertThat(element, instanceOf(ReferenceVertex.class)); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } };
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) { final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get(); final VertexProperty vertexProperty = hostVertex.graph().features().vertex().properties().willAllowId(baseVertexProperty.id()) ? hostVertex.property(hostVertex.graph().features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) : hostVertex.property(hostVertex.graph().features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value()); baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); return vertexProperty; }
@Override public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) { assertEquals(v, element); assertEquals(label, element.label()); assertEquals(id, element.id()); assertEquals("to-change", oldValue.key()); assertEquals("blah", oldValue.value()); assertEquals("dah", setValue); triggered.set(true); } };
public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) { final Vertex baseVertex = attachableVertex.get(); final Vertex vertex = hostGraph.features().vertex().willAllowId(baseVertex.id()) ? hostGraph.addVertex(T.id, baseVertex.id(), T.label, baseVertex.label()) : hostGraph.addVertex(T.label, baseVertex.label()); baseVertex.properties().forEachRemaining(vp -> { final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(vp.id()) ? vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value(), T.id, vp.id()) : vertex.property(hostGraph.features().vertex().getCardinality(vp.key()), vp.key(), vp.value()); vp.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); }); return vertex; }