| Method from org.hibernate.id.enhanced.SequenceStyleGenerator Detail: |
protected DatabaseStructure buildDatabaseStructure(Properties params,
Dialect dialect,
boolean forceTableUse,
String sequenceName,
int initialValue,
int incrementSize) {
boolean useSequence = dialect.supportsSequences() && !forceTableUse;
if ( useSequence ) {
return new SequenceStructure( dialect, sequenceName, initialValue, incrementSize );
}
else {
String valueColumnName = determineValueColumnName( params );
return new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize );
}
}
Build the database structure. |
public void configure(Type type,
Properties params,
Dialect dialect) throws MappingException {
this.identifierType = type;
boolean forceTableUse = PropertiesHelper.getBoolean( FORCE_TBL_PARAM, params, false );
final String sequenceName = determineSequenceName( params );
final int initialValue = determineInitialValue( params );
int incrementSize = determineIncrementSize( params );
final String optimizationStrategy = determineOptimizationStrategy( params, incrementSize );
incrementSize = determineAdjustedIncrementSize( optimizationStrategy, incrementSize );
if ( dialect.supportsSequences() && !forceTableUse ) {
if ( OptimizerFactory.POOL.equals( optimizationStrategy ) && !dialect.supportsPooledSequences() ) {
forceTableUse = true;
log.info(
"Forcing table use for sequence-style generator due to pooled optimizer selection where db does not support pooled sequences"
);
}
}
this.databaseStructure = buildDatabaseStructure( params, dialect, forceTableUse, sequenceName, initialValue, incrementSize );
this.optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
this.databaseStructure.prepare( optimizer );
}
|
protected int determineAdjustedIncrementSize(String optimizationStrategy,
int incrementSize) {
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;
}
return incrementSize;
}
In certain cases we need to adjust the increment size based on the
selected optimizer. This is the hook to achieve that. |
protected int determineIncrementSize(Properties params) {
return PropertiesHelper.getInt( INCREMENT_PARAM, params, DEFAULT_INCREMENT_SIZE );
}
Determine the increment size to be applied. The exact implications of
this value depends on the optimizer being used.
Called during configuration . |
protected int determineInitialValue(Properties params) {
return PropertiesHelper.getInt( INITIAL_PARAM, params, DEFAULT_INITIAL_VALUE );
}
Determine the initial sequence value to use. This value is used when
initializing the database structure
(i.e. sequence/table).
Called during configuration . |
protected String determineOptimizationStrategy(Properties params,
int incrementSize) {
String defOptStrategy = incrementSize < = 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
return PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
}
|
protected String determineSequenceName(Properties params) {
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 );
}
return sequenceName;
}
Determine the name of the sequence (or table if this resolves to a physical table)
to use.
Called during configuration . |
protected String determineValueColumnName(Properties params) {
return PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
}
Determine the name of the column used to store the generator value in
the db.
Called during configuration when resolving to a
physical table. |
public Serializable generate(SessionImplementor session,
Object object) throws HibernateException {
return optimizer.generate( databaseStructure.buildCallback( session ) );
}
|
public Object generatorKey() {
return databaseStructure.getName();
}
|
public DatabaseStructure getDatabaseStructure() {
return databaseStructure;
}
Getter for property 'databaseStructure'. |
public Type getIdentifierType() {
return identifierType;
}
Getter for property 'identifierType'. |
public Optimizer getOptimizer() {
return optimizer;
}
Getter for property 'optimizer'. |
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
return databaseStructure.sqlCreateStrings( dialect );
}
|
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
return databaseStructure.sqlDropStrings( dialect );
}
|