Save This Page
Home » hibernate-distribution-3.3.1.GA-dist » org.hibernate » id » enhanced » [javadoc | source]
org.hibernate.id.enhanced
public class: TableGenerator [javadoc | source]
java.lang.Object
   org.hibernate.engine.TransactionHelper
      org.hibernate.id.enhanced.TableGenerator

All Implemented Interfaces:
    Configurable, PersistentIdentifierGenerator

An enhanced version of table-based id generation.

Unlike the simplistic legacy one (which, btw, was only ever intended for subclassing support) we "segment" the table into multiple values. Thus a single table can actually serve as the persistent storage for multiple independent generators. One approach would be to segment the values by the name of the entity for which we are performing generation, which would mean that we would have a row in the generator table for each entity name. Or any configuration really; the setup is very flexible.

In this respect it is very simliar to the legacy org.hibernate.id.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 genertators (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

Field Summary
public static final  String CONFIG_PREFER_SEGMENT_PER_ENTITY     
public static final  String TABLE_PARAM     
public static final  String DEF_TABLE     
public static final  String VALUE_COLUMN_PARAM     
public static final  String DEF_VALUE_COLUMN     
public static final  String SEGMENT_COLUMN_PARAM     
public static final  String DEF_SEGMENT_COLUMN     
public static final  String SEGMENT_VALUE_PARAM     
public static final  String DEF_SEGMENT_VALUE     
public static final  String SEGMENT_LENGTH_PARAM     
public static final  int DEF_SEGMENT_LENGTH     
public static final  String INITIAL_PARAM     
public static final  int DEFAULT_INITIAL_VALUE     
public static final  String INCREMENT_PARAM     
public static final  int DEFAULT_INCREMENT_SIZE     
public static final  String OPT_PARAM     
Method from org.hibernate.id.enhanced.TableGenerator Summary:
buildInsertQuery,   buildSelectQuery,   buildUpdateQuery,   configure,   determineDefaultSegmentValue,   determineIncrementSize,   determineInitialValue,   determineSegmentColumnName,   determineSegmentColumnSize,   determineSegmentValue,   determineValueColumnName,   determneGeneratorTableName,   doWorkInCurrentTransaction,   generate,   generatorKey,   getIdentifierType,   getIncrementSize,   getInitialValue,   getOptimizer,   getSegmentColumnName,   getSegmentValue,   getSegmentValueLength,   getTableAccessCount,   getTableName,   getValueColumnName,   sqlCreateStrings,   sqlDropStrings
Methods from org.hibernate.engine.TransactionHelper:
doWorkInCurrentTransaction,   doWorkInNewTransaction
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.hibernate.id.enhanced.TableGenerator Detail:
 protected String buildInsertQuery() 
 protected String buildSelectQuery(Dialect dialect) 
 protected String buildUpdateQuery() 
 public  void configure(Type type,
    Properties params,
    Dialect dialect) throws MappingException 
    {@inheritDoc}
 protected String determineDefaultSegmentValue(Properties params) 
 protected int determineIncrementSize(Properties params) 
 protected int determineInitialValue(Properties params) 
 protected String determineSegmentColumnName(Properties params) 
    Determine the name of the column used to indicate the segment for each row. This column acts as the primary key.

    Called during configuration .

 protected int determineSegmentColumnSize(Properties params) 
 protected String determineSegmentValue(Properties params) 
    Determine the segment value corresponding to this generator instance.

    Called during configuration .

 protected String determineValueColumnName(Properties params) 
    Determine the name of the column in which we will store the generator persistent value.

    Called during configuration .

 protected String determneGeneratorTableName(Properties params) 
    Determine the table name to use for the generator values.

    Called during configuration .

 public Serializable doWorkInCurrentTransaction(Connection conn,
    String sql) throws SQLException 
    {@inheritDoc}
 public synchronized Serializable generate(SessionImplementor session,
    Object obj) 
    {@inheritDoc}
 public Object generatorKey() 
    {@inheritDoc}
 public final Type getIdentifierType() 
    Type mapping for the identifier.
 public final int getIncrementSize() 
    The amount of increment to use. The exact implications of this depends on the optimizer being used.
 public final int getInitialValue() 
    The initial value to use when we find no previous state in the generator table corresponding to our sequence.
 public final Optimizer getOptimizer() 
    The optimizer being used by this generator.
 public final String getSegmentColumnName() 
    The name of the column in which we store the segment to which each row belongs. The value here acts as PK.
 public final String getSegmentValue() 
    The value in 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() 
    The size of the segment column in the underlying table.

    NOTE : should really have been called 'segmentColumnLength' or even better 'segmentColumnSize'

 public final long getTableAccessCount() 
    Getter for property 'tableAccessCount'. Only really useful for unit test assertions.
 public final String getTableName() 
    The name of the table in which we store this generator's persistent state.
 public final String getValueColumnName() 
    The name of the column in which we store our persistent generator value.
 public String[] sqlCreateStrings(Dialect dialect) throws HibernateException 
    {@inheritDoc}
 public String[] sqlDropStrings(Dialect dialect) throws HibernateException 
    {@inheritDoc}