FileDocCategorySizeDatePackage
SequenceStyleGenerator.javaAPI DocHibernate 3.2.56872Thu Mar 15 04:33:16 GMT 2007org.hibernate.id.enhanced

SequenceStyleGenerator

public class SequenceStyleGenerator extends Object implements org.hibernate.id.PersistentIdentifierGenerator, org.hibernate.id.Configurable
Generates identifier values based on an sequence-style database structure. Variations range from actually using a sequence to using a table to mimic a sequence. These variations are encapsulated by the {@link DatabaseStructure} interface internally.

General configuration parameters:
NAME DEFAULT DESCRIPTION
{@link #SEQUENCE_PARAM} {@link #DEF_SEQUENCE_NAME} The name of the sequence/table to use to store/retrieve values
{@link #INITIAL_PARAM} {@link #DEFAULT_INITIAL_VALUE} The initial value to be stored for the given segment; the effect in terms of storage varies based on {@link Optimizer} and {@link DatabaseStructure}
{@link #INCREMENT_PARAM} {@link #DEFAULT_INCREMENT_SIZE} The increment size for the underlying segment; the effect in terms of storage varies based on {@link Optimizer} and {@link DatabaseStructure}
{@link #OPT_PARAM} depends on defined increment size Allows explicit definition of which optimization strategy to use
{@link #FORCE_TBL_PARAM} false Allows explicit definition of which optimization strategy to use

Configuration parameters used specifically when the underlying structure is a table:
NAME DEFAULT DESCRIPTION
{@link #VALUE_COLUMN_PARAM} {@link #DEF_VALUE_COLUMN} The name of column which holds the sequence value for the given segment

author
Steve Ebersole

Fields Summary
private static final Log
log
public static final String
SEQUENCE_PARAM
public static final String
DEF_SEQUENCE_NAME
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
public static final String
FORCE_TBL_PARAM
public static final String
VALUE_COLUMN_PARAM
public static final String
DEF_VALUE_COLUMN
private DatabaseStructure
databaseStructure
private Optimizer
optimizer
private org.hibernate.type.Type
identifierType
Constructors Summary
Methods Summary
public voidconfigure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.dialect.Dialect dialect)

		identifierType = type;
		boolean forceTableUse = PropertiesHelper.getBoolean( FORCE_TBL_PARAM, params, false );

		String sequenceName = PropertiesHelper.getString( SEQUENCE_PARAM, params, DEF_SEQUENCE_NAME );
		if ( sequenceName.indexOf( '." ) < 0 ) {
			String schemaName = params.getProperty( SCHEMA );
			String catalogName = params.getProperty( CATALOG );
			sequenceName = Table.qualify( catalogName, schemaName, sequenceName );
		}
		int initialValue = PropertiesHelper.getInt( INITIAL_PARAM, params, DEFAULT_INITIAL_VALUE );
		int incrementSize = PropertiesHelper.getInt( INCREMENT_PARAM, params, DEFAULT_INCREMENT_SIZE );

		String valueColumnName = PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );

		String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
		String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
		if ( OptimizerFactory.NONE.equals( optimizationStrategy ) && incrementSize > 1 ) {
			log.warn( "config specified explicit optimizer of [" + OptimizerFactory.NONE + "], but [" + INCREMENT_PARAM + "=" + incrementSize + "; honoring optimizer setting" );
			incrementSize = 1;
		}
		if ( dialect.supportsSequences() && !forceTableUse ) {
			if ( OptimizerFactory.POOL.equals( optimizationStrategy ) && !dialect.supportsPooledSequences() ) {
				// TODO : may even be better to fall back to a pooled table strategy here so that the db stored values remain consistent...
				optimizationStrategy = OptimizerFactory.HILO;
			}
			databaseStructure = new SequenceStructure( dialect, sequenceName, initialValue, incrementSize );
		}
		else {
			databaseStructure = new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize );
		}

		optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
		databaseStructure.prepare( optimizer );
	
public java.io.Serializablegenerate(org.hibernate.engine.SessionImplementor session, java.lang.Object object)

		return optimizer.generate( databaseStructure.buildCallback( session ) );
	
public java.lang.ObjectgeneratorKey()

		return databaseStructure.getName();
	
public DatabaseStructuregetDatabaseStructure()


	   
		return databaseStructure;
	
public org.hibernate.type.TypegetIdentifierType()

		return identifierType;
	
public OptimizergetOptimizer()

		return optimizer;
	
public java.lang.String[]sqlCreateStrings(org.hibernate.dialect.Dialect dialect)

		return databaseStructure.sqlCreateStrings( dialect );
	
public java.lang.String[]sqlDropStrings(org.hibernate.dialect.Dialect dialect)

		return databaseStructure.sqlDropStrings( dialect );