Matthew Simon Cavalletto

NAME

DBIx::SQLEngine::Mixin::SeqTable

SYNOPSIS

  # Classes can inherit this behavior if they don't have native sequences
  push @DBIx::SQLEngine::AcmeDB::ISA, 'DBIx::SQLEngine::Mixin::SeqTable';
  
  # Public interface for SeqTable functionality
  $nextid = $sqldb->seq_increment( $table, $field );

  # Housekeeping functions for setup and removal
  $sqldb->seq_create_table();
  $sqldb->seq_insert_record( $table, $field );
  $sqldb->seq_delete_record( $table, $field );
  $sqldb->seq_drop_table();

DESCRIPTION

This mixin supports SQL database servers which do natively support an auto-incrementing or unique sequence trigger. Instead, a special table is allocated to store sequence values, and queries are used to atomically retrieve and increment the sequence value to ensure uniqueness.

REFERENCE

seq_table_name

Constant 'dbix_sqlengine_seq'.

seq_create_table

  $sqldb->seq_create_table()

Issues a SQL create table statement to create the sequence table.

seq_drop_table

  $sqldb->seq_drop_table()

Issues a SQL drop table statement to remove the sequence table.

seq_insert_record

  $sqldb->seq_insert_record( $table, $field )

Creates a record in the sequence table for a given field in a particular table.

seq_delete_record

  $sqldb->seq_delete_record( $table, $field )

Removes the corresponding record in the sequence table.

seq_bootstrap_init

  $sqldb->seq_bootstrap_init( $table, $field ) : $current_value

Scans the designated field in a given table to determine its maximum value, and then stores that in sequence table.

seq_fetch_current

  $sqldb->seq_fetch_current( $table, $field ) : $current_value

Fetches the current sequence value.

seq_increment

  $sqldb->seq_increment( $table, $field ) : $new_value

Increments the sequence, and returns the newly allocated value.

This is the primary "public" interface of this package.

If someone else has completed the same increment before we have, our update will have no effect and we'll immeidiately try again and again until successful.

If the table does not yet exist, attempts to create it automatically.

If the sequence record does not yet exist, attempts to create it automatically.

SEE ALSO

See DBIx::Sequence for another version of the sequence-table functionality, which greatly inspired this module.