@Test public void readRelGroupWithHugeTypeInV3_0_2() throws IOException { assertCanReadRelGroup( new PhysicalLogCommandReaderV3_0_2() ); }
private IndexCommandHeader readIndexCommandHeader( ReadableChannel channel ) throws IOException { byte firstHeaderByte = channel.get(); byte valueType = (byte) ((firstHeaderByte & 0x1C) >> 2); byte entityType = (byte) ((firstHeaderByte & 0x2) >> 1); boolean entityIdNeedsLong = (firstHeaderByte & 0x1) > 0; byte secondHeaderByte = channel.get(); boolean startNodeNeedsLong = (secondHeaderByte & 0x80) > 0; boolean endNodeNeedsLong = (secondHeaderByte & 0x40) > 0; int indexNameId = getUnsignedShort( channel ); int keyId = getUnsignedShort( channel ); return new IndexCommandHeader( valueType, entityType, entityIdNeedsLong, indexNameId, startNodeNeedsLong, endNodeNeedsLong, keyId ); }
private <T> int readDynamicRecords( ReadableChannel channel, T target, DynamicRecordAdder<T> adder ) throws IOException { int numberOfRecords = channel.getInt(); assert numberOfRecords >= 0; while ( numberOfRecords > 0 ) { DynamicRecord read = readDynamicRecord( channel ); if ( read == null ) { return -1; } adder.add( target, read ); numberOfRecords--; } return numberOfRecords; }
private Command visitIndexDefineCommand( ReadableChannel channel ) throws IOException { readIndexCommandHeader( channel ); MutableObjectIntMap<String> indexNames = readMap( channel ); MutableObjectIntMap<String> keys = readMap( channel ); IndexDefineCommand command = new IndexDefineCommand(); command.init( indexNames, keys ); return command; }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
private Command visitIndexAddNodeCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt(); Object value = readIndexValue( header.valueType, channel ); AddNodeCommand command = new AddNodeCommand(); command.init( header.indexNameId, entityId.longValue(), header.keyId, value ); return command; }
@Test public void readRelationshipCommandWithFixedReferenceFormat302() throws IOException { InMemoryClosableChannel channel = new InMemoryClosableChannel(); RelationshipRecord before = new RelationshipRecord( 42, true, 1, 2, 3, 4, 5, 6, 7, true, true ); before.setUseFixedReferences( true ); RelationshipRecord after = new RelationshipRecord( 42, true, 1, 8, 3, 4, 5, 6, 7, true, true ); after.setUseFixedReferences( true ); new Command.RelationshipCommand( before, after ).serialize( channel ); PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2(); Command command = reader.read( channel ); assertTrue( command instanceof Command.RelationshipCommand ); Command.RelationshipCommand relationshipCommand = (Command.RelationshipCommand) command; assertEquals( before, relationshipCommand.getBefore() ); assertTrue( relationshipCommand.getBefore().isUseFixedReferences() ); assertEquals( after, relationshipCommand.getAfter() ); assertTrue( relationshipCommand.getAfter().isUseFixedReferences() ); }
PropertyBlock block = readPropertyBlock( channel ); if ( block == null ) int deletedRecords = readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ); if ( deletedRecords == -1 ) while ( deletedRecords-- > 0 ) DynamicRecord read = readDynamicRecord( channel ); if ( read == null )
private PropertyBlock readPropertyBlock( ReadableChannel channel ) throws IOException { PropertyBlock toReturn = new PropertyBlock(); byte blockSize = channel.get(); // the size is stored in bytes // 1 assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value"; // Read in blocks long[] blocks = readLongs( channel, blockSize / 8 ); assert blocks.length == blockSize / 8 : blocks.length + " longs were read in while i asked for what corresponds to " + blockSize; assert PropertyType.getPropertyTypeOrThrow( blocks[0] ).calculateNumberOfBlocksUsed( blocks[0] ) == blocks.length : blocks.length + " is not a valid number of blocks for type " + PropertyType.getPropertyTypeOrThrow( blocks[0] ); /* * Ok, now we may be ready to return, if there are no DynamicRecords. So * we start building the Object */ toReturn.setValueBlocks( blocks ); /* * Read in existence of DynamicRecords. Remember, this has already been * read in the buffer with the blocks, above. */ if ( readDynamicRecords( channel, toReturn, PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return toReturn; }
private Command visitIndexDeleteCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); DeleteCommand command = new DeleteCommand(); command.init( header.indexNameId, header.entityType ); return command; }
private PropertyKeyTokenRecord readPropertyKeyTokenRecord( int id, ReadableChannel channel ) throws IOException { // in_use(byte)+count(int)+key_blockId(int) byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return record; }
private Command visitLabelTokenCommand( ReadableChannel channel ) throws IOException { int id = channel.getInt(); LabelTokenRecord before = readLabelTokenRecord( id, channel ); if ( before == null ) { return null; } LabelTokenRecord after = readLabelTokenRecord( id, channel ); if ( after == null ) { return null; } return new Command.LabelTokenCommand( before, after ); }
@Test public void readRelationshipGroupCommandWithFixedReferenceFormat302() throws IOException { // Given InMemoryClosableChannel channel = new InMemoryClosableChannel(); RelationshipGroupRecord before = new RelationshipGroupRecord( 42, 3 ); before.setUseFixedReferences( true ); RelationshipGroupRecord after = new RelationshipGroupRecord( 42, 3, 4, 5, 6, 7, 8, true ); after.setUseFixedReferences( true ); new Command.RelationshipGroupCommand( before, after ).serialize( channel ); // When PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2(); Command command = reader.read( channel ); assertTrue( command instanceof Command.RelationshipGroupCommand); Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command; // Then assertEquals( before, relationshipGroupCommand.getBefore() ); assertEquals( after, relationshipGroupCommand.getAfter() ); assertTrue( relationshipGroupCommand.getBefore().isUseFixedReferences() ); assertTrue( relationshipGroupCommand.getAfter().isUseFixedReferences() ); }
private Command visitIndexRemoveCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt(); Object value = readIndexValue( header.valueType, channel ); RemoveCommand command = new RemoveCommand(); command.init( header.indexNameId, header.entityType, entityId.longValue(), header.keyId, value ); return command; }
PropertyBlock block = readPropertyBlock( channel ); if ( block == null ) int deletedRecords = readDynamicRecords( channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER ); if ( deletedRecords == -1 ) while ( deletedRecords-- > 0 ) DynamicRecord read = readDynamicRecord( channel ); if ( read == null )
private Command visitIndexDefineCommand( ReadableChannel channel ) throws IOException { readIndexCommandHeader( channel ); MutableObjectIntMap<String> indexNames = readMap( channel ); MutableObjectIntMap<String> keys = readMap( channel ); IndexDefineCommand command = new IndexDefineCommand(); command.init( indexNames, keys ); return command; }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
private PropertyBlock readPropertyBlock( ReadableChannel channel ) throws IOException { PropertyBlock toReturn = new PropertyBlock(); byte blockSize = channel.get(); // the size is stored in bytes // 1 assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value"; // Read in blocks long[] blocks = readLongs( channel, blockSize / 8 ); assert blocks.length == blockSize / 8 : blocks.length + " longs were read in while i asked for what corresponds to " + blockSize; assert PropertyType.getPropertyTypeOrThrow( blocks[0] ).calculateNumberOfBlocksUsed( blocks[0] ) == blocks.length : blocks.length + " is not a valid number of blocks for type " + PropertyType.getPropertyTypeOrThrow( blocks[0] ); /* * Ok, now we may be ready to return, if there are no DynamicRecords. So * we start building the Object */ toReturn.setValueBlocks( blocks ); /* * Read in existence of DynamicRecords. Remember, this has already been * read in the buffer with the blocks, above. */ if ( readDynamicRecords( channel, toReturn, PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return toReturn; }
private Command visitIndexCreateCommand( ReadableChannel channel ) throws IOException { IndexCommandHeader header = readIndexCommandHeader( channel ); Map<String,String> config = read2bMap( channel ); CreateCommand command = new CreateCommand(); command.init( header.indexNameId, header.entityType, config ); return command; }
readDynamicRecords( channel, dynamicLabelRecords, COLLECTION_DYNAMIC_RECORD_ADDER ); record.setLabelField( labelField, dynamicLabelRecords ); record.setInUse( inUse );