@Override public long getNextRecordReference( PropertyRecord record ) { return record.getNextProp(); }
@Override public long otherReference( PropertyRecord record ) { return record.getNextProp(); }
@Override public long valueFrom( PropertyRecord record ) { return record.getNextProp(); }
public Collection<PropertyRecord> getPropertyRecordChain( long firstRecordId ) { long nextProp = firstRecordId; List<PropertyRecord> toReturn = new LinkedList<>(); while ( nextProp != Record.NO_NEXT_PROPERTY.intValue() ) { PropertyRecord propRecord = new PropertyRecord( nextProp ); getRecord( nextProp, propRecord, RecordLoad.NORMAL ); toReturn.add( propRecord ); nextProp = propRecord.getNextProp(); } return toReturn; }
@Override public void checkReference( PropertyRecord record, PropertyRecord property, CheckerEngine<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> engine, RecordAccess records ) { if ( record.getId() != property.getId() ) { if ( !property.inUse() || Record.NO_NEXT_PROPERTY.is( property.getNextProp() ) ) { wrongOwner( engine.report() ); } else if ( property.getNextProp() != record.getId() ) { engine.comparativeCheck( property( records, property.getNextProp() ), this ); } } }
@Override protected PropertyRecord fetchNextOrNull() { if ( Record.NO_NEXT_PROPERTY.is( next ) ) { return null; } PropertyRecord record = referenceTo( access.getPropertyStore(), next ).record(); next = record.getNextProp(); return record; } };
public void getPropertyChain( long nextProp, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords, Listener<PropertyBlock> collector ) { while ( nextProp != Record.NO_NEXT_PROPERTY.intValue() ) { PropertyRecord propRecord = propertyRecords.getOrLoad( nextProp, null ).forReadingData(); for ( PropertyBlock propBlock : propRecord ) { collector.receive( propBlock ); } nextProp = propRecord.getNextProp(); } }
@Override public void checkReference( RECORD record, PropertyRecord property, CheckerEngine<RECORD, REPORT> engine, RecordAccess records ) { for ( int key : keys( property ) ) { if ( !keys.add( key ) ) { engine.report().propertyKeyNotUniqueInChain(); } } if ( !Record.NO_NEXT_PROPERTY.is( property.getNextProp() ) ) { engine.comparativeCheck( records.property( property.getNextProp() ), this ); } }
private static PropertyRecord[] extractPropertyRecords( RecordAccess<PropertyRecord,PrimitiveRecord> propertyRecordAccess, long nextProp ) { List<PropertyRecord> result = new ArrayList<>(); while ( !Record.NULL_REFERENCE.is( nextProp ) ) { PropertyRecord record = propertyRecordAccess.getIfLoaded( nextProp ).forReadingLinkage(); result.add( record ); nextProp = record.getNextProp(); } return result.toArray( new PropertyRecord[result.size()] ); }
@Override protected PropertyRecord fetchNextOrNull() { if ( Record.NO_NEXT_PROPERTY.is( next ) ) { return null; } PropertyRecord record = reference( properties, next, Version.LATEST ).record(); next = record.getNextProp(); return record; } };
propertyRecordId = propertyRecord.getNextProp();
public void deletePropertyChain( PrimitiveRecord primitive, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords ) { long nextProp = primitive.getNextProp(); while ( nextProp != Record.NO_NEXT_PROPERTY.intValue() ) { RecordProxy<PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad( nextProp, primitive ); // TODO forChanging/forReading piggy-backing PropertyRecord propRecord = propertyChange.forChangingData(); deletePropertyRecordIncludingValueRecords( propRecord ); nextProp = propRecord.getNextProp(); propRecord.setChanged( primitive ); } primitive.setNextProp( Record.NO_NEXT_PROPERTY.intValue() ); }
@Override protected void assertRecordsEqual( PropertyRecord actualRecord, PropertyRecord expectedRecord ) { assertNotNull( "actualRecord", actualRecord ); assertNotNull( "expectedRecord", expectedRecord ); assertThat( "getDeletedRecords", actualRecord.getDeletedRecords(), is( expectedRecord.getDeletedRecords() ) ); assertThat( "getNextProp", actualRecord.getNextProp(), is( expectedRecord.getNextProp() ) ); assertThat( "getEntityId", actualRecord.getNodeId(), is( expectedRecord.getNodeId() ) ); assertThat( "getPrevProp", actualRecord.getPrevProp(), is( expectedRecord.getPrevProp() ) ); assertThat( "getRelId", actualRecord.getRelId(), is( expectedRecord.getRelId() ) ); assertThat( "getId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getLongId", actualRecord.getId(), is( expectedRecord.getId() ) ); List<PropertyBlock> actualBlocks = Iterables.asList( actualRecord ); List<PropertyBlock> expectedBlocks = Iterables.asList( expectedRecord ); assertThat( "getPropertyBlocks().size", actualBlocks.size(), is( expectedBlocks.size() ) ); for ( int i = 0; i < actualBlocks.size(); i++ ) { PropertyBlock actualBlock = actualBlocks.get( i ); PropertyBlock expectedBlock = expectedBlocks.get( i ); assertPropertyBlocksEqual( i, actualBlock, expectedBlock ); } }
@Test public void readPropertyCommandWithSecondaryUnit() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); after.setRequiresSecondaryUnit( true ); after.setSecondaryUnitId( 78 ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); verifySecondaryUnit( after, neoStoreCommand.getAfter() ); }
@Test public void readPropertyCommandWithNonRequiredSecondaryUnit() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); after.setRequiresSecondaryUnit( false ); after.setSecondaryUnitId( 78 ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); verifySecondaryUnit( after, neoStoreCommand.getAfter() ); }
private void assertChain( ExpectedRecord... expectedRecords ) { long nextProp = primitive.forReadingLinkage().getNextProp(); int expectedRecordCursor = 0; while ( !Record.NO_NEXT_PROPERTY.is( nextProp ) ) { PropertyRecord record = records.getIfLoaded( nextProp ).forReadingData(); assertRecord( record, expectedRecords[expectedRecordCursor++] ); nextProp = record.getNextProp(); } }
private boolean visitPropertyRecordChain( long firstPropertyRecordId, Visitor<PropertyRecord,RuntimeException> visitor ) throws CircularPropertyRecordChainException { if ( Record.NO_NEXT_PROPERTY.is( firstPropertyRecordId ) ) { return false; } MutableLongSet visitedPropertyRecordIds = new LongHashSet( 8 ); visitedPropertyRecordIds.add( firstPropertyRecordId ); long nextProp = firstPropertyRecordId; while ( !Record.NO_NEXT_PROPERTY.is( nextProp ) ) { PropertyRecord propRecord = propertyStore.getRecord( nextProp, propertyStore.newRecord(), FORCE ); nextProp = propRecord.getNextProp(); if ( !Record.NO_NEXT_PROPERTY.is( nextProp ) && !visitedPropertyRecordIds.add( nextProp ) ) { throw new CircularPropertyRecordChainException( propRecord ); } if ( visitor.visit( propRecord ) ) { return true; } } return false; }
@Test public void readPropertyCommandWithFixedReferenceFormat300() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); assertTrue( neoStoreCommand.getBefore().isUseFixedReferences() ); assertTrue( neoStoreCommand.getAfter().isUseFixedReferences() ); }
@Test public void readPropertyCommandWithFixedReferenceFormat302() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); PropertyRecord before = new PropertyRecord( 1 ); PropertyRecord after = new PropertyRecord( 2 ); before.setUseFixedReferences( true ); after.setUseFixedReferences( true ); new Command.PropertyCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2(); Command command = reader.read( channel ); assertTrue( command instanceof Command.PropertyCommand); Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand) command; // Then assertEquals( before.getNextProp(), neoStoreCommand.getBefore().getNextProp() ); assertEquals( after.getNextProp(), neoStoreCommand.getAfter().getNextProp() ); assertTrue( neoStoreCommand.getBefore().isUseFixedReferences() ); assertTrue( neoStoreCommand.getAfter().isUseFixedReferences() ); }
@Override public void assertRecordsEquals( PropertyRecord written, PropertyRecord read ) { assertEquals( written.getPrevProp(), read.getPrevProp() ); assertEquals( written.getNextProp(), read.getNextProp() ); assertEquals( written.isNodeSet(), read.isNodeSet() ); if ( written.isNodeSet() ) { assertEquals( written.getNodeId(), read.getNodeId() ); } else { assertEquals( written.getRelId(), read.getRelId() ); } assertEquals( written.numberOfProperties(), read.numberOfProperties() ); Iterator<PropertyBlock> writtenBlocks = written.iterator(); Iterator<PropertyBlock> readBlocks = read.iterator(); while ( writtenBlocks.hasNext() ) { assertTrue( readBlocks.hasNext() ); assertBlocksEquals( writtenBlocks.next(), readBlocks.next() ); } }