@CompileStatic @Slf4j class PooledIdGenerator extends Object
An Thread safe implementation that caches a range of values in memory by the key name (ie: "tablename.id") Default cache allocation size is 50 but can be set to other values. requires another IdGenerator implementation to be set in the constructor. Usually a Jdbc type implmentation that will get the values for this class for both initialization and when this runs out of allocated ids.
Modifiers | Name | Description |
---|---|---|
class |
PooledIdGenerator.IdTuple |
Used before creating large batches where you know the count and want to pre pool and id range larger than the default to avoid the DB round trips to keep incrementing the sequence in the table. |
Type | Name and description |
---|---|
Long |
defaultBatchSize |
Constructor and description |
---|
PooledIdGenerator
() |
PooledIdGenerator
(IdGenerator generator) |
Type Params | Return Type | Name and description |
---|---|---|
|
AtomicReference<IdTuple> |
findOrCreate(String keyName) |
|
long |
getAndUpdate(String keyName, AtomicReference<IdTuple> idAtomic) Uses a lambda/closure to go get a new set of ids if the current iterator is at its max |
|
long |
getBatchSize(String keyName) |
|
long |
getNextId(String keyName) |
|
long |
getNextId(String keyName, long batchSize) this implementation does nothing here. throws IllegalAccessException |
|
void |
setBatchSize(String keyName, Long batchSize) override the default batchSize for the specified key |
|
void |
setGenerator(IdGenerator generator) |
Uses a lambda/closure to go get a new set of ids if the current iterator is at its max
this implementation does nothing here. throws IllegalAccessException
override the default batchSize for the specified key
Groovy Documentation