org.hibernate.id

Class MultipleHiLoPerTableGenerator

Implemented Interfaces:
Configurable, IdentifierGenerator, PersistentIdentifierGenerator

public class MultipleHiLoPerTableGenerator
extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable

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

static String
DEFAULT_TABLE
static String
ID_TABLE
static String
MAX_LO
static String
PK_COLUMN_NAME
static String
PK_LENGTH_NAME
static String
PK_VALUE_NAME
static String
VALUE_COLUMN_NAME

Fields inherited from interface org.hibernate.id.IdentifierGenerator

ENTITY_NAME

Fields inherited from interface org.hibernate.id.PersistentIdentifierGenerator

CATALOG, PK, SCHEMA, SQL_STATEMENT_LOGGER, TABLE, TABLES

Method Summary

void
configure(Type type, Properties params, Dialect dialect)
Configure this instance, given the value of parameters specified by the user as <param> elements.
Serializable
doWorkInCurrentTransaction(Connection conn, String sql)
Serializable
generate(SessionImplementor session, Object obj)
Generate a new identifier.
Object
generatorKey()
String[]
sqlCreateStrings(Dialect dialect)
String[]
sqlDropStrings(Dialect dialect)

Methods inherited from class org.hibernate.engine.TransactionHelper

doWorkInCurrentTransaction, doWorkInNewTransaction

Field Details

DEFAULT_TABLE

public static final String DEFAULT_TABLE

ID_TABLE

public static final String ID_TABLE

MAX_LO

public static final String MAX_LO

PK_COLUMN_NAME

public static final String PK_COLUMN_NAME

PK_LENGTH_NAME

public static final String PK_LENGTH_NAME

PK_VALUE_NAME

public static final String PK_VALUE_NAME

VALUE_COLUMN_NAME

public static final String VALUE_COLUMN_NAME

Method Details

configure

public void configure(Type type,
                      Properties params,
                      Dialect dialect)
            throws MappingException
Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.
Specified by:
configure in interface Configurable
Parameters:
params - param values, keyed by parameter name

doWorkInCurrentTransaction

public Serializable doWorkInCurrentTransaction(Connection conn,
                                               String sql)
            throws SQLException
Overrides:
doWorkInCurrentTransaction in interface TransactionHelper

generate

public Serializable generate(SessionImplementor session,
                             Object obj)
            throws HibernateException
Generate a new identifier.
Specified by:
generate in interface IdentifierGenerator
Parameters:
session -
Returns:
a new identifier

generatorKey

public Object generatorKey()
Specified by:
generatorKey in interface PersistentIdentifierGenerator

sqlCreateStrings

public String[] sqlCreateStrings(Dialect dialect)
            throws HibernateException
Specified by:
sqlCreateStrings in interface PersistentIdentifierGenerator

sqlDropStrings

public String[] sqlDropStrings(Dialect dialect)
            throws HibernateException
Specified by:
sqlDropStrings in interface PersistentIdentifierGenerator