Detailed Description

AbstractRDBMapper 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 52 of file AbstractRDBMapper.php.

+ Inheritance diagram for AbstractRDBMapper:

Public Member Functions

 __construct (PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ConcurrencyManager $concurrencyManager, EventManager $eventManager)
 
 __destruct ()
 
 __sleep ()
 
 setConnectionParams ($params)
 
 getConnectionParams ()
 
 getConnection ()
 
 getAdapter ()
 
 getQuoteIdentifierSymbol ()
 
 quoteIdentifier ($identifier)
 
 quoteValue ($value)
 
 getRealTableName ()
 
 executeSql ($sql, $parameters=[])
 
 select (SelectStatement $selectStmt, PagingInfo $pagingInfo=null)
 
 executeOperation (PersistenceOperation $operation)
 
 getRelations ($hierarchyType='all')
 
 getAttributes (array $tags=[], $matchMode='all')
 
 isSortable ($roleName=null)
 
 getSortkey ($roleName=null)
 
 getDefaultOrder ($roleName=null)
 
 constructOID ($data)
 
 renderCriteria (Criteria $criteria, $placeholder=null, $tableName=null, $columnName=null)
 
 loadObjectsFromSQL (SelectStatement $selectStmt, $buildDepth=BuildDepth::SINGLE, PagingInfo $pagingInfo=null, &$originalData=null)
 
 handleDbEvent ($e)
 
 beginTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 
 getStatements ()
 
 getSelectSQL ($criteria=null, $alias=null, $attributes=null, $orderby=null, PagingInfo $pagingInfo=null, $queryId=null)
 
 isForeignKey ($name)
 
- Public Member Functions inherited from AbstractMapper
 setLogStrategy (OutputStrategy $logStrategy)
 
 getTypeDisplayName (Message $message)
 
 getTypeDescription (Message $message)
 
 hasRelation ($roleName)
 
 getRelation ($roleName)
 
 getRelationsByType ($type)
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 getReferences ()
 
 getAttributeDisplayName ($name, Message $message)
 
 getAttributeDescription ($name, Message $message)
 
 getProperties ()
 
 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 ()
 
 getPkNames ()
 

Public Attributes

const SEQUENCE_CLASS = 'DBSequence'
 
const INTERNAL_VALUE_PREFIX = '_mapper_internal_'
 

Protected Member Functions

 getSequenceMapper ()
 
 getNextId ()
 
 getRelationIncludingNM ($roleName)
 
 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)
 

Static Protected Member Functions

static getMapper ($type, $strict=true)
 

Additional Inherited Members

- Protected Attributes inherited from AbstractMapper
 $persistenceFacade = null
 
 $permissionManager = null
 
 $concurrencyManager = null
 
 $eventManager = null
 

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
$persistenceFacade
$permissionManager
$concurrencyManager
$eventManager

Reimplemented from AbstractMapper.

Definition at line 92 of file AbstractRDBMapper.php.

◆ __destruct()

__destruct ( )

Destructor.

Definition at line 113 of file AbstractRDBMapper.php.

Member Function Documentation

◆ __sleep()

__sleep ( )

Select data to be stored in the session.

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

Definition at line 121 of file AbstractRDBMapper.php.

◆ setConnectionParams()

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 132 of file AbstractRDBMapper.php.

◆ getConnectionParams()

getConnectionParams ( )

Get the connection parameters.

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

Definition at line 144 of file AbstractRDBMapper.php.

◆ getConnection()

getConnection ( )
See also
RDBMapper::getConnection()

Implements RDBMapper.

Definition at line 151 of file AbstractRDBMapper.php.

◆ getAdapter()

getAdapter ( )
See also
RDBMapper::getAdapter()

Implements RDBMapper.

Definition at line 161 of file AbstractRDBMapper.php.

◆ getMapper()

static getMapper (   $type,
  $strict = true 
)
staticprotected

Get the mapper for a Node and optionally check if it is a supported one.

