private void removeVertex(String property, Object value) { final GraphTraversal<Vertex, Vertex> traversal = graph.traversal().V().has(property, value); if (traversal.hasNext()) { traversal.next().remove(); graph.tx().commit(); } }
newTx(); vs[2] = getV(tx, vs[2]); vs[2].remove(); vs[3] = getV(tx, vs[3]); vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
String n = u.<String>value("name"); if (n.endsWith("Don")) { u.remove(); } else if (n.endsWith("Lewis")) { u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
newTx(); vs[2] = getV(tx, vs[2]); vs[2].remove(); vs[3] = getV(tx, vs[3]); vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
final String n = u.value("name"); if (n.endsWith("Don")) { u.remove(); } else if (n.endsWith("Lewis")) { u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
graph.vertices().forEachRemaining(v -> v.remove()); v1 = graph.addVertex(); v1.property(property, value1);
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_VERTICES, supported = false) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldSupportRemoveVerticesIfAVertexCanBeRemoved() throws Exception { try { graph.addVertex().remove(); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_REMOVE_VERTICES)); } catch (Exception e) { validateException(Vertex.Exceptions.vertexRemovalNotSupported(), e); } }
/** * Generate a graph with lots of vertices, then iterate the vertices and remove them from the graph */ @Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_VERTICES) public void shouldRemoveVerticesWithoutConcurrentModificationException() { for (int i = 0; i < 100; i++) { graph.addVertex(); } final Iterator<Vertex> vertexIterator = graph.vertices(); assertTrue(vertexIterator.hasNext()); while (vertexIterator.hasNext()) { vertexIterator.next().remove(); } assertFalse(vertexIterator.hasNext()); tryCommit(graph, graph -> assertFalse(graph.vertices().hasNext())); }
@Test public void testRemoveVertexOneByOne() { HugeGraph graph = graph(); init10Vertices(); List<Vertex> vertexes = graph.traversal().V().toList(); Assert.assertEquals(10, vertexes.size()); for (int i = 0; i < vertexes.size(); i++) { vertexes.get(i).remove(); graph.tx().commit(); Assert.assertEquals(9 - i, graph.traversal().V().toList().size()); } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_EDGES, supported = false) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldSupportRemoveEdgesIfEdgeCanBeRemoved() throws Exception { try { final Vertex v = graph.addVertex(); v.addEdge("friend", v); v.remove(); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_REMOVE_EDGES)); } catch (Exception ex) { validateException(Edge.Exceptions.edgeRemovalNotSupported(), ex); } }
@Test public void testInsertAndDeleteVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.remove(); graph.tx().commit(); Assert.assertNull(vertex("author", "id", 1)); }
@Test public void testAppendAndDeleteVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Wuhan"); vertex.remove(); graph.tx().commit(); Assert.assertNull(vertex("author", "id", 1)); }
@Test public void testDeleteAndAppendVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.property("lived", "Shanghai"); graph.tx().commit(); Assert.assertNull(vertex("author", "id", 1)); }
public void testRemoveVertexAfterAddVertexWithTx() { HugeGraph graph = graph(); GraphTransaction tx = graph.openTransaction(); Vertex java1 = tx.addVertex(T.label, "book", "name", "java-1"); tx.addVertex(T.label, "book", "name", "java-2"); tx.commit(); java1.remove(); tx.commit(); tx.close(); List<Vertex> vertexes = graph.traversal().V().toList(); Assert.assertEquals(1, vertexes.size()); assertNotContains(vertexes, T.label, "book", "name", "java-2"); }
@Test public void testDeleteAndEliminateVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.property("lived").remove(); graph.tx().commit(); Assert.assertNull(vertex("author", "id", 1)); }
@Test public void testEliminateAndDeleteVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.remove(); graph.tx().commit(); Assert.assertNull(vertex("author", "id", 1)); }
@Test public void testRemoveVertex() { HugeGraph graph = graph(); init10Vertices(); List<Vertex> vertexes = graph.traversal().V().toList(); Assert.assertEquals(10, vertexes.size()); assertContains(vertexes, T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); Vertex vertex = vertex("author", "id", 1); vertex.remove(); graph.tx().commit(); vertexes = graph.traversal().V().toList(); Assert.assertEquals(9, vertexes.size()); assertNotContains(vertexes, T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); }
@Test public void testUpdateVertexPropertyOfRemovingVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.tx().commit(); vertex.remove(); Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived").remove(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived", "Shanghai"); }); }
@Test public void testDeleteAndInsertVertex() { HugeGraph graph = graph(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.traversal().V().hasLabel("author").has("id", 1).next().remove(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); graph.tx().commit(); Vertex vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }