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.
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.
The general algorithms used to determine the bucket is:
upperLimit = (databaseValue * incrementSize) + 1lowerLimit = upperLimit - incrementSizeAs an example, consider a case with incrementSize of 20. Initially, the database holds 1:
upperLimit = (1 * 20) + 1 = 21lowerLimit = 21 - 20 = 1From 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:
upperLimit = (2 * 20) + 1 = 41lowerLimit = 41 - 20 = 21Note, 'value' always (after init) holds the next value to return
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Lock | lock
Use a lock instead of the monitor lock to avoid pinning when using virtual threads. |
| private static final Logger | |
| private HiLoOptimizer. | |
| private Map |
| Access | Constructor and Description |
|---|---|
| public | HiLoOptimizer(Class<?>
The Java type of the values to be generated returnClass, int The increment size. incrementSize)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | applyIncrementSizeToSourceValues()
Implements org. |
| public Serializable | generate(AccessCallback
Callback to access the underlying value source. callback)Implements org. |
| public IntegralDataTypeHolder | |
| public IntegralDataTypeHolder | getLastSourceValue()
Implements org. |
| public IntegralDataTypeHolder | |
| private HiLoOptimizer. | |
| private HiLoOptimizer. |
| lock | back to summary |
|---|---|
| private final Lock lock Use a lock instead of the monitor lock to avoid pinning when using virtual threads. | |
| log | back to summary |
|---|---|
| private static final Logger log | |
| noTenantState | back to summary |
|---|---|
| private HiLoOptimizer. | |
| tenantSpecificState | back to summary |
|---|---|
| private Map<String, HiLoOptimizer. | |
| HiLoOptimizer | back to summary |
|---|---|
| public HiLoOptimizer(Class<?> returnClass, int incrementSize) Constructs a
| |
| applyIncrementSizeToSourceValues | back to summary |
|---|---|
| public boolean applyIncrementSizeToSourceValues() Implements org. Doc from org. Are increments to be applied to the values stored in the underlying value source?
| |
| generate | back to summary |
|---|---|
| public Serializable generate(AccessCallback callback) Implements org. Doc from org. Generate an identifier value accounting for this specific optimization. All known implementors are synchronized. Consider carefully if a new implementation could drop this requirement.
| |
| getHiValue | back to summary |
|---|---|
| public IntegralDataTypeHolder getHiValue() Getter for property 'upperLimit'. Exposure intended for testing purposes.
| |
| getLastSourceValue | back to summary |
|---|---|
| public IntegralDataTypeHolder getLastSourceValue() Implements org. Doc from org. 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.
| |
| getLastValue | back to summary |
|---|---|
| public IntegralDataTypeHolder getLastValue() Getter for property 'lastValue'. Exposure intended for testing purposes.
| |
| locateGenerationState | back to summary |
|---|---|
| private HiLoOptimizer. | |
| noTenantGenerationState | back to summary |
|---|---|
| private HiLoOptimizer. | |
| Modifier and Type | Field and Description |
|---|---|
| private IntegralDataTypeHolder | |
| private IntegralDataTypeHolder | |
| private IntegralDataTypeHolder |
| Access | Constructor and Description |
|---|---|
| private |
| lastSourceValue | back to summary |
|---|---|
| private IntegralDataTypeHolder lastSourceValue | |
| upperLimit | back to summary |
|---|---|
| private IntegralDataTypeHolder upperLimit | |
| value | back to summary |
|---|---|
| private IntegralDataTypeHolder value | |
| GenerationState | back to summary |
|---|---|
| private GenerationState() | |