The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SLOOPS::Factory - a general persistent object managing class.

DESCRIPTION

This is the main class to use this persistance framework. Use it to seek objects, to save them, to delete them ...

AUTHOR

jerome@eteve.net

SYNOPSIS

use SLOOPS::Factory [ { debug => 0|1 } ];

my $f = SLOOPS::Factory->instance();

[ $f->setCache(0|1) ; ]

[ my $dbDriver = # A valid dbDriver ; # Only one time needed for the life of the instance. $f->dbDriver($dbDriver); ]

# Then use the methods..

METHODS

setCache

Sets the cache on 1 /off 0 : $f->setCache(1); $f->setCache(0);

Setting the cache on allows to get always the same instance of object that old exactly the same data when you fetch object.

createObject

Usage:

    my $o = $f->createObject("ObjectClass");

fetchObject

Fetch an object of class $oclass identified by $id from the database.

usage :

    my $o = $f->fetchObject($oclass,$id);

findBaseClass

Utility function. Returns the base class of any persistent class.

fetchObjectReal

Fetch the object $dbid. $oclass is the real class of this object.

saveObject

Stores the object in the database and add an _dbid_ to it. If _dbid_ is allready set, redirect to syncObject .

Returns the object database id (_dbid_)

SQL equiv: insert.

saveObject

Synchronize the object value with the database. Returns the object database id ( _dbid_ )

SQL equiv: update.

deleteObject

Removes the object from the database.

Empty the object from all database properties, turning it into a plain perl-space object.

SQL equiv: delete

find

Returns the only instance found with the given constraints and existence. Returns Undef if none found. Dies if more than one instance is found.

Usage:

my $contraints = { ... } ; # See seekIds for syntax my $existences = { ... } ; # See seekIds for syntax

my $o = $f->find($class,$constraints,$existences);

findOrCreate

Returns a newly created object with the equality constraints and the reference constraints used to initiate the object if it doesn't exists in the database.

Returns the object from the database if it's allready there.

Dies if more than one object fullfills the given constraints.

Usage:

my $contraints = { ... } ; # See seekIds for syntax my $existences = { ... } ; # See seekIds for syntax

my $o = $f->findOrCreate($class,$constraints,$existences);

seekObjects

Same usage as seekIds, but return a set of allready constructed objects.

seekIds

Returns a collection of id of object for the class $class in the database. These object matches the constraints.

Contraints can concern super class attributes and references.

usage :

    my $constraint = {
        'field1' => [ $operator , $value ],
        ...
        'reference1' => $referencedObject
    };

my $existence = { 'field1' => 'exist' , # Field is set 'field2' => undef , # field is not set 'reference1' => 'exist' , # idem 'reference2' => undef # idem ... };

    my $ids = $self->seekIds('ClassName' , $constraint , $existence );

findDistinctFieldsFrom

Finds the distinct values of the given $field in the instances of the $class that match the constraints $constraints and $existence like in seekIds .

If $field is a name of reference instead of a plain field, it returns the collection of corresponding object.

Usage:

my $ObjsOrScalars = $f->findDistinctFieldsFrom($field , $class , $constraints , $existence );