Top Description Fields Constructors Methods
org.hibernate.id

public Class MultipleHiLoPerTableGenerator

extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable
Class Inheritance
All Implemented Interfaces
org.hibernate.id.Configurable, org.hibernate.id.PersistentIdentifierGenerator, org.hibernate.id.IdentifierGenerator
Imports
java.io.Serializable, java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, .Types, java.util.Properties, org.slf4j.Logger, .LoggerFactory, org.hibernate.HibernateException, .LockMode, .MappingException, org.hibernate.cfg.ObjectNameNormalizer, org.hibernate.id.enhanced.AccessCallback, .OptimizerFactory, org.hibernate.jdbc.util.FormatStyle, org.hibernate.dialect.Dialect, org.hibernate.engine.SessionImplementor, .TransactionHelper, org.hibernate.mapping.Table, org.hibernate.type.Type, org.hibernate.util.PropertiesHelper

A hilo IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction to the Session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may not be used when the user is supplying connections. In this case a SequenceHiLoGenerator would be a better choice (where supported).

A hilo IdentifierGenerator that uses a database table to store the last generated values. A table can contains several hi values. They are distinct from each other through a key

This implementation is not compliant with a user connection

Allowed parameters (all of them are optional):

Authors
Emmanuel Bernard, Klaus Richarz.

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
public static final String
private static final String
private OptimizerFactory.LegacyHiLoAlgorithmOptimizer
public static final String
private String
private int
private static final Logger
public static final String
private int
public static final String
public static final String
public static final String
private String
private String
private Class<T>
private String
private String
public static final String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
configure(Type type, Properties
param values, keyed by parameter name
params
,
Dialect dialect)

Implements org.hibernate.id.Configurable.configure.

Configure this instance, given the value of parameters specified by the user as <param> elements.
public Serializable
public synchronized Serializable
generate(final SessionImplementor session, Object
the entity or toplevel collection for which the id is being generated
obj
)

Implements org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.
public Object
generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Return a key unique to the underlying database objects.
public String[]
sqlCreateStrings(Dialect
The dialect against which to generate the create command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.
public String[]
sqlDropStrings(Dialect
The dialect against which to generate the drop command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.
Inherited from org.hibernate.engine.TransactionHelper:
doWorkInNewTransaction

Field Detail

DEFAULT_PK_COLUMNback to summary
private static final String DEFAULT_PK_COLUMN
DEFAULT_PK_LENGTHback to summary
private static final int DEFAULT_PK_LENGTH
DEFAULT_TABLEback to summary
public static final String DEFAULT_TABLE
DEFAULT_VALUE_COLUMNback to summary
private static final String DEFAULT_VALUE_COLUMN
hiloOptimizerback to summary
private OptimizerFactory.LegacyHiLoAlgorithmOptimizer hiloOptimizer
ID_TABLEback to summary
public static final String ID_TABLE
insertback to summary
private String insert
keySizeback to summary
private int keySize
logback to summary
private static final Logger log
MAX_LOback to summary
public static final String MAX_LO
maxLoback to summary
private int maxLo
PK_COLUMN_NAMEback to summary
public static final String PK_COLUMN_NAME
PK_LENGTH_NAMEback to summary
public static final String PK_LENGTH_NAME
PK_VALUE_NAMEback to summary
public static final String PK_VALUE_NAME
pkColumnNameback to summary
private String pkColumnName
queryback to summary
private String query
returnClassback to summary
private Class<T> returnClass
tableNameback to summary
private String tableName
updateback to summary
private String update
VALUE_COLUMN_NAMEback to summary
public static final String VALUE_COLUMN_NAME
valueColumnNameback to summary
private String valueColumnName

Constructor Detail

MultipleHiLoPerTableGeneratorback to summary
public MultipleHiLoPerTableGenerator()

Method Detail

configureback to summary
public void configure(Type type, Properties params, Dialect dialect) throws MappingException

Implements org.hibernate.id.Configurable.configure.

Doc from org.hibernate.id.Configurable.configure.

Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.

Parameters
params:Properties

param values, keyed by parameter name

doWorkInCurrentTransactionback to summary
public Serializable doWorkInCurrentTransaction(Connection conn, String sql) throws SQLException

Implements abstract org.hibernate.engine.TransactionHelper.doWorkInCurrentTransaction.

Doc from org.hibernate.engine.TransactionHelper.doWorkInCurrentTransaction.

The work to be done

generateback to summary
public synchronized Serializable generate(final SessionImplementor session, Object obj) throws HibernateException

Implements org.hibernate.id.IdentifierGenerator.generate.

Doc from org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.

Parameters
obj:Object

the entity or toplevel collection for which the id is being generated

Returns:Serializable

a new identifier

generatorKeyback to summary
public Object generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Doc from org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.

Returns:Object

Object an identifying key for this generator

sqlCreateStringsback to summary
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.

Parameters
dialect:Dialect

The dialect against which to generate the create command(s)

Returns:String[]

The create command(s)

Exceptions
HibernateException:
problem creating the create command(s)
sqlDropStringsback to summary
public String[] sqlDropStrings(Dialect dialect) throws HibernateException

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.

Parameters
dialect:Dialect

The dialect against which to generate the drop command(s)

Returns:String[]

The drop command(s)

Exceptions
HibernateException:
problem creating the drop command(s)