Detailed Description

RDBMapper maps objects of one type to a relational database schema.

It defines a persistence mechanism that specialized mappers customize by overriding the given template methods.

Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 49 of file RDBMapper.php.

+ Inheritance diagram for RDBMapper:

Public Member Functions

 __construct (PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ConcurrencyManager $concurrencyManager, EventManager $eventManager, Message $message)
 
 __sleep ()
 
 setConnectionParams ($params)
 
 getConnectionParams ()
 
 enableProfiler ()
 
 disableProfiler ()
 
 getProfiler ()
 
 getQuoteIdentifierSymbol ()
 
 quoteIdentifier ($identifier)
 
 quoteValue ($value)
 
 getRealTableName ()
 
 executeSql ($sql, $isSelect=false, $bindValues=array())
 
 executeOperation (PersistenceOperation $operation)
 
 getRelations ($hierarchyType='all')
 
 getRelation ($roleName)
 
 getRelationsByType ($type)
 
 getAttributes (array $tags=array(), $matchMode='all')
 
 getAttribute ($name)
 
 isSortable ($roleName=null)
 
 getSortkey ($roleName=null)
 
 getDefaultOrder ($roleName=null)
 
 renderCriteria (Criteria $criteria, $placeholder=null, $tableName=null, $columnName=null)
 
 getConnection ()
 
 loadObjectsFromSQL (SelectStatement $selectStmt, $buildDepth=BuildDepth::SINGLE, PagingInfo $pagingInfo=null)
 
 beginTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 
 getSelectSQL ($criteria=null, $alias=null, $orderby=null, PagingInfo $pagingInfo=null, $queryId=null)
 
 isForeignKey ($name)
 
