BufferedGroup( RelationshipRecord edge, BufferedGroup next ) { this.label = edge.getType(); this.next = next; }
@Override public long valueFrom( RelationshipRecord record ) { return record.getType(); }
@Override public void checkConsistency( RelationshipRecord record, CheckerEngine<RelationshipRecord,ConsistencyReport.RelationshipConsistencyReport> engine, RecordAccess records ) { if ( record.getType() < 0 ) { engine.report().illegalRelationshipType(); } else { engine.comparativeCheck( records.relationshipType( record.getType() ), this ); } }
@Override protected void linkStart( RelationshipRecord record ) { long firstNextRel = cache.getAndPutRelationship( record.getFirstNode(), record.getType(), Direction.OUTGOING, record.getId(), true ); record.setFirstNextRel( firstNextRel ); }
private EntityUpdates.Builder gatherUpdatesFromCommandsForRelationship( long relationshipId, RelationshipCommand relationshipCommand, List<PropertyCommand> propertyCommands ) { long reltypeBefore; long reltypeAfter; if ( relationshipCommand != null ) { reltypeBefore = relationshipCommand.getBefore().getType(); reltypeAfter = relationshipCommand.getAfter().getType(); } else { RelationshipRecord relationshipRecord = loadRelationship( relationshipId ); reltypeBefore = reltypeAfter = relationshipRecord.getType(); } EntityUpdates.Builder relationshipPropertyUpdates = EntityUpdates.forEntity( relationshipId ).withTokens( reltypeBefore ).withTokensAfter( reltypeAfter ); if ( propertyCommands != null ) { converter.convertPropertyRecord( relationshipId, Iterables.cast( propertyCommands ), relationshipPropertyUpdates ); } return relationshipPropertyUpdates; }
@Override protected void linkEnd( RelationshipRecord record ) { long secondNextRel = cache.getAndPutRelationship( record.getSecondNode(), record.getType(), Direction.INCOMING, record.getId(), true ); record.setSecondNextRel( secondNextRel ); }
@Override public BatchRelationship getRelationshipById( long relId ) { RelationshipRecord record = getRelationshipRecord( relId ).forReadingData(); return batchRelationshipOf( relId, record.getType(), record.getFirstNode(), record.getSecondNode() ); }
@Override public void checkReference( RECORD record, RelationshipRecord relationshipRecord, CheckerEngine<RECORD,REPORT> engine, RecordAccess records ) { if ( relationshipRecord.inUse() ) { // Relationship indexes are always semantically multi-token, which means that the relationship record just need to have one of the possible // relationship types mentioned by the index. Relationships can't have more than one type anyway. long type = relationshipRecord.getType(); if ( Arrays.binarySearch( indexRelationshipTypes, type ) < 0 ) { // The relationship did not have any of the relationship types mentioned by the index. for ( long indexRelationshipType : indexRelationshipTypes ) { engine.report().relationshipDoesNotHaveExpectedRelationshipType( relationshipRecord, indexRelationshipType ); } } } else { engine.report().relationshipNotInUse( relationshipRecord ); } } }
@Override protected void linkLoop( RelationshipRecord record ) { long firstNextRel = cache.getAndPutRelationship( record.getFirstNode(), record.getType(), BOTH, record.getId(), true ); record.setFirstNextRel( firstNextRel ); record.setSecondNextRel( firstNextRel ); } }
Record( RelationshipRecord record, Record next ) { if ( record != null ) { id = record.getId(); type = record.getType(); nextProp = record.getNextProp(); firstNode = record.getFirstNode(); secondNode = record.getSecondNode(); } else { id = NO_ID; type = NO_ID; nextProp = NO_ID; firstNode = NO_ID; secondNode = NO_ID; } this.next = next; } }
public Function<RelationshipRecord,Check<RelationshipRecord,ConsistencyReport.RelationshipConsistencyReport>> forRelationships( final ConsistencyReporter reporter ) { return relationship -> { int[] propertyKeys = relationships.get( relationship.getType() ); if ( propertyKeys != null ) { final MutableIntSet keys = new IntHashSet( propertyKeys.length ); for ( int key : propertyKeys ) { keys.add( key ); } return new RealCheck<>( relationship, ConsistencyReport.RelationshipConsistencyReport.class, reporter, RecordType.RELATIONSHIP, keys ); } return noCheck(); }; }
@Override public <EXCEPTION extends Exception> void relationshipVisit( long relationshipId, RelationshipVisitor<EXCEPTION> relationshipVisitor ) throws EntityNotFoundException, EXCEPTION { // TODO Please don't create a record for this, it's ridiculous RelationshipRecord record = relationshipStore.getRecord( relationshipId, relationshipStore.newRecord(), CHECK ); if ( !record.inUse() ) { throw new EntityNotFoundException( EntityType.RELATIONSHIP, relationshipId ); } relationshipVisitor.visit( relationshipId, record.getType(), record.getFirstNode(), record.getSecondNode() ); }
@Override protected void linkStart( RelationshipRecord record ) { int typeId = record.getType(); long firstPrevRel = cache.getAndPutRelationship( record.getFirstNode(), typeId, Direction.OUTGOING, record.getId(), false ); if ( firstPrevRel == ID_NOT_FOUND ) { // First one record.setFirstInFirstChain( true ); firstPrevRel = cache.getCount( record.getFirstNode(), typeId, Direction.OUTGOING ); } record.setFirstPrevRel( firstPrevRel ); }
@Override protected void linkEnd( RelationshipRecord record ) { int typeId = record.getType(); long secondPrevRel = cache.getAndPutRelationship( record.getSecondNode(), typeId, Direction.INCOMING, record.getId(), false ); if ( secondPrevRel == ID_NOT_FOUND ) { // First one record.setFirstInSecondChain( true ); secondPrevRel = cache.getCount( record.getSecondNode(), typeId, Direction.INCOMING ); } record.setSecondPrevRel( secondPrevRel ); }
private void connectRelationshipToDenseNode( NodeRecord node, RelationshipRecord rel, RecordAccess<RelationshipRecord, Void> relRecords, RecordAccess<RelationshipGroupRecord, Integer> relGroupRecords, ResourceLocker locks ) { RelationshipGroupRecord group = relGroupGetter.getOrCreateRelationshipGroup( node, rel.getType(), relGroupRecords ).forChangingData(); DirectionWrapper dir = DirectionIdentifier.wrapDirection( rel, node ); long nextRel = dir.getNextRel( group ); setCorrectNextRel( node, rel, nextRel ); connect( node.getId(), nextRel, rel, relRecords, locks ); dir.setNextRel( group, rel.getId() ); }
@Override protected void linkLoop( RelationshipRecord record ) { int typeId = record.getType(); long prevRel = cache.getAndPutRelationship( record.getFirstNode(), typeId, Direction.BOTH, record.getId(), false ); if ( prevRel == ID_NOT_FOUND ) { // First one record.setFirstInFirstChain( true ); record.setFirstInSecondChain( true ); prevRel = cache.getCount( record.getFirstNode(), typeId, Direction.BOTH ); } record.setFirstPrevRel( prevRel ); record.setSecondPrevRel( prevRel ); } }
@Override public void checkReference( RelationshipGroupRecord record, RelationshipRecord referred, CheckerEngine<RelationshipGroupRecord, RelationshipGroupConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { relationshipNotInUse( engine.report() ); } else { if ( !isFirstInChain( referred ) ) { relationshipNotFirstInChain( engine.report() ); } if ( referred.getType() != record.getType() ) { relationshipOfOtherType( engine.report() ); } } }
@Override protected void assertRecordsEqual( RelationshipRecord actualRecord, RelationshipRecord expectedRecord ) { assertNotNull( "actualRecord", actualRecord ); assertNotNull( "expectedRecord", expectedRecord ); assertThat( "getFirstNextRel", actualRecord.getFirstNextRel(), is( expectedRecord.getFirstNextRel() ) ); assertThat( "getFirstNode", actualRecord.getFirstNode(), is( expectedRecord.getFirstNode() ) ); assertThat( "getFirstPrevRel", actualRecord.getFirstPrevRel(), is( expectedRecord.getFirstPrevRel() ) ); assertThat( "getSecondNextRel", actualRecord.getSecondNextRel(), is( expectedRecord.getSecondNextRel() ) ); assertThat( "getSecondNode", actualRecord.getSecondNode(), is( expectedRecord.getSecondNode() ) ); assertThat( "getSecondPrevRel", actualRecord.getSecondPrevRel(), is( expectedRecord.getSecondPrevRel() ) ); assertThat( "getType", actualRecord.getType(), is( expectedRecord.getType() ) ); assertThat( "isFirstInFirstChain", actualRecord.isFirstInFirstChain(), is( expectedRecord.isFirstInFirstChain() ) ); assertThat( "isFirstInSecondChain", actualRecord.isFirstInSecondChain(), is( expectedRecord.isFirstInSecondChain() ) ); assertThat( "getId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getLongId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getNextProp", actualRecord.getNextProp(), is( expectedRecord.getNextProp() ) ); assertThat( "inUse", actualRecord.inUse(), is( expectedRecord.inUse() ) ); }
private String diff( RelationshipRecord expected, RelationshipRecord actual ) { if ( actual.getId() == expected.getId() && actual.getFirstNode() == expected.getFirstNode() && actual.getSecondNode() == expected.getSecondNode() && actual.getType() == expected.getType() && actual.getFirstPrevRel() == expected.getFirstPrevRel() && actual.getFirstNextRel() == expected.getFirstNextRel() && actual.getSecondPrevRel() == expected.getSecondPrevRel() && actual.getSecondNextRel() == expected.getSecondNextRel() && actual.isFirstInFirstChain() == expected.isFirstInFirstChain() && actual.isFirstInSecondChain() == expected.isFirstInSecondChain() ) { return null; } return describeDiff( expected.toString(), actual.toString() ); }
@Override public RecordKey<RelationshipRecord> relationship() { return ( written, read ) -> { assertEquals( written.getNextProp(), read.getNextProp() ); assertEquals( written.getFirstNode(), read.getFirstNode() ); assertEquals( written.getSecondNode(), read.getSecondNode() ); assertEquals( written.getType(), read.getType() ); assertEquals( written.getFirstPrevRel(), read.getFirstPrevRel() ); assertEquals( written.getFirstNextRel(), read.getFirstNextRel() ); assertEquals( written.getSecondPrevRel(), read.getSecondPrevRel() ); assertEquals( written.getSecondNextRel(), read.getSecondNextRel() ); assertEquals( written.isFirstInFirstChain(), read.isFirstInFirstChain() ); assertEquals( written.isFirstInSecondChain(), read.isFirstInSecondChain() ); }; }