@Override public RelationshipScanCursor allocateRelationshipScanCursor() { RelationshipScanCursor n = cursors.allocateRelationshipScanCursor(); allCursors.add( n ); return n; }
static int countRelationships( Transaction transaction ) { int result = 0; try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor() ) { transaction.dataRead().allRelationshipsScan( cursor ); while ( cursor.next() ) { result++; } } return result; }
RelationshipScanCursor cursor = ktx.cursors().allocateRelationshipScanCursor(); ktx.dataRead().allRelationshipsScan( cursor ); return new PrefetchingResourceIterator<Relationship>()
private void scanEverythingBelongingToRelationships( RelationshipMappings relMappings ) try ( RelationshipScanCursor relationshipScanCursor = cursors.allocateRelationshipScanCursor(); PropertyCursor propertyCursor = cursors.allocatePropertyCursor() )
private void updateReader( KernelTransactionImplementation kti ) throws Exception { modifiedEntityIdsInThisTransaction.clear(); // Clear this so we don't filter out entities who have had their changes reversed since last time. writer.resetWriterState(); AllStoreHolder read = (AllStoreHolder) kti.dataRead(); TransactionState transactionState = kti.txState(); try ( NodeCursor nodeCursor = visitingNodes ? kti.cursors().allocateNodeCursor() : null; RelationshipScanCursor relationshipCursor = visitingNodes ? null : kti.cursors().allocateRelationshipScanCursor(); PropertyCursor propertyCursor = kti.cursors().allocatePropertyCursor() ) { transactionState.accept( txStateVisitor.init( read, nodeCursor, relationshipCursor, propertyCursor ) ); } FulltextIndexReader baseReader = (FulltextIndexReader) read.indexReader( descriptor, false ); FulltextIndexReader nearRealTimeReader = writer.getNearRealTimeReader(); currentReader = new TransactionStateFulltextIndexReader( baseReader, nearRealTimeReader, modifiedEntityIdsInThisTransaction ); lastUpdateRevision = kti.getTransactionDataRevision(); }
Value relationshipGetProperty( Transaction transaction, long relationship, int property ) { try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor(); PropertyCursor properties = transaction.cursors().allocatePropertyCursor() ) { transaction.dataRead().singleRelationship( relationship, cursor ); if ( !cursor.next() ) { return NO_VALUE; } else { cursor.properties( properties ); while ( properties.next() ) { if ( properties.propertyKey() == property ) { return properties.propertyValue(); } } return NO_VALUE; } } }
private void iterateForRelationships(KernelTransaction ktx, Read read, CursorFactory cursors, BatchJobResult result) { try (RelationshipScanCursor cursor = cursors.allocateRelationshipScanCursor()) { for (long id = batchStart; id < batchStart + batchSize; id++) { read.singleRelationship(id, cursor); processAndReport(ktx, cursor::next, consumer, cursor, result); } } }
@Test public void propertyTypeShouldBeTxStateAware() throws Exception { // Given long relationship; try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() ); tx.success(); } // Then try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor properties = tx.cursors().allocatePropertyCursor() ) { tx.dataRead().singleRelationship( relationship, relationships ); assertTrue( relationships.next() ); assertFalse( hasProperties( relationships, tx ) ); int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); tx.dataWrite().relationshipSetProperty( relationship, prop, stringValue( "foo" ) ); relationships.properties( properties ); assertTrue( properties.next() ); assertThat( properties.propertyType(), equalTo( ValueGroup.TEXT ) ); } } }
@Test public void shouldScanRelationshipInTransaction() throws Exception { final int nRelationshipsInStore = 10; int type; long n1, n2; try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); // setup some in store relationships type = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); relateNTimes( nRelationshipsInStore, type, n1, n2, tx ); tx.success(); } try ( Transaction tx = beginTransaction() ) { long r = tx.dataWrite().relationshipCreate( n1, type, n2 ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) { tx.dataRead().allRelationshipsScan( relationship ); assertCountRelationships( relationship, nRelationshipsInStore + 1, n1, type, n2 ); } tx.success(); } }
@Test public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationship() throws Exception { try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); long relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() ); try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() ) { tx.dataRead().singleRelationship( relationship, cursor ); assertTrue( cursor.next() ); assertFalse( hasProperties( cursor, tx ) ); tx.dataWrite().relationshipSetProperty( relationship, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), stringValue( "foo" ) ); assertTrue( hasProperties( cursor, tx ) ); } } }
NO_VALUE ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor property = tx.cursors().allocatePropertyCursor() )
@Test public void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Exception { final int nRelationshipsInStore = 5 + 1 + 5; int type; long n1, n2, r; try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); type = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); relateNTimes( 5, type, n1, n2, tx ); r = tx.dataWrite().relationshipCreate( n1, type, n2 ); relateNTimes( 5, type, n1, n2, tx ); tx.success(); } try ( Transaction tx = beginTransaction() ) { assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) { tx.dataRead().allRelationshipsScan( relationship ); assertCountRelationships( relationship, nRelationshipsInStore - 1, n1, type, n2 ); } tx.success(); } }
NO_VALUE ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor property = tx.cursors().allocatePropertyCursor() )
@Test public void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws Exception { int label; long n1, n2, r; try ( Transaction tx = beginTransaction() ) { n1 = tx.dataWrite().nodeCreate(); n2 = tx.dataWrite().nodeCreate(); label = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); long decoyNode = tx.dataWrite().nodeCreate(); tx.dataWrite().relationshipCreate( n2, label, decoyNode ); // to have >1 relationship in the db r = tx.dataWrite().relationshipCreate( n1, label, n2 ); tx.success(); } try ( Transaction tx = beginTransaction() ) { assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() ) { tx.dataRead().singleRelationship( r, relationship ); assertFalse( "should not find relationship", relationship.next() ); } tx.success(); } }
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor property = tx.cursors().allocatePropertyCursor() )
@Test public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception { // Given long relationship; try ( Transaction tx = beginTransaction() ) { Write write = tx.dataWrite(); int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" ); relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() ); tx.success(); } // Then try ( Transaction tx = beginTransaction() ) { try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() ) { tx.dataRead().singleRelationship( relationship, cursor ); assertTrue( cursor.next() ); assertFalse( hasProperties( cursor, tx ) ); tx.dataWrite().relationshipSetProperty( relationship, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), stringValue( "foo" ) ); assertTrue( hasProperties( cursor, tx ) ); } } }
assertEquals( tx.dataWrite().relationshipSetProperty( relationshipId, propToken, stringValue( "world" ) ), NO_VALUE ); try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor property = tx.cursors().allocatePropertyCursor() )
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() )
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(); PropertyCursor property = tx.cursors().allocatePropertyCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )