Class TableGenerator
- java.lang.Object
-
- org.datanucleus.store.valuegenerator.AbstractGenerator<T>
-
- org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
-
- org.datanucleus.store.rdbms.valuegenerator.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
-
-
Field Summary
Fields Modifier and Type Field Description protected org.datanucleus.store.connection.ManagedConnection
connection
Connection to the datastore.static String
DEFAULT_NEXTVALUE_COLUMN_NAME
Default name for the column storing the next value of the sequence.static String
DEFAULT_SEQUENCE_COLUMN_NAME
Default name for the column storing the name of the sequence.static String
DEFAULT_TABLE_NAME
Default name for the datastore table storing the sequence values.protected boolean
repositoryExists
Flag for whether we know that the repository exists.-
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
Constructors Constructor Description TableGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
createRepository()
Method to create the repository for ids to be stored.static Class
getStorageClass()
Accessor for the storage class for values generated with this generator.SequenceTable
getTable()
Convenience accessor for the table being used.protected void
initialiseSequenceTable()
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
repositoryExists()
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
-
-
-
-
Field Detail
-
connection
protected org.datanucleus.store.connection.ManagedConnection connection
Connection to the datastore.
-
repositoryExists
protected boolean repositoryExists
Flag for whether we know that the repository exists.
-
DEFAULT_TABLE_NAME
public static final String DEFAULT_TABLE_NAME
Default name for the datastore table storing the sequence values. Defaults to SEQUENCE_TABLE- See Also:
- Constant Field Values
-
DEFAULT_SEQUENCE_COLUMN_NAME
public static final String DEFAULT_SEQUENCE_COLUMN_NAME
Default name for the column storing the name of the sequence.- See Also:
- Constant Field Values
-
DEFAULT_NEXTVALUE_COLUMN_NAME
public static final String DEFAULT_NEXTVALUE_COLUMN_NAME
Default name for the column storing the next value of the sequence.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TableGenerator
public TableGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
Constructor.- Parameters:
storeMgr
- StoreManagername
- Symbolic name for this generatorprops
- Properties defining the behaviour of this generator
-
-
Method Detail
-
getStorageClass
public static Class getStorageClass()
Accessor for the storage class for values generated with this generator.- Returns:
- Storage class (in this case Long.class)
-
getTable
public SequenceTable getTable()
Convenience accessor for the table being used.- Returns:
- The table
-
reserveBlock
public org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> reserveBlock(long size)
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
-
-