@Override public Relationship getRelationshipById( long id ) { return database.getRelationshipById( id ); }
private Relationship relationship( long id ) throws RelationshipNotFoundException { try { return graphDb.getRelationshipById( id ); } catch ( NotFoundException e ) { throw new RelationshipNotFoundException( e ); } }
protected Relationship getRelationship( GraphDatabaseAPI graphDb, URI uri ) throws BadInputException, RelationshipNotFoundException { try { return graphDb.getRelationshipById( extractId( uri ) ); } catch ( NotFoundException e ) { throw new RelationshipNotFoundException( e ); } }
public void removeFromRelationshipIndexNoKeyValue( String indexName, long id ) { graphDb.index().forRelationships( indexName ).remove( graphDb.getRelationshipById( id ) ); }
private Relationship relationship( long id ) throws RelationshipNotFoundException { try ( Transaction tx = graphDb.beginTx() ) { Relationship relationship = graphDb.getRelationshipById( id ); tx.success(); return relationship; } catch ( NotFoundException e ) { throw new RelationshipNotFoundException( e ); } }
public void removeFromRelationshipIndexNoValue( String indexName, String key, long id ) { graphDb.index().forRelationships( indexName ).remove( graphDb.getRelationshipById( id ), key ); }
public void removeFromRelationshipIndex( String indexName, String key, String value, long id ) { graphDb.index().forRelationships( indexName ).remove( graphDb.getRelationshipById( id ), key, value ); }
public IndexedEntityRepresentation getIndexedRelationship( String indexName, String key, String value, long id ) { if ( !relationshipIsIndexed( indexName, key, value, id ) ) { throw new NotFoundException(); } Relationship node = graphDb.getRelationshipById( id ); return new IndexedEntityRepresentation( node, key, value, new RelationshipIndexRepresentation( indexName, Collections.emptyMap() ) ); }
public IndexedEntityRepresentation addToRelationshipIndex( String indexName, String key, String value, long relationshipId ) { Relationship relationship = graphDb.getRelationshipById( relationshipId ); Index<Relationship> index = graphDb.index().forRelationships( indexName ); index.add( relationship, key, value ); return new IndexedEntityRepresentation( relationship, key, value, new RelationshipIndexRepresentation( indexName, Collections.emptyMap() ) ); }
public boolean relationshipIsIndexed( String indexName, String key, Object value, long relationshipId ) { Index<Relationship> index = graphDb.index().forRelationships( indexName ); Relationship expectedNode = graphDb.getRelationshipById( relationshipId ); try ( IndexHits<Relationship> hits = index.get( key, value ) ) { return iterableContains( hits, expectedNode ); } }
@Override protected WeightedRelationshipResult fetchNextOrNull() { if ( cursor.next() ) { return new WeightedRelationshipResult( graphDatabaseAPI.getRelationshipById( cursor.relationshipReference() ), cursor.score() ); } else { close(); return null; } } };
@Deprecated @Description( "Get relationship from explicit automatic index. Replaces `START r=relationship:relationship_auto_index(key " + "= 'A')`" ) @Procedure( name = "db.index.explicit.auto.seekRelationships", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<RelationshipResult> relationshipAutoIndexSeek( @Name( "key" ) String key, @Name( "value" ) Object value ) { try ( Statement ignore = tx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = tx.cursors().allocateRelationshipExplicitIndexCursor(); tx.indexRead() .relationshipExplicitIndexLookup( cursor, "relationship_auto_index", key, value, -1, -1 ); return toStream( cursor, id -> new RelationshipResult( graphDatabaseAPI.getRelationshipById( id ) ) ); } catch ( KernelException e ) { // auto index will not exist if no relationships have been added that match the auto-index rules return Stream.empty(); } }
private Runnable getById() { return () -> { dbr.getGraphDatabaseAPI().getNodeById( node.getId() ); dbr.getGraphDatabaseAPI().getRelationshipById( relationship.getId() ); }; }
@Deprecated @Description( "Get relationship from explicit index. Replaces `START r=relationship:relIndex(key = 'A')`" ) @Procedure( name = "db.index.explicit.seekRelationships", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<RelationshipResult> relationshipManualIndexSeek( @Name( "indexName" ) String manualIndexName, @Name( "key" ) String key, @Name( "value" ) Object value ) throws ProcedureException { try ( Statement ignore = tx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = tx.cursors().allocateRelationshipExplicitIndexCursor(); tx.indexRead().relationshipExplicitIndexLookup( cursor, manualIndexName, key, value, -1, -1 ); return toStream( cursor, id -> new RelationshipResult( graphDatabaseAPI.getRelationshipById( id ) ) ); } catch ( KernelException e ) { throw new ProcedureException( Status.LegacyIndex.LegacyIndexNotFound, "Relationship index %s not found", manualIndexName ); } }
db.getRelationshipById( relIdA ).delete(); db.getRelationshipById( relIdB ).delete(); try ( Result result = db.execute( format( QUERY_RELS, "rels", "value" ) ) )
@Test public void queryResultsMustIncludeRelationshipsWithPropertiesAddedToBeIndexed() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } long relId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); Node node = db.createNode(); Relationship rel = node.createRelationshipTo( node, REL ); relId = rel.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { Relationship rel = db.getRelationshipById( relId ); rel.setProperty( PROP, "value" ); assertQueryFindsIds( db, false, "rels", "prop:value", relId ); tx.success(); } }
@Test public void queryResultsMustNotIncludeRelationshipsWithRemovedIndexedProperties() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } long relId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); Node node = db.createNode(); Relationship rel = node.createRelationshipTo( node, REL ); rel.setProperty( PROP, "value" ); relId = rel.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).removeProperty( PROP ); assertQueryFindsIds( db, false, "rels", "value" ); tx.success(); } }
@Test public void queryResultsMustIncludeUpdatedValuesOfChangedRelationshipProperties() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } long relId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); Node node = db.createNode(); Relationship rel = node.createRelationshipTo( node, REL ); rel.setProperty( PROP, "primo" ); relId = rel.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).setProperty( PROP, "secundo" ); assertQueryFindsIds( db, false, "rels", "primo" ); assertQueryFindsIds( db, false, "rels", "secundo", relId ); tx.success(); } }
@Test public void queryResultsMustIncludeOldRelationshipPropertyValuesWhenRemovalsAreUndone() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } long relId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); Node node = db.createNode(); Relationship rel = node.createRelationshipTo( node, REL ); rel.setProperty( PROP, "primo" ); relId = rel.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { Relationship rel = db.getRelationshipById( relId ); assertQueryFindsIds( db, false, "rels", "primo", relId ); rel.removeProperty( PROP ); assertQueryFindsIds( db, false, "rels", "primo" ); rel.setProperty( PROP, "primo" ); assertQueryFindsIds( db, false, "rels", "primo", relId ); tx.success(); } }
@Test public void shouldTellIfRelExists() { // Given long node = createLabeledNode( db, map() ).getId(); long created; long createdAndRemoved; long neverExisted; try ( Transaction tx = db.beginTx() ) { created = db.createNode().createRelationshipTo( db.createNode(), withName( "Banana" ) ).getId(); createdAndRemoved = db.createNode().createRelationshipTo( db.createNode(), withName( "Banana" ) ).getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( createdAndRemoved ).delete(); tx.success(); } neverExisted = created + 99; // When & then assertTrue( relationshipExists( node )); assertFalse( relationshipExists( createdAndRemoved ) ); assertFalse( relationshipExists( neverExisted ) ); }