public class ObjectSequenceId extends AbstractIdSource
IdSource to create unique object IDs from a database sequence.
To reduce the number of roundtrips the sequence is multiplied by a sequence-multiplier and a counter just incremented within that range.
The creation of the sequence is backend-specific. For example, postgres expects:
CREATE SEQUENCE object_sequence_id;
| Modifier and Type | Field and Description |
|---|---|
static int |
GLOBAL_MULTIPLIER
Default global multiplier to allow application-specific offsets.
|
static int |
SEQUENCE_MULTIPLIER
Default sequence multiplier.
|
| Constructor and Description |
|---|
ObjectSequenceId(String name)
Creates a sequence id with default multipliers.
|
ObjectSequenceId(String name,
int sequenceMultiplier,
int globalMultiplier)
Creates a sequence id source.
|
| Modifier and Type | Method and Description |
|---|---|
protected long |
addGlobalOffset(long nextId)
Adds some global offset to the id.
|
boolean |
isLockFree()
Returns whether retrieving an id is a lock-free operation.
|
long |
nextId(Db db)
Get the next unique ID.
|
assertDbNotRemote, assertOneRowAffected, getName, toStringpublic static final int GLOBAL_MULTIPLIER
public static final int SEQUENCE_MULTIPLIER
public ObjectSequenceId(String name, int sequenceMultiplier, int globalMultiplier)
name - the source and sequence namesequenceMultiplier - the sequence multiplierglobalMultiplier - the global multiplierpublic ObjectSequenceId(String name)
name - the source namepublic boolean isLockFree()
IdSourcepublic long nextId(Db db)
IdSourcedb - the current db connection to be checked against getDb()protected long addGlobalOffset(long nextId)
nextId - the computed new id
Copyright © 2016 Krake Softwaretechnik. All rights reserved.