wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
RDBMapper Class Reference
+ Inheritance diagram for RDBMapper:

Public Member Functions

 RDBMapper ($params)
 
 __sleep ()
 
 connect ()
 
 getNextId ()
 
 getSequenceTablename ()
 
 executeSql ($sql, $isSelect=false)
 
 select ($sql, &$pagingInfo)
 
 isPkValue ($name, $dataType)
 
 constructOID ($type, $data)
 
 getPKNamesForType ($type)
 
loadImpl ($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
 
createImpl ($type, $buildDepth, $buildAttribs=null)
 
 saveImpl (&$object)
 
 deleteImpl ($oid, $recursive=true)
 
getConnection ()
 
 getOIDs ($type, $criteria=null, $orderby=null, &$pagingInfo)
 
 loadObjects ($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null, $selectChildOIDs=true, $omitObjects=false)
 
createObjectFromData ($attribs, $data=null)
 
 appendChildData (&$object, $buildDepth, $buildAttribs=null, $buildTypes=null)
 
 startTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 
createObject ($oid=null)
 
 appendObject (&$object, &$dependendObject)
 
 applyDataOnLoad (&$object, $objectData, $attribs)
 
 applyDataOnCreate (&$object, $objectData, $attribs)
 
 prepareInsert (&$object)
 
 getType ()
 
 getObjectDefinition ()
 
 getSelectSQL ($condStr, $orderStr=null, $attribs=null, $asArray=false)
 
 getChildrenSelectSQL ($oid, $compositionOnly=false)
 
 getChildrenDisassociateSQL ($oid, $sharedOnly=false)
 
 getInsertSQL (&$object)
 
 getUpdateSQL (&$object)
 
 getDeleteSQL ($oid)
 
 createPKCondition ($oid)
 
- Public Member Functions inherited from PersistenceMapper
 getType ()
 
 getPkNames ()
 
 setDataConverter ($dataConverter)
 
 getDataConverter ()
 
 enableLogging ($logStrategy)
 
 disableLogging ()
 
 isLogging ()
 
 logAction (&$obj)
 
load ($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
 
create ($type, $buildDepth, $buildAttribs=null)
 
 save (&$object)
 
 delete ($oid, $recursive=true)
 
 checkAuthorization ($oid, $action)
 
 authorizationFailedError ($oid, $action)
 
 initialize (&$object)
 
 isValidOID ($oid)
 
loadImpl ($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
 
createImpl ($type, $buildDepth, $buildAttribs=null)
 
 saveImpl (&$object)
 
 deleteImpl ($oid, $recursive=true)
 
 getOIDs ($type, $criteria=null, $orderby=null, &$pagingInfo)
 
 loadObjects ($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
 
 getOrderBy ()
 
 startTransaction ()
 
 commitTransaction ()
 
 rollbackTransaction ()
 

Public Attributes

 $_connParams = null
 
 $_conn = null
 
 $_dbPrefix = ''
 
 $_idSelectStmt = null
 
 $_idInsertStmt = null
 
 $_idUpdateStmt = null
 
- Public Attributes inherited from PersistenceMapper
 $_dataConverter = null
 
 $_type = ''
 
 $_logging = false
 
 $_logStrategy = null
 

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.

wCMF - wemove Content Management Framework Copyright (C) 2005-2014 wemove digital solutions GmbH

Licensed under the terms of any of the following licenses at your choice:

See the license.txt file distributed with this work for additional information.

Id:
class.RDBMapper.php 1462 2014-02-04 23:52:27Z iherwig
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 36 of file class.RDBMapper.php.

Member Function Documentation

RDBMapper::RDBMapper (   $params)

Constructor.

Parameters
paramsInitialization data given in an assoziative array with the following keys: dbType, dbHostName, dbUserName, dbPassword, dbName OR dbConnection 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 54 of file class.RDBMapper.php.

RDBMapper::__sleep ( )

Select data to be stored in the session. PDO throws an excetption if tried to be (un-)serialized.

Definition at line 64 of file class.RDBMapper.php.

RDBMapper::connect ( )

Actually connect to the database using the parameters given to the constructor.

Definition at line 72 of file class.RDBMapper.php.

References PersistenceFacade\getInstance(), and WCMFException\throwEx().

Referenced by commitTransaction(), deleteImpl(), executeSql(), getConnection(), loadObjects(), rollbackTransaction(), saveImpl(), select(), and startTransaction().

+ Here is the call graph for this function:

RDBMapper::getNextId ( )

Get a new id for inserting into the database

Returns
An id value.

Definition at line 117 of file class.RDBMapper.php.

References Log\error(), PersistenceFacade\getInstance(), and WCMFException\throwEx().

Referenced by NodeUnifiedRDBMapper\prepareInsert().

+ Here is the call graph for this function:

RDBMapper::getSequenceTablename ( )

Get the name of the sequence table

Returns
The name.

Definition at line 154 of file class.RDBMapper.php.

References PersistenceFacade\getInstance().

+ Here is the call graph for this function:

RDBMapper::executeSql (   $sql,
  $isSelect = false 
)

Execute a query on the connection.

Parameters
sqlThe sql command
isSelectTrue/False wether the statement is a select statement (default: false)
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 168 of file class.RDBMapper.php.

References connect(), Log\debug(), Log\error(), WCMFException\getStackTrace(), Log\isDebugEnabled(), and WCMFException\throwEx().

Referenced by deleteImpl(), saveImpl(), and select().

+ Here is the call graph for this function:

RDBMapper::select (   $sql,
$pagingInfo 
)

Execute a select query on the connection.

Parameters
sqlThe sql command
pagingInfoAn PagingInfo instance describing which page to load
Returns
An array as the result of PDOStatement::fetchAll(PDO::FETCH_ASSOC)

Definition at line 199 of file class.RDBMapper.php.

References connect(), Log\error(), executeSql(), and WCMFException\throwEx().

Referenced by loadObjects().

+ Here is the call graph for this function:

RDBMapper::isPkValue (   $name,
  $dataType 
)

Check if a value is a primary key value

Parameters
nameThe name of the value
dataTypeThe datatype of the value
Returns
True/False

Definition at line 236 of file class.RDBMapper.php.

Referenced by NodeRDBMapper\applyDataOnCreate(), and saveImpl().

RDBMapper::constructOID (   $type,
  $data 
)

Construct an object id from given row data

Parameters
typeThe type of object
dataAn associative array with the pk column names as keys and pk values as values
Returns
The oid

Definition at line 247 of file class.RDBMapper.php.

References PersistenceFacade\composeOID(), and getPKNamesForType().

Referenced by createObjectFromData(), and getOIDs().

+ Here is the call graph for this function:

RDBMapper::getPKNamesForType (   $type)

Get the pk column names for a given type

Parameters
typeThe type of object
Returns
An array of column names

Definition at line 261 of file class.RDBMapper.php.

References PersistenceFacade\getInstance().

Referenced by constructOID().

+ Here is the call graph for this function:

& RDBMapper::loadImpl (   $oid,
  $buildDepth,
  $buildAttribs = null,
  $buildTypes = null 
)
See Also
PersistenceMapper::loadImpl()

Definition at line 271 of file class.RDBMapper.php.

References createPKCondition(), PersistenceFacade\getInstance(), and PersistenceFacade\getOIDParameter().

+ Here is the call graph for this function:

& RDBMapper::createImpl (   $type,
  $buildDepth,
  $buildAttribs = null 
)
See Also
PersistenceMapper::createImpl()
Note
The type parameter is not used here because this class only constructs one type

Definition at line 289 of file class.RDBMapper.php.

References appendObject(), BUILDDEPTH_INFINITE, BUILDDEPTH_MAX, BUILDDEPTH_REQUIRED, BUILDDEPTH_SINGLE, createObjectFromData(), PersistenceFacade\getInstance(), getObjectDefinition(), getType(), and WCMFException\throwEx().

+ Here is the call graph for this function:

RDBMapper::saveImpl ( $object)
RDBMapper::deleteImpl (   $oid,
  $recursive = true 
)
& RDBMapper::getConnection ( )

Get the database connection.

Returns
A reference to the ADONewConnection object

Definition at line 457 of file class.RDBMapper.php.

References $_conn, and connect().

Referenced by NodeUnifiedRDBMapper\quote().

+ Here is the call graph for this function:

RDBMapper::getOIDs (   $type,
  $criteria = null,
  $orderby = null,
$pagingInfo 
)
See Also
PersistenceMapper::getOIDs()
Note
The type parameter is not used here because this class only constructs one type

Definition at line 468 of file class.RDBMapper.php.

References BUILDDEPTH_SINGLE, constructOID(), getType(), and loadObjects().

+ Here is the call graph for this function:

RDBMapper::loadObjects (   $type,
  $buildDepth,
  $criteria = null,
  $orderby = null,
$pagingInfo,
  $buildAttribs = null,
  $buildTypes = null,
  $selectChildOIDs = true,
  $omitObjects = false 
)
See Also
PersistenceFacade::loadObjects()
Note
The additional parameter selectChildOIDs indicates wether to load the oids of the children or not and is used internally only

Definition at line 490 of file class.RDBMapper.php.

References appendChildData(), BUILDDEPTH_INFINITE, BUILDDEPTH_SINGLE, connect(), createObjectFromData(), getSelectSQL(), getType(), select(), STATE_CLEAN, and WCMFException\throwEx().

Referenced by getOIDs().

+ Here is the call graph for this function:

& RDBMapper::createObjectFromData (   $attribs,
  $data = null 
)

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

Parameters
attribsAn array of attributes to create
dataThe '_data' array contained in the array returned by getObjectDefinition
See Also
RDBMapper::applyDataOnLoad()
Returns
A reference to the object

Definition at line 561 of file class.RDBMapper.php.

References applyDataOnCreate(), applyDataOnLoad(), constructOID(), createObject(), getObjectDefinition(), and getType().

Referenced by createImpl(), and loadObjects().

+ Here is the call graph for this function:

RDBMapper::appendChildData ( $object,
  $buildDepth,
  $buildAttribs = null,
  $buildTypes = null 
)

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

Parameters
objectA reference to the object to append the children to
buildDepth
See Also
PersistenceFacade::loadObjects()
Parameters
buildAttribs
See Also
PersistenceFacade::loadObjects()
Parameters
buildTypes
See Also
PersistenceFacade::loadObjects()

Definition at line 604 of file class.RDBMapper.php.

References appendObject(), BUILDDEPTH_INFINITE, BUILDDEPTH_SINGLE, getChildrenSelectSQL(), and PersistenceFacade\getInstance().

Referenced by loadObjects().

+ Here is the call graph for this function:

RDBMapper::startTransaction ( )
See Also
PersistenceMapper::startTransaction()

Definition at line 635 of file class.RDBMapper.php.

References connect().

+ Here is the call graph for this function:

RDBMapper::commitTransaction ( )
See Also
PersistenceMapper::commitTransaction()

Definition at line 645 of file class.RDBMapper.php.

References connect().

+ Here is the call graph for this function:

RDBMapper::rollbackTransaction ( )
See Also
PersistenceMapper::rollbackTransaction()
Note
Rollbacks have to be supported by the database.

Definition at line 656 of file class.RDBMapper.php.

References connect().

+ Here is the call graph for this function:

& RDBMapper::createObject (   $oid = null)

TEMPLATE METHODS Subclasses must implement this method to define their object type. Factory method for the supported object type.

Note
Subclasses must implement this method to define their object type.
Parameters
oidThe object id (maybe null)
Returns
A reference to the created object.

Definition at line 675 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by createObjectFromData().

+ Here is the call graph for this function:

RDBMapper::appendObject ( $object,
$dependendObject 
)

Add a dependend object (child) to an object.

Note
Subclasses must implement this method to define their object type.
Parameters
objectThe object to add to.
dependendObjectThe object to add.

Definition at line 685 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by appendChildData(), and createImpl().

+ Here is the call graph for this function:

RDBMapper::applyDataOnLoad ( $object,
  $objectData,
  $attribs 
)

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
objectDataThe array returned by the getObjectDefinition method with the '_data' array filled with the rows returned by execution of the database select statement (given by getSelectSQL). These rows hold the loaded data.
attribsThe build attributes for the type of object (given in the buildAttribs parameter of the loadImpl method)

Definition at line 698 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by createObjectFromData().

+ Here is the call graph for this function:

RDBMapper::applyDataOnCreate ( $object,
  $objectData,
  $attribs 
)

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
objectDataThe array returned by the getObjectDefinition method. The default data are extracted from this.
attribsThe build attributes for the type of object (given in the buildAttribs parameter of the loadImpl method).

Definition at line 709 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by createObjectFromData().

+ Here is the call graph for this function:

RDBMapper::prepareInsert ( $object)

Set the object primary key values for inserting the object to the database.

Note
Subclasses must implement this method to define their object type.
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 for the insert statement, use RDBMapper::getNextId().

Definition at line 720 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by saveImpl().

+ Here is the call graph for this function:

RDBMapper::getType ( )

Get the object type this mapper supports.

Note
Subclasses must implement this method to define their object type.
Returns
The name of the supported object type.

Definition at line 729 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by createImpl(), TableRDBMapper\createObject(), NodeRDBMapper\createObject(), createObjectFromData(), NodeUnifiedRDBMapper\getColumnName(), getOIDs(), TableUnifiedRDBMapper\getSelectSQL(), TableUnifiedRDBMapper\getUpdateSQL(), TableUnifiedRDBMapper\isValidOID(), NodeUnifiedRDBMapper\isValidOID(), loadObjects(), and NodeUnifiedRDBMapper\translateAppToDatabase().

+ Here is the call graph for this function:

RDBMapper::getObjectDefinition ( )

Get the object type definition.

Note
Subclasses must implement this method to define their object type.
Returns
An assoziative array with unchangeable keys '_properties', '_datadef', '_children', '_data' plus application specific keys. The predefined keys hold the following structures:
  • _properties: An array of assoziative arrays with the keys 'name', 'value' for every property (e.g. array('name' => 'display_value', 'value' => 'name'))
  • _datadef: The structure of this key must be defined in the subclasses!
  • _parents: An array of assoziative arrays with the key 'type' for every parent (e.g. array('type' => 'author'))
  • _children: An array of assoziative arrays with the keys 'type', 'minOccurs', 'maxOccurs', 'aggregation', 'composition' for every child (e.g. array('type' => 'textblock', 'minOccurs' => 0, 'maxOccurs' => 'unbounded', 'aggregation' => true, 'composition' => false))
  • _data: An assoziative array where the keys are the data item names defined in the _datadef array (e.g. array('title' => 'Hello User!'))
    Note
    The _data array will be overridden with data provided by the db select. No need for definition at this point!

Definition at line 750 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by createImpl(), and createObjectFromData().

+ Here is the call graph for this function:

RDBMapper::getSelectSQL (   $condStr,
  $orderStr = null,
  $attribs = null,
  $asArray = false 
)

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

Note
Subclasses must implement this method to define their object type.
Parameters
condStrThe condition string (without 'WHERE').
orderStrThe order string (without 'ORDER BY') (default: null uses default order).
attribsAn array listing the attributes to load (default: null loads all attributes).
asArrayTrue to get an associative array with keys 'attributeStr', 'tableStr', 'conditionStr', 'orderStr' and the appropriate query parts as value. [default: false]
Returns
A SQL command that selects all object data that match the condition or an array with the query parts. Additionally columns 'ptype0' ('ptype1', ...) and 'pid0' ('pid1', ...) that define the objects parent are expected.
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.

Definition at line 767 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by loadObjects().

+ Here is the call graph for this function:

RDBMapper::getChildrenSelectSQL (   $oid,
  $compositionOnly = false 
)

Get the SQL commands to select the objects children from the database.

Note
Subclasses must implement this method to define their object type.
Parameters
oidThe object id of the object to load the children for.
compositionOnlyTrue/False indicates wether to only select composition children or all [default: false].
Returns
An associative array with the children types as keys and the corresponding SQL conditions to be used as criteria parameter in PersistenceFacade::loadObjects().
Note
We need to return an array because MySql doesn't support unions prior to version 4

Definition at line 780 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by appendChildData(), and deleteImpl().

+ Here is the call graph for this function:

RDBMapper::getChildrenDisassociateSQL (   $oid,
  $sharedOnly = false 
)

Get the SQL command to disassociate the objects children from the object (e.g. setting the foreign key to null).

Note
Subclasses must implement this method to define their object type.
Parameters
oidThe object id of the object to disassociate the children from.
sharedOnlyTrue/False indicates wether to only disassociate shared children or all [default: false].
Returns
An array of SQL commands that disassociate all object children.

Definition at line 791 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by deleteImpl().

+ Here is the call graph for this function:

RDBMapper::getInsertSQL ( $object)

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

Note
Subclasses must implement this method to define their object type.
Parameters
objectA reference to the object to insert.
Returns
An array of SQL commands that insert a new object.

Definition at line 801 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by saveImpl().

+ Here is the call graph for this function:

RDBMapper::getUpdateSQL ( $object)

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

Note
Subclasses must implement this method to define their object type.
Parameters
objectA reference to the object to update.
Returns
An array of SQL commands that update an existing object.

Definition at line 811 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by saveImpl().

+ Here is the call graph for this function:

RDBMapper::getDeleteSQL (   $oid)

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

Note
Subclasses must implement this method to define their object type.
Parameters
oidThe object id of the object to delete.
Returns
An array of SQL commands that delete an existing object.

Definition at line 821 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by deleteImpl().

+ Here is the call graph for this function:

RDBMapper::createPKCondition (   $oid)

Create a condition string for the primary key values of the form id1=val1, id2=val2, ...

Note
Subclasses must implement this method to define their object type.
Parameters
oidThe object id that defines the primary key values
Returns
The string

Definition at line 831 of file class.RDBMapper.php.

References WCMFException\throwEx().

Referenced by loadImpl().

+ Here is the call graph for this function:

Member Data Documentation

RDBMapper::$_connParams = null

Definition at line 38 of file class.RDBMapper.php.

RDBMapper::$_conn = null

Definition at line 39 of file class.RDBMapper.php.

Referenced by getConnection().

RDBMapper::$_dbPrefix = ''

Definition at line 40 of file class.RDBMapper.php.

RDBMapper::$_idSelectStmt = null

Definition at line 43 of file class.RDBMapper.php.

RDBMapper::$_idInsertStmt = null

Definition at line 44 of file class.RDBMapper.php.

RDBMapper::$_idUpdateStmt = null

Definition at line 45 of file class.RDBMapper.php.


The documentation for this class was generated from the following file: