public class HiLoOptimizer extends AbstractOptimizer
Optimizer which applies a 'hilo' algorithm in memory to achieve
optimization.
<p/>
A 'hilo' algorithm is simply a means for a single value stored in the
database to represent a "bucket" of possible, contiguous values. The
database value identifies which particular bucket we are on.
<p/>
This database value must be paired with another value that defines the
size of the bucket; the number of possible values available.
The incrementSize
serves this purpose. The
naming here is meant more for consistency in that this value serves the
same purpose as the increment supplied to the PooledOptimizer
.
<p/>
The general algorithms used to determine the bucket are:<ol>
<li>upperLimit = (databaseValue * incrementSize) + 1
</li>
<li>lowerLimit = upperLimit - incrementSize
</li>
</ol>
As an example, consider a case with incrementSize of 20. Initially the
database holds 1:<ol>
<li>upperLimit = (1 * 20) + 1 = 21
</li>
<li>lowerLimit = 21 - 20 = 1
</li>
</ol>
From there we increment the value from lowerLimit until we reach the
upperLimit, at which point we would define a new bucket. The database
now contains 2, though incrementSize remains unchanged:<ol>
<li>upperLimit = (2 * 20) + 1 = 41
</li>
<li>lowerLimit = 41 - 20 = 21
</li>
</ol>
And so on…
<p/>
Note, 'value' always (after init) holds the next value to return
incrementSize, returnClass
Constructor and Description |
---|
HiLoOptimizer(Class returnClass,
int incrementSize)
Constructs a HiLoOptimizer
|
Modifier and Type | Method and Description |
---|---|
boolean |
applyIncrementSizeToSourceValues()
Are increments to be applied to the values stored in the underlying
value source?
|
Serializable |
generate(AccessCallback callback)
Generate an identifier value accounting for this specific optimization.
|
IntegralDataTypeHolder |
getHiValue()
Getter for property 'upperLimit'.
|
IntegralDataTypeHolder |
getLastSourceValue()
A common means to access the last value obtained from the underlying
source.
|
IntegralDataTypeHolder |
getLastValue()
Getter for property 'lastValue'.
|
getIncrementSize, getReturnClass
public HiLoOptimizer(Class returnClass, int incrementSize)
Constructs a HiLoOptimizer
returnClass
- The Java type of the values to be generatedincrementSize
- The increment size.public Serializable generate(AccessCallback callback)
Optimizer
Generate an identifier value accounting for this specific optimization.
All known implementors are synchronized. Consider carefully if a new implementation could drop this requirement.
callback
- Callback to access the underlying value source.public IntegralDataTypeHolder getLastSourceValue()
Optimizer
A common means to access the last value obtained from the underlying source. This is intended for testing purposes, since accessing the underlying database source directly is much more difficult.
public boolean applyIncrementSizeToSourceValues()
Optimizer
Are increments to be applied to the values stored in the underlying value source?
public IntegralDataTypeHolder getLastValue()
Getter for property 'lastValue'. <p/> Exposure intended for testing purposes.
public IntegralDataTypeHolder getHiValue()
Getter for property 'upperLimit'. <p/> Exposure intended for testing purposes.
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.