private void writeLabelTokenRecord( WritableChannel channel, LabelTokenRecord record ) throws IOException { // id+in_use(byte)+type_blockId(int)+nr_type_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ).putInt( record.getNameId() ); writeDynamicRecords( channel, record.getNameRecords() ); } }
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 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; }
@Override public void write( MetaDataRecord record, PageCursor cursor, int recordSize ) { assert record.inUse(); cursor.putByte( Record.IN_USE.byteValue() ); cursor.putLong( record.getValue() ); } }
private void setRecord( PageCursor cursor, Position position, long value ) { if ( !cursor.isWriteLocked() ) { throw new IllegalArgumentException( "Cannot write record without a page cursor that is write-locked" ); } int offset = offsetForId( position.id ); cursor.setOffset( offset ); cursor.putByte( Record.IN_USE.byteValue() ); cursor.putLong( value ); checkForDecodingErrors( cursor, position.id, NORMAL ); }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); 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 new Command.PropertyKeyTokenCommand( null, record ); }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); 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 new Command.PropertyKeyTokenCommand( null, record ); }
private void writeRelationshipTypeTokenRecord( WritableChannel channel, RelationshipTypeTokenRecord record ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ); channel.putInt( record.getNameId() ); if ( record.isLight() ) { channel.putInt( 0 ); } else { writeDynamicRecords( channel, record.getNameRecords() ); } } }
private void writePropertyKeyTokenRecord( WritableChannel channel, PropertyKeyTokenRecord record ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int) byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue(); channel.put( inUse ); channel.putInt( record.getPropertyCount() ).putInt( record.getNameId() ); if ( record.isLight() ) { channel.putInt( 0 ); } else { writeDynamicRecords( channel, record.getNameRecords() ); } } }
private Command visitRelationshipGroupCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); byte inUseByte = channel.get(); boolean inUse = inUseByte == Record.IN_USE.byteValue(); if ( inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseByte ); } int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); return new Command.RelationshipGroupCommand( null, record ); }
private Command visitRelationshipGroupCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); byte inUseByte = channel.get(); boolean inUse = inUseByte == Record.IN_USE.byteValue(); if ( inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseByte ); } int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); return new Command.RelationshipGroupCommand( null, record ); }
@Test( expected = InvalidRecordException.class ) public void getRecord() throws IOException { when( pageCursor.getByte() ).thenReturn( Record.NOT_IN_USE.byteValue() ); LabelTokenStore store = new UnusedLabelTokenStore(); store.getRecord( 7, store.newRecord(), NORMAL ); }
@Override public void read( MetaDataRecord record, PageCursor cursor, RecordLoad mode, int recordSize ) { int id = record.getIntId(); Position[] values = Position.values(); if ( id >= values.length ) { record.initialize( false, FIELD_NOT_PRESENT ); return; } Position position = values[id]; int offset = position.id() * recordSize; cursor.setOffset( offset ); boolean inUse = cursor.getByte() == Record.IN_USE.byteValue(); long value = inUse ? cursor.getLong() : FIELD_NOT_PRESENT; record.initialize( inUse, value ); }
private static void assertValidRelGroupCommand( StorageCommand command ) { assertThat( command, instanceOf( RelationshipGroupCommand.class ) ); RelationshipGroupCommand relGroupCommand = (RelationshipGroupCommand) command; RelationshipGroupRecord record = relGroupCommand.getAfter(); assertEquals( ID, record.getId() ); if ( IN_USE_FLAG == Record.IN_USE.byteValue() ) { assertTrue( record.inUse() ); } else if ( IN_USE_FLAG == Record.NOT_IN_USE.byteValue() ) { assertFalse( record.inUse() ); } else { throw new IllegalStateException( "Illegal inUse flag: " + IN_USE_FLAG ); } assertEquals( TYPE_AS_INT, record.getType() ); assertEquals( NEXT, record.getNext() ); assertEquals( FIRST_OUT, record.getFirstOut() ); assertEquals( FIRST_IN, record.getFirstIn() ); assertEquals( FIRST_LOOP, record.getNext() ); assertEquals( OWNING_NODE, record.getOwningNode() ); }
private RelationshipGroupRecord readRelationshipGroupRecord( long id, ReadableChannel channel ) throws IOException { byte flags = channel.get(); boolean inUse = bitFlag( flags, Record.IN_USE.byteValue() ); boolean requireSecondaryUnit = bitFlag( flags, Record.REQUIRE_SECONDARY_UNIT ); boolean hasSecondaryUnit = bitFlag( flags, Record.HAS_SECONDARY_UNIT ); boolean usesFixedReferenceFormat = bitFlag( flags, Record.USES_FIXED_REFERENCE_FORMAT ); int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); record.setRequiresSecondaryUnit( requireSecondaryUnit ); if ( hasSecondaryUnit ) { record.setSecondaryUnitId( channel.getLong() ); } record.setUseFixedReferences( usesFixedReferenceFormat ); return record; }
private RelationshipGroupRecord readRelationshipGroupRecord( long id, ReadableChannel channel ) throws IOException { byte flags = channel.get(); boolean inUse = bitFlag( flags, Record.IN_USE.byteValue() ); boolean requireSecondaryUnit = bitFlag( flags, Record.REQUIRE_SECONDARY_UNIT ); boolean hasSecondaryUnit = bitFlag( flags, Record.HAS_SECONDARY_UNIT ); boolean usesFixedReferenceFormat = bitFlag( flags, Record.USES_FIXED_REFERENCE_FORMAT ); int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); record.setRequiresSecondaryUnit( requireSecondaryUnit ); if ( hasSecondaryUnit ) { record.setSecondaryUnitId( channel.getLong() ); } record.setUseFixedReferences( usesFixedReferenceFormat ); return record; }
private void writeRelationshipGroupRecord( WritableChannel channel, RelationshipGroupRecord record ) throws IOException { byte flags = bitFlags( bitFlag( record.inUse(), Record.IN_USE.byteValue() ), bitFlag( record.requiresSecondaryUnit(), Record.REQUIRE_SECONDARY_UNIT ), bitFlag( record.hasSecondaryUnitId(), Record.HAS_SECONDARY_UNIT ), bitFlag( record.isUseFixedReferences(), Record.USES_FIXED_REFERENCE_FORMAT ) ); channel.put( flags ); channel.putShort( (short) record.getType() ); channel.putLong( record.getNext() ); channel.putLong( record.getFirstOut() ); channel.putLong( record.getFirstIn() ); channel.putLong( record.getFirstLoop() ); channel.putLong( record.getOwningNode() ); if ( record.hasSecondaryUnitId() ) { channel.putLong( record.getSecondaryUnitId() ); } } }
private void writeNodeRecord( WritableChannel channel, NodeRecord record ) throws IOException { byte flags = bitFlags( bitFlag( record.inUse(), Record.IN_USE.byteValue() ), bitFlag( record.isCreated(), Record.CREATED_IN_TX ), bitFlag( record.requiresSecondaryUnit(), Record.REQUIRE_SECONDARY_UNIT ), bitFlag( record.hasSecondaryUnitId(), Record.HAS_SECONDARY_UNIT ), bitFlag( record.isUseFixedReferences(), Record.USES_FIXED_REFERENCE_FORMAT ) ); channel.put( flags ); if ( record.inUse() ) { channel.put( record.isDense() ? (byte) 1 : (byte) 0 ); channel.putLong( record.getNextRel() ).putLong( record.getNextProp() ); channel.putLong( record.getLabelField() ); if ( record.hasSecondaryUnitId() ) { channel.putLong( record.getSecondaryUnitId() ); } } // Always write dynamic label records because we want to know which ones have been deleted // especially if the node has been deleted. writeDynamicRecords( channel, record.getDynamicLabelRecords() ); } }
private void writeRelationshipRecord( WritableChannel channel, RelationshipRecord record ) throws IOException { byte flags = bitFlags( bitFlag( record.inUse(), Record.IN_USE.byteValue() ), bitFlag( record.isCreated(), Record.CREATED_IN_TX ), bitFlag( record.requiresSecondaryUnit(), Record.REQUIRE_SECONDARY_UNIT ), bitFlag( record.hasSecondaryUnitId(), Record.HAS_SECONDARY_UNIT ), bitFlag( record.isUseFixedReferences(), Record.USES_FIXED_REFERENCE_FORMAT ) ); channel.put( flags ); if ( record.inUse() ) { channel.putLong( record.getFirstNode() ).putLong( record.getSecondNode() ).putInt( record.getType() ) .putLong( record.getFirstPrevRel() ).putLong( record.getFirstNextRel() ) .putLong( record.getSecondPrevRel() ).putLong( record.getSecondNextRel() ) .putLong( record.getNextProp() ) .put( (byte) ((record.isFirstInFirstChain() ? 1 : 0) | (record.isFirstInSecondChain() ? 2 : 0)) ); if ( record.hasSecondaryUnitId() ) { channel.putLong( record.getSecondaryUnitId() ); } } else { channel.putInt( record.getType() ); } } }