TableGenerator
in package
Table ID Generator for those poor languages that are missing sequences.
WARNING: The Table Id Generator clones a second independent database connection to work correctly. This means using the generator requests that generate IDs will have two open database connections. This is necessary to be safe from transaction failures in the main connection. Make sure to only ever use one TableGenerator otherwise you end up with many connections.
TableID Generator does not work with SQLite.
The TableGenerator does not take care of creating the SQL Table itself. You
should look at the TableGeneratorSchemaVisitor
to do this for you.
Otherwise the schema for a table looks like:
CREATE sequences ( sequence_name VARCHAR(255) NOT NULL, sequence_value INT NOT NULL DEFAULT 1, sequence_increment_by INT NOT NULL DEFAULT 1, PRIMARY KEY (sequence_name) );
Technically this generator works as follows:
- Use a robust transaction serialization level.
- Open transaction
- Acquire a read lock on the table row (SELECT .. FOR UPDATE)
- Increment current value by one and write back to database
- Commit transaction
If you are using a sequence_increment_by value that is larger than one the ID Generator will keep incrementing values until it hits the incrementation gap before issuing another query.
If no row is present for a given sequence a new one will be created with the default values 'value' = 1 and 'increment_by' = 1
Tags
Table of Contents
Properties
- $conn : Connection
- $generatorTableName : string
- $sequences : array<string|int, array<string|int, mixed>>
Methods
- __construct() : mixed
- nextValue() : int
- Generates the next unused value for the given sequence name.
Properties
$conn
private
Connection
$conn
$generatorTableName
private
string
$generatorTableName
$sequences
private
array<string|int, array<string|int, mixed>>
$sequences
= []
Methods
__construct()
public
__construct(Connection $conn[, string $generatorTableName = 'sequences' ]) : mixed
Parameters
- $conn : Connection
- $generatorTableName : string = 'sequences'
Tags
nextValue()
Generates the next unused value for the given sequence name.
public
nextValue(string $sequence) : int
Parameters
- $sequence : string