Class TableGenerator
- All Implemented Interfaces:
org.datanucleus.store.valuegenerator.ValueGenerator<Long>
public final class TableGenerator
extends org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
Identity generator for RDBMS databases that generates ids using a table in the database.
This generator is coupled to core and can't be used in standalone mode.
The following properties define the name of the sequence being generated. If "sequence-name" is specified then it is used. Otherwise the name of the sequence will either be based on the table name or the class name (for what we are generating the ids).
- sequence-name - Name for the sequence
- sequence-table-basis - Basic for the sequence name (if "sequence-name" not provided). This can be "table" or "class".
The following properties define the table where the identities are generated.
- sequence-catalog-name - the catalog name for the table (defaults to the default catalog)
- sequence-schema-name - the schema name for the table (defaults to the default schema)
- sequence-table-name - the table name for the table (defaults to SEQUENCE_TABLE)
- sequence-name-column-name - the name for the column that represent sequence names
- sequence-nextval-column-name - the name for the column that represent incrementing sequence values
The following properties control the initial value, and the number of ids that are cached (generated) in each call.
- key-initial-value - start value (if we have no current value). If not specified and we have no current value then we do a "SELECT max(column-name) FROM table-name" for the column being incremented
- key-cache-size - number of unique identifiers to cache (defaults to 5)
The following properties are used when finding the starting point for the identities generated.
- table-name - name of the table whose column we are generating the value for
- column-name - name of the column that we are generating the value for
-
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.ManagedConnection
Connection to the datastore.static final String
Default name for the column storing the next value of the sequence.static final String
Default name for the column storing the name of the sequence.static final String
Default name for the datastore table storing the sequence values.protected boolean
Flag for whether we know that the repository exists.private final String
Name of the sequence that we are storing values under in the SequenceTable.private SequenceTable
Table where we store the identities for each table.Fields inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator
connectionProvider, properties
Fields inherited from class org.datanucleus.store.valuegenerator.AbstractGenerator
allocationSize, block, initialValue, name, storeMgr
Fields 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
ConstructorsConstructorDescriptionTableGenerator
(org.datanucleus.store.StoreManager storeMgr, String name, Properties props) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Method to create the repository for ids to be stored.static Class
Accessor for the storage class for values generated with this generator.getTable()
Convenience accessor for the table being used.protected void
Method to initialise the sequence table used for storing the sequence values.protected org.datanucleus.store.valuegenerator.ValueGenerationBlock
<Long> obtainGenerationBlock
(int number) Get a new ValueGenerationBlock with the specified number of ids.protected boolean
Method to return if the repository already exists.org.datanucleus.store.valuegenerator.ValueGenerationBlock
<Long> reserveBlock
(long size) Method to reserve a block of "size" identities.Methods inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator
getConnectionPreference, setConnectionProvider
Methods 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. -
sequenceTable
Table where we store the identities for each table. -
sequenceName
Name of the sequence that we are storing values under in the SequenceTable. -
DEFAULT_TABLE_NAME
Default name for the datastore table storing the sequence values. Defaults to SEQUENCE_TABLE- See Also:
-
DEFAULT_SEQUENCE_COLUMN_NAME
Default name for the column storing the name of the sequence.- See Also:
-
DEFAULT_NEXTVALUE_COLUMN_NAME
Default name for the column storing the next value of the sequence.- See Also:
-
-
Constructor Details
-
TableGenerator
Constructor.- Parameters:
storeMgr
- StoreManagername
- Symbolic name for this generatorprops
- Properties defining the behaviour of this generator
-
-
Method Details
-
getStorageClass
Accessor for the storage class for values generated with this generator.- Returns:
- Storage class (in this case Long.class)
-
getTable
Convenience accessor for the table being used.- Returns:
- The table
-
reserveBlock
Method to reserve a block of "size" identities.- Specified by:
reserveBlock
in classorg.datanucleus.store.valuegenerator.AbstractGenerator<Long>
- Parameters:
size
- Block size- Returns:
- The reserved block
-
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 repository for ids to be stored.- Returns:
- Whether it was created successfully.
-
initialiseSequenceTable
protected void initialiseSequenceTable()Method to initialise the sequence table used for storing the sequence values. -
obtainGenerationBlock
protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> obtainGenerationBlock(int number) Get a new ValueGenerationBlock with the specified number of ids.- Overrides:
obtainGenerationBlock
in classorg.datanucleus.store.valuegenerator.AbstractGenerator<Long>
- Parameters:
number
- The number of additional ids required- Returns:
- the ValueGenerationBlock
-