RDBMapper.php
53 private static $_inTransaction = array(); // registry for transaction status (boolean), key: connId
134 if (isset($this->_connectionParams['dbType']) && isset($this->_connectionParams['dbHostName']) &&
135 isset($this->_connectionParams['dbUserName']) && isset($this->_connectionParams['dbPassword']) &&
138 $this->_connId = join(',', array($this->_connectionParams['dbType'], $this->_connectionParams['dbHostName'],
139 $this->_connectionParams['dbUserName'], $this->_connectionParams['dbPassword'], $this->_connectionParams['dbName']));
164 $this->_connectionParams['dbName'] = FileUtil::realpath(WCMF_BASE.$this->_connectionParams['dbName']);
248 $this->_idInsertStmt = $sequenceConn->prepare("INSERT INTO ".$sequenceTable." (id) VALUES (0)");
313 * @param $isSelect Boolean whether the statement is a select statement (optional, default: _false_)
314 * @param $bindValues An array of data to bind to the placeholders (optional, default: empty array)
315 * @return If isSelect is true, an array as the result of PDOStatement::fetchAll(PDO::FETCH_ASSOC),
335 self::$_logger->error("The query: ".$sql."\ncaused the following exception:\n".$ex->getMessage());
343 * @param $pagingInfo An PagingInfo instance describing which page to load (optional, default: _null_)
375 self::$_logger->error("The query: ".$selectStmt."\ncaused the following exception:\n".$ex->getMessage());
428 self::$_logger->error("The operation: ".$operation."\ncaused the following exception:\n".$ex->getMessage());
483 throw new PersistenceException("No relation to '".$roleName."' exists in '".$this->getType()."'");
656 * @param $placeholder Placeholder (':columnName', '?') used instead of the value (optional, default: _null_)
657 * @param $tableName The table name to use (may differ from criteria's type attribute) (optional)
658 * @param $columnName The column name to use (may differ from criteria's attribute attribute) (optional)
661 public function renderCriteria(Criteria $criteria, $placeholder=null, $tableName=null, $columnName=null) {
721 if ($buildDepth < 0 && !in_array($buildDepth, array(BuildDepth::SINGLE, BuildDepth::REQUIRED))) {
729 if ($buildDepth != BuildDepth::REQUIRED && $buildDepth != BuildDepth::SINGLE && $buildDepth > 0) {
741 ($buildDepth == BuildDepth::REQUIRED && $curRelationDesc->getOtherMinMultiplicity() > 0 && $curRelationDesc->getOtherAggregationKind() != 'none')
745 $childObject = $this->_persistenceFacade->create($curRelationDesc->getOtherType(), BuildDepth::SINGLE);
748 $childObject = $this->_persistenceFacade->create($curRelationDesc->getOtherType(), $newBuildDepth);
876 protected function getOIDsImpl($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null) {
894 protected function loadObjectsImpl($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null) {
898 $objects = $this->loadObjectsFromQueryParts($type, $buildDepth, $criteria, $orderby, $pagingInfo);
905 * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
907 * @param $criteria An array of Criteria instances that define conditions on the type's attributes (optional, default: _null_)
908 * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
912 protected function loadObjectsFromQueryParts($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null) {
913 if ($buildDepth < 0 && !in_array($buildDepth, array(BuildDepth::INFINITE, BuildDepth::SINGLE))) {
927 * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
932 public function loadObjectsFromSQL(SelectStatement $selectStmt, $buildDepth=BuildDepth::SINGLE, PagingInfo $pagingInfo=null) {
970 * @param $data An associative array with the attribute names as keys and the attribute values as values
999 * @param $object A reference to the object created with createObject method to which the data should be applied
1000 * @param $objectData An associative array with the data returned by execution of the database select statement
1017 * @param $object A reference to the object created with createObject method to which the data should be applied
1040 if ($buildDepth != BuildDepth::SINGLE && $buildDepth != BuildDepth::INFINITE && $buildDepth > 0) {
1043 $loadNextGeneration = (($buildDepth != BuildDepth::SINGLE) && ($buildDepth > 0 || $buildDepth == BuildDepth::INFINITE));
1059 $object->setValue($role, isset($relatives[$oidStr]) ? $relatives[$oidStr] : null, true, false);
1095 throw new PersistenceException("Can only load related objects, if they are mapped by an RDBMapper instance.");
1103 list($selectStmt, $objValueName, $relValueName) = $otherMapper->getRelationSelectSQL($objects, $thisRole, $criteria, $orderby, $pagingInfo);
1104 $relatedObjects = $otherMapper->loadObjectsFromSQL($selectStmt, ($buildDepth == BuildDepth::PROXIES_ONLY) ? BuildDepth::SINGLE : $buildDepth, $pagingInfo);
1194 return isset(self::$_inTransaction[$this->_connId]) && self::$_inTransaction[$this->_connId] === true;
1203 * Get the names of the attributes in the mapped class to order by default and the sort directions
1204 * (ASC or DESC). The roleName parameter allows to ask for the order with respect to a specific role.
1206 * @return An array of assciative arrays with the keys sortFieldName and sortDirection (ASC or DESC)
1212 * @return An associative array with the relation names as keys and the RelationDescription instances as values.
1218 * @return An associative array with the attribute names as keys and the AttributeDescription instances as values.
1232 * @note The object does not have the final object id set. If a new id value for a primary key column is needed.
1233 * @note The prepared object will be used in the application afterwards. So values that are only to be modified for
1241 * @param $criteria An array of Criteria instances that define conditions on the type's attributes (optional, default: _null_)
1243 * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
1244 * @param $pagingInfo An PagingInfo instance describing which page to load (optional, default: _null_))
1245 * @param $queryId Identifier for the query cache (maybe null to let implementers handle it). (default: _null_)
1246 * @return SelectStatement instance that selects all object data that match the condition or an array with the query parts.
1247 * @note The names of the data item columns MUST match the data item names provided in the '_datadef' array from RDBMapper::getObjectDefinition()
1248 * Use alias names if not! The selected data will be put into the '_data' array of the object definition.
1250 abstract public function getSelectSQL($criteria=null, $alias=null, $orderby=null, PagingInfo $pagingInfo=null, $queryId=null);
1253 * Get the SQL command to select those objects from the database that are related to the given object.
1256 * @param $otherObjectProxies Array of PersistentObjectProxy instances for the objects to load the relatives for.
1258 * @param $criteria An array of Criteria instances that define conditions on the object's attributes (optional, default: _null_)
1259 * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
1260 * @param $pagingInfo An PagingInfo instance describing which page to load (optional, default: _null_)
1261 * @return Array with SelectStatement instance and the attribute names which establish the relation between
setIsInTransaction($isInTransaction)
Set the transaction state for the connection.
Definition: RDBMapper.php:1185
getDefaultOrder($roleName=null)
Definition: RDBMapper.php:605
setState($state)
Set the state of the object to one of the STATE constants.
prepareForStorage(PersistentObject $object)
Set the object primary key and foreign key values for storing the object in the database.
getOwnDefaultOrder($roleName=null)
TEMPLATE METHODS Subclasses must implement this method to define their object type.
UpdateOperation instances hold data necessary to accomplish an update operation on the persistent sto...
Definition: UpdateOperation.php:21
const STATE_CLEAN
Definition: PersistentObject.php:26
query($fetchMode=null, $bind=array())
Definition: SelectStatement.php:158
__construct(PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ConcurrencyManager $concurrencyManager, EventManager $eventManager, Message $message)
Constructor.
Definition: RDBMapper.php:83
getSelectSQL($criteria=null, $alias=null, $orderby=null, PagingInfo $pagingInfo=null, $queryId=null)
Get the SQL command to select object data from the database.
getAttributeDescriptions()
Get a list of all AttributeDescriptions.
RDBMapper maps objects of one type to a relational database schema.
Definition: RDBMapper.php:49
isForeignKey($name)
Determine if an attribute is a foreign key.
EventManager is responsible for dispatching events to registered listeners.
Definition: EventManager.php:21
getOIDsImpl($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Definition: RDBMapper.php:876
loadRelationImpl(array $objects, $role, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Definition: RDBMapper.php:1079
loadObjectsFromSQL(SelectStatement $selectStmt, $buildDepth=BuildDepth::SINGLE, PagingInfo $pagingInfo=null)
Load objects defined by a select statement.
Definition: RDBMapper.php:932
IllegalArgumentException signals an exception in method arguments.
Definition: IllegalArgumentException.php:18
InsertOperation holds data necessary to accomplish an insert operation on the persistent store...
Definition: InsertOperation.php:21
createObjectFromData(array $data)
Create an object of the mapper's type with the given attributes from the given data.
Definition: RDBMapper.php:973
getQuoteIdentifierSymbol()
Definition: RDBMapper.php:275
const INTERNAL_VALUE_PREFIX
Definition: RDBMapper.php:73
getRelationSelectSQL(array $otherObjectProxies, $otherRole, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Get the SQL command to select those objects from the database that are related to the given object...
logAction(PersistentObject $obj)
Log the state of the given object.
Definition: AbstractMapper.php:326
getRelationsByType($type)
Definition: RDBMapper.php:457
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:27
PersistenceMapper defines the interface for all mapper classes.
Definition: PersistenceMapper.php:26
getUpdateSQL(PersistentObject $object)
Get the SQL command to update a object in the database.
getAttributes(array $tags=array(), $matchMode='all')
Definition: RDBMapper.php:530
ConcurrencyManager is used to handle concurrency for objects.
Definition: ConcurrencyManager.php:32
getOperator()
Get the comparison operator used to compare the given value with the attribute's value.
Definition: Criteria.php:108
loadObjectsImpl($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Definition: RDBMapper.php:894
hasRelation($roleName)
Definition: AbstractMapper.php:87
Criteria defines a condition on a PersistentObject's attribute used to select specific instances...
Definition: Criteria.php:21
applyDataOnLoad(PersistentObject $object, array $objectData)
Apply the loaded object data to the object.
Definition: RDBMapper.php:1003
createPKCondition(ObjectId $oid)
Create an array of condition Criteria instances for the primary key values.
PagingInfo contains information about a paged list.
Definition: PagingInfo.php:18
getRelationImpl($roleName, $includeManyToMany)
Internal implementation of PersistenceMapper::getRelation()
Definition: RDBMapper.php:474
loadObjects($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Definition: AbstractMapper.php:270
Message is used to get localized messages to be used in the user interface.
Definition: Message.php:23
AbstractMapper provides a basic implementation for other mapper classes.
Definition: AbstractMapper.php:38
const STATE_DELETED
Definition: PersistentObject.php:29
getInsertSQL(PersistentObject $object)
Get the SQL command to insert a object into the database.
const STATE_DIRTY
Definition: PersistentObject.php:27
PersistentObjectProxy is proxy for an PersistentObject instance.
Definition: PersistentObjectProxy.php:25
getType()
Get the entity type that this mapper handles.
getTableName()
Get the name of the database table, where this type is mapped to.
addRelatedObjects(array $objects, $buildDepth=BuildDepth::SINGLE)
Append the child data to a list of object.
Definition: RDBMapper.php:1036
quoteIdentifier($identifier)
Definition: RDBMapper.php:285
PersistenceException signals an exception in the persistence service.
Definition: PersistenceException.php:18
DeleteOperation holds data necessary to accomplish an delete operation on the persistent store...
Definition: DeleteOperation.php:21
initialize(array $data)
Initialize the object with a set of data.
getRelationDescriptions()
Get a list of all RelationDescriptions.
getType()
Get the type of PersistentObject on which the operation should be executed.
Definition: PersistenceOperation.php:45
loadObjectsFromQueryParts($type, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Load objects defined by several query parts.
Definition: RDBMapper.php:912
renderCriteria(Criteria $criteria, $placeholder=null, $tableName=null, $columnName=null)
Render a Criteria instance as string.
Definition: RDBMapper.php:661
select(SelectStatement $selectStmt, PagingInfo $pagingInfo=null)
Execute a select query on the connection.
Definition: RDBMapper.php:346
rollbackTransaction()
Definition: RDBMapper.php:1171
PermissionManager implementations are used to handle all authorization requests.
Definition: PermissionManager.php:22
Instances of RDBManyToManyRelationDescription describe a many to many relation from 'this' end to 'ot...
Definition: RDBManyToManyRelationDescription.php:26
static realpath($path)
Realpath function that also works for non existing paths code from http://www.php.net/manual/en/function.realpath.php.
Definition: FileUtil.php:225
getRelations($hierarchyType='all')
Definition: RDBMapper.php:437
hasAttribute($name)
Definition: AbstractMapper.php:104
createImpl($type, $buildDepth=BuildDepth::SINGLE)
Definition: RDBMapper.php:720
Instances of ReferenceDescription describe reference attributes of PersistentObjects.
Definition: ReferenceDescription.php:21
A PersistenceOperation instance holds data necessary to accomplish an operation on the persistent sto...
Definition: PersistenceOperation.php:21
PersistenceFacade defines the interface for PersistenceFacade implementations.
Definition: PersistenceFacade.php:23
createObject(ObjectId $oid=null)
Factory method for the supported object type.
executeSql($sql, $isSelect=false, $bindValues=array())
Execute a query on the connection.
Definition: RDBMapper.php:318
getDeleteSQL(ObjectId $oid)
Get the SQL command to delete a object from the database.
applyDataOnCreate(PersistentObject $object)
Apply the default data to the object.
Definition: RDBMapper.php:1019
removeValue($name)
Definition: PersistentObjectProxy.php:270
loadRelation(array $objects, $role, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Definition: AbstractMapper.php:296
isInTransaction()
Check if the connection is currently in a transaction.
Definition: RDBMapper.php:1193
saveImpl(PersistentObject $object)
Definition: RDBMapper.php:760
loadImpl(ObjectId $oid, $buildDepth=BuildDepth::SINGLE)
Definition: RDBMapper.php:700
executeOperation(PersistenceOperation $operation)
Definition: RDBMapper.php:383
deleteImpl(PersistentObject $object)
Definition: RDBMapper.php:804
getPkNames()
Get the names of the primary key values.
PersistentObject defines the interface of all persistent objects.
Definition: PersistentObject.php:24