Unlike the simplistic legacy one (which 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.
By default, we use a single row for all generators (the default segment). The configuration parameter prefer_entity_table_as_segment_value can be used to change that to instead default to using a row for each entity name.
| Parameter name | Default value | Interpretation |
| table_name | hibernate_sequences | The name of the table to use to store/retrieve values |
| value_column_name | next_val | The name of column which holds the sequence value for the given segment |
| segment_column_name | sequence_name | The name of the column which holds the segment key |
| segment_value | default | The value indicating which segment is used by this generator; refers to values in the segment_column_name column |
| segment_value_length | 255 | The data length of the segment_column_name column; used for schema creation |
| initial_value | 1 | The initial value to be stored for the given segment |
| increment_size | 50 | The increment size for the underlying segment;
see the discussion on Optimizer for more details. |
| optimizer | depends on defined increment size | Allows explicit definition of which optimization strategy to use |
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| public static final String | CONFIG_PREFER_SEGMENT_PER_ENTITY
By default, in the absence of a segment_value setting, we use a single row for all generators. |
| private String | |
| public static final String | DEF_SEGMENT_COLUMN
The default segment_column_name value |
| public static final int | DEF_SEGMENT_LENGTH
The default segment_value_length value |
| public static final String | DEF_SEGMENT_VALUE
The default segment_value value, unless |
| public static final String | DEF_TABLE
The default table_name value |
| public static final String | DEF_VALUE_COLUMN
The default value_column_name value |
| private Type | |
| private int | |
| private int | |
| private String | |
| private static final CoreMessageLogger | |
| private Optimizer | |
| private QualifiedName | |
| private QualifiedName | |
| public static final String | SEGMENT_COLUMN_PARAM
The name of the column which holds the segment key. |
| public static final String | SEGMENT_LENGTH_PARAM
Indicates the length of the column defined by |
| 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 by segment_column_name. |
| private String | |
| private String | |
| private int | |
| private String | |
| private boolean | |
| public static final String | TABLE_PARAM
Configures the name of the table to use. |
| private String | |
| public static final String | VALUE_COLUMN_PARAM
The name of column which holds the sequence value. |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected String | |
| protected String | |
| protected String | |
| public void | configure(Type
The id property type descriptor type, Properties param values, keyed by parameter name parameters, ServiceRegistry Access to service that may be needed. serviceRegistry)Overrides default org. <param> elements.
|
| protected String | Returns: The default segment value to use.The params supplied in the generator config (plus some standard useful extras). params)Used in the cases where |
| protected QualifiedName | Returns: The table name to use.The params supplied in the generator config (plus some standard useful extras). params, JdbcEnvironment The JDBC environment jdbcEnvironment, ServiceRegistry serviceRegistry)Determine the table name to use for the generator values. |
| protected int | |
| protected int | |
| private static OptimizerDescriptor | |
| protected String | Returns: The name of the segment columnThe params supplied in the generator config (plus some standard useful extras). params, JdbcEnvironment The JDBC environment jdbcEnvironment)Determine the name of the column used to indicate the segment for each row. |
| protected int | Returns: The size of the segment columnThe params supplied in the generator config (plus some standard useful extras). params)Determine the size of the Called during configuration. |
| protected String | Returns: The name of the value columnThe params supplied in the generator config (plus some standard useful extras). params)Determine the segment value corresponding to this generator instance. |
| protected String | Returns: The name of the value columnThe params supplied in the generator config (plus some standard useful extras). params, JdbcEnvironment The JDBC environment jdbcEnvironment)Determine the name of the column in which we will store the generator persistent value. |
| private ResultSet | executeQuery(PreparedStatement ps, SessionEventListenerManager listener, String sql, SharedSessionContractImplementor session)
|
| private int | executeUpdate(PreparedStatement ps, SessionEventListenerManager listener, String sql, SharedSessionContractImplementor session)
|
| public Object | generate(final SharedSessionContractImplementor
The session from which the request originates session, final Object the entity or collection (idbag) for which the id is being generated obj)Implements org. |
| protected InitCommand | |
| public String[] | |
| public final Type | |
| public final int | |
| public final int | Returns: The initial value to use.The initial value to use when we find no previous state in the generator table corresponding to our sequence. |
| public final Optimizer | Returns: Out optimizer.Implements org. |
| public final String | Returns: The segment column nameThe name of the column in which we store the segment to which each row belongs. |
| public final String | Returns: The segment value for this generator instance.The value in |
| public final int | Returns: the column size.The size of the |
| public final long | Returns: Value for property 'tableAccessCount'.Getter for property 'tableAccessCount'. |
| public final String | Returns: The table name.The name of the table in which we store this generator's persistent state. |
| public final String | Returns: The name of the value column.The name of the column in which we store our persistent generator value. |
| public void | initialize(SqlStringGenerationContext
A context to help generate SQL strings context)Overrides default org. |
| private IntegralDataTypeHolder | |
| private IntegralDataTypeHolder | nextValue(Connection connection, SqlStatementLogger logger, SessionEventListenerManager listener, SharedSessionContractImplementor session)
|
| private PreparedStatement | prepareStatement(Connection connection, String sql, SqlStatementLogger logger, SessionEventListenerManager listener, SharedSessionContractImplementor session)
|
| public void | registerExportables(Database
The database instance database)Overrides default org. Implements org. |
| accessCount | back to summary |
|---|---|
| private long accessCount | |
| CONFIG_PREFER_SEGMENT_PER_ENTITY | back to summary |
|---|---|
| public static final String CONFIG_PREFER_SEGMENT_PER_ENTITY By default, in the absence of a segment_value setting, 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. | |
| contributor | back to summary |
|---|---|
| private String contributor | |
| DEF_SEGMENT_COLUMN | back to summary |
|---|---|
| public static final String DEF_SEGMENT_COLUMN The default segment_column_name value | |
| DEF_SEGMENT_LENGTH | back to summary |
|---|---|
| public static final int DEF_SEGMENT_LENGTH The default segment_value_length value | |
| DEF_SEGMENT_VALUE | back to summary |
|---|---|
| public static final String DEF_SEGMENT_VALUE The default segment_value value, unless | |
| DEF_TABLE | back to summary |
|---|---|
| public static final String DEF_TABLE The default table_name value | |
| DEF_VALUE_COLUMN | back to summary |
|---|---|
| public static final String DEF_VALUE_COLUMN The default value_column_name value | |
| identifierType | back to summary |
|---|---|
| private Type identifierType | |
| incrementSize | back to summary |
|---|---|
| private int incrementSize | |
| initialValue | back to summary |
|---|---|
| private int initialValue | |
| insertQuery | back to summary |
|---|---|
| private String insertQuery | |
| LOG | back to summary |
|---|---|
| private static final CoreMessageLogger LOG | |
| optimizer | back to summary |
|---|---|
| private Optimizer optimizer | |
| physicalTableName | back to summary |
|---|---|
| private QualifiedName physicalTableName | |
| qualifiedTableName | back to summary |
|---|---|
| private QualifiedName qualifiedTableName | |
| SEGMENT_COLUMN_PARAM | back to summary |
|---|---|
| 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 is sequence_name | |
| SEGMENT_LENGTH_PARAM | back to summary |
|---|---|
| public static final String SEGMENT_LENGTH_PARAM Indicates the length of the column defined by | |
| SEGMENT_VALUE_PARAM | back to summary |
|---|---|
| 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 by segment_column_name. The default value for setting is | |
| segmentColumnName | back to summary |
|---|---|
| private String segmentColumnName | |
| segmentValue | back to summary |
|---|---|
| private String segmentValue | |
| segmentValueLength | back to summary |
|---|---|
| private int segmentValueLength | |
| selectQuery | back to summary |
|---|---|
| private String selectQuery | |
| storeLastUsedValue | back to summary |
|---|---|
| private boolean storeLastUsedValue | |
| TABLE_PARAM | back to summary |
|---|---|
| public static final String TABLE_PARAM Configures the name of the table to use. The default value is hibernate_sequences | |
| updateQuery | back to summary |
|---|---|
| private String updateQuery | |
| VALUE_COLUMN_PARAM | back to summary |
|---|---|
| public static final String VALUE_COLUMN_PARAM The name of column which holds the sequence value. The default value is next_val | |
| valueColumnName | back to summary |
|---|---|
| private String valueColumnName | |
| TableGenerator | back to summary |
|---|---|
| public TableGenerator() | |
| buildInsertQuery | back to summary |
|---|---|
| protected String buildInsertQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) | |
| buildSelectQuery | back to summary |
|---|---|
| protected String buildSelectQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) | |
| buildUpdateQuery | back to summary |
|---|---|
| protected String buildUpdateQuery(String formattedPhysicalTableName, SqlStringGenerationContext context) | |
| configure | back to summary |
|---|---|
| public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException Overrides default org. Doc from org. Configure this instance, given the value of parameters
specified by the user as
This method is called just once, following instantiation,
and before
| |
| determineDefaultSegmentValue | back to summary |
|---|---|
| protected String determineDefaultSegmentValue(Properties params) Used in the cases where
| |
| determineGeneratorTableName | back to summary |
|---|---|
| protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry) Determine the table name to use for the generator values. Called during configuration.
| |
| determineIncrementSize | back to summary |
|---|---|
| protected int determineIncrementSize(Properties params) | |
| determineInitialValue | back to summary |
|---|---|
| protected int determineInitialValue(Properties params) | |
| determineOptimizationStrategy | back to summary |
|---|---|
| private static OptimizerDescriptor determineOptimizationStrategy(Properties parameters, int incrementSize) | |
| determineSegmentColumnName | back to summary |
|---|---|
| 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 during configuration.
| |
| determineSegmentColumnSize | back to summary |
|---|---|
| protected int determineSegmentColumnSize(Properties params) Determine the size of the Called during configuration.
| |
| determineSegmentValue | back to summary |
|---|---|
| protected String determineSegmentValue(Properties params) Determine the segment value corresponding to this generator instance. Called during configuration.
| |
| determineValueColumnName | back to summary |
|---|---|
| protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) Determine the name of the column in which we will store the generator persistent value. Called during configuration.
| |
| executeQuery | back to summary |
|---|---|
| private ResultSet executeQuery(PreparedStatement ps, SessionEventListenerManager listener, String sql, SharedSessionContractImplementor session) throws SQLException | |
| executeUpdate | back to summary |
|---|---|
| private int executeUpdate(PreparedStatement ps, SessionEventListenerManager listener, String sql, SharedSessionContractImplementor session) throws SQLException | |
| generate | back to summary |
|---|---|
| public Object generate(final SharedSessionContractImplementor session, final Object obj) Implements org. Doc from org. Generate a new identifier.
| |
| generateInsertInitCommand | back to summary |
|---|---|
| protected InitCommand generateInsertInitCommand(SqlStringGenerationContext context) | |
| getAllSqlForTests | back to summary |
|---|---|
| public String[] getAllSqlForTests()
Deprecated Exposed for tests only.
| |
| getIdentifierType | back to summary |
|---|---|
| public final Type getIdentifierType() Type mapping for the identifier.
| |
| getIncrementSize | back to summary |
|---|---|
| public final int getIncrementSize() The amount of increment to use. The exact implications of this depends on the optimizer being used.
| |
| getInitialValue | back to summary |
|---|---|
| public final int getInitialValue() The initial value to use when we find no previous state in the generator table corresponding to our sequence.
| |
| getOptimizer | back to summary |
|---|---|
| public final Optimizer getOptimizer() Implements org. The optimizer being used by this generator. | |
| getSegmentColumnName | back to summary |
|---|---|
| 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.
| |
| getSegmentValue | back to summary |
|---|---|
| public final String getSegmentValue() The value in
| |
| getSegmentValueLength | back to summary |
|---|---|
| public final int getSegmentValueLength() The size of the API Note This should really have been called
| |
| getTableAccessCount | back to summary |
|---|---|
| public final long getTableAccessCount() Getter for property 'tableAccessCount'. Only really useful for unit test assertions.
| |
| getTableName | back to summary |
|---|---|
| public final String getTableName() The name of the table in which we store this generator's persistent state.
| |
| getValueColumnName | back to summary |
|---|---|
| public final String getValueColumnName() The name of the column in which we store our persistent generator value.
| |
| initialize | back to summary |
|---|---|
| public void initialize(SqlStringGenerationContext context) Overrides default org. Doc from org. Initializes this instance, in particular pre-generates SQL as necessary.
This method is called after
| |
| makeValue | back to summary |
|---|---|
| private IntegralDataTypeHolder makeValue() | |
| nextValue | back to summary |
|---|---|
| private IntegralDataTypeHolder nextValue(Connection connection, SqlStatementLogger logger, SessionEventListenerManager listener, SharedSessionContractImplementor session) throws SQLException | |
| prepareStatement | back to summary |
|---|---|
| private PreparedStatement prepareStatement(Connection connection, String sql, SqlStatementLogger logger, SessionEventListenerManager listener, SharedSessionContractImplementor session) throws SQLException | |
| registerExportables | back to summary |
|---|---|
| public void registerExportables(Database database) Overrides default org. Implements org. Doc from org. Register database objects used by this identifier generator, for example, a sequence or tables.
This method is called just once, after
| |