Parameters
$typeThe type of Node to get the mapper for
$strictBoolean indicating if the mapper must be an instance of RDBMapper (default true)
Returns
RDBMapper instance

Definition at line 174 of file AbstractRDBMapper.php.

◆ getSequenceMapper()

getSequenceMapper ( )
protected

Get the sequence mapper.

Returns
PersistenceMapper

Definition at line 266 of file AbstractRDBMapper.php.

◆ getNextId()

getNextId ( )
protected

Get a new id for inserting into the database.

Returns
An id value.

Definition at line 277 of file AbstractRDBMapper.php.

◆ getQuoteIdentifierSymbol()

getQuoteIdentifierSymbol ( )
See also
RDBMapper::getQuoteIdentifierSymbol()

Implements RDBMapper.

Definition at line 329 of file AbstractRDBMapper.php.

◆ quoteIdentifier()

quoteIdentifier (   $identifier)
See also
RDBMapper::quoteIdentifier()

Implements RDBMapper.

Definition at line 339 of file AbstractRDBMapper.php.

◆ quoteValue()

quoteValue (   $value)
See also
RDBMapper::quoteValue()

Implements RDBMapper.

Definition at line 349 of file AbstractRDBMapper.php.

◆ getRealTableName()

getRealTableName ( )
See also
RDBMapper::getRealTableName()

Implements RDBMapper.

Definition at line 359 of file AbstractRDBMapper.php.

◆ executeSql()

executeSql (   $sql,
  $parameters = [] 
)

Execute a query on the connection.

Parameters
$sqlThe SQL statement as string
$parametersAn associative array of parameter name/values pairs 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 370 of file AbstractRDBMapper.php.

◆ select()

select ( SelectStatement  $selectStmt,
PagingInfo  $pagingInfo = null 
)
See also
RDBMapper::select()

Implements RDBMapper.

Definition at line 393 of file AbstractRDBMapper.php.

◆ executeOperation()

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

Implements PersistenceMapper.

Definition at line 430 of file AbstractRDBMapper.php.

◆ getRelations()

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

Implements PersistenceMapper.

Definition at line 485 of file AbstractRDBMapper.php.

◆ getRelationIncludingNM()

getRelationIncludingNM (   $roleName)
protected

Implementation of PersistenceMapper::getRelation() including nm classes in many to many relations.

Parameters
$roleNameThe role name of the relation
Returns
RelationDescription

Definition at line 496 of file AbstractRDBMapper.php.

◆ getAttributes()

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

Implements PersistenceMapper.

Definition at line 540 of file AbstractRDBMapper.php.

◆ isSortable()

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

Implements PersistenceMapper.

Definition at line 568 of file AbstractRDBMapper.php.

◆ getSortkey()

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

Implements PersistenceMapper.

Definition at line 575 of file AbstractRDBMapper.php.

◆ getDefaultOrder()

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

Implements PersistenceMapper.

Definition at line 586 of file AbstractRDBMapper.php.

◆ isPkValue()

isPkValue (   $name)
protected

Check if a value is a primary key value.

Parameters
$nameThe name of the value
Returns
Boolean

Definition at line 615 of file AbstractRDBMapper.php.

◆ constructOID()

constructOID (   $data)
See also
RDBMapper::constructOID()

Implements RDBMapper.

Definition at line 623 of file AbstractRDBMapper.php.

◆ renderCriteria()

renderCriteria ( Criteria  $criteria,
  $placeholder = null,
  $tableName = null,
  $columnName = null 
)
See also
RDBMapper::renderCriteria()

Implements RDBMapper.

Definition at line 635 of file AbstractRDBMapper.php.

◆ loadImpl()

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

Reimplemented from AbstractMapper.

Definition at line 679 of file AbstractRDBMapper.php.

◆ createImpl()

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

Reimplemented from AbstractMapper.

Definition at line 699 of file AbstractRDBMapper.php.

◆ saveImpl()

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

Reimplemented from AbstractMapper.

Definition at line 739 of file AbstractRDBMapper.php.

◆ deleteImpl()

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

Reimplemented from AbstractMapper.

