private void removeDuplicateEdgesAsync(GraphManager gm, Edge edge){ //now read all older versions of an edge, and remove them. Finally calling delete final SearchByEdge searchByEdge = new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); //load our versions, only retain the most recent one gm.loadEdgeVersions(searchByEdge).skip(1).flatMap(edgeToDelete -> { if (logger.isDebugEnabled()) { logger.debug("Duplicate edge. Marking edge {} for deletion", edgeToDelete); } return gm.markEdge(edgeToDelete ); }).lastOrDefault(null).doOnNext(lastEdge -> { //no op if we hit our default if (lastEdge == null) { return; } //don't queue delete b/c that de-indexes, we need to delete the edges only since we have a version still existing to index. gm.deleteEdge(lastEdge).toBlocking().lastOrDefault(null); // this should throw an exception }).toBlocking().lastOrDefault(null);//this should throw an exception }
@Test( expected = NullPointerException.class ) public void invalidEdgeTypesDelete() { final GraphManager em = emf.createEdgeManager( scope ); em.markEdge( null ); }
return gm.markEdge( edgeToDelete ); } )
graphManager.markEdge(edge).toBlocking().lastOrDefault(null); edgesDeleted++;
@Override public void removeItemFromCollection( String collectionName, EntityRef itemRef ) throws Exception { Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); // remove edge from collection to item GraphManager gm = managerCache.getGraphManager( applicationScope ); // mark the edge versions and take the first for later delete edge queue event ( load is descending ) final Edge markedSourceEdge = gm.loadEdgeVersions( CpNamingUtils.createEdgeFromCollectionName( cpHeadEntity.getId(), collectionName, entityId ) ) .flatMap(edge -> gm.markEdge(edge)).toBlocking().firstOrDefault(null); Edge markedReversedEdge = null; CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collectionName ); if (collection != null && collection.getLinkedCollection() != null) { // delete reverse edges final String pluralType = InflectionUtils.pluralize( cpHeadEntity.getId().getType() ); markedReversedEdge = gm.loadEdgeVersions( CpNamingUtils.createEdgeFromCollectionName( entityId, pluralType, cpHeadEntity.getId() ) ) .flatMap(reverseEdge -> gm.markEdge(reverseEdge)).toBlocking().firstOrDefault(null); } /** * Remove from the index. This will call gm.deleteEdge which also deletes the reverse edge(s) and de-indexes * older versions of the edge(s). * */ if( markedSourceEdge != null ) { indexService.queueDeleteEdge(applicationScope, markedSourceEdge); } if( markedReversedEdge != null ){ indexService.queueDeleteEdge(applicationScope, markedReversedEdge); } }
.flatMap( edge -> manager.markEdge( edge )) .flatMap( edge -> manager.deleteEdge( edge ) ).countLong().toBlocking().last();
@Override public void deleteConnection( ConnectionRef connectionRef ) throws Exception { // First, clean up the dictionary records of the connection EntityRef connectingEntityRef = connectionRef.getSourceRefs(); // source EntityRef connectedEntityRef = connectionRef.getTargetRefs(); // target String connectionType = connectionRef.getTargetRefs().getConnectionType(); if ( logger.isTraceEnabled() ) { logger.trace( "Deleting connection '{}' from source {}:{} \n to target {}:{}", connectionType, connectingEntityRef.getType(), connectingEntityRef.getUuid(), connectedEntityRef.getType(), connectedEntityRef.getUuid() ); } Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ); org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId ); GraphManager gm = managerCache.getGraphManager( applicationScope ); final Id sourceId = new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ); final SearchByEdge search = createConnectionSearchByEdge( sourceId, connectionType, targetEntity.getId() ); //delete all the edges and queue their processing gm.loadEdgeVersions( search ).flatMap( returnedEdge -> gm.markEdge( returnedEdge ) ) .doOnNext( returnedEdge -> { if ( !skipIndexingForType( returnedEdge.getSourceNode().getType() ) || !skipIndexingForType( returnedEdge.getTargetNode().getType() ) ) { indexService.queueDeleteEdge(applicationScope, returnedEdge); } }).toBlocking() .lastOrDefault( null ); }
.flatMap( edge -> manager.markEdge( edge )) .flatMap( edge -> manager.deleteEdge( edge ) ).countLong().toBlocking().last();
gm.markEdge( edge1 ).toBlocking().last();
gm.markEdge( edge1 ).toBlocking().last();
@Test public void testWriteReadEdgeDeleteTarget() { GraphManager gm = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); gm.writeEdge( edge ).toBlocking().last(); //now test retrieving it SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null ); Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search ); //implicitly blows up if more than 1 is returned from "single" Edge returned = edges.toBlocking().single(); assertEquals( "Correct edge returned", edge, returned ); SearchByIdType searchById = createSearchByEdgeAndId( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), edge.getSourceNode().getType(), null ); edges = gm.loadEdgesToTargetByType( searchById ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().single(); assertEquals( "Correct edge returned", edge, returned ); //now delete it gm.markEdge( edge ).toBlocking().last(); //now test retrieval, should be null edges = gm.loadEdgesToTarget( search ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "No edge returned", returned ); //no search by type, should be null as well edges = gm.loadEdgesToTargetByType( searchById ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "No edge returned", returned ); }
final Edge toBeMarkedEdge = graphManager.markEdge( connectionSearch ).toBlocking().firstOrDefault( null ); final Edge toBeDeletedEdge = graphManager.deleteEdge( toBeMarkedEdge ).toBlocking().firstOrDefault( null );
returned = gm.markEdge( edge ).toBlocking().last();
final Edge toBeMarkedEdge = graphManager.markEdge( connectionSearch ).toBlocking().firstOrDefault( null ); final Edge toBeDeletedEdge = graphManager.deleteEdge( toBeMarkedEdge ).toBlocking().first();