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)
 
 __sleep ()
 
 setConnectionParams ($params)
 
 getConnectionParams ()
 
 getQuoteIdentifierSymbol ()
 
 quoteIdentifier ($identifier)
 
 quoteValue ($value)
 
 getRealTableName ()
 
 executeSql ($sql, $parameters=[])
 
 select (SelectStatement $selectStmt, PagingInfo $pagingInfo=null)
 
 executeOperation (PersistenceOperation $operation)
 
 getRelations ($hierarchyType='all')
 
 getRelation ($roleName)
 
 getRelationsByType ($type)
 
 getAttributes (array $tags=[], $matchMode='all')
 
 getAttribute ($name)
 
 isSortable ($roleName=null)
 
 getSortkey ($roleName=null)
 
 getDefaultOrder ($roleName=null)
 
 constructOID ($data)
 
 renderCriteria (Criteria $criteria, $placeholder=null, $tableName=null, $columnName=null)
 
 getConnection ()
 
 getAdapter ()
 
 loadObjectsFromSQL (SelectStatement $selectStmt, $buildDepth=BuildDepth::SINGLE, PagingInfo $pagingInfo=null, &$originalData=null)
 
 beginTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 
 getSelectSQL ($criteria=null, $alias=null, $attributes=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)
 
 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 SEQUENCE_CLASS = 'DBSequence'
 
const INTERNAL_VALUE_PREFIX = '_mapper_internal_'
 

Protected Member Functions

 getNextId ()
 
 getRelationImpl ($roleName, $includeManyToMany)
 
 getReferences ()
 
 isPkValue ($name)
 
 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)
 
 convertValueFromStorage ($valueName, $value)
 
 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
 

Constructor & Destructor Documentation

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

Constructor.

Parameters
$persistenceFacade
$permissionManager
$concurrencyManager
$eventManager

Definition at line 83 of file RDBMapper.php.

Member Function Documentation

__sleep ( )

Select data to be stored in the session.

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

Definition at line 99 of file RDBMapper.php.

setConnectionParams (   $params)

Set the connection parameters.

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

Definition at line 110 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 122 of file RDBMapper.php.

getNextId ( )
protected

Get a new id for inserting into the database.

Returns
An id value.

Definition at line 204 of file RDBMapper.php.

getQuoteIdentifierSymbol ( )
See also
PersistenceMapper::getQuoteIdentifierSymbol

Implements PersistenceMapper.

Definition at line 253 of file RDBMapper.php.

quoteIdentifier (   $identifier)
See also
PersistenceMapper::quoteIdentifier

Implements PersistenceMapper.

Definition at line 263 of file RDBMapper.php.

quoteValue (   $value)
See also
PersistenceMapper::quoteValue

Implements PersistenceMapper.

Definition at line 273 of file RDBMapper.php.

getRealTableName ( )

Get the table name with the dbprefix added.

Returns
The table name

Definition at line 284 of file RDBMapper.php.

executeSql (   $sql,
  $parameters = [] 
)

Execute a query on the connection.

Parameters
$sqlThe SQL statement as string
$parametersAn array of values to replace the placeholders with (optional, default: empty array)
Returns
If the query is a select, an array of associative arrays containing the selected data, the number of affected rows else

Definition at line 295 of file RDBMapper.php.

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

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 321 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 358 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 413 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 426 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 433 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 450 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 507 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 526 of file RDBMapper.php.

getReferences ( )
protected

Get the references to other entities.

Returns
Array of AttributeDescription instances

Definition at line 540 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 564 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 571 of file RDBMapper.php.

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

Implements PersistenceMapper.

Definition at line 582 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 611 of file RDBMapper.php.

constructOID (   $data)

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 621 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
Array with condition (string) and placeholder (string)

Definition at line 638 of file RDBMapper.php.

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

Definition at line 679 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 699 of file RDBMapper.php.

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

Definition at line 739 of file RDBMapper.php.

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

Definition at line 783 of file RDBMapper.php.

getConnection ( )

Get the database connection.

Returns
PDOConnection

Definition at line 844 of file RDBMapper.php.

getAdapter ( )

Get the database adapter.

Returns
Zend

Definition at line 855 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 866 of file RDBMapper.php.

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

Definition at line 889 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 907 of file RDBMapper.php.

loadObjectsFromSQL ( SelectStatement  $selectStmt,
  $buildDepth = BuildDepth::SINGLE,
PagingInfo  $pagingInfo = null,
$originalData = 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)
$originalDataA reference that will receive the original database data (optional)
Returns
Array of PersistentObject instances

Definition at line 928 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 978 of file RDBMapper.php.

convertValueFromStorage (   $valueName,
  $value 
)
protected

Convert value after retrieval from storage.

Parameters
$valueName
$value
Returns
Mixed

Definition at line 1010 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 1028 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 1070 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 1133 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 1149 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 1166 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 1180 of file RDBMapper.php.

isInTransaction ( )
protected

Check if the connection is currently in a transaction.

Returns
Boolean

Definition at line 1188 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
PersitentObject
prepareForStorage ( PersistentObject  $object)
abstractprotected

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

Parameters
$objectPersistentObject instance 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,
  $attributes = 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)
$attributesAn array holding names of attributes to select (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))
$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
$objectPersistentObject instance 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
$objectPersistentObject instance 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 SEQUENCE_CLASS = 'DBSequence'

Definition at line 51 of file RDBMapper.php.

const INTERNAL_VALUE_PREFIX = '_mapper_internal_'

Definition at line 74 of file RDBMapper.php.