private long getRecordValue( PageCursor cursor, Position position, long defaultValue ) { MetaDataRecord record = newRecord(); try { record.setId( position.id ); recordFormat.read( record, cursor, FORCE, RECORD_SIZE ); if ( record.inUse() ) { return record.getValue(); } return defaultValue; } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } }
private void setRecord( Position position, long value ) { MetaDataRecord record = new MetaDataRecord(); record.initialize( true, value ); record.setId( position.id ); updateRecord( record ); }
@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 ); }
MetaDataRecord record = new MetaDataRecord(); record.setId( position.id ); do if ( record.inUse() ) value = record.getValue();
if ( cursor.checkAndClearBoundsFlag() ) MetaDataRecord neoStoreRecord = new MetaDataRecord(); neoStoreRecord.setId( position.id ); throw new UnderlyingStorageException( buildOutOfBoundsExceptionMessage( neoStoreRecord, 0, offset, RECORD_SIZE, pageSize, neoStore.getAbsolutePath() ) );
@Test public void mustSupportScanningAllRecords() throws Exception { File file = createMetaDataFile(); MetaDataStore.Position[] positions = MetaDataStore.Position.values(); long storeVersion = versionStringToLong( Standard.LATEST_RECORD_FORMATS.storeVersion()); writeCorrectMetaDataRecord( file, positions, storeVersion ); List<Long> actualValues = new ArrayList<>(); try ( MetaDataStore store = newMetaDataStore() ) { store.scanAllRecords( record -> { actualValues.add( record.getValue() ); return false; } ); } List<Long> expectedValues = Arrays.stream( positions ).map( p -> { if ( p == MetaDataStore.Position.STORE_VERSION ) { return storeVersion; } else { return p.ordinal() + 1L; } } ).collect( Collectors.toList() ); assertThat( actualValues, is( expectedValues ) ); }
@Override public MetaDataRecord newRecord() { return new MetaDataRecord(); }
@Override public void clear() { initialize( false, -1 ); }
MetaDataRecord record = new MetaDataRecord(); record.setId( position.id ); do if ( record.inUse() ) value = record.getValue();
if ( cursor.checkAndClearBoundsFlag() ) MetaDataRecord neoStoreRecord = new MetaDataRecord(); neoStoreRecord.setId( position.id ); throw new UnderlyingStorageException( buildOutOfBoundsExceptionMessage( neoStoreRecord, 0, offset, RECORD_SIZE, pageSize, neoStore.getAbsolutePath() ) );
@Override public MetaDataRecord newRecord() { return new MetaDataRecord(); }
@Override public void clear() { initialize( false, -1 ); }
private long getRecordValue( PageCursor cursor, Position position, long defaultValue ) { MetaDataRecord record = newRecord(); try { record.setId( position.id ); recordFormat.read( record, cursor, FORCE, RECORD_SIZE ); if ( record.inUse() ) { return record.getValue(); } return defaultValue; } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } }
private void setRecord( Position position, long value ) { MetaDataRecord record = new MetaDataRecord(); record.initialize( true, value ); record.setId( position.id ); updateRecord( record ); }
@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 ); }
@Override public MetaDataRecord newRecord() { return new MetaDataRecord(); }
@Override public MetaDataRecord newRecord() { return new MetaDataRecord(); }