@Override public Relationship entity( long id, GraphDatabaseService graphDatabaseService ) { return graphDatabaseService.getRelationshipById( id ); }
@Override protected Relationship materialize( long id ) { this.score = cursor.score(); this.size = cursor.expectedTotalNumberOfResults(); return graphDatabaseService.getRelationshipById( id ); } }
public static RelationshipOutput forExistingEntityOrNull( GraphDatabaseService db, ScoreEntityIterator.ScoreEntry result ) { try { return new RelationshipOutput( db.getRelationshipById( result.entityId() ), result.score() ); } catch ( NotFoundException ignore ) { // This relationship was most likely deleted by a concurrent transaction, so we just ignore it. return null; } } }
private static void getRelationshipById( long index ) { Relationship value = graphdb.getRelationshipById( index ); fail( String.format( "Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index ) ); }
private static void getRelationshipByIdReadOnly( long index ) { Relationship value = graphDbReadOnly.getRelationshipById( index ); fail( String.format( "Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index ) ); } }
private static void assertRelationshipNotExist( GraphDatabaseService db, long id ) { try { db.getRelationshipById( id ); fail( "Exception expected" ); } catch ( Exception e ) { assertThat( e, instanceOf( NotFoundException.class ) ); } }
private Thread newThreadForRelationshipAction( final long relationshipId, final Consumer<Relationship> relConsumer ) { return new Thread( () -> { try ( Transaction tx = db.beginTx() ) { Relationship relationship = db.getRelationshipById( relationshipId ); barrier.await(); relConsumer.accept( relationship ); tx.success(); } catch ( Exception e ) { ex.set( e ); } } ); }
Relationship rel = graphDb.getRelationshipById( iterator.visitData.get( node.getId() ).cameFromRelationship ); while ( rel != null ) node = rel.getOtherNode( node ); long nextRelId = iterator.visitData.get( node.getId() ).cameFromRelationship; rel = nextRelId == -1 ? null : graphDb.getRelationshipById( nextRelId );
@Test public void shouldUpdatePropertyToRelationshipInTransaction() throws Exception { // Given long relationshipId; String propertyKey = "prop"; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId(); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "world" ) ), equalTo( stringValue( "hello" ) ) ); assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, intValue( 1337 ) ), equalTo( stringValue( "world" ) ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( 1337 ) ); } }
@Test public void shouldAddPropertyToRelationship() throws Exception { // Given long relationshipId; String propertyKey = "prop"; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); relationshipId = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId(); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) ); } }
@Test public void shouldUpdatePropertyToRelationship() throws Exception { // Given long relationshipId; String propertyKey = "prop"; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); r.setProperty( propertyKey, 42 ); relationshipId = r.getId(); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, token, stringValue( "hello" ) ), equalTo( intValue( 42 ) ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( "hello" ) ); } }
assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) );
@Test public void shouldRemoveNonExistingPropertyFromRelationship() throws Exception { // Given long relationshipId; String propertyKey = "prop"; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); relationshipId = proxy.getId(); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( NO_VALUE ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) ); } }
@Test public void shouldRemovePropertyFromRelationship() throws Exception { // Given long relationshipId; String propertyKey = "prop"; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship proxy = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); relationshipId = proxy.getId(); proxy.setProperty( propertyKey, 42 ); tx.success(); } // When try ( Transaction tx = beginTransaction() ) { int token = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().relationshipRemoveProperty( relationshipId, token ), equalTo( intValue( 42 ) ) ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertFalse( graphDb.getRelationshipById( relationshipId ).hasProperty( "prop" ) ); } }
Relationship rel = db.getRelationshipById( relId ); rel.setProperty( "since", 2010 ); tx.success();
graph.getRelationshipById( relId ); fail( "Get relationship by id on deleted node should " + "throw exception" );
db.getRelationshipById( relationship.getId() ); // should throw NotFoundException tx.success();
graphDb.getRelationshipById( relationshipId ).getProperty( propKey ), equalTo( "hello" ) );
getGraphDb().getRelationshipById( rel.getId() );
graphDb.getRelationshipById( relationshipId ).hasProperty( propKey ) );