@Override public void deleteEdge(Edge edge, Authorizations authorizations) { checkNotNull(edge, "Edge cannot be null"); if (!((InMemoryEdge) edge).canRead(authorizations)) { return; } deleteAllExtendedDataForElement(edge, authorizations); this.edges.remove(edge.getId()); getSearchIndex().deleteElement(this, edge, authorizations); if (hasEventListeners()) { fireGraphEvent(new DeleteEdgeEvent(this, edge)); } }
@Override public void deleteEdge(Edge edge, Authorizations authorizations) { checkNotNull(edge); Span trace = Trace.start("deleteEdge"); trace.data("edgeId", edge.getId()); try { getSearchIndex().deleteElement(this, edge, authorizations); ColumnVisibility visibility = visibilityToAccumuloVisibility(edge.getVisibility()); Mutation outMutation = new Mutation(edge.getVertexId(Direction.OUT)); outMutation.putDelete(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), visibility); Mutation inMutation = new Mutation(edge.getVertexId(Direction.IN)); inMutation.putDelete(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), visibility); addMutations(VertexiumObjectType.VERTEX, outMutation, inMutation); deleteAllExtendedDataForElement(edge, authorizations); // Deletes everything else related to edge. addMutations(VertexiumObjectType.EDGE, getDeleteRowMutation(edge.getId())); if (hasEventListeners()) { queueEvent(new DeleteEdgeEvent(this, edge)); } } finally { trace.stop(); } }
@Override public void deleteEdge(Edge edge, Authorizations authorizations) { checkNotNull(edge); Span trace = Trace.start("deleteEdge"); trace.data("edgeId", edge.getId()); try { getSearchIndex().deleteElement(this, edge, authorizations); ColumnVisibility visibility = visibilityToAccumuloVisibility(edge.getVisibility()); Mutation outMutation = new Mutation(edge.getVertexId(Direction.OUT)); outMutation.putDelete(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), visibility); Mutation inMutation = new Mutation(edge.getVertexId(Direction.IN)); inMutation.putDelete(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), visibility); addMutations(VertexiumObjectType.VERTEX, outMutation, inMutation); deleteAllExtendedDataForElement(edge, authorizations); // Deletes everything else related to edge. addMutations(VertexiumObjectType.EDGE, getDeleteRowMutation(edge.getId())); if (hasEventListeners()) { queueEvent(new DeleteEdgeEvent(this, edge)); } } finally { trace.stop(); } }
@Test public void testDeleteEdge() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); Assert.assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.deleteEdge("e1", AUTHORIZATIONS_B); } catch (NullPointerException e) { // expected } Assert.assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.deleteEdge("e1", AUTHORIZATIONS_A); graph.flush(); Assert.assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); Assert.assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); Assert.assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new DeleteEdgeEvent(graph, addedEdge) ); }
@Override public int hashCode() { return getEdge().hashCode(); }
@Test public void testDeleteEdge() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); Assert.assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.deleteEdge("e1", AUTHORIZATIONS_B); } catch (NullPointerException e) { // expected } Assert.assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.deleteEdge("e1", AUTHORIZATIONS_A); graph.flush(); Assert.assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); Assert.assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); Assert.assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new DeleteEdgeEvent(graph, addedEdge) ); }
@Override public int hashCode() { return getEdge().hashCode(); }