Definition at line 783 of file AbstractRDBMapper.php.

◆ getOIDsImpl()

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

Reimplemented from AbstractMapper.

Definition at line 844 of file AbstractRDBMapper.php.

◆ loadObjectsImpl()

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

Reimplemented from AbstractMapper.

Definition at line 867 of file AbstractRDBMapper.php.

◆ loadObjectsFromQueryParts()

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 885 of file AbstractRDBMapper.php.

◆ loadObjectsFromSQL()

loadObjectsFromSQL ( SelectStatement  $selectStmt,
  $buildDepth = BuildDepth::SINGLE,
PagingInfo  $pagingInfo = null,
$originalData = null 
)
See also
RDBMapper::loadObjectsFromSQL()

Implements RDBMapper.

Definition at line 900 of file AbstractRDBMapper.php.

◆ createObjectFromData()

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 950 of file AbstractRDBMapper.php.

◆ convertValueFromStorage()

convertValueFromStorage (   $valueName,
  $value 
)
protected

Convert value after retrieval from storage.

Parameters
$valueName
$value
Returns
Mixed

Definition at line 982 of file AbstractRDBMapper.php.

◆ addRelatedObjects()

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 1000 of file AbstractRDBMapper.php.

◆ loadRelationImpl()

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

Reimplemented from AbstractMapper.

Definition at line 1042 of file AbstractRDBMapper.php.

◆ handleDbEvent()

handleDbEvent (   $e)

Handle an event triggered from the laminas db layer.

Parameters
$e

Definition at line 1099 of file AbstractRDBMapper.php.

◆ beginTransaction()

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 1112 of file AbstractRDBMapper.php.

◆ commitTransaction()

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 1129 of file AbstractRDBMapper.php.

◆ rollbackTransaction()

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 1146 of file AbstractRDBMapper.php.

◆ getStatements()

getStatements ( )
See also
PersistenceMapper::getStatements() This method an array of arrays with the first item being the sql string and the second the bind parameter array

Implements PersistenceMapper.

Definition at line 1160 of file AbstractRDBMapper.php.

◆ setIsInTransaction()

setIsInTransaction (   $isInTransaction)
protected

Set the transaction state for the connection.

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

Definition at line 1168 of file AbstractRDBMapper.php.

◆ isInTransaction()

isInTransaction ( )
protected

Check if the connection is currently in a transaction.

Returns
Boolean

Definition at line 1176 of file AbstractRDBMapper.php.

◆ getOwnDefaultOrder()

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()

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()

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()

createObject ( ObjectId  $oid = null)
abstractprotected

Factory method for the supported object type.

Parameters
$oidThe object id (maybe null)
Returns
PersitentObject

◆ prepareForStorage()

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().

Reimplemented in NodeUnifiedRDBMapper.

◆ getSelectSQL()

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.

Reimplemented in NodeUnifiedRDBMapper.

◆ getRelationSelectSQL()

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)

Reimplemented in NodeUnifiedRDBMapper.

◆ getInsertSQL()

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.

Reimplemented in NodeUnifiedRDBMapper.

◆ getUpdateSQL()

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.

Reimplemented in NodeUnifiedRDBMapper.

◆ getDeleteSQL()

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.

Reimplemented in NodeUnifiedRDBMapper.

◆ createPKCondition()

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

Reimplemented in NodeUnifiedRDBMapper.

◆ getTableName()

getTableName ( )
abstractprotected

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

Returns
String

◆ isForeignKey()

isForeignKey (   $name)
abstract

Determine if an attribute is a foreign key.

Returns
Boolean

Reimplemented in NodeUnifiedRDBMapper.

Member Data Documentation

◆ SEQUENCE_CLASS

const SEQUENCE_CLASS = 'DBSequence'

Definition at line 54 of file AbstractRDBMapper.php.

◆ INTERNAL_VALUE_PREFIX

const INTERNAL_VALUE_PREFIX = '_mapper_internal_'

Definition at line 83 of file AbstractRDBMapper.php.