public class

SequenceStyleGenerator

extends Object
implements Configurable PersistentIdentifierGenerator
java.lang.Object
   ↳ org.hibernate.id.enhanced.SequenceStyleGenerator

Class Overview

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

Summary

Constants
int DEFAULT_INCREMENT_SIZE
int DEFAULT_INITIAL_VALUE
String DEF_SEQUENCE_NAME
String DEF_VALUE_COLUMN
String FORCE_TBL_PARAM
String INCREMENT_PARAM
String INITIAL_PARAM
String OPT_PARAM
String SEQUENCE_PARAM
String VALUE_COLUMN_PARAM
[Expand]
Inherited Constants
From interface org.hibernate.id.IdentifierGenerator
From interface org.hibernate.id.PersistentIdentifierGenerator
[Expand]
Inherited Fields
From interface org.hibernate.id.PersistentIdentifierGenerator
Public Constructors
SequenceStyleGenerator()
Public Methods
void configure(Type type, Properties params, Dialect dialect)
Configure this instance, given the value of parameters specified by the user as <param> elements.
Serializable generate(SessionImplementor session, Object object)
Generate a new identifier.
Object generatorKey()
Return a key unique to the underlying database objects.
DatabaseStructure getDatabaseStructure()
Getter for property 'databaseStructure'.
Type getIdentifierType()
Getter for property 'identifierType'.
Optimizer getOptimizer()
Getter for property 'optimizer'.
String[] sqlCreateStrings(Dialect dialect)
The SQL required to create the underlying database objects.
String[] sqlDropStrings(Dialect dialect)
The SQL required to remove the underlying database objects.
Protected Methods
DatabaseStructure buildDatabaseStructure(Type type, Properties params, Dialect dialect, boolean forceTableUse, String sequenceName, int initialValue, int incrementSize)
Build the database structure.
int determineAdjustedIncrementSize(String optimizationStrategy, int incrementSize)
In certain cases we need to adjust the increment size based on the selected optimizer.
int determineIncrementSize(Properties params)
Determine the increment size to be applied.
int determineInitialValue(Properties params)
Determine the initial sequence value to use.
String determineOptimizationStrategy(Properties params, int incrementSize)
Determine the optimizer to use.
String determineSequenceName(Properties params, Dialect dialect)
Determine the name of the sequence (or table if this resolves to a physical table) to use.
String determineValueColumnName(Properties params, Dialect dialect)
Determine the name of the column used to store the generator value in the db.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.id.Configurable
From interface org.hibernate.id.IdentifierGenerator
From interface org.hibernate.id.PersistentIdentifierGenerator

Constants

public static final int DEFAULT_INCREMENT_SIZE

Constant Value: 1 (0x00000001)

public static final int DEFAULT_INITIAL_VALUE

Constant Value: 1 (0x00000001)

public static final String DEF_SEQUENCE_NAME

Constant Value: "hibernate_sequence"

public static final String DEF_VALUE_COLUMN

Constant Value: "next_val"

public static final String FORCE_TBL_PARAM

Constant Value: "force_table_use"

public static final String INCREMENT_PARAM

Constant Value: "increment_size"

public static final String INITIAL_PARAM

Constant Value: "initial_value"

public static final String OPT_PARAM

Constant Value: "optimizer"

public static final String SEQUENCE_PARAM

Constant Value: "sequence_name"

public static final String VALUE_COLUMN_PARAM

Constant Value: "value_column"

Public Constructors

public SequenceStyleGenerator ()

Public Methods

public void configure (Type type, Properties params, Dialect dialect)

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 param values, keyed by parameter name

public Serializable generate (SessionImplementor session, Object object)

Generate a new identifier.

Parameters
object the entity or toplevel collection for which the id is being generated
Returns
  • a new identifier

public Object generatorKey ()

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

Returns
  • Object an identifying key for this generator

public DatabaseStructure getDatabaseStructure ()

Getter for property 'databaseStructure'.

Returns
  • Value for property 'databaseStructure'.

public Type getIdentifierType ()

Getter for property 'identifierType'.

Returns
  • Value for property 'identifierType'.

public Optimizer getOptimizer ()

Getter for property 'optimizer'.

Returns
  • Value for property 'optimizer'.

public String[] sqlCreateStrings (Dialect dialect)

The SQL required to create the underlying database objects.

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

public String[] sqlDropStrings (Dialect dialect)

The SQL required to remove the underlying database objects.

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

Protected Methods

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

Build the database structure.

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

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 The optimizer strategy (name)
incrementSize The determined increment size
Returns
  • The adjusted increment size.

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 The params supplied in the generator config (plus some standard useful extras).
Returns
  • The increment size

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 The params supplied in the generator config (plus some standard useful extras).
Returns
  • The initial value

protected String determineOptimizationStrategy (Properties params, int incrementSize)

Determine the optimizer to use.

Called during configuration.

Parameters
params The params supplied in the generator config (plus some standard useful extras).
incrementSize The determined increment size
Returns
  • The optimizer strategy (name)

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 The params supplied in the generator config (plus some standard useful extras).
dialect The dialect in effect
Returns
  • The sequence name

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 The params supplied in the generator config (plus some standard useful extras).
dialect The dialect in effect.
Returns
  • The value column name