use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project sqlg by pietermartin.
the class SqlgDropStepBarrier method processNextStart.
@Override
protected Traverser.Admin<S> processNextStart() {
if (this.first) {
this.first = false;
EventStrategy eventStrategy = null;
if (!this.callbackRegistry.getCallbacks().isEmpty()) {
eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
}
while (this.starts.hasNext()) {
Traverser.Admin<S> start = this.starts.next();
Object object = start.get();
if (object instanceof SqlgElement) {
SqlgElement sqlgElement = (SqlgElement) object;
RecordId recordId = (RecordId) sqlgElement.id();
SchemaTable schemaTable = recordId.getSchemaTable();
Long id = recordId.getId();
if (sqlgElement instanceof SqlgVertex) {
Optional<VertexLabel> vertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable());
Preconditions.checkState(vertexLabelOptional.isPresent());
SqlgVertex sqlgVertex = (SqlgVertex) sqlgElement;
boolean added = this.verticesToDelete.put(vertexLabelOptional.get(), id);
if (added && eventStrategy != null) {
final Event removeEvent = new Event.VertexRemovedEvent(eventStrategy.detach(sqlgVertex));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
for (EdgeLabel outEdgeLabel : vertexLabelOptional.get().getOutEdgeLabels().values()) {
// Get all the edges, register to the callBack and delete.
if (eventStrategy != null) {
Iterator<Edge> edges = sqlgVertex.edges(Direction.OUT);
while (edges.hasNext()) {
Edge edge = edges.next();
SchemaTable schemaTableEdge = ((SqlgEdge) edge).getSchemaTablePrefixed().withOutPrefix();
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId) edge.id()).getId());
if (added) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else {
this.foreignKeyOutEdgesToDelete.put(Pair.of(outEdgeLabel, vertexLabelOptional.get()), id);
}
}
for (EdgeLabel inEdgeLabel : vertexLabelOptional.get().getInEdgeLabels().values()) {
// Get all the edges, register to the callBack and delete.
if (!this.callbackRegistry.getCallbacks().isEmpty()) {
Iterator<Edge> edges = sqlgVertex.edges(Direction.IN);
while (edges.hasNext()) {
Edge edge = edges.next();
SchemaTable schemaTableEdge = ((SqlgEdge) edge).getSchemaTablePrefixed().withOutPrefix();
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId) edge.id()).getId());
if (added) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else {
this.foreignKeyInEdgesToDelete.put(Pair.of(inEdgeLabel, vertexLabelOptional.get()), id);
}
}
} else if (sqlgElement instanceof SqlgEdge) {
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTable.getSchema(), schemaTable.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
boolean added = this.edgesToDelete.put(edgeLabelOptional.get(), id);
if (added && eventStrategy != null) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach((SqlgEdge) sqlgElement));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else if (object instanceof SqlgProperty) {
SqlgProperty sqlgProperty = (SqlgProperty) object;
if (eventStrategy != null) {
final Event removeEvent;
if (sqlgProperty.element() instanceof Edge) {
removeEvent = new Event.EdgePropertyRemovedEvent(eventStrategy.detach((Edge) sqlgProperty.element()), eventStrategy.detach(sqlgProperty));
} else if (sqlgProperty instanceof VertexProperty)
removeEvent = new Event.VertexPropertyRemovedEvent(eventStrategy.detach((VertexProperty) sqlgProperty));
else
throw new IllegalStateException("The incoming object is not removable: " + object);
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
sqlgProperty.remove();
} else {
throw new IllegalStateException("Expected SqlgElement or SqlgProperty. Found " + object.getClass().getSimpleName());
}
}
}
for (Pair<EdgeLabel, VertexLabel> edgeLabelVertexLabelPair : this.foreignKeyOutEdgesToDelete.keySet()) {
EdgeLabel outEdgeLabel = edgeLabelVertexLabelPair.getKey();
VertexLabel vertexLabel = edgeLabelVertexLabelPair.getValue();
Collection<Long> ids = this.foreignKeyOutEdgesToDelete.get(edgeLabelVertexLabelPair);
String sql = this.sqlgGraph.getSqlDialect().dropWithForeignKey(true, outEdgeLabel, vertexLabel, ids, !this.callbackRegistry.getCallbacks().isEmpty());
SqlgSqlExecutor.executeDropEdges(this.sqlgGraph, outEdgeLabel, sql, this.callbackRegistry.getCallbacks());
}
for (Pair<EdgeLabel, VertexLabel> edgeLabelVertexLabelPair : this.foreignKeyInEdgesToDelete.keySet()) {
EdgeLabel inEdgeLabel = edgeLabelVertexLabelPair.getKey();
VertexLabel vertexLabel = edgeLabelVertexLabelPair.getValue();
Collection<Long> ids = this.foreignKeyInEdgesToDelete.get(edgeLabelVertexLabelPair);
String sql = this.sqlgGraph.getSqlDialect().dropWithForeignKey(false, inEdgeLabel, vertexLabel, ids, !this.callbackRegistry.getCallbacks().isEmpty());
SqlgSqlExecutor.executeDropEdges(this.sqlgGraph, inEdgeLabel, sql, this.callbackRegistry.getCallbacks());
}
for (EdgeLabel edgeLabel : this.edgesToDelete.keySet()) {
Collection<Long> ids = this.edgesToDelete.get(edgeLabel);
String sql = this.sqlgGraph.getSqlDialect().drop(edgeLabel, ids);
SqlgSqlExecutor.executeDrop(this.sqlgGraph, sql);
}
for (VertexLabel vertexLabel : this.verticesToDelete.keySet()) {
Collection<Long> ids = this.verticesToDelete.get(vertexLabel);
String sql = this.sqlgGraph.getSqlDialect().drop(vertexLabel, ids);
SqlgSqlExecutor.executeDrop(this.sqlgGraph, sql);
}
// The standard TraversalFilterStep.filter calls TraversalUtil.test which normally resets the traversal for every incoming start.
reset();
throw FastNoSuchElementException.instance();
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class PropertyTypesTest method localPropertyReturnsLocalPropertyWithCorrectPropNameAndCorrectConverter.
@Test
public void localPropertyReturnsLocalPropertyWithCorrectPropNameAndCorrectConverter() throws IOException {
Converter converter = mock(Converter.class);
JsonNode value = jsn("value");
given(converter.jsonToTinkerpop(value)).willReturn("converted-value");
LocalProperty instance = localProperty("propName", converter);
Vertex vertex = mock(Vertex.class);
VertexProperty vertexProperty = mock(VertexProperty.class);
given(vertex.property("propName")).willReturn(vertexProperty);
instance.setJson(vertex, null);
instance.setJson(vertex, value);
verify(vertex, times(1)).property("propName", "converted-value");
verify(vertexProperty, times(1)).remove();
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class PropertyTypesTest method localPropertyReturnsLocalPropertyWithCorrectPropNameAndStringConverter.
@Test
public void localPropertyReturnsLocalPropertyWithCorrectPropNameAndStringConverter() throws IOException {
LocalProperty instance = localProperty("propName");
Vertex vertex = mock(Vertex.class);
VertexProperty vertexProperty = mock(VertexProperty.class);
given(vertex.property("propName")).willReturn(vertexProperty);
instance.setJson(vertex, null);
instance.setJson(vertex, jsn("value"));
verify(vertex, times(1)).property("propName", "value");
verify(vertexProperty, times(1)).remove();
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class D3GraphTest method mockVertex.
private Vertex mockVertex(String timId, String type, String labelPropertyKey, String label) {
Vertex mockDocumentVertex = mock(Vertex.class);
VertexProperty timIdProperty = mock(VertexProperty.class);
VertexProperty typesProperty = mock(VertexProperty.class);
given(timIdProperty.value()).willReturn(timId);
given(typesProperty.value()).willReturn("[\"" + type + "\"]");
given(mockDocumentVertex.property("tim_id")).willReturn(timIdProperty);
given(mockDocumentVertex.property("types")).willReturn(typesProperty);
given(mockDocumentVertex.value(labelPropertyKey)).willReturn(label);
given(mockDocumentVertex.keys()).willReturn(Sets.newHashSet(labelPropertyKey));
return mockDocumentVertex;
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class VertexDuplicator method duplicateVertex.
public static Vertex duplicateVertex(GraphTraversalSource traversal, Vertex vertex, IndexHandler indexHandler) {
Vertex duplicate = traversal.addV().next();
for (Iterator<VertexProperty<Object>> properties = vertex.properties(); properties.hasNext(); ) {
VertexProperty<Object> property = properties.next();
duplicate.property(property.key(), property.value());
}
for (String label : ((Neo4jVertex) vertex).labels()) {
((Neo4jVertex) duplicate).addLabel(label);
}
moveIncomingEdges(vertex, duplicate, indexHandler);
moveOutgoingEdges(vertex, duplicate, indexHandler);
vertex.property(IS_LATEST, false);
duplicate.property(IS_LATEST, true);
vertex.addEdge(VERSION_OF, duplicate);
return duplicate;
}
Aggregations