Class SequenceGenerator
- All Implemented Interfaces:
org.datanucleus.store.valuegenerator.ValueGenerator<Long>
public final class SequenceGenerator
extends org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
ValueGenerator utilising datastore (RDBMS) sequences.
It uses a statement like
"select {sequence}.nextval from dual" to get the next value in the sequence.
It is datastore-dependent since there is no RDBMS-independent statement.
SequenceGenerator works with Longs, so clients using this generator must cast the ID to Long.
Optional user properties
- sequence-catalog-name - catalog for the sequence
- sequence-schema-name - schema for the sequence
- key-initial-value - the initial value for the sequence
- key-cache-size - number of unique identifiers to cache
- key-min-value - determines the minimum value a sequence can generate
- key-max-value - determines the maximum value a sequence can generate
- key-database-cache-size - specifies how many sequence numbers are to be preallocated and stored in memory for faster access
-
Nested Class Summary
Nested classes/interfaces inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator
org.datanucleus.store.valuegenerator.AbstractConnectedGenerator.ConnectionPreference -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.datanucleus.store.connection.ManagedConnectionConnection to the datastore.protected booleanFlag for whether we know that the repository exists.protected StringName of the sequence that we are creating values forFields inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator
connectionProvider, propertiesFields inherited from class org.datanucleus.store.valuegenerator.AbstractGenerator
allocationSize, block, initialValue, name, storeMgrFields inherited from interface org.datanucleus.store.valuegenerator.ValueGenerator
PROPERTY_CATALOG_NAME, PROPERTY_CLASS_NAME, PROPERTY_COLUMN_NAME, PROPERTY_FIELD_NAME, PROPERTY_KEY_CACHE_SIZE, PROPERTY_KEY_DATABASE_CACHE_SIZE, PROPERTY_KEY_INITIAL_VALUE, PROPERTY_KEY_MAX_VALUE, PROPERTY_KEY_MIN_VALUE, PROPERTY_ROOT_CLASS_NAME, PROPERTY_SCHEMA_NAME, PROPERTY_SEQUENCE_NAME, PROPERTY_SEQUENCETABLE_CATALOG, PROPERTY_SEQUENCETABLE_NAME_COLUMN, PROPERTY_SEQUENCETABLE_NEXTVAL_COLUMN, PROPERTY_SEQUENCETABLE_SCHEMA, PROPERTY_SEQUENCETABLE_TABLE, PROPERTY_TABLE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionSequenceGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanMethod to create the sequence.static ClassAccessor for the storage class for values generated with this generator.protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> obtainGenerationBlock(int number) Get a new ValueGenerationBlock with the specified number of ids.protected booleanMethod to return if the repository already exists.protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> reserveBlock(long size) Reserve a block of ids.Methods inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator
getConnectionPreference, setConnectionProviderMethods inherited from class org.datanucleus.store.valuegenerator.AbstractGenerator
allocate, current, currentValue, getName, next, nextValue, obtainGenerationBlock, reserveBlock
-
Field Details
-
connection
protected org.datanucleus.store.connection.ManagedConnection connectionConnection to the datastore. -
repositoryExists
protected boolean repositoryExistsFlag for whether we know that the repository exists. -
sequenceName
Name of the sequence that we are creating values for
-
-
Constructor Details
-
SequenceGenerator
public SequenceGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props) Constructor.- Parameters:
storeMgr- StoreManagername- Symbolic name for the generatorprops- Properties controlling the behaviour of the generator
-
-
Method Details
-
getStorageClass
Accessor for the storage class for values generated with this generator.- Returns:
- Storage class (in this case Long.class)
-
reserveBlock
-
repositoryExists
protected boolean repositoryExists()Method to return if the repository already exists.- Returns:
- Whether the repository exists
-
createRepository
protected boolean createRepository()Method to create the sequence.- Returns:
- Whether it was created successfully.
-
obtainGenerationBlock
protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> obtainGenerationBlock(int number) Get a new ValueGenerationBlock with the specified number of ids.- Overrides:
obtainGenerationBlockin classorg.datanucleus.store.valuegenerator.AbstractGenerator<Long>- Parameters:
number- The number of additional ids required- Returns:
- the ValueGenerationBlock
-