Apache Zeta Components Manual :: Docs For Class ezcPersistentSessionFoundation
PersistentObject::ezcPersistentSessionFoundation
Interface ezcPersistentSessionFoundation
Interface for ezcPersistentSession and its decorators.
This interface defines the public methods of ezcPersistentSession and decorators for this class. The interface needs to be implemented by any class that can be used like ezcPersistentSession, especially, if this class shall be used with ezcPersistentSessionInstance.
Source for this file: /PersistentObject/src/interfaces/persistent_session_foundation.php
Version: | //autogen// |
Properties
ezcDbHandler | read |
$database
The database handler set in the constructor. |
ezcPersistentDefinitionManager | read |
$definitionManager
The persistent definition manager set in the constructor. |
Method Summary
public void |
addRelatedObject(
$object
, $relatedObject
, [ $relationName
= null] )
Create a relation between $object and $relatedObject. |
public ezcQueryDelete |
createDeleteQuery(
$class
)
Returns a delete query for the given persistent object $class. |
public ezcQuerySelect |
createFindQuery(
$class
)
Returns a select query for the given persistent object $class. |
public ezcPersistentFindQuery |
createRelationFindQuery(
$object
, $relatedClass
, [ $relationName
= null] )
Returns the base query for retrieving related objects. |
public ezcQueryUpdate |
createUpdateQuery(
$class
)
Returns an update query for the given persistent object $class. |
public void |
delete(
$object
)
Deletes the persistent object $object. |
public void |
deleteFromQuery(
$query
)
Deletes persistent objects using the query $query. |
public array(object($class)) |
find(
$query
, [ $class
= null] )
Returns the result of the query $query as a list of objects. |
public ezcPersistentFindIterator |
findIterator(
$query
, [ $class
= null] )
Returns the result of $query for the $class as an iterator. |
public array(string=>string) |
generateAliasMap(
$def
, [ $prefixTableName
= true] )
Returns a hash map between property and column name for the given definition $def. |
public array(int=>string) |
getColumnsFromDefinition(
$def
, [ $prefixTableName
= true] )
Returns all the columns defined in the persistent object. |
public object($relatedClass) |
getRelatedObject(
$object
, $relatedClass
, [ $relationName
= null] )
Returns the related object of a given $relatedClass for an $object. |
public array(int=>object($relatedClass)) |
getRelatedObjects(
$object
, $relatedClass
, [ $relationName
= null] )
Returns the related objects of a given $relatedClass for an $object. |
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(
$object
, $id
)
Loads the persistent object with the id $id into the object $object. |
public void |
refresh(
$object
)
Syncronizes the contents of $object with those in the database. |
public void |
removeRelatedObject(
$object
, $relatedObject
, [ $relationName
= null] )
Removes the relation between $object and $relatedObject. |
public void |
save(
$object
)
Saves the new persistent object $object to the database using an INSERT INTO query. |
public void |
saveOrUpdate(
$object
)
Saves or updates the persistent object $object to the database. |
public void |
update(
$object
)
Saves the new persistent object $object to the database using an UPDATE query. |
public void |
updateFromQuery(
$query
)
Updates persistent objects using the query $query. |
Methods
addRelatedObject
Create a relation between $object and $relatedObject.
This method is used to create a relation between the given source $object and the desired $relatedObject. The related object is not stored in the database automatically, only the desired properties are set. An exception is {@ezcPersistentManyToManyRelation}s, where the relation record is stored automatically and there is no need to store $relatedObject explicitly after establishing the relation.
If there are multiple relations defined between the class of $object and $relatedObject (via ezcPersistentRelationCollection), the $relationName parameter becomes mandatory to determine, which exact relation should be used.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | |
$relatedObject |
object | |
$relationName |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentRelationOperationNotSupportedException |
if a relation to create is marked as "reverse" ezcPersistentRelation->reverse. |
ezcPersistentRelationNotFoundException |
if the deisred relation is not defined. |
createDeleteQuery
Returns a delete query for the given persistent object $class.
The query is initialized to delete from the correct table and it is only neccessary to set the where clause.
Example:
- $q->where( $q->expr->gt( 'age', $q->bindValue( 15 ) ) );
Parameters:
Name | Type | Description |
---|---|---|
$class |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if there is no such persistent class. |
createFindQuery
Returns a select query for the given persistent object $class.
The query is initialized to fetch all columns from the correct table and has correct alias mappings between columns and property names of the persistent $class.
Example:
Parameters:
Name | Type | Description |
---|---|---|
$class |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if there is no such persistent class. |
createRelationFindQuery
Returns the base query for retrieving related objects.
See getRelatedObject() and getRelatedObjects(). Can be modified by additional where conditions and simply be used with find() and the related class name, to retrieve a sub-set of related objects.
If multiple relations are defined for the $relatedClass (using ezcPersistentRelationCollection), the parameter $relationName becomes mandatory to determine which relation definition to use. For normal relations, this parameter is silently ignored.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | |
$relatedClass |
string | |
$relationName |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentRelationNotFoundException |
if the given $object does not have a relation to $relatedClass. |
createUpdateQuery
Returns an update query for the given persistent object $class.
The query is initialized to update the correct table and it is only neccessary to set the correct values.
Parameters:
Name | Type | Description |
---|---|---|
$class |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentDefinitionNotFoundException |
if there is no such persistent class. |
delete
Deletes the persistent object $object.
This method will perform a DELETE query based on the identifier of the persistent object $object. After delete() the ID property of $object will be reset to null. It is possible to save() $object afterwards. $object will then be stored with a new ID.
If you defined relations for the given object, these will be checked to be defined as cascading. If cascading is configured, the related objects with this relation will be deleted, too.
Relations that support cascading are:
- ezcPersistenOneToManyRelation
- ezcPersistenOneToOne
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | The persistent object to delete. |
Exceptions:
Type | 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
Deletes persistent objects using the query $query.
The $query should be created using createDeleteQuery().
Currently this method only executes the provided query. Future releases PersistentSession may introduce caching of persistent objects. When caching is introduced it will be required to use this method to run cusom delete queries. To avoid being incompatible with future releases it is advisable to always use this method when running custom delete queries on persistent objects.
Parameters:
Name | Type | Description |
---|---|---|
$query |
ezcQueryDelete |
Exceptions:
Type | Description |
---|---|
ezcPersistentQueryException |
if the delete query failed. |
find
Returns the result of the query $query as a list of objects.
Returns the persistent objects found for $class using the submitted $query. $query should be created using createFindQuery() to ensure correct alias mappings and can be manipulated as needed.
Example:
If you are retrieving large result set, consider using findIterator() instead.
Example:
- foreach( $objects as $object )
- {
- // ...
- }
Parameters:
Name | Type | Description |
---|---|---|
$query |
ezcPersistentFindQuery|ezcQuerySelect | |
$class |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentDefinitionNotFoundException |
if there is no such persistent class. |
ezcPersistentQueryException |
if the find query failed. |
ezcBaseValueException |
if $query parameter is not an instance of ezcPersistentFindQuery or ezcQuerySelect. Or if $class is missing if you use ezcQuerySelect. |
findIterator
Returns the result of $query for the $class as an iterator.
This method is similar to find() but returns an ezcPersistentFindIterator instead of an array of objects. This is useful if you are going to loop over the objects and just need them one at the time. Because you only instantiate one object it is faster than find(). In addition, only 1 record is retrieved from the database in each iteration, which may reduce the data transfered between the database and PHP, if you iterate only through a small subset of the affected records.
Note that if you do not loop over the complete result set you must call ezcPersistentFindIterator::flush() before issuing another query.
Parameters:
Name | Type | Description |
---|---|---|
$query |
ezcPersistentFindQuery|ezcQuerySelect | |
$class |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentDefinitionNotFoundException |
if there is no such persistent class. |
ezcPersistentQueryException |
if the find query failed. |
ezcBaseValueException |
if $query parameter is not an instance of ezcPersistentFindQuery or ezcQuerySelect. Or if $class is missing if you use ezcQuerySelect. |
generateAliasMap
Returns a hash map between property and column name for the given definition $def.
The alias map can be used with the query classes. If $prefixTableName is set to false, only the column names are used as alias targets.
Parameters:
Name | Type | Description |
---|---|---|
$def |
ezcPersistentObjectDefinition | Definition. |
$prefixTableName |
bool |
getColumnsFromDefinition
Returns all the columns defined in the persistent object.
If $prefixTableName is set to false, raw column names will be used, without prefixed table name.
Parameters:
Name | Type | Description |
---|---|---|
$def |
ezcPersistentObjectDefinition | Defintion. |
$prefixTableName |
bool |
getRelatedObject
Returns the related object of a given $relatedClass for an $object.
This method returns the related object of type $relatedClass for the object $object. This method (in contrast to getRelatedObjects()) always returns a single result object, no matter if more related objects could be found (e.g. ezcPersistentOneToManyRelation). If no related object is found, an exception is thrown, while getRelatedObjects() just returns an empty array in this case.
Example:
- echo "Address of this person: " . $relatedAddress->__toString();
Relations that should preferably be used with this method are:
For other relation types getRelatedObjects() is recommended.If multiple relations are defined for the $relatedClass (using ezcPersistentRelationCollection), the parameter $relationName becomes mandatory to determine which relation definition to use. For normal relations, this parameter is silently ignored.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | |
$relatedClass |
string | |
$relationName |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentRelationNotFoundException |
if the given $object does not have a relation to $relatedClass. |
getRelatedObjects
Returns the related objects of a given $relatedClass for an $object.
This method returns the related objects of type $relatedClass for the given $object. This method (in contrast to getRelatedObject()) always returns an array of found objects, no matter if only 1 object was found (e.g. ezcPersistentManyToOneRelation), none or several (ezcPersistentManyToManyRelation).
Example:
Relations that should preferably be used with this method are:
For other relation types getRelatedObject() is recommended.If multiple relations are defined for the $relatedClass (using ezcPersistentRelationCollection), the parameter $relationName becomes mandatory to determine which relation definition to use. For normal relations, this parameter is silently ignored.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | |
$relatedClass |
string | |
$relationName |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentRelationNotFoundException |
if the given $object does not have a relation to $relatedClass. |
load
Returns the persistent object of class $class with id $id.
Parameters:
Name | Type | Description |
---|---|---|
$class |
string | |
$id |
int |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if the object is not available. |
ezcPersistentObjectException |
if there is no such persistent class. |
loadIfExists
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
Loads the persistent object with the id $id into the object $object.
The class of the persistent object to load is determined by the class of $object.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | |
$id |
int |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if the object is not available. |
ezcPersistentDefinitionNotFoundException |
if $object is not of a valid persistent object type. |
ezcPersistentQueryException |
if the find query failed. |
refresh
Syncronizes the contents of $object with those in the database.
Note that calling this method is equavalent with calling loadIntoObject() on $object with the id of $object. Any changes made to $object prior to calling refresh() will be discarded.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if $object is not of a valid persistent object type. |
ezcPersistentObjectException |
if $object is not persistent already. |
ezcPersistentObjectException |
if the select query failed. |
removeRelatedObject
Removes the relation between $object and $relatedObject.
This method is used to delete an existing relation between 2 objects. Like addRelatedObject() this method does not store the related object after removing its relation properties (unset), except for ezcPersistentManyToManyRelation()s, for which the relation record is deleted from the database.
If between the classes of $object and $relatedObject multiple relations are defined using a ezcPersistentRelationCollection, the $relationName parameter becomes necessary. It defines which exact relation to affect here.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object | Source object of the relation. |
$relatedObject |
object | Related object. |
$relationName |
string |
Exceptions:
Type | Description |
---|---|
ezcPersistentRelationOperationNotSupportedException |
if a relation to create is marked as "reverse". |
ezcPersistentRelationNotFoundException |
if the deisred relation is not defined. |
save
Saves the new persistent object $object to the database using an INSERT INTO query.
The correct ID is set to $object.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object |
Exceptions:
Type | Description |
---|---|
ezcPersistentObjectException |
if $object is not of a valid persistent object type. |
ezcPersistentObjectException |
if $object is already stored to the database. |
ezcPersistentObjectException |
if it was not possible to generate a unique identifier for the new object. |
ezcPersistentObjectException |
if the insert query failed. |
saveOrUpdate
Saves or updates the persistent object $object 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 |
---|---|---|
$object |
object |
Exceptions:
Type | Description |
---|---|
ezcPersistentDefinitionNotFoundException |
if the definition of the persistent object could not be loaded. |
ezcPersistentObjectException |
if $object is not of a valid persistent object type. |
ezcPersistentObjectException |
if any of the definition requirements are not met. |
ezcPersistentObjectException |
if the insert or update query failed. |
update
Saves the new persistent object $object to the database using an UPDATE query.
Parameters:
Name | Type | Description |
---|---|---|
$object |
object |
Exceptions:
Type | Description |
---|---|
ezcPersistentDefinitionNotFoundException |
if $object is not of a valid persistent object type. |
ezcPersistentObjectNotPersistentException |
if $object is not stored in the database already. |
ezcPersistentQueryException |
updateFromQuery
Updates persistent objects using the query $query.
The $query should be created using createUpdateQuery().
Currently this method only executes the provided query. Future releases PersistentSession may introduce caching of persistent objects. When caching is introduced it will be required to use this method to run cusom delete queries. To avoid being incompatible with future releases it is advisable to always use this method when running custom delete queries on persistent objects.
Parameters:
Name | Type | Description |
---|---|---|
$query |
ezcQueryUpdate |
Exceptions:
Type | Description |
---|---|
ezcPersistentQueryException |
if the update query failed. |