PersistentObject: ezcPersistentSession
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcPersistentSession
|
ezcPersistentSession is the main runtime interface for manipulation of persistent objects. [
source]
Persistent objects can be stored calling save() resulting in an INSERT query. If the object is already persistent you can store it using update() which results in an UPDATE query. If you want to query persistent objects you can use the find methods.
Method Summary
|
public ezcPersistentSession |
__construct(
$db, $manager )
Constructs a new persistent session that works on the database $db. |
|
public void |
createDeleteQuery(
$class )
|
|
public ezcQuerySelect |
createFindQuery(
$class )
Returns a select query for the given persistent object $class. |
|
public void |
createUpdateQuery(
$class )
|
|
public void |
delete(
$pObject )
Deletes the persistent object $pObject. |
|
public void |
deleteFromQuery(
$query )
|
|
public array(object) |
find(
$query, $class )
Returns the result of the query $query as a list of objects. |
|
public void |
findIterator(
$query, $class )
|
|
public object |
load(
$class, $id )
Returns the persistent object of class $class with id $id. |
|
public object|null |
loadIfExists(
$class, $id )
Returns the persistent object of class $class with id $id. |
|
public void |
loadIntoObject(
$pObject, $id )
Loads the persistent object with the id $id into the object $pObject. |
|
public void |
refresh(
$pObject )
Syncronizes the contents of $pObject with those in the database. |
|
public void |
save(
$pObject )
Saves the new persistent object $pObject to the database using an INSERT INTO query. |
|
public void |
saveOrUpdate(
$pObject )
Saves or update the persistent object $pObject to the database. |
|
public void |
update(
$pObject )
Saves the new persistent object $pObject to the database using an UPDATE query. |
|
public void |
updateFromQuery(
$query )
|
Methods
__construct
Constructs a new persistent session that works on the database $db.
The $manager provides valid persistent object definitions to the session.
Parameters
| Name |
Type |
Description |
$db |
PDO |
|
createDeleteQuery
void createDeleteQuery(
$class )
Parameters
| Name |
Type |
Description |
$class |
|
|
createFindQuery
Returns a select query for the given persistent object $class.
The query is initialized to fetch all columns from the correct table.
Example:
1. $q = $session->createFindQuery( 'Person' );
2. $allPersons = $session->find( $q, 'Person' );
Parameters
| Name |
Type |
Description |
$class |
string |
|
Throws
| Class | Description |
ezcPersistentObjectException |
if there is no such persistent class. |
createUpdateQuery
void createUpdateQuery(
$class )
Parameters
| Name |
Type |
Description |
$class |
|
|
delete
void delete(
object
$pObject )
Deletes the persistent object $pObject.
This method will perform a DELETE query based on the identifier of the persistent object. After delete() the identifier in $pObject will be reset to null. It is possible to save() $pObject afterwords. The object will then be stored with a new id.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
Throws
| Class | Description |
ezcPersistentDefinitionNotFoundxception |
if $the object is not recognized as a persistent object. |
ezcPersistentObjectNotPersistentException |
if the object is not persistent already. |
ezcPersistentQueryException |
if the object could not be deleted. |
deleteFromQuery
void deleteFromQuery(
$query )
Parameters
find
array(object) find(
$query, string
$class )
Returns the result of the query $query as a list of objects.
Example:
1. $q = $session->createFindQuery( 'Person' );
2. $allPersons = $session->find( $q, 'Person' );
If you are retrieving large result set, consider using findIterator() instead.
Parameters
Throws
| Class | Description |
ezcPersistentDefinitionNotFoundException |
if there is no such persistent class. |
ezcPersistentQueryException |
if the find query failed |
findIterator
void findIterator(
$query,
$class )
Parameters
load
object load(
string
$class, int
$id )
Returns the persistent object of class $class with id $id.
Parameters
| Name |
Type |
Description |
$class |
string |
|
$id |
int |
|
Throws
| Class | Description |
ezcPersistentException |
if the object is not available. |
ezcPersistentException |
if there is no such persistent class. |
loadIfExists
object|null loadIfExists(
string
$class, int
$id )
Returns the persistent object of class $class with id $id.
This method is equivalent to load() except that it returns null instead of throwing an exception if the object does not exist.
Parameters
| Name |
Type |
Description |
$class |
string |
|
$id |
int |
|
loadIntoObject
void loadIntoObject(
object
$pObject, int
$id )
Loads the persistent object with the id $id into the object $pObject.
The class of the persistent object to load is determined by the class of $pObject.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
$id |
int |
|
Throws
| Class | Description |
ezcPersistentException |
if the object is not available. |
ezcPersistentDefinitionNotFoundException |
if $pObject is not of a valid persistent object type. |
ezcPersistentQueryException |
if the find query failed |
refresh
void refresh(
object
$pObject )
Syncronizes the contents of $pObject with those in the database.
Note that calling this method is equavalent with calling loadIntoObject on $pObject with the id of $pObject. Any changes made to $pObject prior to calling refresh() will be discarded.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
Throws
| Class | Description |
ezcPersistentException |
if $pObject is not of a valid persistent object type. |
ezcPersistentException |
if $pObject is not persistent already |
ezcPersistentException |
if the select query failed. |
save
void save(
object
$pObject )
Saves the new persistent object $pObject to the database using an INSERT INTO query.
The correct ID is set to $pObject.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
Throws
| Class | Description |
ezcPersistentException |
if $pObject is not of a valid persistent object type. |
ezcPersistentException |
if $pObject is already stored to the database. |
ezcPersistentException |
if it was not possible to generate a unique identifier for the new object |
ezcPersistentException |
if the insert query failed. |
saveOrUpdate
void saveOrUpdate(
object
$pObject )
Saves or update the persistent object $pObject to the database.
If the object is a new object an INSERT INTO query will be executed. If the object is persistent already it will be updated with an UPDATE query.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
Throws
| Class | Description |
ezcPersistentException |
if $pObject is not of a valid persistent object type. |
ezcPersistentException |
if any of the definition requirements are not met. |
ezcPersistentException |
if the insert or update query failed. |
update
void update(
object
$pObject )
Saves the new persistent object $pObject to the database using an UPDATE query.
Parameters
| Name |
Type |
Description |
$pObject |
object |
|
Throws
| Class | Description |
ezcPersistentDefinitionNotFoundException |
if $pObject is not of a valid persistent object type. |
ezcPersistentObjectNotPersistentException |
if $pObject is not stored in the database already. |
ezcPersistentQueryException |
|
updateFromQuery
void updateFromQuery(
$query )
Parameters
Last updated: Thu, 01 Nov 2007