类 SequenceStyleGenerator
- java.lang.Object
-
- org.hibernate.id.enhanced.SequenceStyleGenerator
-
- 所有已实现的接口:
ExportableProducer,BulkInsertionCapableIdentifierGenerator,Configurable,IdentifierGenerator,PersistentIdentifierGenerator
public class SequenceStyleGenerator extends Object implements PersistentIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, Configurable
Generates identifier values based on a sequence-style database structure. Variations range from actually using a sequence to using a table to mimic a sequence. These variations are encapsulated by theDatabaseStructureinterface internally. NOTE that by default we utilize a single database sequence for all generators. The configuration parameterCONFIG_PREFER_SEQUENCE_PER_ENTITYcan be used to create dedicated sequence for each entity based on its name. Sequence suffix can be controlled withCONFIG_SEQUENCE_PER_ENTITY_SUFFIXoption. General configuration parameters:
Configuration parameters used specifically when the underlying structure is a table:NAME DEFAULT DESCRIPTION SEQUENCE_PARAMDEF_SEQUENCE_NAMEThe name of the sequence/table to use to store/retrieve values INITIAL_PARAMDEFAULT_INITIAL_VALUEThe initial value to be stored for the given segment; the effect in terms of storage varies based on OptimizerandDatabaseStructureINCREMENT_PARAMDEFAULT_INCREMENT_SIZEThe increment size for the underlying segment; the effect in terms of storage varies based on OptimizerandDatabaseStructureOPT_PARAMdepends on defined increment size Allows explicit definition of which optimization strategy to use FORCE_TBL_PARAMfalse Allows explicit definition of which optimization strategy to use NAME DEFAULT DESCRIPTION VALUE_COLUMN_PARAMDEF_VALUE_COLUMNThe name of column which holds the sequence value for the given segment - 作者:
- Steve Ebersole, Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringCONFIG_PREFER_SEQUENCE_PER_ENTITYUsed to create dedicated sequence for each entity based on the entity name.static StringCONFIG_SEQUENCE_PER_ENTITY_SUFFIXIndicates the suffix to use in naming the identifier sequence/table name, by appending the suffix to the name of the entity.static StringDEF_SEQUENCE_NAMEThe default value forSEQUENCE_PARAM, in the absence of anyCONFIG_PREFER_SEQUENCE_PER_ENTITYsetting.static StringDEF_SEQUENCE_SUFFIXThe default value forCONFIG_SEQUENCE_PER_ENTITY_SUFFIXstatic StringDEF_VALUE_COLUMNThe default value forVALUE_COLUMN_PARAMstatic intDEFAULT_INCREMENT_SIZEThe default value forINCREMENT_PARAMstatic intDEFAULT_INITIAL_VALUEThe default value forINITIAL_PARAMstatic StringFORCE_TBL_PARAMA flag to force using a table as the underlying structure rather than a sequence.static StringINCREMENT_PARAMIndicates the increment size to use.static StringINITIAL_PARAMIndicates the initial value to use.static StringOPT_PARAMIndicates the optimizer to use, either naming aOptimizerimplementation class or naming aStandardOptimizerDescriptorby namestatic StringSEQUENCE_PARAMIndicates the name of the sequence (or table) to use.static StringVALUE_COLUMN_PARAMIndicates the name of the column holding the identifier values.-
从接口继承的字段 org.hibernate.id.IdentifierGenerator
ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME
-
从接口继承的字段 org.hibernate.id.PersistentIdentifierGenerator
CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, TABLE, TABLES
-
-
构造器概要
构造器 构造器 说明 SequenceStyleGenerator()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected DatabaseStructurebuildDatabaseStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, boolean forceTableUse, QualifiedName sequenceName, int initialValue, int incrementSize)Build the database structure.protected DatabaseStructurebuildSequenceStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize)protected DatabaseStructurebuildTableStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize)voidconfigure(Type type, Properties params, ServiceRegistry serviceRegistry)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.StringdetermineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect)Return the select expression fragment, if any, that generates the identifier values.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 QualifiedNamedetermineSequenceName(Properties params, Dialect dialect, JdbcEnvironment jdbcEnv, ServiceRegistry serviceRegistry)Determine the name of the sequence (or table if this resolves to a physical table) to use.protected IdentifierdetermineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment)Determine the name of the column used to store the generator value in the db.Serializablegenerate(SharedSessionContractImplementor session, Object object)Generate a new identifier.ObjectgeneratorKey()Return a key unique to the underlying database objects.DatabaseStructuregetDatabaseStructure()Getter for property 'databaseStructure'.TypegetIdentifierType()Getter for property 'identifierType'.OptimizergetOptimizer()Getter for property 'optimizer'.protected booleanisPhysicalSequence(JdbcEnvironment jdbcEnvironment, boolean forceTableUse)voidregisterExportables(Database database)Register the contained exportable things to theDatabaseString[]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.booleansupportsBulkInsertionIdentifierGeneration()Given the configuration of this generator, is identifier generation as part of bulk insertion supported?-
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
从接口继承的方法 org.hibernate.id.IdentifierGenerator
supportsJdbcBatchInserts
-
-
-
-
字段详细资料
-
SEQUENCE_PARAM
public static final String SEQUENCE_PARAM
Indicates the name of the sequence (or table) to use. The default value isDEF_SEQUENCE_NAME, althoughCONFIG_PREFER_SEQUENCE_PER_ENTITYeffects the default as well.- 另请参阅:
- 常量字段值
-
DEF_SEQUENCE_NAME
public static final String DEF_SEQUENCE_NAME
The default value forSEQUENCE_PARAM, in the absence of anyCONFIG_PREFER_SEQUENCE_PER_ENTITYsetting.- 另请参阅:
- 常量字段值
-
INITIAL_PARAM
public static final String INITIAL_PARAM
Indicates the initial value to use. The default value isDEFAULT_INITIAL_VALUE- 另请参阅:
- 常量字段值
-
DEFAULT_INITIAL_VALUE
public static final int DEFAULT_INITIAL_VALUE
The default value forINITIAL_PARAM- 另请参阅:
- 常量字段值
-
INCREMENT_PARAM
public static final String INCREMENT_PARAM
Indicates the increment size to use. The default value isDEFAULT_INCREMENT_SIZE- 另请参阅:
- 常量字段值
-
DEFAULT_INCREMENT_SIZE
public static final int DEFAULT_INCREMENT_SIZE
The default value forINCREMENT_PARAM- 另请参阅:
- 常量字段值
-
CONFIG_PREFER_SEQUENCE_PER_ENTITY
public static final String CONFIG_PREFER_SEQUENCE_PER_ENTITY
Used to create dedicated sequence for each entity based on the entity name. Sequence suffix can be controlled withCONFIG_SEQUENCE_PER_ENTITY_SUFFIXoption.- 另请参阅:
- 常量字段值
-
CONFIG_SEQUENCE_PER_ENTITY_SUFFIX
public static final String CONFIG_SEQUENCE_PER_ENTITY_SUFFIX
Indicates the suffix to use in naming the identifier sequence/table name, by appending the suffix to the name of the entity. Used in conjunction withCONFIG_PREFER_SEQUENCE_PER_ENTITY.- 另请参阅:
- 常量字段值
-
DEF_SEQUENCE_SUFFIX
public static final String DEF_SEQUENCE_SUFFIX
The default value forCONFIG_SEQUENCE_PER_ENTITY_SUFFIX- 另请参阅:
- 常量字段值
-
OPT_PARAM
public static final String OPT_PARAM
Indicates the optimizer to use, either naming aOptimizerimplementation class or naming aStandardOptimizerDescriptorby name- 另请参阅:
- 常量字段值
-
FORCE_TBL_PARAM
public static final String FORCE_TBL_PARAM
A flag to force using a table as the underlying structure rather than a sequence.- 另请参阅:
- 常量字段值
-
VALUE_COLUMN_PARAM
public static final String VALUE_COLUMN_PARAM
Indicates the name of the column holding the identifier values. The default value isDEF_VALUE_COLUMN- 另请参阅:
- 常量字段值
-
DEF_VALUE_COLUMN
public static final String DEF_VALUE_COLUMN
The default value forVALUE_COLUMN_PARAM- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
getDatabaseStructure
public DatabaseStructure getDatabaseStructure()
Getter for property 'databaseStructure'.- 返回:
- Value for property 'databaseStructure'.
-
getOptimizer
public Optimizer getOptimizer()
Getter for property 'optimizer'.- 返回:
- Value for property 'optimizer'.
-
getIdentifierType
public Type getIdentifierType()
Getter for property 'identifierType'.- 返回:
- Value for property 'identifierType'.
-
configure
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException
从接口复制的说明:ConfigurableConfigure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.- 指定者:
configure在接口中Configurable- 参数:
type- The id property type descriptorparams- param values, keyed by parameter nameserviceRegistry- Access to service that may be needed.- 抛出:
MappingException
-
determineSequenceName
protected QualifiedName determineSequenceName(Properties params, Dialect dialect, JdbcEnvironment jdbcEnv, ServiceRegistry serviceRegistry)
Determine the name of the sequence (or table if this resolves to a physical table) to use. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).dialect- The dialect in effectjdbcEnv- The JdbcEnvironment- 返回:
- The sequence name
-
determineValueColumnName
protected Identifier determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment)
Determine the name of the column used to store the generator value in the db. Called duringconfigurationwhen resolving to a physical table.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment- The JDBC environment- 返回:
- The value column name
-
determineInitialValue
protected int determineInitialValue(Properties params)
Determine the initial sequence value to use. This value is used when initializing thedatabase structure(i.e. sequence/table). Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).- 返回:
- The initial value
-
determineIncrementSize
protected int determineIncrementSize(Properties params)
Determine the increment size to be applied. The exact implications of this value depends on theoptimizerbeing used. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).- 返回:
- The increment size
-
determineOptimizationStrategy
protected String determineOptimizationStrategy(Properties params, int incrementSize)
Determine the optimizer to use. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).incrementSize- Thedetermined increment size- 返回:
- The optimizer strategy (name)
-
determineAdjustedIncrementSize
protected int determineAdjustedIncrementSize(String 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.- 参数:
optimizationStrategy- The optimizer strategy (name)incrementSize- Thedetermined increment size- 返回:
- 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.- 参数:
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).- 返回:
- An abstraction for the actual database structure in use (table vs. sequence).
-
isPhysicalSequence
protected boolean isPhysicalSequence(JdbcEnvironment jdbcEnvironment, boolean forceTableUse)
-
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)
-
generate
public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException
从接口复制的说明:IdentifierGeneratorGenerate a new identifier.- 指定者:
generate在接口中IdentifierGenerator- 参数:
session- The session from which the request originatesobject- the entity or collection (idbag) for which the id is being generated- 返回:
- a new identifier
- 抛出:
HibernateException- Indicates trouble generating the identifier
-
generatorKey
public Object generatorKey()
从接口复制的说明:PersistentIdentifierGeneratorReturn a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.- 指定者:
generatorKey在接口中PersistentIdentifierGenerator- 返回:
- Object an identifying key for this generator
-
sqlCreateStrings
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException
从接口复制的说明:PersistentIdentifierGeneratorThe SQL required to create the underlying database objects.- 指定者:
sqlCreateStrings在接口中PersistentIdentifierGenerator- 参数:
dialect- The dialect against which to generate the create command(s)- 返回:
- The create command(s)
- 抛出:
HibernateException- problem creating the create command(s)
-
sqlDropStrings
public String[] sqlDropStrings(Dialect dialect) throws HibernateException
从接口复制的说明:PersistentIdentifierGeneratorThe SQL required to remove the underlying database objects.- 指定者:
sqlDropStrings在接口中PersistentIdentifierGenerator- 参数:
dialect- The dialect against which to generate the drop command(s)- 返回:
- The drop command(s)
- 抛出:
HibernateException- problem creating the drop command(s)
-
supportsBulkInsertionIdentifierGeneration
public boolean supportsBulkInsertionIdentifierGeneration()
从接口复制的说明:BulkInsertionCapableIdentifierGeneratorGiven the configuration of this generator, is identifier generation as part of bulk insertion supported? IMPL NOTE : Mainly here to allow stuff like SequenceStyleGenerator which *can* support this based on configuration- 指定者:
supportsBulkInsertionIdentifierGeneration在接口中BulkInsertionCapableIdentifierGenerator- 返回:
trueif bulk insertions are supported;falseotherwise.
-
determineBulkInsertionIdentifierGenerationSelectFragment
public String determineBulkInsertionIdentifierGenerationSelectFragment(Dialect dialect)
从接口复制的说明:BulkInsertionCapableIdentifierGeneratorReturn the select expression fragment, if any, that generates the identifier values.- 指定者:
determineBulkInsertionIdentifierGenerationSelectFragment在接口中BulkInsertionCapableIdentifierGenerator- 参数:
dialect- The dialect against which the insert will be performed.- 返回:
- The identifier value generation fragment (SQL).
nullindicates that no fragment is needed.
-
registerExportables
public void registerExportables(Database database)
从接口复制的说明:ExportableProducerRegister the contained exportable things to theDatabase- 指定者:
registerExportables在接口中ExportableProducer- 参数:
database- The database instance
-
-