Adrian Witas > Persistence-Entity > Persistence::ValueGenerator::TableGenerator

Download:
Persistence-Entity-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Persistence::ValueGenerator::TableGenerator - Unique value generator based on database table

CLASS HIERARCHY ^

 Persistence::ValueGenerator
    |
    +----Persistence::ValueGenerator::TableGenerator

SYNOPSIS ^

   use Persistence::ValueGenerator::TableGenerator;

   my $generator = Persistence::ValueGenerator::TableGenerator->new(
        name                     => 'pk_generator',
        entity_manager_name      => $entity_manager_name,
        table                    => 'primary_key_generator',
        schema                   => '',
        primary_key_column_name  => 'pk_column',
        primary_key_column_value => 'empno',
        value_column             => 'value_column',
        allocation_size          =>  20,
    );

   my $seq = $generator->nextval;

   or 

   use Persistence::ValueGenerator::TableGenerator ':all';

   my $generator = table_generator 'pk_generator' => (
        entity_manager_name      => $entity_manager_name,
        table                    => 'primary_key_generator',
        schema                   => '',
        primary_key_column_name  => 'pk_column',
        primary_key_column_value => 'empno',
        value_column             => 'value_column',
        allocation_size          =>  20,
   );

DESCRIPTION ^

Represents sequence generator that uses table name The primary_key_column_name holds a value that is used to match the primary key you are generating for. The value_column holds the value of the counter.

    use Persistence::ValueGenerator::TableGenerator;
    use Persistence::Entity::Manager;

    my $entity_manager = Persistence::Entity::Manager->new(connection_name => 'my_connection');
    my $generator = Persistence::ValueGenerator::TableGenerator->new(
        entity_manager           => $entity_manager,
        name                     => 'pk_generator',
        table                    => 'seq_generator',
        schema                   => '',
        primary_key_column_name  => 'pk_column',
        primary_key_column_value => 'empno',
        value_column             => 'value_column',
        allocation_size          =>  20,
    );

   # for that instance you need the following table
   # CREATE TABLE seq_generator(pk_column VARCHAR2(30), value_column double)
   # CREATE emp(empno number, ename varchar2(100), deptno number);

EXPORT ^

table_generator by ':all' tag.

ATTRIBUTES

table

Table name of the generator table.

schema

Schema name of the generator table.

primary_key_column_name

Name of the column that identifies the specific table primary key you are generating for.

primary_key_column_value

Used to match up with the primary key you are generating for.

value_column

Specifies the name of the column that will hold the counter for the generated primary key.

METHODS

initialise
initialise
initailise_entity
id

returns schma.table as id

retrieve_next_value

Checks current seq number in database, increments counter by $self->allocation_size + 1

table_generator

Creates a new instance of Persistence::ValueGenerator::TableGenerator

SEE ALSO ^

Persistence::Entity Persistence::Entity::GeneratedValue

COPYRIGHT AND LICENSE ^

The Persistence::ValueGenerator::TableGenerator module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

AUTHOR ^

Adrian Witas, adrian@webapp.strefa.pl

syntax highlighting: