HHH-11709 : NoopOptimizer skips negative values and 0 when it has a positive incrementSize
This commit is contained in:
parent
d211b41319
commit
bb0a4b6e6f
|
@ -38,12 +38,6 @@ public final class NoopOptimizer extends AbstractOptimizer {
|
||||||
// The lastSourceValue field is only accessed by tests,
|
// The lastSourceValue field is only accessed by tests,
|
||||||
// so this is not a concern.
|
// so this is not a concern.
|
||||||
IntegralDataTypeHolder value = callback.getNextValue();
|
IntegralDataTypeHolder value = callback.getNextValue();
|
||||||
if ( incrementSize > 0 ) {
|
|
||||||
while ( value.lt( 1 ) ) {
|
|
||||||
value = callback.getNextValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastSourceValue = value;
|
lastSourceValue = value;
|
||||||
return value.makeValue();
|
return value.makeValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,16 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
|
||||||
assertEquals( 10, sequence.getTimesCalled() );
|
assertEquals( 10, sequence.getTimesCalled() );
|
||||||
assertEquals( 10, sequence.getCurrentValue() );
|
assertEquals( 10, sequence.getCurrentValue() );
|
||||||
|
|
||||||
// test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
|
// As of HHH-11709 being fixed, Hibernate will use the value retrieved from the sequence,
|
||||||
|
// rather than incrementing 1.
|
||||||
sequence = new SourceMock( 0 );
|
sequence = new SourceMock( 0 );
|
||||||
optimizer = buildNoneOptimizer( -1, 1 );
|
optimizer = buildNoneOptimizer( -1, 1 );
|
||||||
for ( int i = 1; i < 11; i++ ) {
|
for ( int i = 1; i < 11; i++ ) {
|
||||||
final Long next = ( Long ) optimizer.generate( sequence );
|
final Long next = ( Long ) optimizer.generate( sequence );
|
||||||
assertEquals( i, next.intValue() );
|
assertEquals( i-1, next.intValue() );
|
||||||
}
|
}
|
||||||
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
assertEquals( 10, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
||||||
assertEquals( 10, sequence.getCurrentValue() );
|
assertEquals( 9, sequence.getCurrentValue() );
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testBasicNoOptimizerUsageWithNegativeValues() {
|
public void testBasicNoOptimizerUsageWithNegativeValues() {
|
||||||
|
@ -55,15 +56,16 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
|
||||||
assertEquals( 10, sequence.getTimesCalled() );
|
assertEquals( 10, sequence.getTimesCalled() );
|
||||||
assertEquals( -10, sequence.getCurrentValue() );
|
assertEquals( -10, sequence.getCurrentValue() );
|
||||||
|
|
||||||
// test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
|
// As of HHH-11709 being fixed, Hibernate will use the value retrieved from the sequence,
|
||||||
|
// rather than incrementing 1.
|
||||||
sequence = new SourceMock( 0 );
|
sequence = new SourceMock( 0 );
|
||||||
optimizer = buildNoneOptimizer( -1, 1 );
|
optimizer = buildNoneOptimizer( -1, 1 );
|
||||||
for ( int i = 1; i < 11; i++ ) {
|
for ( int i = 1; i < 11; i++ ) {
|
||||||
final Long next = ( Long ) optimizer.generate( sequence );
|
final Long next = ( Long ) optimizer.generate( sequence );
|
||||||
assertEquals( i, next.intValue() );
|
assertEquals( i-1, next.intValue() );
|
||||||
}
|
}
|
||||||
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
assertEquals( 10, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
||||||
assertEquals( 10, sequence.getCurrentValue() );
|
assertEquals( 9, sequence.getCurrentValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -73,7 +75,7 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
// test historic sequence behavior, where the initial values start at 1...
|
// test historic sequence behavior, where the initial values start at 1...
|
||||||
SourceMock sequence = new SourceMock( 1 );
|
SourceMock sequence = new SourceMock( 1 );
|
||||||
Optimizer optimizer = buildHiloOptimizer( -1, increment );
|
Optimizer optimizer = buildHiloOptimizer( -1, incremepnt );
|
||||||
for ( int i = 1; i <= increment; i++ ) {
|
for ( int i = 1; i <= increment; i++ ) {
|
||||||
next = ( Long ) optimizer.generate( sequence );
|
next = ( Long ) optimizer.generate( sequence );
|
||||||
assertEquals( i, next.intValue() );
|
assertEquals( i, next.intValue() );
|
||||||
|
|
Loading…
Reference in New Issue