Class SequenceStyleGenerator
- All Implemented Interfaces:
Serializable
,ExportableProducer
,BeforeExecutionGenerator
,Generator
,BulkInsertionCapableIdentifierGenerator
,Configurable
,IdentifierGenerator
,OptimizableGenerator
,PersistentIdentifierGenerator
- Direct Known Subclasses:
OrderedSequenceGenerator
DatabaseStructure
interface internally.
Parameter name | Default value | Interpretation |
"sequence_name" | The name of the sequence/table to use to store/retrieve values | |
"initial_value" | 1 | The initial value to be stored for the given segment;
the effect in terms of storage varies based on Optimizer
and DatabaseStructure |
"increment_size" | 50 | The increment size for the underlying segment;
the effect in terms of storage varies based on Optimizer
and DatabaseStructure |
"optimizer" | depends on defined increment size | Allows explicit definition of which optimization strategy to use |
"force_table_use" | false |
Allows explicit definition of which optimization strategy to use |
Configuration parameters used specifically when the underlying structure is a table:
Parameter name | Default value | Interpretation |
"value_column" | "next_val" | The name of column which holds the sequence value for the given segment |
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
Specifies the suffix to use for an implicit sequence name - appended to the entity-name / collection-rolestatic final String
The default value forCONFIG_SEQUENCE_PER_ENTITY_SUFFIX
static final String
The default value forVALUE_COLUMN_PARAM
static final String
A flag to force using a table as the underlying structure rather than a sequence.static final String
Indicates the name of the sequence (or table) to use.static final String
Indicates the name of the column holding the identifier values.Fields inherited from interface org.hibernate.id.IdentifierGenerator
CONTRIBUTOR_NAME, ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME
Fields inherited from interface org.hibernate.id.OptimizableGenerator
DEFAULT_INCREMENT_SIZE, DEFAULT_INITIAL_VALUE, IMPLICIT_NAME_BASE, INCREMENT_PARAM, INITIAL_PARAM, OPT_PARAM
Fields inherited from interface org.hibernate.id.PersistentIdentifierGenerator
CATALOG, IDENTIFIER_NORMALIZER, OPTIONS, PK, SCHEMA, TABLE, TABLES
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyConfiguration
(SequenceGenerator generatorConfig, BiConsumer<String, String> configCollector) protected DatabaseStructure
buildDatabaseStructure
(Type type, Properties params, JdbcEnvironment jdbcEnvironment, boolean forceTableUse, QualifiedName sequenceName, int initialValue, int incrementSize) Build the database structure.protected DatabaseStructure
buildSequenceStructure
(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) protected DatabaseStructure
buildTableStructure
(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) void
configure
(GeneratorCreationContext creationContext, Properties parameters) Configure this instance, given the value of parameters specified by the user as XML<param>
elements and@Parameter
annotations.protected int
determineAdjustedIncrementSize
(OptimizerDescriptor optimizationStrategy, int incrementSize) In certain cases we need to adjust the increment size based on the selected optimizer.Return the select expression fragment, if any, that generates the identifier values.protected int
determineIncrementSize
(Properties params) Determine the increment size to be applied.protected int
determineInitialValue
(Properties params) Determine the initial sequence value to use.protected OptimizerDescriptor
determineOptimizationStrategy
(Properties params, int incrementSize) Determine the optimizer to use.protected QualifiedName
determineSequenceName
(Properties params, JdbcEnvironment jdbcEnv, ServiceRegistry serviceRegistry) Determine the name of the sequence (or table if this resolves to a physical table) to use.protected Identifier
determineValueColumnName
(Properties params, JdbcEnvironment jdbcEnvironment) Determine the name of the column used to store the generator value in the db.generate
(SharedSessionContractImplementor session, Object object) Generate a new identifier.Getter for property 'databaseStructure'.Getter for property 'identifierType'.Getter for property 'optimizer'.void
initialize
(SqlStringGenerationContext context) Initializes this instance, pre-generating SQL if necessary.protected boolean
isPhysicalSequence
(JdbcEnvironment jdbcEnvironment, boolean forceTableUse) void
registerExportables
(Database database) Register database objects used by this identifier generator, for example, a sequence or tables.boolean
Given the configuration of this generator, is identifier generation as part of bulk insertion supported?Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hibernate.generator.BeforeExecutionGenerator
generatedOnExecution
Methods inherited from interface org.hibernate.generator.Generator
allowAssignedIdentifiers, allowMutation, generatedBeforeExecution, generatedOnExecution, generatesOnInsert, generatesOnUpdate, generatesSometimes
Methods inherited from interface org.hibernate.id.IdentifierGenerator
configure, generate, getEventTypes
-
Field Details
-
SEQUENCE_PARAM
Indicates the name of the sequence (or table) to use. The implicit value is based on the entity / collection-role name- See Also:
-
ALT_SEQUENCE_PARAM
- See Also:
-
CONFIG_SEQUENCE_PER_ENTITY_SUFFIX
Specifies the suffix to use for an implicit sequence name - appended to the entity-name / collection-role- See Also:
-
DEF_SEQUENCE_SUFFIX
The default value forCONFIG_SEQUENCE_PER_ENTITY_SUFFIX
- See Also:
-
FORCE_TBL_PARAM
A flag to force using a table as the underlying structure rather than a sequence.- See Also:
-
VALUE_COLUMN_PARAM
Indicates the name of the column holding the identifier values. The default value is "next_val"- See Also:
-
DEF_VALUE_COLUMN
The default value forVALUE_COLUMN_PARAM
- See Also:
-
-
Constructor Details
-
SequenceStyleGenerator
public SequenceStyleGenerator()
-
-
Method Details
-
getDatabaseStructure
Getter for property 'databaseStructure'.- Returns:
- Value for property 'databaseStructure'.
-
getOptimizer
Getter for property 'optimizer'.- Specified by:
getOptimizer
in interfaceOptimizableGenerator
- Returns:
- Value for property 'optimizer'.
-
getIdentifierType
Getter for property 'identifierType'.- Returns:
- Value for property 'identifierType'.
-
configure
public void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException Description copied from interface:Configurable
Configure this instance, given the value of parameters specified by the user as XML<param>
elements and@Parameter
annotations.This method is called just once, following instantiation. If this instance also implements
ExportableProducer
, then this method is always called beforeExportableProducer.registerExportables(Database)
,- Specified by:
configure
in interfaceConfigurable
- Parameters:
creationContext
- Access to the generator creation contextparameters
- param values, keyed by parameter name- Throws:
MappingException
- when there's something wrong with the given parameters
-
registerExportables
Description copied from interface:IdentifierGenerator
Register database objects used by this identifier generator, for example, a sequence or tables.This method is called just once, after
Configurable.configure(GeneratorCreationContext, Properties)
.- Specified by:
registerExportables
in interfaceExportableProducer
- Specified by:
registerExportables
in interfaceIdentifierGenerator
- Parameters:
database
- The database instance
-
initialize
Description copied from interface:Configurable
Initializes this instance, pre-generating SQL if necessary.If this instance also implements
ExportableProducer
, then this method is always called afterExportableProducer.registerExportables(Database)
, and before first use.- Specified by:
initialize
in interfaceConfigurable
- Parameters:
context
- A context to help generate SQL strings
-
determineSequenceName
protected QualifiedName determineSequenceName(Properties params, JdbcEnvironment jdbcEnv, ServiceRegistry serviceRegistry) Determine the name of the sequence (or table if this resolves to a physical table) to use.Called during configuration.
- Parameters:
params
- The params supplied in the generator config (plus some standard useful extras).jdbcEnv
- The JdbcEnvironment- Returns:
- The sequence name
-
determineValueColumnName
Determine the name of the column used to store the generator value in the db.Called during configuration when resolving to a physical table.
- Parameters:
params
- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment
- The JDBC environment- 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 during configuration.
- 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 the optimizer being used.Called during configuration.
- 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 during configuration.
- Parameters:
params
- The params supplied in the generator config (plus some standard useful extras).incrementSize
- Thedetermined increment size
- Returns:
- The optimizer strategy (name)
-
determineAdjustedIncrementSize
protected int determineAdjustedIncrementSize(OptimizerDescriptor optimizationStrategy, int incrementSize) 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, JdbcEnvironment jdbcEnvironment, boolean forceTableUse, QualifiedName 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).jdbcEnvironment
- The JDBC environment in which the sequence will be 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).
-
isPhysicalSequence
-
buildSequenceStructure
protected DatabaseStructure buildSequenceStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) -
buildTableStructure
protected DatabaseStructure buildTableStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) -
supportsBulkInsertionIdentifierGeneration
public boolean supportsBulkInsertionIdentifierGeneration()Description copied from interface:BulkInsertionCapableIdentifierGenerator
Given the configuration of this generator, is identifier generation as part of bulk insertion supported?- Specified by:
supportsBulkInsertionIdentifierGeneration
in interfaceBulkInsertionCapableIdentifierGenerator
- Returns:
true
if bulk insertions are supported;false
otherwise.
-
determineBulkInsertionIdentifierGenerationSelectFragment
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) Description copied from interface:BulkInsertionCapableIdentifierGenerator
Return the select expression fragment, if any, that generates the identifier values.- Specified by:
determineBulkInsertionIdentifierGenerationSelectFragment
in interfaceBulkInsertionCapableIdentifierGenerator
- Returns:
- The identifier value generation fragment (SQL).
null
indicates that no fragment is needed.
-
applyConfiguration
public static void applyConfiguration(SequenceGenerator generatorConfig, BiConsumer<String, String> configCollector)
-