@Override public int hashCode() { return getEdge().hashCode(); }
@Override public void removeEdge(Edge edge, Authorizations authorizations) { if (!((InMemoryEdge) edge).canRead(authorizations)) { return; } this.edges.remove(edge.getId()); getSearchIndex().removeElement(this, edge, authorizations); if (hasEventListeners()) { fireGraphEvent(new RemoveEdgeEvent(this, edge)); } }
@Override public void removeEdge(Edge edge, Authorizations authorizations) { checkNotNull(edge); getSearchIndex().removeElement(this, edge, authorizations); ColumnVisibility visibility = visibilityToAccumuloVisibility(edge.getVisibility()); Mutation outMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.OUT)); outMutation.putDelete(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), visibility); Mutation inMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.IN)); inMutation.putDelete(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), visibility); addMutations(getVerticesWriter(), outMutation, inMutation); // Remove everything else related to edge. addMutations(getEdgesWriter(), getDeleteRowMutation(AccumuloConstants.EDGE_ROW_KEY_PREFIX + edge.getId())); if (hasEventListeners()) { queueEvent(new RemoveEdgeEvent(this, edge)); } }
@Test public void testRemoveEdge() { 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, "label1", VISIBILITY_A, AUTHORIZATIONS_A); assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.removeEdge("e1", AUTHORIZATIONS_B); } catch (IllegalArgumentException e) { // expected } assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.removeEdge("e1", AUTHORIZATIONS_A); assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); 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 RemoveEdgeEvent(graph, addedEdge) ); }
@Override public int hashCode() { return getEdge().hashCode(); }
@Test public void testRemoveEdge() { 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, "label1", VISIBILITY_A, AUTHORIZATIONS_A); assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.removeEdge("e1", AUTHORIZATIONS_B); } catch (IllegalArgumentException e) { // expected } assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.removeEdge("e1", AUTHORIZATIONS_A); assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); 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 RemoveEdgeEvent(graph, addedEdge) ); }