- Public Member Functions inherited from AbstractMapper
 __construct (PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ConcurrencyManager $concurrencyManager, EventManager $eventManager, Message $message)
 
 setLogStrategy (OutputStrategy $logStrategy)
 
 hasRelation ($roleName)
 
 hasAttribute ($name)
 
 load (ObjectId $oid, $buildDepth=BuildDepth::SINGLE)
 
 create ($type, $buildDepth=BuildDepth::SINGLE)
 
 save (PersistentObject $object)
 
 delete (PersistentObject $object)
 
 getOIDs ($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadObjects ($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadRelation (array $objects, $role, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
- Public Member Functions inherited from PersistenceMapper
 getType ()
 
 getTypeDisplayName (Message $message)
 
 getTypeDescription (Message $message)
 
 getPkNames ()
 
 getAttributeDisplayName ($name, Message $message)
 
 getAttributeDescription ($name, Message $message)
 
 getProperties ()
 

Public Attributes

const INTERNAL_VALUE_PREFIX = '_mapper_internal_'
 

Protected Member Functions

 getNextId ()
 
 select (SelectStatement $selectStmt, PagingInfo $pagingInfo=null)
 
 getRelationImpl ($roleName, $includeManyToMany)
 
 getReferences ()
 
 isPkValue ($name)
 
 constructOID ($data)
 
 loadImpl (ObjectId $oid, $buildDepth=BuildDepth::SINGLE)
 
 createImpl ($type, $buildDepth=BuildDepth::SINGLE)
 
 saveImpl (PersistentObject $object)
 
 deleteImpl (PersistentObject $object)
 
 getOIDsImpl ($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadObjectsImpl ($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadObjectsFromQueryParts ($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 createObjectFromData (array $data)
 
 applyDataOnLoad (PersistentObject $object, array $objectData)
 
 applyDataOnCreate (PersistentObject $object)
 
 addRelatedObjects (array $objects, $buildDepth=BuildDepth::SINGLE)
 
 loadRelationImpl (array $objects, $role, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 setIsInTransaction ($isInTransaction)
 
 isInTransaction ()
 
 getOwnDefaultOrder ($roleName=null)
 
 getRelationDescriptions ()
 
 getAttributeDescriptions ()
 
 createObject (ObjectId $oid=null)
 
 prepareForStorage (PersistentObject $object)
 
 getRelationSelectSQL (array $otherObjectProxies, $otherRole, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 getInsertSQL (PersistentObject $object)
 
 getUpdateSQL (PersistentObject $object)
 
 getDeleteSQL (ObjectId $oid)
 
 createPKCondition (ObjectId $oid)
 
 getTableName ()
 
- Protected Member Functions inherited from AbstractMapper
 logAction (PersistentObject $obj)
 
 checkAuthorization ($resource, $action)
 
 authorizationFailedError ($resource, $action)
 
 loadImpl (ObjectId $oid, $buildDepth=BuildDepth::SINGLE)
 
 createImpl ($type, $buildDepth=BuildDepth::SINGLE)
 
 saveImpl (PersistentObject $object)
 
 deleteImpl (PersistentObject $object)
 
 getOIDsImpl ($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadObjectsImpl ($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 
 loadRelationImpl (array $objects, $role, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
 

Additional Inherited Members

- Protected Attributes inherited from AbstractMapper
 $_persistenceFacade = null
 
 $_permissionManager = null
 
 $_concurrencyManager = null
 
 $_eventManager = null
 
 $_message = null
 

Constructor & Destructor Documentation

__construct ( PersistenceFacade  $persistenceFacade,
PermissionManager  $permissionManager,
ConcurrencyManager  $concurrencyManager,
EventManager  $eventManager,
Message  $message 
)

Constructor.

Parameters
$persistenceFacade
$permissionManager
$concurrencyManager
$eventManager
$message

Definition at line 83 of file RDBMapper.php.

Member Function Documentation

__sleep ( )

Select data to be stored in the session.

PDO throws an excetption if tried to be (un-)serialized.

Definition at line 100 of file RDBMapper.php.

setConnectionParams (   $params)

Set the connection parameters.

Parameters
$paramsInitialization data given in an assoziative array with the following keys: dbType, dbHostName, dbUserName, dbPassword, dbName if dbPrefix is given it will be appended to every table string, which is usefull if different cms operate on the same database

Definition at line 111 of file RDBMapper.php.

getConnectionParams ( )

Get the connection parameters.

Returns
Assoziative array with the following keys: dbType, dbHostName, dbUserName, dbPassword, dbName, dbPrefix

Definition at line 123 of file RDBMapper.php.

enableProfiler ( )

Enable profiling.

Definition at line 202 of file RDBMapper.php.

disableProfiler ( )

Disable profiling.

Definition at line 212 of file RDBMapper.php.

getProfiler ( )

Get the profiler.

Returns
Zend_Db_Profiler

Definition at line 223 of file RDBMapper.php.

getNextId ( )
protected

Get a new id for inserting into the database.

Returns
An id value.

Definition at line 234 of file RDBMapper.php.

getQuoteIdentifierSymbol ( )
See also
PersistenceMapper::getQuoteIdentifierSymbol

Implements PersistenceMapper.

Definition at line 275 of file RDBMapper.php.

quoteIdentifier (   $identifier)
See also
PersistenceMapper::quoteIdentifier

Implements PersistenceMapper.

Definition at line 285 of file RDBMapper.php.

quoteValue (   $value)
See also
PersistenceMapper::quoteValue

Implements PersistenceMapper.

Definition at line 295 of file RDBMapper.php.

getRealTableName ( )

Get the table name with the dbprefix added.

Returns
The table name

Definition at line 306 of file RDBMapper.php.

executeSql (   $sql,
  $isSelect = false,
  $bindValues = array() 
)

Execute a query on the connection.

Parameters
$sqlThe SQL statement as string
$isSelectBoolean whether the statement is a select statement (optional, default: false)
$bindValuesAn array of data to bind to the placeholders (optional, default: empty array)
Returns
If isSelect is true, an array as the result of PDOStatement::fetchAll(PDO::FETCH_ASSOC), the number of affected rows else

Definition at line 318 of file RDBMapper.php.

select ( SelectStatement  $selectStmt,
PagingInfo  $pagingInfo = null 
)
protected

Execute a select query on the connection.

Parameters
$selectStmtA SelectStatement instance
$pagingInfoAn PagingInfo instance describing which page to load (optional, default: null)
Returns
An array as the result of PDOStatement::fetchAll(PDO::FETCH_ASSOC)

Definition at line 346 of file RDBMapper.php.

executeOperation ( PersistenceOperation  $operation)
See also
PersistenceMapper::executeOperation()

Implements PersistenceMapper.

Definition at line 383 of file RDBMapper.php.

getRelations (   $hierarchyType = 'all')
See also
PersistenceMapper::getRelations()

Implements PersistenceMapper.

Definition at line 437 of file RDBMapper.php.

getRelation (   $roleName)
See also
PersistenceMapper::getRelation()

Implements PersistenceMapper.

Definition at line 450 of file RDBMapper.php.

getRelationsByType (   $type)
See also
PersistenceMapper::getRelationsByType()

Implements PersistenceMapper.

Definition at line 457 of file RDBMapper.php.

getRelationImpl (   $roleName,
  $includeManyToMany 
)
protected

Internal implementation of PersistenceMapper::getRelation()

Parameters
$roleNameThe role name of the relation
$includeManyToManyBoolean whether to also search in relations to many to many objects or not
Returns
RelationDescription

Definition at line 474 of file RDBMapper.php.

getAttributes ( array  $tags = array(),
  $matchMode = 'all' 
)
See also
PersistenceMapper::getAttributes()

Implements PersistenceMapper.

Definition at line 530 of file RDBMapper.php.

getAttribute (   $name)
See also
PersistenceMapper::getAttribute()

Implements PersistenceMapper.

Definition at line 549 of file RDBMapper.php.

getReferences ( )
protected

Get the references to other entities.

Returns
Array of AttributeDescription instances

Definition at line 563 of file RDBMapper.php.

isSortable (   $roleName = null)
See also
PersistenceMapper::isSortable()

Implements PersistenceMapper.

Definition at line 587 of file RDBMapper.php.

getSortkey (   $roleName = null)
See also
PersistenceMapper::getSortkey()

Implements PersistenceMapper.

Definition at line 594 of file RDBMapper.php.

getDefaultOrder (   $roleName = null)
See also
PersistenceMapper::getDefaultOrder()

Implements PersistenceMapper.

Definition at line 605 of file RDBMapper.php.

isPkValue (   $name)
protected

Check if a value is a primary key value.

Parameters
$nameThe name of the value
Returns
Boolean

Definition at line 634 of file RDBMapper.php.

constructOID (   $data)
protected

Construct an object id from given row data.

Parameters
$dataAn associative array with the pk column names as keys and pk values as values
Returns
The oid

Definition at line 644 of file RDBMapper.php.

renderCriteria ( Criteria  $criteria,
  $placeholder = null,
  $tableName = null,
  $columnName = null 
)

Render a Criteria instance as string.

Parameters
$criteriaThe Criteria instance
$placeholderPlaceholder (':columnName', '?') used instead of the value (optional, default: null)
$tableNameThe table name to use (may differ from criteria's type attribute) (optional)
$columnNameThe column name to use (may differ from criteria's attribute attribute) (optional)
Returns
String

Definition at line 661 of file RDBMapper.php.

loadImpl ( ObjectId  $oid,
  $buildDepth = BuildDepth::SINGLE 
)
protected
See also
AbstractMapper::loadImpl()

Definition at line 700 of file RDBMapper.php.

createImpl (   $type,
  $buildDepth = BuildDepth::SINGLE 
)
protected
See also
AbstractMapper::createImpl()
Note
The type parameter is not used here because this class only constructs one type

Definition at line 720 of file RDBMapper.php.

saveImpl ( PersistentObject  $object)
protected
See also
AbstractMapper::saveImpl()

Definition at line 760 of file RDBMapper.php.

deleteImpl ( PersistentObject  $object)
protected
See also
AbstractMapper::deleteImpl()

Definition at line 804 of file RDBMapper.php.

getConnection ( )

Get the database connection.

Returns
A reference to the PDOConnection object

Definition at line 865 of file RDBMapper.php.

getOIDsImpl (   $type,
  $criteria = null,
  $orderby = null,
PagingInfo  $pagingInfo = null 
)
protected
See also
PersistenceMapper::getOIDsImpl()
Note
The type parameter is not used here because this class only constructs one type

Definition at line 876 of file RDBMapper.php.

loadObjectsImpl (   $type,
  $buildDepth = BuildDepth::SINGLE,
  $criteria = null,
  $orderby = null,
PagingInfo  $pagingInfo = null 
)
protected
See also
PersistenceFacade::loadObjectsImpl()

Definition at line 894 of file RDBMapper.php.

loadObjectsFromQueryParts (   $type,
  $buildDepth = BuildDepth::SINGLE,
  $criteria = null,
  $orderby = null,
PagingInfo  $pagingInfo = null 
)
protected

Load objects defined by several query parts.

Parameters
$typeThe type of the object
$buildDepthOne of the BUILDDEPTH constants or a number describing the number of generations to build (except BuildDepth::REQUIRED, BuildDepth::PROXIES_ONLY) (default: BuildDepth::SINGLE)
$criteriaAn array of Criteria instances that define conditions on the type's attributes (optional, default: null)
$orderbyAn array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: null)
$pagingInfoA reference PagingInfo instance (optional, default: null)
Returns
Array of PersistentObject instances

Definition at line 912 of file RDBMapper.php.

loadObjectsFromSQL ( SelectStatement  $selectStmt,
  $buildDepth = BuildDepth::SINGLE,
PagingInfo  $pagingInfo = null 
)

Load objects defined by a select statement.

Parameters
$selectStmtA SelectStatement instance
$buildDepthOne of the BUILDDEPTH constants or a number describing the number of generations to build (except BuildDepth::REQUIRED, BuildDepth::PROXIES_ONLY) (default: BuildDepth::SINGLE)
$pagingInfoA reference PagingInfo instance (optional, default: null)
Returns
Array of PersistentObject instances

Definition at line 932 of file RDBMapper.php.

createObjectFromData ( array  $data)
protected

Create an object of the mapper's type with the given attributes from the given data.

Parameters
$dataAn associative array with the attribute names as keys and the attribute values as values
Returns
PersistentObject

Definition at line 973 of file RDBMapper.php.

applyDataOnLoad ( PersistentObject  $object,
array  $objectData 
)
protected

Apply the loaded object data to the object.

Note
Subclasses must implement this method to define their object type.
Parameters
$objectA reference to the object created with createObject method to which the data should be applied
$objectDataAn associative array with the data returned by execution of the database select statement (given by getSelectSQL).

Definition at line 1003 of file RDBMapper.php.

applyDataOnCreate ( PersistentObject  $object)
protected

Apply the default data to the object.

Note
Subclasses must implement this method to define their object type.
Parameters
$objectA reference to the object created with createObject method to which the data should be applied

Definition at line 1019 of file RDBMapper.php.

addRelatedObjects ( array  $objects,
  $buildDepth = BuildDepth::SINGLE 
)
protected

Append the child data to a list of object.

If the buildDepth does not determine to load a child generation, only the oids of the children will be loaded.

Parameters
$objectsArray of PersistentObject instances to append the children to
$buildDepth
See also
PersistenceFacade::loadObjects()

Definition at line 1036 of file RDBMapper.php.

loadRelationImpl ( array  $objects,
  $role,
  $buildDepth = BuildDepth::SINGLE,
  $criteria = null,
  $orderby = null,
PagingInfo  $pagingInfo = null 
)
protected
See also
AbstractMapper::loadRelationImpl()

Definition at line 1079 of file RDBMapper.php.

beginTransaction ( )
See also
PersistenceMapper::beginTransaction() Since all RDBMapper instances with the same connection parameters share one connection, the call will be ignored, if the method was already called for another instance.

Implements PersistenceMapper.

Definition at line 1138 of file RDBMapper.php.

commitTransaction ( )
See also
PersistenceMapper::commitTransaction() Since all RDBMapper instances with the same connection parameters share one connection, the call will be ignored, if the method was already called for another instance.

Implements PersistenceMapper.

Definition at line 1154 of file RDBMapper.php.

rollbackTransaction ( )
See also
PersistenceMapper::rollbackTransaction()
Note
Rollbacks have to be supported by the database. Since all RDBMapper instances with the same connection parameters share one connection, the call will be ignored, if the method was already called for another instance.

Implements PersistenceMapper.

Definition at line 1171 of file RDBMapper.php.

setIsInTransaction (   $isInTransaction)
protected

Set the transaction state for the connection.

Parameters
$isInTransactionBoolean whether the connection is in a transaction or not

Definition at line 1185 of file RDBMapper.php.

isInTransaction ( )
protected

Check if the connection is currently in a transaction.

Returns
Boolean

Definition at line 1193 of file RDBMapper.php.

getOwnDefaultOrder (   $roleName = null)
abstractprotected

TEMPLATE METHODS Subclasses must implement this method to define their object type.

Get the names of the attributes in the mapped class to order by default and the sort directions (ASC or DESC). The roleName parameter allows to ask for the order with respect to a specific role.

Parameters
$roleNameThe role name of the relation (optional, default: null)
Returns
An array of assciative arrays with the keys sortFieldName and sortDirection (ASC or DESC)
getRelationDescriptions ( )
abstractprotected

Get a list of all RelationDescriptions.

Returns
An associative array with the relation names as keys and the RelationDescription instances as values.
getAttributeDescriptions ( )
abstractprotected

Get a list of all AttributeDescriptions.

Returns
An associative array with the attribute names as keys and the AttributeDescription instances as values.
createObject ( ObjectId  $oid = null)
abstractprotected

Factory method for the supported object type.

Parameters
$oidThe object id (maybe null)
Returns
A reference to the created object.
prepareForStorage ( PersistentObject  $object)
abstractprotected

Set the object primary key and foreign key values for storing the object in the database.

Parameters
$objectA reference to the object to insert.
Note
The object does not have the final object id set. If a new id value for a primary key column is needed.
The prepared object will be used in the application afterwards. So values that are only to be modified for the storage process should be changed in getInsertSQL() and getUpdateSQL() only! for the insert statement, use RDBMapper::getNextId().
getSelectSQL (   $criteria = null,
  $alias = null,
  $orderby = null,
PagingInfo  $pagingInfo = null,
  $queryId = null 
)
abstract

Get the SQL command to select object data from the database.

Parameters
$criteriaAn array of Criteria instances that define conditions on the type's attributes (optional, default: null)
$aliasThe alias for the table name (default: null)
$orderbyAn array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: null)
$pagingInfoAn PagingInfo instance describing which page to load (optional, default: null))
$queryIdIdentifier for the query cache (maybe null to let implementers handle it). (default: null)
Returns
SelectStatement instance that selects all object data that match the condition or an array with the query parts.
Note
The names of the data item columns MUST match the data item names provided in the '_datadef' array from RDBMapper::getObjectDefinition() Use alias names if not! The selected data will be put into the '_data' array of the object definition.
getRelationSelectSQL ( array  $otherObjectProxies,
  $otherRole,
  $criteria = null,
  $orderby = null,
PagingInfo  $pagingInfo = null 
)
abstractprotected

Get the SQL command to select those objects from the database that are related to the given object.

Note
Navigability may not be checked in this method
In case of a sortable many to many relation, the sortkey value must also be selected
Parameters
$otherObjectProxiesArray of PersistentObjectProxy instances for the objects to load the relatives for.
$otherRoleThe role of the other object in relation to the objects to load.
$criteriaAn array of Criteria instances that define conditions on the object's attributes (optional, default: null)
$orderbyAn array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: null)
$pagingInfoAn PagingInfo instance describing which page to load (optional, default: null)
Returns
Array with SelectStatement instance and the attribute names which establish the relation between the loaded objects and the proxies (proxies's attribute name first)
getInsertSQL ( PersistentObject  $object)
abstractprotected

Get the SQL command to insert a object into the database.

Parameters
$objectA reference to the object to insert.
Returns
Array of PersistenceOperation instances that insert a new object.
getUpdateSQL ( PersistentObject  $object)
abstractprotected

Get the SQL command to update a object in the database.

Parameters
$objectA reference to the object to update.
Returns
Array of PersistenceOperation instances that update an existing object.
getDeleteSQL ( ObjectId  $oid)
abstractprotected

Get the SQL command to delete a object from the database.

Parameters
$oidThe object id of the object to delete.
Returns
Array of PersistenceOperation instances that delete an existing object.
createPKCondition ( ObjectId  $oid)
abstractprotected

Create an array of condition Criteria instances for the primary key values.

Parameters
$oidThe object id that defines the primary key values
Returns
Array of Criteria instances
getTableName ( )
abstractprotected

Get the name of the database table, where this type is mapped to.

Returns
String
isForeignKey (   $name)
abstract

Determine if an attribute is a foreign key.

Returns
Boolean

Member Data Documentation

const INTERNAL_VALUE_PREFIX = '_mapper_internal_'

Definition at line 73 of file RDBMapper.php.