org.hibernate.id.enhanced

Class TableGenerator

Implemented Interfaces:
Configurable, IdentifierGenerator, PersistentIdentifierGenerator

public class TableGenerator
extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable

An enhanced version of explicit table-based generator. The main basis conceptualization is similiar to the legacy 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 externalization of the notion of an optimizer.

Configuration parameters:

NAMEDEFAULTDESCRIPTION
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_PARAM column
SEGMENT_LENGTH_PARAMDEF_SEGMENT_LENGTHThe data length of the SEGMENT_COLUMN_PARAM column; used for schema creation
INITIAL_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 Optimizer for more details.
OPT_PARAMdepends on defined increment sizeAllows explicit definition of which optimization strategy to use
Author:
Steve Ebersole

Field Summary

static int
DEFAULT_INCREMENT_SIZE
static int
DEFAULT_INITIAL_VALUE
static String
DEF_SEGMENT_COLUMN
static int
DEF_SEGMENT_LENGTH
static String
DEF_SEGMENT_VALUE
static String
DEF_TABLE
static String
DEF_VALUE_COLUMN
static String
INCREMENT_PARAM
static String
INITIAL_PARAM
static String
OPT_PARAM
static String
SEGMENT_COLUMN_PARAM
static String
SEGMENT_LENGTH_PARAM
static String
SEGMENT_VALUE_PARAM
static String
TABLE_PARAM
static String
VALUE_COLUMN_PARAM

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()
Type
getIdentifierType()
int
getIncrementSize()
int
getInitialValue()
Optimizer
getOptimizer()
String
getSegmentColumnName()
String
getSegmentValue()
int
getSegmentValueLength()
long
getTableAccessCount()
String
getTableName()
String
getValueColumnName()
String[]
sqlCreateStrings(Dialect dialect)
String[]
sqlDropStrings(Dialect dialect)

Methods inherited from class org.hibernate.engine.TransactionHelper

doWorkInCurrentTransaction, doWorkInNewTransaction

Field Details

DEFAULT_INCREMENT_SIZE

public static final int DEFAULT_INCREMENT_SIZE
Field Value:
1

DEFAULT_INITIAL_VALUE

public static final int DEFAULT_INITIAL_VALUE
Field Value:
1

DEF_SEGMENT_COLUMN

public static final String DEF_SEGMENT_COLUMN

DEF_SEGMENT_LENGTH

public static final int DEF_SEGMENT_LENGTH
Field Value:
255

DEF_SEGMENT_VALUE

public static final String DEF_SEGMENT_VALUE

DEF_TABLE

public static final String DEF_TABLE

DEF_VALUE_COLUMN

public static final String DEF_VALUE_COLUMN

INCREMENT_PARAM

public static final String INCREMENT_PARAM

INITIAL_PARAM

public static final String INITIAL_PARAM

OPT_PARAM

public static final String OPT_PARAM

SEGMENT_COLUMN_PARAM

public static final String SEGMENT_COLUMN_PARAM

SEGMENT_LENGTH_PARAM

public static final String SEGMENT_LENGTH_PARAM

SEGMENT_VALUE_PARAM

public static final String SEGMENT_VALUE_PARAM

TABLE_PARAM

public static final String TABLE_PARAM

VALUE_COLUMN_PARAM

public static final String VALUE_COLUMN_PARAM

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)
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

getIdentifierType

public Type getIdentifierType()

getIncrementSize

public int getIncrementSize()

getInitialValue

public int getInitialValue()

getOptimizer

public Optimizer getOptimizer()

getSegmentColumnName

public String getSegmentColumnName()

getSegmentValue

public String getSegmentValue()

getSegmentValueLength

public int getSegmentValueLength()

getTableAccessCount

public long getTableAccessCount()

getTableName

public String getTableName()

getValueColumnName

public String getValueColumnName()

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