org.hibernate.id
Class TableGenerator

java.lang.Object
  extended by org.hibernate.engine.TransactionHelper
      extended by org.hibernate.id.TableGenerator
All Implemented Interfaces:
Configurable, IdentifierGenerator, PersistentIdentifierGenerator
Direct Known Subclasses:
TableHiLoGenerator

public class TableGenerator
extends TransactionHelper
implements PersistentIdentifierGenerator, Configurable

An IdentifierGenerator that uses a database table to store the last generated value. It is not intended that applications use this strategy directly. However, it may be used to build other (efficient) strategies. The returned type is Integer.

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 Hibernate is fetching connections when the user is supplying connections.

The returned value is of type integer.

Mapping parameters supported: table, column

Author:
Gavin King
See Also:
TableHiLoGenerator

Field Summary
static java.lang.String COLUMN
          The column parameter
static java.lang.String DEFAULT_COLUMN_NAME
          Default column name
static java.lang.String DEFAULT_TABLE_NAME
          Default table name
static java.lang.String TABLE
          The table parameter
 
Fields inherited from interface org.hibernate.id.PersistentIdentifierGenerator
CATALOG, PK, SCHEMA, SQL_STATEMENT_LOGGER, TABLES
 
Fields inherited from interface org.hibernate.id.IdentifierGenerator
ENTITY_NAME
 
Constructor Summary
TableGenerator()
           
 
Method Summary
 void configure(Type type, java.util.Properties params, Dialect dialect)
          Configure this instance, given the value of parameters specified by the user as <param> elements.
 java.io.Serializable doWorkInCurrentTransaction(java.sql.Connection conn, java.lang.String sql)
          The work to be done
 java.io.Serializable generate(SessionImplementor session, java.lang.Object object)
          Generate a new identifier.
 java.lang.Object generatorKey()
          Return a key unique to the underlying database objects.
 java.lang.String[] sqlCreateStrings(Dialect dialect)
          The SQL required to create the underlying database objects.
 java.lang.String[] sqlDropStrings(Dialect dialect)
          The SQL required to remove the underlying database objects.
 
Methods inherited from class org.hibernate.engine.TransactionHelper
doWorkInNewTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLUMN

public static final java.lang.String COLUMN
The column parameter

See Also:
Constant Field Values

DEFAULT_COLUMN_NAME

public static final java.lang.String DEFAULT_COLUMN_NAME
Default column name

See Also:
Constant Field Values

TABLE

public static final java.lang.String TABLE
The table parameter

See Also:
Constant Field Values

DEFAULT_TABLE_NAME

public static final java.lang.String DEFAULT_TABLE_NAME
Default table name

See Also:
Constant Field Values
Constructor Detail

TableGenerator

public TableGenerator()
Method Detail

configure

public void configure(Type type,
                      java.util.Properties params,
                      Dialect dialect)
Description copied from interface: Configurable
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
params - param values, keyed by parameter name

generate

public java.io.Serializable generate(SessionImplementor session,
                                     java.lang.Object object)
                              throws HibernateException
Description copied from interface: IdentifierGenerator
Generate a new identifier.

Specified by:
generate in interface IdentifierGenerator
object - the entity or toplevel collection for which the id is being generated
Returns:
a new identifier
Throws:
HibernateException

sqlCreateStrings

public java.lang.String[] sqlCreateStrings(Dialect dialect)
                                    throws HibernateException
Description copied from interface: PersistentIdentifierGenerator
The SQL required to create the underlying database objects.

Specified by:
sqlCreateStrings in interface PersistentIdentifierGenerator
Parameters:
dialect - The dialect against which to generate the create command(s)
Returns:
The create command(s)
Throws:
HibernateException - problem creating the create command(s)

sqlDropStrings

public java.lang.String[] sqlDropStrings(Dialect dialect)
Description copied from interface: PersistentIdentifierGenerator
The SQL required to remove the underlying database objects.

Specified by:
sqlDropStrings in interface PersistentIdentifierGenerator
Parameters:
dialect - The dialect against which to generate the drop command(s)
Returns:
The drop command(s)

generatorKey

public java.lang.Object generatorKey()
Description copied from interface: PersistentIdentifierGenerator
Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.

Specified by:
generatorKey in interface PersistentIdentifierGenerator
Returns:
Object an identifying key for this generator

doWorkInCurrentTransaction

public java.io.Serializable doWorkInCurrentTransaction(java.sql.Connection conn,
                                                       java.lang.String sql)
                                                throws java.sql.SQLException
Description copied from class: TransactionHelper
The work to be done

Specified by:
doWorkInCurrentTransaction in class TransactionHelper
Throws:
java.sql.SQLException


Copyright © 2008 Hibernate.org. All Rights Reserved.