public long nextId( StoreType type ) { return idGenerator( type ).nextId(); }
@Override public long nextId() { assert !closed; long id; while ( currentBatch == null || (id = currentBatch.nextId()) == VALUE_REPRESENTING_NULL ) { currentBatch = source.nextIdBatch( batchSize ).iterator(); } return id; }
@Override public long nextId() { long id; if ( batch == null || (id = batch.nextId()) == -1 ) { IdRange idRange = source.nextIdBatch( batchSize ); while ( IdValidator.hasReservedIdInRange( idRange.getRangeStart(), idRange.getRangeStart() + idRange.getRangeLength() ) ) { idRange = source.nextIdBatch( batchSize ); } batch = new IdRangeIterator( idRange ); id = batch.nextId(); } return id; }
@Test public void shouldContinueThroughEmptyIdBatch() { // given IdSequence idSource = mock( IdSequence.class ); Iterator<IdRange> ranges = asList( new IdRange( EMPTY_LONG_ARRAY, 0, BATCH_SIZE ), new IdRange( EMPTY_LONG_ARRAY, BATCH_SIZE, 0 ), new IdRange( EMPTY_LONG_ARRAY, BATCH_SIZE, BATCH_SIZE ) ).iterator(); when( idSource.nextIdBatch( anyInt() ) ).thenAnswer( invocation -> ranges.next() ); RenewableBatchIdSequence ids = new RenewableBatchIdSequence( idSource, BATCH_SIZE, excessIds::add ); // when/then for ( long expectedId = 0; expectedId < BATCH_SIZE * 2; expectedId++ ) { assertEquals( expectedId, ids.nextId() ); } }
@Override public DynamicRecord nextRecord() { return allocateRecord( idGenerator.nextId() ); }
@Override public long nextId() { assert !closed; long id; while ( currentBatch == null || (id = currentBatch.nextId()) == VALUE_REPRESENTING_NULL ) { currentBatch = source.nextIdBatch( batchSize ).iterator(); } return id; }
@Override public long nextId() { long id; if ( batch == null || (id = batch.nextId()) == -1 ) { IdRange idRange = source.nextIdBatch( batchSize ); while ( IdValidator.hasReservedIdInRange( idRange.getRangeStart(), idRange.getRangeStart() + idRange.getRangeLength() ) ) { idRange = source.nextIdBatch( batchSize ); } batch = new IdRangeIterator( idRange ); id = batch.nextId(); } return id; }
/** * Even if instances are meant to be accessed by a single thread at a time, lifecycle calls * can guard for it nonetheless. Only the first call to close will perform close. */ @Override public synchronized void close() { if ( !closed && currentBatch != null ) { long id; while ( (id = currentBatch.nextId()) != VALUE_REPRESENTING_NULL ) { excessIdConsumer.accept( id ); } currentBatch = null; } closed = true; }
PropertyRecord currentRecord = propertyRecords.create( propertyRecordIdGenerator.nextId(), owner ) .forChangingData(); createdPropertyRecords.accept( currentRecord ); long propertyId = propertyRecordIdGenerator.nextId(); currentRecord = propertyRecords.create( propertyId, owner ).forChangingData(); createdPropertyRecords.accept( currentRecord );
@Override public void prepare( RECORD record, int recordSize, IdSequence idSequence ) { actual.prepare( record, recordSize, idSequence ); if ( !record.hasSecondaryUnitId() ) { record.setSecondaryUnitId( idSequence.nextId() ); } }
@Test public void shouldReturnIdImmediatelyAfterRecordId() { // given PrepareIdSequence idSequence = new SecondaryUnitPrepareIdSequence(); IdSequence actual = mock( IdSequence.class ); // when long recordId = 10; IdSequence prepared = idSequence.apply( actual ).apply( recordId ); long nextRecordId = prepared.nextId(); // then assertEquals( 10 + 1, nextRecordId ); verifyNoMoreInteractions( actual ); }
long id = idGenerator.nextId(); change = relGroupRecords.create( id, type ); RelationshipGroupRecord record = change.forChangingData();
freeHost = propertyRecords.create( propertyRecordIdGenerator.nextId(), primitive ).forChangingData(); freeHost.setInUse( true ); if ( primitive.getNextProp() != Record.NO_NEXT_PROPERTY.intValue() )
@Override public DynamicRecord nextRecord() { return allocateRecord( idGenerator.nextId() ); }
public long nextId( StoreType type ) { return idGenerator( type ).nextId(); }
/** * Even if instances are meant to be accessed by a single thread at a time, lifecycle calls * can guard for it nonetheless. Only the first call to close will perform close. */ @Override public synchronized void close() { if ( !closed && currentBatch != null ) { long id; while ( (id = currentBatch.nextId()) != VALUE_REPRESENTING_NULL ) { excessIdConsumer.accept( id ); } currentBatch = null; } closed = true; }
@Override public final void prepare( RECORD record, int recordSize, IdSequence idSequence ) { if ( record.inUse() ) { int requiredLength = HEADER_BYTE + requiredDataLength( record ); boolean requiresSecondaryUnit = requiredLength > recordSize; record.setRequiresSecondaryUnit( requiresSecondaryUnit ); if ( record.requiresSecondaryUnit() && !record.hasSecondaryUnitId() ) { // Allocate a new id at this point, but this is not the time to free this ID the the case where // this record doesn't need this secondary unit anymore... that needs to be done when applying to store. record.setSecondaryUnitId( idSequence.nextId() ); } } }
PropertyRecord currentRecord = propertyRecords.create( propertyRecordIdGenerator.nextId(), owner ) .forChangingData(); createdPropertyRecords.accept( currentRecord ); long propertyId = propertyRecordIdGenerator.nextId(); currentRecord = propertyRecords.create( propertyId, owner ).forChangingData(); createdPropertyRecords.accept( currentRecord );
@Override public final void prepare( RECORD record, int recordSize, IdSequence idSequence ) { if ( record.inUse() ) { record.setUseFixedReferences( canUseFixedReferences( record, recordSize )); if ( !record.isUseFixedReferences() ) { int requiredLength = HEADER_BYTE + requiredDataLength( record ); boolean requiresSecondaryUnit = requiredLength > recordSize; record.setRequiresSecondaryUnit( requiresSecondaryUnit ); if ( record.requiresSecondaryUnit() && !record.hasSecondaryUnitId() ) { // Allocate a new id at this point, but this is not the time to free this ID the the case where // this record doesn't need this secondary unit anymore... that needs to be done when applying to store. record.setSecondaryUnitId( idSequence.nextId() ); } } } }