NAME

Persistence::Entity::Manager - Persistence entity manager.

SYNOPSIS

use Persistence::Entity::Manager; use SQL::Entity; use SQL::Entity::Column ':all'; use SQL::Entity::Condition ':all';

my $entity_manager = Persistence::Entity::Manager->new(
    name            => 'my_manager'
    connection_name => 'my_connection'
);

$entity_manager->add_entities(SQL::Entity->new(
    name                  => 'emp',
    primary_key          => ['empno'],
    columns               => [
        sql_column(name => 'ename'),
        sql_column(name => 'empno'),
        sql_column(name => 'deptno')
    ],
    triggers => {
    on_fetch => sub { ... },
    before_insert => sub { ... ]
));

{
    package Employee;
    use Abstract::Meta::Class ':all';
    use Persistence::ORM ':all';

    entity 'emp';
    column empno => has('$.no') ;
    column ename => has('$.name');
}

{
    my ($emp) = $entity_manager->find(emp => 'Employee', name => 'foo');
    #object attribute name as part of the condition

    my (@emp) = $entity_manager->find(emp => 'Employee', sql_cond('ename', 'LIKE' 'a%');
}

{
    $entity_manager->begin_work;
    eval {
        my $emp = Employee->new(name => 'foo');
        $manager->insert($user);


        $emp->set_deptno(10);
        $manager->update($emp);

        $manager->delete($emp)

        my ($emp) = $entity_manager->find(emp => 'Employee', name => 'foo');

        $entity_manager->commit;
     };

     $entity_manager->rollback if($@);
}

DESCRIPTION

Entity manager.

EXPORT

None.

ATTRIBUTES

name
entities
entities
connection_name
_connection
persitence_mangement

If this option is set, then state of the all merged or created object by entity manager will be tracked (it's database state is stored in local cache), unless thay become detached by calling $entity_manager->detach($obj) or $entity_manager->detach_all or for persitence_mangement = transaction $entity_manager->commit, $entity_manager->rollback

Note: Using this option you must ensure that there are not obsolete objects in the local cache by detching all objects that are no longer in use, it may be resource consuming (memory).

If persitence_mangement is not set then extra sql will be issued to get object state from database for update, delete.

_persistence_cache

Stores datebase state of the object. The key is the object reference, the values database row.

_lazy_fetch_flag

Hash that stores information about lazy retrieve for objects attribute

METHODS

initialise
manager

Return entity amanger object, takes entity manager name

initialise_operation
has_pending_operation
complete_operation
find_entity_mappings

Returns entity mapping object Takes object or class name, and optionally must_exists_validation flag that will raise an error if mapping object does not exist.

find

Returns list of objects or resultsets for passed in entity that meets passed in condition Takes entity name, class name to which resultset will be casted, (if class name is undef then hash ref will be return instead), list of names parameters that will be used as condition or condition object. If class name has the ORM mapping, then name parameters must be objects' attributs . Condition object always should use entity column.

my ($emp) = $entity_manager->find(emp => 'Employee', name => 'adrian');
or

my @emp = $entity_manager->find(emp => 'Employee', sql_cond('ename', 'LIKE', 'a%'));
#array of Employee objects.

or 
my @emp = $entity_manager->find(emp => undef, sql_cond('ename', 'LIKE', 'a%'));
#array of resultset (hash ref)
lock

Returns and locks list and of objects or resultsets for passed in entity that meets passed in condition Takes entity name, class name to which resultset will be casted, (if class name is undef then hash ref will be return instead), list of names parameters that will be used as condition or condition object. If class name has the ORM mapping, then name parameters must be objects' attributs . Condition object always should use entity column.

my ($emp) = $entity_manager->find(emp => 'Employee', name => 'adrian');
or

my @emp = $entity_manager->find(emp => 'Employee', sql_cond('ename', 'LIKE', 'a%'));
#array of Employee objects.

or 
my @emp = $entity_manager->find(emp => undef, sql_cond('ename', 'LIKE', 'a%'));
#array of resultset (hash ref)
_condition_converter

Converts

query

Returns new query object. Takes entity name, optionally class name.

refersh

Refresh object's data

insert

Inserts object that is mapped to the entity, takes the object as parameter

_update_generated_values

Updates object by generated values.

_to_many_insert_relationship
update

Updates object that is mapped to the entity, takes the object as parameter

merge

Merges object that is mapped to the entity, takes the object as parameter

delete

Delets object that is mapped to the entity, takes object as parameter

_delete_to_many_relationship
_delete_to_one_relationship
_deserialise_object

Casts result set to passed in class name, optionally uses Object-relational mapping.

changed_column_values

Returns hash ref of fields_values that have been changed.

begin_work
commit
rollback
_manage_object

Creates database state of the object in the persistence cache. Takes object, resultset as parameters.

detach

Removes database object state from cache.

detach_all

Clears entity cache.

add_lazy_fetch_flag

Adds lazy flag. Takes object and attirubte for lazy retrieval.

has_lazy_fetch_flag

Returns true if passed in object has lazy flag for passed in attribute.

connection

Returns connection object.

SEE ALSO

Abstract::Meta::Class Persistence::ORM SQL::Entity SQL::Entity::Condition

COPYRIGHT

The SQL::EntityManager 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

See also Abstract::Meta::Class.