类 TableGenerator
- java.lang.Object
-
- org.hibernate.id.enhanced.TableGenerator
-
public class TableGenerator extends Object implements PersistentIdentifierGenerator, Configurable
An enhanced version of table-based id generation. Unlike the simplistic legacy one (which, btw, was only ever intended for subclassing support) we "segment" the table into multiple values. Thus a single table can actually serve as the persistent storage for multiple independent generators. One approach would be to segment the values by the name of the entity for which we are performing generation, which would mean that we would have a row in the generator table for each entity name. Or any configuration really; the setup is very flexible. In this respect it is very similar to the legacyMultipleHiLoPerTableGeneratorin terms of the underlying storage structure (namely a single table capable of holding multiple generator values). The differentiator is, as withSequenceStyleGeneratoras well, the externalized notion of an optimizer. NOTE that by default we use a single row for all generators (based onDEF_SEGMENT_VALUE). The configuration parameterCONFIG_PREFER_SEGMENT_PER_ENTITYcan be used to change that to instead default to using a row for each entity name. Configuration parameters:NAME DEFAULT DESCRIPTION TABLE_PARAMDEF_TABLEThe name of the table to use to store/retrieve values VALUE_COLUMN_PARAMDEF_VALUE_COLUMNThe name of column which holds the sequence value for the given segment SEGMENT_COLUMN_PARAMDEF_SEGMENT_COLUMNThe name of the column which holds the segment key SEGMENT_VALUE_PARAMDEF_SEGMENT_VALUEThe value indicating which segment is used by this generator; refers to values in the SEGMENT_COLUMN_PARAMcolumnSEGMENT_LENGTH_PARAMDEF_SEGMENT_LENGTHThe data length of the SEGMENT_COLUMN_PARAMcolumn; used for schema creationINITIAL_PARAMDEFAULT_INITIAL_VALUEThe initial value to be stored for the given segment INCREMENT_PARAMDEFAULT_INCREMENT_SIZEThe increment size for the underlying segment; see the discussion on Optimizerfor more details.OPT_PARAMdepends on defined increment size Allows explicit definition of which optimization strategy to use - 作者:
- Steve Ebersole
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringCONFIG_PREFER_SEGMENT_PER_ENTITYBy default (in the absence of aSEGMENT_VALUE_PARAMsetting) we use a single row for all generators.static StringDEF_SEGMENT_COLUMNThe defaultSEGMENT_COLUMN_PARAMvaluestatic intDEF_SEGMENT_LENGTHThe defaultSEGMENT_LENGTH_PARAMvaluestatic StringDEF_SEGMENT_VALUEThe defaultSEGMENT_VALUE_PARAMvalue, unlessCONFIG_PREFER_SEGMENT_PER_ENTITYis specifiedstatic StringDEF_TABLEThe defaultTABLE_PARAMvaluestatic StringDEF_VALUE_COLUMNThe defaultVALUE_COLUMN_PARAMvaluestatic intDEFAULT_INCREMENT_SIZEThe defaultINCREMENT_PARAMvaluestatic intDEFAULT_INITIAL_VALUEThe defaultINITIAL_PARAMvaluestatic 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 by naming aStandardOptimizerDescriptorby namestatic StringSEGMENT_COLUMN_PARAMThe name of the column which holds the segment key.static StringSEGMENT_LENGTH_PARAMIndicates the length of the column defined bySEGMENT_COLUMN_PARAM.static StringSEGMENT_VALUE_PARAMThe value indicating which segment is used by this generator, as indicated by the actual value stored in the column indicated bySEGMENT_COLUMN_PARAM.static StringTABLE_PARAMConfigures the name of the table to use.static StringVALUE_COLUMN_PARAMThe name of column which holds the sequence value.-
从接口继承的字段 org.hibernate.id.IdentifierGenerator
ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME
-
从接口继承的字段 org.hibernate.id.PersistentIdentifierGenerator
CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, TABLE, TABLES
-
-
构造器概要
构造器 构造器 说明 TableGenerator()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected StringbuildInsertQuery()protected StringbuildSelectQuery(Dialect dialect)protected StringbuildUpdateQuery()voidconfigure(Type type, Properties params, ServiceRegistry serviceRegistry)Configure this instance, given the value of parameters specified by the user as <param> elements.protected StringdetermineDefaultSegmentValue(Properties params)Used in the cases wheredetermineSegmentValue(java.util.Properties)is unable to determine the value to use.protected QualifiedNamedetermineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry)Determine the table name to use for the generator values.protected intdetermineIncrementSize(Properties params)protected intdetermineInitialValue(Properties params)protected StringdetermineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment)Determine the name of the column used to indicate the segment for each row.protected intdetermineSegmentColumnSize(Properties params)Determine the size of thesegment columnprotected StringdetermineSegmentValue(Properties params)Determine the segment value corresponding to this generator instance.protected StringdetermineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment)Determine the name of the column in which we will store the generator persistent value.Serializablegenerate(SharedSessionContractImplementor session, Object obj)Generate a new identifier.protected InitCommandgenerateInsertInitCommand()ObjectgeneratorKey()Return a key unique to the underlying database objects.TypegetIdentifierType()Type mapping for the identifier.intgetIncrementSize()The amount of increment to use.intgetInitialValue()The initial value to use when we find no previous state in the generator table corresponding to our sequence.OptimizergetOptimizer()The optimizer being used by this generator.StringgetSegmentColumnName()The name of the column in which we store the segment to which each row belongs.StringgetSegmentValue()The value insegment columncorresponding to this generator instance.intgetSegmentValueLength()The size of thesegment columnin the underlying table.longgetTableAccessCount()Getter for property 'tableAccessCount'.StringgetTableName()The name of the table in which we store this generator's persistent state.StringgetValueColumnName()The name of the column in which we store our persistent generator value.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.-
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
从接口继承的方法 org.hibernate.id.IdentifierGenerator
supportsJdbcBatchInserts
-
-
-
-
字段详细资料
-
CONFIG_PREFER_SEGMENT_PER_ENTITY
public static final String CONFIG_PREFER_SEGMENT_PER_ENTITY
By default (in the absence of aSEGMENT_VALUE_PARAMsetting) we use a single row for all generators. This setting can be used to change that to instead default to using a row for each entity name.- 另请参阅:
- 常量字段值
-
TABLE_PARAM
public static final String TABLE_PARAM
Configures the name of the table to use. The default value isDEF_TABLE- 另请参阅:
- 常量字段值
-
DEF_TABLE
public static final String DEF_TABLE
The defaultTABLE_PARAMvalue- 另请参阅:
- 常量字段值
-
VALUE_COLUMN_PARAM
public static final String VALUE_COLUMN_PARAM
The name of column which holds the sequence value. The default value isDEF_VALUE_COLUMN- 另请参阅:
- 常量字段值
-
DEF_VALUE_COLUMN
public static final String DEF_VALUE_COLUMN
The defaultVALUE_COLUMN_PARAMvalue- 另请参阅:
- 常量字段值
-
SEGMENT_COLUMN_PARAM
public static final String SEGMENT_COLUMN_PARAM
The name of the column which holds the segment key. The segment defines the different buckets (segments) of values currently tracked in the table. The default value isDEF_SEGMENT_COLUMN- 另请参阅:
- 常量字段值
-
DEF_SEGMENT_COLUMN
public static final String DEF_SEGMENT_COLUMN
The defaultSEGMENT_COLUMN_PARAMvalue- 另请参阅:
- 常量字段值
-
SEGMENT_VALUE_PARAM
public static final String SEGMENT_VALUE_PARAM
The value indicating which segment is used by this generator, as indicated by the actual value stored in the column indicated bySEGMENT_COLUMN_PARAM. The default value for setting isDEF_SEGMENT_VALUE, althoughCONFIG_PREFER_SEGMENT_PER_ENTITYeffects the default as well.- 另请参阅:
- 常量字段值
-
DEF_SEGMENT_VALUE
public static final String DEF_SEGMENT_VALUE
The defaultSEGMENT_VALUE_PARAMvalue, unlessCONFIG_PREFER_SEGMENT_PER_ENTITYis specified- 另请参阅:
- 常量字段值
-
SEGMENT_LENGTH_PARAM
public static final String SEGMENT_LENGTH_PARAM
Indicates the length of the column defined bySEGMENT_COLUMN_PARAM. Used in schema export. The default value isDEF_SEGMENT_LENGTH- 另请参阅:
- 常量字段值
-
DEF_SEGMENT_LENGTH
public static final int DEF_SEGMENT_LENGTH
The defaultSEGMENT_LENGTH_PARAMvalue- 另请参阅:
- 常量字段值
-
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 defaultINITIAL_PARAMvalue- 另请参阅:
- 常量字段值
-
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 defaultINCREMENT_PARAMvalue- 另请参阅:
- 常量字段值
-
OPT_PARAM
public static final String OPT_PARAM
Indicates the optimizer to use, either naming aOptimizerimplementation class or by naming aStandardOptimizerDescriptorby name- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
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
-
getIdentifierType
public final Type getIdentifierType()
Type mapping for the identifier.- 返回:
- The identifier type mapping.
-
getTableName
public final String getTableName()
The name of the table in which we store this generator's persistent state.- 返回:
- The table name.
-
getSegmentColumnName
public final String getSegmentColumnName()
The name of the column in which we store the segment to which each row belongs. The value here acts as PK.- 返回:
- The segment column name
-
getSegmentValue
public final String getSegmentValue()
The value insegment columncorresponding to this generator instance. In other words this value indicates the row in which this generator instance will store values.- 返回:
- The segment value for this generator instance.
-
getSegmentValueLength
public final int getSegmentValueLength()
The size of thesegment columnin the underlying table. NOTE : should really have been called 'segmentColumnLength' or even better 'segmentColumnSize'- 返回:
- the column size.
-
getValueColumnName
public final String getValueColumnName()
The name of the column in which we store our persistent generator value.- 返回:
- The name of the value column.
-
getInitialValue
public final int getInitialValue()
The initial value to use when we find no previous state in the generator table corresponding to our sequence.- 返回:
- The initial value to use.
-
getIncrementSize
public final int getIncrementSize()
The amount of increment to use. The exact implications of this depends on theoptimizerbeing used.- 返回:
- The increment amount.
-
getOptimizer
public final Optimizer getOptimizer()
The optimizer being used by this generator.- 返回:
- Out optimizer.
-
getTableAccessCount
public final long getTableAccessCount()
Getter for property 'tableAccessCount'. Only really useful for unit test assertions.- 返回:
- Value for property 'tableAccessCount'.
-
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
-
determineGeneratorTableName
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry)
Determine the table name to use for the generator values. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment- The JDBC environment- 返回:
- The table name to use.
- 另请参阅:
getTableName()
-
determineSegmentColumnName
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment)
Determine the name of the column used to indicate the segment for each row. This column acts as the primary key. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment- The JDBC environment- 返回:
- The name of the segment column
- 另请参阅:
getSegmentColumnName()
-
determineValueColumnName
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment)
Determine the name of the column in which we will store the generator persistent value. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment- The JDBC environment- 返回:
- The name of the value column
- 另请参阅:
getValueColumnName()
-
determineSegmentValue
protected String determineSegmentValue(Properties params)
Determine the segment value corresponding to this generator instance. Called duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).- 返回:
- The name of the value column
- 另请参阅:
getSegmentValue()
-
determineDefaultSegmentValue
protected String determineDefaultSegmentValue(Properties params)
Used in the cases wheredetermineSegmentValue(java.util.Properties)is unable to determine the value to use.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).- 返回:
- The default segment value to use.
-
determineSegmentColumnSize
protected int determineSegmentColumnSize(Properties params)
Determine the size of thesegment columnCalled duringconfiguration.- 参数:
params- The params supplied in the generator config (plus some standard useful extras).- 返回:
- The size of the segment column
- 另请参阅:
getSegmentValueLength()
-
determineInitialValue
protected int determineInitialValue(Properties params)
-
determineIncrementSize
protected int determineIncrementSize(Properties params)
-
buildUpdateQuery
protected String buildUpdateQuery()
-
buildInsertQuery
protected String buildInsertQuery()
-
generateInsertInitCommand
protected InitCommand generateInsertInitCommand()
-
generate
public Serializable generate(SharedSessionContractImplementor session, Object obj)
从接口复制的说明:IdentifierGeneratorGenerate a new identifier.- 指定者:
generate在接口中IdentifierGenerator- 参数:
session- The session from which the request originatesobj- the entity or collection (idbag) for which the id is being generated- 返回:
- a new identifier
-
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)
-
registerExportables
public void registerExportables(Database database)
从接口复制的说明:ExportableProducerRegister the contained exportable things to theDatabase- 指定者:
registerExportables在接口中ExportableProducer- 参数:
database- The database instance
-
-