Persistence::Entity::Manager - Persistence entity manager.
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($@); }
Entity manager.
None.
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.
Stores datebase state of the object. The key is the object reference, the values database row.
Hash that stores information about lazy retrieve for objects attribute
Return entity amanger object, takes entity manager name
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.
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)
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.
Converts
Returns new query object. Takes entity name, optionally class name.
Refresh object's data
Inserts object that is mapped to the entity, takes the object as parameter
Updates object by generated values.
Updates object that is mapped to the entity, takes the object as parameter
Merges object that is mapped to the entity, takes the object as parameter
Delets object that is mapped to the entity, takes object as parameter
Casts result set to passed in class name, optionally uses Object-relational mapping.
Returns hash ref of fields_values that have been changed.
Creates database state of the object in the persistence cache. Takes object, resultset as parameters.
Removes database object state from cache.
Clears entity cache.
Adds lazy flag. Takes object and attirubte for lazy retrieval.
Returns true if passed in object has lazy flag for passed in attribute.
Returns connection object.
Abstract::Meta::Class Persistence::ORM SQL::Entity SQL::Entity::Condition
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.
Adrian Witas, adrian@webapp.strefa.pl
See also Abstract::Meta::Class.
To install Persistence::Entity, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Persistence::Entity
CPAN shell
perl -MCPAN -e shell install Persistence::Entity
For more information on module installation, please visit the detailed CPAN module installation guide.