Top Description Fields Constructors Methods
org.hibernate.id.enhanced

public Class SequenceStyleGenerator

extends Object
implements PersistentIdentifierGenerator, Configurable
Class Inheritance
All Implemented Interfaces
org.hibernate.id.Configurable, org.hibernate.id.PersistentIdentifierGenerator, org.hibernate.id.IdentifierGenerator
Imports
java.util.Properties, java.io.Serializable, org.slf4j.Logger, .LoggerFactory, org.hibernate.cfg.Environment, .ObjectNameNormalizer, org.hibernate.id.PersistentIdentifierGenerator, .Configurable, org.hibernate.HibernateException, .MappingException, org.hibernate.engine.SessionImplementor, org.hibernate.mapping.Table, org.hibernate.util.PropertiesHelper, org.hibernate.type.Type, org.hibernate.dialect.Dialect

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 DatabaseStructure interface internally.

General configuration parameters:

NAME DEFAULT DESCRIPTION
SEQUENCE_PARAM DEF_SEQUENCE_NAME The name of the sequence/table to use to store/retrieve values
INITIAL_PARAM DEFAULT_INITIAL_VALUE The initial value to be stored for the given segment; the effect in terms of storage varies based on Optimizer and DatabaseStructure
INCREMENT_PARAM DEFAULT_INCREMENT_SIZE The increment size for the underlying segment; the effect in terms of storage varies based on Optimizer and DatabaseStructure
OPT_PARAM depends on defined increment size Allows explicit definition of which optimization strategy to use
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
VALUE_COLUMN_PARAM DEF_VALUE_COLUMN The name of column which holds the sequence value for the given segment
Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private DatabaseStructure
public static final String
public static final String
public static final int
public static final int
public static final String
private Type
public static final String
public static final String
private static final Logger
public static final String
private Optimizer
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected DatabaseStructure

Returns:

An abstraction for the actual database structure in use (table vs. sequence).
buildDatabaseStructure
(Type
The Hibernate type of the identifier property
type
,
Properties
The params supplied in the generator config (plus some standard useful extras).
params
,
Dialect
The dialect being used.
dialect
,
boolean
Should a table be used even if the dialect supports sequences?
forceTableUse
,
String
The name to use for the sequence or table.
sequenceName
,
int
The initial value.
initialValue
,
int
the increment size to use (after any adjustments).
incrementSize
)

Build the database structure.

public void
configure(Type type, Properties
param values, keyed by parameter name
params
,
Dialect dialect)

Implements org.hibernate.id.Configurable.configure.

Configure this instance, given the value of parameters specified by the user as <param> elements.
protected int

Returns:

The adjusted increment size.
determineAdjustedIncrementSize
(String
The optimizer strategy (name)
optimizationStrategy
,
int incrementSize)

In certain cases we need to adjust the increment size based on the selected optimizer.

protected int

Returns:

The increment size
determineIncrementSize
(Properties
The params supplied in the generator config (plus some standard useful extras).
params
)

Determine the increment size to be applied.

protected int

Returns:

The initial value
determineInitialValue
(Properties
The params supplied in the generator config (plus some standard useful extras).
params
)

Determine the initial sequence value to use.

protected String

Returns:

The optimizer strategy (name)
determineOptimizationStrategy
(Properties
The params supplied in the generator config (plus some standard useful extras).
params
,
int incrementSize)

Determine the optimizer to use.

protected String

Returns:

The sequence name
determineSequenceName
(Properties
The params supplied in the generator config (plus some standard useful extras).
params
,
Dialect
The dialect in effect
dialect
)

Determine the name of the sequence (or table if this resolves to a physical table) to use.

protected String

Returns:

The value column name
determineValueColumnName
(Properties
The params supplied in the generator config (plus some standard useful extras).
params
,
Dialect
The dialect in effect.
dialect
)

Determine the name of the column used to store the generator value in the db.

public Serializable
generate(SessionImplementor session, Object
the entity or toplevel collection for which the id is being generated
object
)

Implements org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.
public Object
generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Return a key unique to the underlying database objects.
public DatabaseStructure

Returns:

Value for property 'databaseStructure'.
getDatabaseStructure
()

Getter for property 'databaseStructure'.

public Type

Returns:

Value for property 'identifierType'.
getIdentifierType
()

Getter for property 'identifierType'.

public Optimizer

Returns:

Value for property 'optimizer'.
getOptimizer
()

Getter for property 'optimizer'.

