C# Class NHibernate.Id.Enhanced.TableGenerator

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 similar to the legacy MultipleHiLoPerTableGenerator (not available in NHibernate) 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 generators (based on DefaultSegmentValue). The configuration parameter ConfigPreferSegmentPerEntity can be used to change that to instead default to using a row for each entity name.

Configuration parameters:
NAME DEFAULT DESCRIPTION
TableParam DefaultTable The name of the table to use to store/retrieve values
ValueColumnParam DefaultValueColumn The name of column which holds the sequence value for the given segment
SegmentColumnParam DefaultSegmentColumn The name of the column which holds the segment key
SegmentValueParam DefaultSegmentValue The value indicating which segment is used by this generator; refers to values in the SegmentColumnParam column
SegmentLengthParam DefaultSegmentLength The data length of the SegmentColumnParam column; used for schema creation
InitialParam DefaltInitialValue The initial value to be stored for the given segment
IncrementParam DefaultIncrementSize The increment size for the underlying segment; see the discussion on Optimizer for more details.
OptimizerParam depends on defined increment size Allows explicit definition of which optimization strategy to use
Inheritance: NHibernate.Engine.TransactionHelper, IPersistentIdentifierGenerator, IConfigurable
Mostrar archivo Open project: nhibernate/nhibernate-core Class Usage Examples

Public Methods

Method Description
Configure ( IType type, string>.IDictionary parms, Dialect dialect ) : void
DoWorkInCurrentTransaction ( ISessionImplementor session, System conn, System transaction ) : object
GeneratorKey ( ) : string
SqlCreateStrings ( Dialect dialect ) : string[]
SqlDropString ( Dialect dialect ) : string[]

Protected Methods

Method Description
BuildInsertQuery ( ) : void
BuildSelectQuery ( Dialect dialect ) : void
BuildUpdateQuery ( ) : void
DetermineDefaultSegmentValue ( string>.IDictionary parms ) : string

Used in the cases where DetermineSegmentValue is unable to determine the value to use.

DetermineGeneratorTableName ( string>.IDictionary parms, Dialect dialect ) : string

Determine the table name to use for the generator values. Called during configuration.

DetermineIncrementSize ( string>.IDictionary parms ) : int
DetermineInitialValue ( string>.IDictionary parms ) : int
DetermineSegmentColumnName ( string>.IDictionary parms, Dialect dialect ) : string

Determine the name of the column used to indicate the segment for each row. This column acts as the primary key. Called during configuration.

DetermineSegmentColumnSize ( string>.IDictionary parms ) : int

Determine the size of the SegmentColumnName segment column. Called during configuration.

DetermineSegmentValue ( string>.IDictionary parms ) : string

Determine the segment value corresponding to this generator instance. Called during configuration.

DetermineValueColumnName ( string>.IDictionary parms, Dialect dialect ) : string

Determine the name of the column in which we will store the generator persistent value. Called during configuration.

Private Methods

Method Description
Generate ( ISessionImplementor session, object obj ) : object

Method Details

BuildInsertQuery() protected method

protected BuildInsertQuery ( ) : void
return void

BuildSelectQuery() protected method

protected BuildSelectQuery ( Dialect dialect ) : void
dialect Dialect
return void

BuildUpdateQuery() protected method

protected BuildUpdateQuery ( ) : void
return void

Configure() public method

public Configure ( IType type, string>.IDictionary parms, Dialect dialect ) : void
type IType
parms string>.IDictionary
dialect Dialect
return void

DetermineDefaultSegmentValue() protected method

Used in the cases where DetermineSegmentValue is unable to determine the value to use.
protected DetermineDefaultSegmentValue ( string>.IDictionary parms ) : string
parms string>.IDictionary
return string

DetermineGeneratorTableName() protected method

Determine the table name to use for the generator values. Called during configuration.
protected DetermineGeneratorTableName ( string>.IDictionary parms, Dialect dialect ) : string
parms string>.IDictionary The parameters supplied in the generator config (plus some standard useful extras).
dialect Dialect The dialect
return string

DetermineIncrementSize() protected method

protected DetermineIncrementSize ( string>.IDictionary parms ) : int
parms string>.IDictionary
return int

DetermineInitialValue() protected method

protected DetermineInitialValue ( string>.IDictionary parms ) : int
parms string>.IDictionary
return int

DetermineSegmentColumnName() protected method

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 DetermineSegmentColumnName ( string>.IDictionary parms, Dialect dialect ) : string
parms string>.IDictionary The parameters supplied in the generator config (plus some standard useful extras).
dialect Dialect The
return string

DetermineSegmentColumnSize() protected method

Determine the size of the SegmentColumnName segment column. Called during configuration.
protected DetermineSegmentColumnSize ( string>.IDictionary parms ) : int
parms string>.IDictionary
return int

DetermineSegmentValue() protected method

Determine the segment value corresponding to this generator instance. Called during configuration.
protected DetermineSegmentValue ( string>.IDictionary parms ) : string
parms string>.IDictionary
return string

DetermineValueColumnName() protected method

Determine the name of the column in which we will store the generator persistent value. Called during configuration.
protected DetermineValueColumnName ( string>.IDictionary parms, Dialect dialect ) : string
parms string>.IDictionary
dialect Dialect
return string

DoWorkInCurrentTransaction() public method

public DoWorkInCurrentTransaction ( ISessionImplementor session, System conn, System transaction ) : object
session ISessionImplementor
conn System
transaction System
return object

GeneratorKey() public method

public GeneratorKey ( ) : string
return string

SqlCreateStrings() public method

public SqlCreateStrings ( Dialect dialect ) : string[]
dialect Dialect
return string[]

SqlDropString() public method

public SqlDropString ( Dialect dialect ) : string[]
dialect Dialect
return string[]