public class TableGenerator extends Object implements PersistentIdentifierGenerator, Configurable
MultipleHiLoPerTableGenerator
in terms of the
underlying storage structure (namely a single table capable of holding
multiple generator values). The differentiator is, as with
SequenceStyleGenerator
as well, the externalized notion
of an optimizer.
NOTE that by default we use a single row for all generators (based
on DEF_SEGMENT_VALUE
). The configuration parameter
CONFIG_PREFER_SEGMENT_PER_ENTITY
can be used to change that to
instead default to using a row for each entity name.
Configuration parameters:
NAME | DEFAULT | DESCRIPTION |
TABLE_PARAM |
DEF_TABLE |
The name of the table to use to store/retrieve values |
VALUE_COLUMN_PARAM |
DEF_VALUE_COLUMN |
The name of column which holds the sequence value for the given segment |
SEGMENT_COLUMN_PARAM |
DEF_SEGMENT_COLUMN |
The name of the column which holds the segment key |
SEGMENT_VALUE_PARAM |
DEF_SEGMENT_VALUE |
The value indicating which segment is used by this generator; refers to values in the SEGMENT_COLUMN_PARAM column |
SEGMENT_LENGTH_PARAM |
DEF_SEGMENT_LENGTH |
The data length of the SEGMENT_COLUMN_PARAM column; used for schema creation |
INITIAL_PARAM |
DEFAULT_INITIAL_VALUE |
The initial value to be stored for the given segment |
INCREMENT_PARAM |
DEFAULT_INCREMENT_SIZE |
The increment size for the underlying segment; see the discussion on Optimizer for more details. |
OPT_PARAM |
depends on defined increment size | Allows explicit definition of which optimization strategy to use |
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG_PREFER_SEGMENT_PER_ENTITY
By default (in the absence of a
SEGMENT_VALUE_PARAM setting) we use a single row for all
generators. |
static String |
DEF_SEGMENT_COLUMN
The default
SEGMENT_COLUMN_PARAM value |
static int |
DEF_SEGMENT_LENGTH
The default
SEGMENT_LENGTH_PARAM value |
static String |
DEF_SEGMENT_VALUE
The default
SEGMENT_VALUE_PARAM value, unless CONFIG_PREFER_SEGMENT_PER_ENTITY is specified |
static String |
DEF_TABLE
The default
TABLE_PARAM value |
static String |
DEF_VALUE_COLUMN
The default
VALUE_COLUMN_PARAM value |
static int |
DEFAULT_INCREMENT_SIZE
The default
INCREMENT_PARAM value |
static int |
DEFAULT_INITIAL_VALUE
The default
INITIAL_PARAM value |
static String |
INCREMENT_PARAM
Indicates the increment size to use.
|
static String |
INITIAL_PARAM
Indicates the initial value to use.
|
static String |
OPT_PARAM
Indicates the optimizer to use, either naming a
Optimizer implementation class or by naming
a StandardOptimizerDescriptor by name |
static String |
SEGMENT_COLUMN_PARAM
The name of the column which holds the segment key.
|
static String |
SEGMENT_LENGTH_PARAM
Indicates the length of the column defined by
SEGMENT_COLUMN_PARAM . |
static 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_PARAM . |
static String |
TABLE_PARAM
Configures the name of the table to use.
|
static String |
VALUE_COLUMN_PARAM
The name of column which holds the sequence value.
|
CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, TABLE, TABLES
ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME
Constructor and Description |
---|
TableGenerator() |
Modifier and Type | Method and Description |
---|---|
protected String |
buildInsertQuery() |
protected String |
buildSelectQuery(Dialect dialect) |
protected String |
buildUpdateQuery() |
void |
configure(Type type,
Properties params,
ServiceRegistry serviceRegistry)
Configure this instance, given the value of parameters
specified by the user as <param> elements.
|
protected String |
determineDefaultSegmentValue(Properties params)
Used in the cases where
determineSegmentValue(java.util.Properties) is unable to
determine the value to use. |
protected QualifiedName |
determineGeneratorTableName(Properties params,
JdbcEnvironment jdbcEnvironment,
ServiceRegistry serviceRegistry)
Determine the table name to use for the generator values.
|
protected int |
determineIncrementSize(Properties params) |
protected int |
determineInitialValue(Properties params) |
protected String |
determineSegmentColumnName(Properties params,
JdbcEnvironment jdbcEnvironment)
Determine the name of the column used to indicate the segment for each
row.
|
protected int |
determineSegmentColumnSize(Properties params)
Determine the size of the
segment column
Called during configuration . |
protected String |
determineSegmentValue(Properties params)
Determine the segment value corresponding to this generator instance.
|
protected String |
determineValueColumnName(Properties params,
JdbcEnvironment jdbcEnvironment)
Determine the name of the column in which we will store the generator persistent value.
|
Serializable |
generate(SharedSessionContractImplementor session,
Object obj)
Generate a new identifier.
|
protected InitCommand |
generateInsertInitCommand() |
Object |
generatorKey()
Return a key unique to the underlying database objects.
|
Type |
getIdentifierType()
Type mapping for the identifier.
|
int |
getIncrementSize()
The amount of increment to use.
|
int |
getInitialValue()
The initial value to use when we find no previous state in the
generator table corresponding to our sequence.
|
Optimizer |
getOptimizer()
The optimizer being used by this generator.
|
String |
getSegmentColumnName()
The name of the column in which we store the segment to which each row
belongs.
|
String |
getSegmentValue()
The value in
segment column which
corresponding to this generator instance. |
int |
getSegmentValueLength()
The size of the
segment column in the
underlying table. |
long |
getTableAccessCount()
Getter for property 'tableAccessCount'.
|
String |
getTableName()
The name of the table in which we store this generator's persistent state.
|
String |
getValueColumnName()
The name of the column in which we store our persistent generator value.
|
void |
registerExportables(Database database)
Register the contained exportable things to the
Database |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
supportsJdbcBatchInserts
public static final String CONFIG_PREFER_SEGMENT_PER_ENTITY
SEGMENT_VALUE_PARAM
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.public static final String TABLE_PARAM
DEF_TABLE
public static final String DEF_TABLE
TABLE_PARAM
valuepublic static final String VALUE_COLUMN_PARAM
DEF_VALUE_COLUMN
public static final String DEF_VALUE_COLUMN
VALUE_COLUMN_PARAM
valuepublic static final String SEGMENT_COLUMN_PARAM
DEF_SEGMENT_COLUMN
public static final String DEF_SEGMENT_COLUMN
SEGMENT_COLUMN_PARAM
valuepublic static final String SEGMENT_VALUE_PARAM
SEGMENT_COLUMN_PARAM
. The default value for setting is DEF_SEGMENT_VALUE
,
although CONFIG_PREFER_SEGMENT_PER_ENTITY
effects the default as well.public static final String DEF_SEGMENT_VALUE
SEGMENT_VALUE_PARAM
value, unless CONFIG_PREFER_SEGMENT_PER_ENTITY
is specifiedpublic static final String SEGMENT_LENGTH_PARAM
SEGMENT_COLUMN_PARAM
. Used in schema export. The
default value is DEF_SEGMENT_LENGTH
public static final int DEF_SEGMENT_LENGTH
SEGMENT_LENGTH_PARAM
valuepublic static final String INITIAL_PARAM
DEFAULT_INITIAL_VALUE
public static final int DEFAULT_INITIAL_VALUE
INITIAL_PARAM
valuepublic static final String INCREMENT_PARAM
DEFAULT_INCREMENT_SIZE
public static final int DEFAULT_INCREMENT_SIZE
INCREMENT_PARAM
valuepublic static final String OPT_PARAM
Optimizer
implementation class or by naming
a StandardOptimizerDescriptor
by namepublic Object generatorKey()
PersistentIdentifierGenerator
generatorKey
in interface PersistentIdentifierGenerator
public final Type getIdentifierType()
public final String getTableName()
public final String getSegmentColumnName()
public final String getSegmentValue()
segment column
which
corresponding to this generator instance. In other words this value
indicates the row in which this generator instance will store values.public final int getSegmentValueLength()
segment column
in the
underlying table.
NOTE : should really have been called 'segmentColumnLength' or
even better 'segmentColumnSize'public final String getValueColumnName()
public final int getInitialValue()
public final int getIncrementSize()
optimizer
being used.public final Optimizer getOptimizer()
public final long getTableAccessCount()
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException
Configurable
configure
in interface Configurable
type
- The id property type descriptorparams
- param values, keyed by parameter nameserviceRegistry
- Access to service that may be needed.MappingException
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment, ServiceRegistry serviceRegistry)
configuration
.params
- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment
- The JDBC environmentgetTableName()
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment)
configuration
.params
- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment
- The JDBC environmentgetSegmentColumnName()
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment)
configuration
.params
- The params supplied in the generator config (plus some standard useful extras).jdbcEnvironment
- The JDBC environmentgetValueColumnName()
protected String determineSegmentValue(Properties params)
configuration
.params
- The params supplied in the generator config (plus some standard useful extras).getSegmentValue()
protected String determineDefaultSegmentValue(Properties params)
determineSegmentValue(java.util.Properties)
is unable to
determine the value to use.params
- The params supplied in the generator config (plus some standard useful extras).protected int determineSegmentColumnSize(Properties params)
segment column
Called during configuration
.params
- The params supplied in the generator config (plus some standard useful extras).getSegmentValueLength()
protected int determineInitialValue(Properties params)
protected int determineIncrementSize(Properties params)
protected String buildUpdateQuery()
protected String buildInsertQuery()
protected InitCommand generateInsertInitCommand()
public Serializable generate(SharedSessionContractImplementor session, Object obj)
IdentifierGenerator
generate
in interface IdentifierGenerator
session
- The session from which the request originatesobj
- the entity or collection (idbag) for which the id is being generatedpublic String[] sqlCreateStrings(Dialect dialect) throws HibernateException
PersistentIdentifierGenerator
sqlCreateStrings
in interface PersistentIdentifierGenerator
dialect
- The dialect against which to generate the create command(s)HibernateException
- problem creating the create command(s)public String[] sqlDropStrings(Dialect dialect) throws HibernateException
PersistentIdentifierGenerator
sqlDropStrings
in interface PersistentIdentifierGenerator
dialect
- The dialect against which to generate the drop command(s)HibernateException
- problem creating the drop command(s)public void registerExportables(Database database)
ExportableProducer
Database
registerExportables
in interface ExportableProducer
database
- The database instanceCopyright © 2021 JBoss by Red Hat. All rights reserved.