public String[]
sqlCreateStrings(Dialect
The dialect against which to generate the create command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.
public String[]
sqlDropStrings(Dialect
The dialect against which to generate the drop command(s)
dialect
)

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databaseStructureback to summary
private DatabaseStructure databaseStructure
DEF_SEQUENCE_NAMEback to summary
public static final String DEF_SEQUENCE_NAME
DEF_VALUE_COLUMNback to summary
public static final String DEF_VALUE_COLUMN
DEFAULT_INCREMENT_SIZEback to summary
public static final int DEFAULT_INCREMENT_SIZE
DEFAULT_INITIAL_VALUEback to summary
public static final int DEFAULT_INITIAL_VALUE
FORCE_TBL_PARAMback to summary
public static final String FORCE_TBL_PARAM
identifierTypeback to summary
private Type identifierType
INCREMENT_PARAMback to summary
public static final String INCREMENT_PARAM
INITIAL_PARAMback to summary
public static final String INITIAL_PARAM
logback to summary
private static final Logger log
OPT_PARAMback to summary
public static final String OPT_PARAM
optimizerback to summary
private Optimizer optimizer
SEQUENCE_PARAMback to summary
public static final String SEQUENCE_PARAM
VALUE_COLUMN_PARAMback to summary
public static final String VALUE_COLUMN_PARAM

Constructor Detail

SequenceStyleGeneratorback to summary
public SequenceStyleGenerator()

Method Detail

buildDatabaseStructureback to summary
protected DatabaseStructure buildDatabaseStructure(Type type, Properties params, Dialect dialect, boolean forceTableUse, String sequenceName, int initialValue, int incrementSize)

Build the database structure.

Parameters
type:Type

The Hibernate type of the identifier property

params:Properties

The params supplied in the generator config (plus some standard useful extras).

dialect:Dialect

The dialect being used.

forceTableUse:boolean

Should a table be used even if the dialect supports sequences?

sequenceName:String

The name to use for the sequence or table.

initialValue:int

The initial value.

incrementSize:int

the increment size to use (after any adjustments).

Returns:DatabaseStructure

An abstraction for the actual database structure in use (table vs. sequence).

configureback to summary
public void configure(Type type, Properties params, Dialect dialect) throws MappingException

Implements org.hibernate.id.Configurable.configure.

Doc from org.hibernate.id.Configurable.configure.

Configure this instance, given the value of parameters specified by the user as <param> elements. This method is called just once, following instantiation.

Parameters
params:Properties

param values, keyed by parameter name

determineAdjustedIncrementSizeback to summary
protected int determineAdjustedIncrementSize(String optimizationStrategy, int incrementSize)

In certain cases we need to adjust the increment size based on the selected optimizer. This is the hook to achieve that.

Parameters
optimizationStrategy:String

The optimizer strategy (name)

incrementSize:int

The determined increment size

Returns:int

The adjusted increment size.

determineIncrementSizeback to summary
protected int determineIncrementSize(Properties params)

Determine the increment size to be applied. The exact implications of this value depends on the optimizer being used.

Called during configuration.

Parameters
params:Properties

The params supplied in the generator config (plus some standard useful extras).

Returns:int

The increment size

determineInitialValueback to summary
protected int determineInitialValue(Properties params)

Determine the initial sequence value to use. This value is used when initializing the database structure (i.e. sequence/table).

Called during configuration.

Parameters
params:Properties

The params supplied in the generator config (plus some standard useful extras).

Returns:int

The initial value

determineOptimizationStrategyback to summary
protected String determineOptimizationStrategy(Properties params, int incrementSize)

Determine the optimizer to use.

Called during configuration.

Parameters
params:Properties

The params supplied in the generator config (plus some standard useful extras).

incrementSize:int

The determined increment size

Returns:String

The optimizer strategy (name)

determineSequenceNameback to summary
protected String determineSequenceName(Properties params, Dialect dialect)

Determine the name of the sequence (or table if this resolves to a physical table) to use.

Called during configuration.

Parameters
params:Properties

The params supplied in the generator config (plus some standard useful extras).

dialect:Dialect

The dialect in effect

Returns:String

The sequence name

determineValueColumnNameback to summary
protected String determineValueColumnName(Properties params, Dialect dialect)

Determine the name of the column used to store the generator value in the db.

Called during configuration when resolving to a physical table.

Parameters
params:Properties

The params supplied in the generator config (plus some standard useful extras).

dialect:Dialect

The dialect in effect.

Returns:String

The value column name

generateback to summary
public Serializable generate(SessionImplementor session, Object object) throws HibernateException

Implements org.hibernate.id.IdentifierGenerator.generate.

Doc from org.hibernate.id.IdentifierGenerator.generate.

Generate a new identifier.

Parameters
object:Object

the entity or toplevel collection for which the id is being generated

Returns:Serializable

a new identifier

generatorKeyback to summary
public Object generatorKey()

Implements org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Doc from org.hibernate.id.PersistentIdentifierGenerator.generatorKey.

Return a key unique to the underlying database objects. Prevents us from trying to create/remove them multiple times.

Returns:Object

Object an identifying key for this generator

getDatabaseStructureback to summary
public DatabaseStructure getDatabaseStructure()

Getter for property 'databaseStructure'.

Returns:DatabaseStructure

Value for property 'databaseStructure'.

getIdentifierTypeback to summary
public Type getIdentifierType()

Getter for property 'identifierType'.

Returns:Type

Value for property 'identifierType'.

getOptimizerback to summary
public Optimizer getOptimizer()

Getter for property 'optimizer'.

Returns:Optimizer

Value for property 'optimizer'.

sqlCreateStringsback to summary
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlCreateStrings.

The SQL required to create the underlying database objects.

Parameters
dialect:Dialect

The dialect against which to generate the create command(s)

Returns:String[]

The create command(s)

Exceptions
HibernateException:
problem creating the create command(s)
sqlDropStringsback to summary
public String[] sqlDropStrings(Dialect dialect) throws HibernateException

Implements org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

Doc from org.hibernate.id.PersistentIdentifierGenerator.sqlDropStrings.

The SQL required to remove the underlying database objects.

Parameters
dialect:Dialect

The dialect against which to generate the drop command(s)

Returns:String[]

The drop command(s)

Exceptions
HibernateException:
problem creating the drop command(s)