@Test public void shouldAccessRelationshipLabels() { // given Map<Integer,Integer> counts = new HashMap<>(); try ( RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor() ) { // when read.allRelationshipsScan( relationships ); while ( relationships.next() ) { counts.compute( relationships.type(), ( k, v ) -> v == null ? 1 : v + 1 ); } } // then assertEquals( 3, counts.size() ); int[] values = new int[3]; int i = 0; for ( int value : counts.values() ) { values[i++] = value; } Arrays.sort( values ); assertArrayEquals( new int[]{1, 6, 6}, values ); }
@Test public void shouldScanRelationships() { // given List<Long> ids = new ArrayList<>(); try ( RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor() ) { // when read.allRelationshipsScan( relationships ); while ( relationships.next() ) { ids.add( relationships.relationshipReference() ); } } assertEquals( RELATIONSHIP_IDS, ids ); }
ktx.dataRead().allRelationshipsScan( cursor ); return new PrefetchingResourceIterator<Relationship>()
static int countRelationships( Transaction transaction ) { int result = 0; try ( RelationshipScanCursor cursor = transaction.cursors().allocateRelationshipScanCursor() ) { transaction.dataRead().allRelationshipsScan( cursor ); while ( cursor.next() ) { result++; } } return result; }
PropertyCursor propertyCursor = cursors.allocatePropertyCursor() ) dataRead.allRelationshipsScan( relationshipScanCursor ); while ( relationshipScanCursor.next() )
@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 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(); } }
ktx.dataRead().allRelationshipsScan( cursor ); return new PrefetchingResourceIterator<Relationship>()
PropertyCursor propertyCursor = cursors.allocatePropertyCursor() ) dataRead.allRelationshipsScan( relationshipScanCursor ); while ( relationshipScanCursor.next() )