Package org.hibernate.id.enhanced
Class SequenceStyleGenerator
java.lang.Object
org.hibernate.id.enhanced.SequenceStyleGenerator
- All Implemented Interfaces:
Configurable,IdentifierGenerator,PersistentIdentifierGenerator
public class SequenceStyleGenerator
extends Object
implements PersistentIdentifierGenerator, Configurable
Generates identifier values based on an sequence-style database structure.
Variations range from actually using a sequence to using a table to mimic
a sequence. These variations are encapsulated by the
Configuration parameters used specifically when the underlying structure is a table:
DatabaseStructure
interface internally.
General configuration parameters:
| NAME | DEFAULT | DESCRIPTION |
SEQUENCE_PARAM |
DEF_SEQUENCE_NAME |
The name of the sequence/table to use to store/retrieve values |
INITIAL_PARAM |
DEFAULT_INITIAL_VALUE |
The initial value to be stored for the given segment; the effect in terms of storage varies based on Optimizer and DatabaseStructure |
INCREMENT_PARAM |
DEFAULT_INCREMENT_SIZE |
The increment size for the underlying segment; the effect in terms of storage varies based on Optimizer and DatabaseStructure |
OPT_PARAM |
depends on defined increment size | Allows explicit definition of which optimization strategy to use | FORCE_TBL_PARAM |
false | Allows explicit definition of which optimization strategy to use |
| NAME | DEFAULT | DESCRIPTION |
VALUE_COLUMN_PARAM |
DEF_VALUE_COLUMN |
The name of column which holds the sequence value for the given segment |
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final intstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface org.hibernate.id.IdentifierGenerator
ENTITY_NAMEFields inherited from interface org.hibernate.id.PersistentIdentifierGenerator
CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, SQL_STATEMENT_LOGGER, TABLE, TABLES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DatabaseStructurebuildDatabaseStructure(Type type, Properties params, Dialect dialect, boolean forceTableUse, String sequenceName, int initialValue, int incrementSize) Build the database structure.voidconfigure(Type type, Properties params, Dialect dialect) Configure this instance, given the value of parameters specified by the user as <param> elements.protected intdetermineAdjustedIncrementSize(String optimizationStrategy, int incrementSize) In certain cases we need to adjust the increment size based on the selected optimizer.protected intdetermineIncrementSize(Properties params) Determine the increment size to be applied.protected intdetermineInitialValue(Properties params) Determine the initial sequence value to use.protected StringdetermineOptimizationStrategy(Properties params, int incrementSize) Determine the optimizer to use.protected StringdetermineSequenceName(Properties params, Dialect dialect) Determine the name of the sequence (or table if this resolves to a physical table) to use.protected StringdetermineValueColumnName(Properties params, Dialect dialect) Determine the name of the column used to store the generator value in the db.generate(SessionImplementor session, Object object) Generate a new identifier.Return a key unique to the underlying database objects.Getter for property 'databaseStructure'.Getter for property 'identifierType'.Getter for property 'optimizer'.String[]sqlCreateStrings(Dialect dialect) The SQL required to create the underlying database objects.String[]sqlDropStrings(Dialect dialect) The SQL required to remove the underlying database objects.
-
Field Details
-
SEQUENCE_PARAM
- See Also:
-
DEF_SEQUENCE_NAME
- See Also:
-
INITIAL_PARAM
- See Also:
-
DEFAULT_INITIAL_VALUE
public static final int DEFAULT_INITIAL_VALUE- See Also:
-
INCREMENT_PARAM
- See Also:
-
DEFAULT_INCREMENT_SIZE
public static final int DEFAULT_INCREMENT_SIZE- See Also:
-
OPT_PARAM
- See Also:
-
FORCE_TBL_PARAM
- See Also:
-
VALUE_COLUMN_PARAM
- See Also:
-
DEF_VALUE_COLUMN
- See Also:
-
-
Constructor Details
-
SequenceStyleGenerator
public SequenceStyleGenerator()
-
-
Method Details
-
getDatabaseStructure
Getter for property 'databaseStructure'.- Returns:
- Value for property 'databaseStructure'.
-
getOptimizer
Getter for property 'optimizer'.- Returns:
- Value for property 'optimizer'.
-
getIdentifierType
Getter for property 'identifierType'.- Returns:
- Value for property 'identifierType'.
-
configure
Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.- Specified by:
configurein interfaceConfigurable- Parameters:
params- param values, keyed by parameter name- Throws:
MappingException
-
determineSequenceName
Determine the name of the sequence (or table if this resolves to a physical table) to use. Called duringconfiguration.- Parameters:
params- The params supplied in the generator config (plus some standard useful extras).dialect- The dialect in effect- Returns:
- The sequence name
-
determineValueColumnName
Determine the name of the column used to store the generator value in the db. Called duringconfigurationwhen resolving to a physical table.- Parameters:
params- The params supplied in the generator config (plus some standard useful extras).dialect- The dialect in effect.- Returns:
- The value column name
-
determineInitialValue
Determine the initial sequence value to use. This value is used when initializing thedatabase structure(i.e. sequence/table). Called duringconfiguration.- Parameters:
params- The params supplied in the generator config (plus some standard useful extras).- Returns:
- The initial value
-
determineIncrementSize
Determine the increment size to be applied. The exact implications of this value depends on theoptimizerbeing used. Called duringconfiguration.- Parameters:
params- The params supplied in the generator config (plus some standard useful extras).- Returns:
- The increment size
-
determineOptimizationStrategy
Determine the optimizer to use. Called duringconfiguration.- Parameters:
params- The params supplied in the generator config (plus some standard useful extras).incrementSize- Thedetermined increment size- Returns:
- The optimizer strategy (name)
-
determineAdjustedIncrementSize
In certain cases we need to adjust the increment size based on the selected optimizer. This is the hook to achieve that.- Parameters:
optimizationStrategy- The optimizer strategy (name)incrementSize- Thedetermined increment size- Returns:
- The adjusted increment size.
-
buildDatabaseStructure
protected DatabaseStructure buildDatabaseStructure(Type type, Properties params, Dialect dialect, boolean forceTableUse, String sequenceName, int initialValue, int incrementSize) Build the database structure.- Parameters:
type- The Hibernate type of the identifier propertyparams- The params supplied in the generator config (plus some standard useful extras).dialect- The dialect being used.forceTableUse- Should a table be used even if the dialect supports sequences?sequenceName- The name to use for the sequence or table.initialValue- The initial value.incrementSize- the increment size to use (after any adjustments).- Returns:
- An abstraction for the actual database structure in use (table vs. sequence).
-
generate
Generate a new identifier.- Specified by:
generatein interfaceIdentifierGenerator- Parameters:
session-object- the entity or toplevel collection for which the id is being generated- Returns:
- a new identifier
- Throws:
HibernateException
-
generatorKey
Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.- Specified by:
generatorKeyin interfacePersistentIdentifierGenerator- Returns:
- Object an identifying key for this generator
-
sqlCreateStrings
The SQL required to create the underlying database objects.- Specified by:
sqlCreateStringsin interfacePersistentIdentifierGenerator- Parameters:
dialect- The dialect against which to generate the create command(s)- Returns:
- The create command(s)
- Throws:
HibernateException- problem creating the create command(s)
-
sqlDropStrings
The SQL required to remove the underlying database objects.- Specified by:
sqlDropStringsin interfacePersistentIdentifierGenerator- Parameters:
dialect- The dialect against which to generate the drop command(s)- Returns:
- The drop command(s)
- Throws:
HibernateException- problem creating the drop command(s)
-