19 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE.
"wcmf/lib/util/class.Log.php");
21 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
22 require_once(BASE.
"wcmf/lib/output/class.OutputStrategy.php");
23 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceMapper.php");
24 require_once(BASE.
"wcmf/lib/persistence/class.ObjectQuery.php");
25 require_once(BASE.
"wcmf/lib/persistence/class.StringQuery.php");
26 require_once(BASE.
"wcmf/lib/persistence/class.PagingInfo.php");
27 require_once(BASE.
"wcmf/lib/persistence/class.ChangeListener.php");
71 function &
load($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
79 if ($this->_isCaching)
81 $cacheKey = $this->
getCacheKey($oid, $buildDepth, $buildAttribs, $buildTypes);
82 if (isset($this->_cache[$cacheKey]))
84 $obj = &$this->_cache[$cacheKey];
92 $mapper = &$this->
getMapper($oidParts[
'type']);
94 $obj = &$mapper->load($oid, $buildDepth, $buildAttribs, $buildTypes);
99 if ($this->_isReadOnly)
100 $obj->setImmutable();
103 if ($this->_isCaching)
105 $cacheKey = $this->
getCacheKey($oid, $buildDepth, $buildAttribs, $buildTypes);
106 $this->_cache[$cacheKey] = &$obj;
121 function &
create($type, $buildDepth, $buildAttribs=null)
130 $obj = &$mapper->create($type, $buildDepth, $buildAttribs);
133 $obj->addChangeListener($this);
145 if ($this->_isReadOnly)
149 $mapper = &$object->getMapper();
151 $result = $mapper->save($object);
160 function delete($oid, $recursive=
true)
162 if ($this->_isReadOnly)
167 $mapper = &$this->
getMapper($oidParts[
'type']);
169 $result = $mapper->delete($oid, $recursive);
179 if (!isset($this->_createdOIDs[$type]))
180 return $this->_createdOIDs[$type];
190 if (isset($this->_createdOIDs[$type]) &&
sizeof($this->_createdOIDs[$type]) > 0)
191 return $this->_createdOIDs[$type][
sizeof($this->_createdOIDs[$type])-1];
203 function getOIDs($type, $criteria=null, $orderby=null, &$pagingInfo)
208 $result = $mapper->getOIDs($type, $criteria, $orderby, $pagingInfo);
214 function getOIDsEx($type, $where=null, $orderby=null, &$pagingInfo)
227 function getFirstOID($type, $criteria=null, $orderby=null, &$pagingInfo)
229 $oids = $this->
getOIDs($type, $criteria, $orderby, $pagingInfo);
230 if (
sizeof($oids) > 0)
256 function loadObjects($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
261 $result = $mapper->loadObjects($type, $buildDepth, $criteria, $orderby, $pagingInfo, $buildAttribs, $buildTypes);
278 function &
loadFirstObject($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
280 $objects = $this->
loadObjects($type, $buildDepth, $criteria, $orderby, $pagingInfo, $buildAttribs, $buildTypes);
281 if (
sizeof($objects) > 0)
295 if (!$this->_inTransaction)
302 $mapperEntries = array_keys($this->_mapperObjects);
303 for ($i=0; $i<
sizeof($mapperEntries); $i++)
306 $this->_inTransaction =
true;
317 if ($this->_inTransaction)
324 $mapperEntries = array_keys($this->_mapperObjects);
325 for ($i=0; $i<
sizeof($mapperEntries); $i++)
328 $this->_inTransaction =
false;
339 if ($this->_inTransaction)
342 Log::debug(
"Rollback Transaction", __CLASS__);
345 $mapperEntries = array_keys($this->_mapperObjects);
346 for ($i=0; $i<
sizeof($mapperEntries); $i++)
349 $this->_inTransaction =
false;
361 if (!isset($this->_mapperObjects[$type]))
366 if (($mapperClass = $parser->getValue($type,
'typemapping')) ===
false)
368 if (($mapperClass = $parser->getValue(
'*',
'typemapping')) ===
false)
370 WCMFException::throwEx(
"No PersistenceMapper found in configfile for type '".$type.
"' in section 'typemapping'", __FILE__, __LINE__);
375 $classFile = $this->
getClassFile($parser, $mapperClass);
378 if (($initSection = $parser->getValue($mapperClass,
'initparams')) !==
false)
380 if (($initParams = $parser->getSection($initSection)) ===
false)
388 $connectionKey = join(
':', array_values($initParams));
389 if (isset($this->_dbConnections[$connectionKey]))
390 $initParams = array(
'dbConnection' => &$this->_dbConnections[$connectionKey]);
393 $isAlreadyInUse =
false;
394 $mapperObjects = array_values($this->_mapperObjects);
395 for ($i=0; $i<
sizeof($mapperObjects); $i++)
397 if (strtolower(get_class($mapperObjects[$i])) == strtolower($mapperClass))
399 $this->_mapperObjects[$type] = &$mapperObjects[$i];
400 $isAlreadyInUse =
true;
406 if (!$isAlreadyInUse)
408 if (file_exists(BASE.$classFile))
410 require_once(BASE.$classFile);
412 $mapperObj =
new $mapperClass($initParams);
414 $mapperObj =
new $mapperClass;
415 $this->_mapperObjects[$type] = &$mapperObj;
419 WCMFException::throwEx(
"Definition of PersistanceMapper ".$mapperClass.
" in '".$classFile.
"' not found.", __FILE__, __LINE__);
424 if (($converterClass = $parser->getValue($type,
'converter')) !==
false ||
425 ($converterClass = $parser->getValue(
'*',
'converter')) !==
false)
427 $classFile = $this->
getClassFile($parser, $converterClass);
428 if ($classFile != null)
431 if (file_exists(BASE.$classFile))
433 require_once(BASE.$classFile);
434 $converterObj =
new $converterClass;
435 $mapperObj->setDataConverter($converterObj);
439 WCMFException::throwEx(
"Definition of DataConverter ".$converterClass.
" in '".$classFile.
"' not found.", __FILE__, __LINE__);
447 if (isset($this->_mapperObjects[$type]))
448 $mapper = &$this->_mapperObjects[$type];
450 $mapper = &$this->_mapperObjects[
'*'];
462 if (($classFile = $parser->getValue($className,
'classmapping')) ===
false)
476 $this->_mapperObjects[$type] = &$mapper;
485 if ($connection != null)
487 $connectionKey = join(
':', array_values($initParams));
488 $this->_dbConnections[$connectionKey] = &$connection;
498 $this->_isReadOnly = $isReadOnly;
506 $this->_logStrategy = $logStrategy;
507 $mapperObjs = array_values($this->_mapperObjects);
508 for($i=0, $count=
sizeof($mapperObjs); $i<$count; $i++) {
509 $mapperObjs[$i]->enableLogging($this->_logStrategy);
511 $this->_logging =
true;
518 $mapperObjs = array_values($this->_mapperObjects);
519 for($i=0, $count=
sizeof($mapperObjs); $i<$count; $i++) {
520 $mapperObjs[$i]->disableLogging();
522 $this->_logging =
false;
539 $this->_isCaching = $isCaching;
546 $this->_cache = array();
556 function getCacheKey($oid, $buildDepth, $buildAttribs, $buildTypes)
558 $key = $oid.
':'.$buildDepth.
':';
559 foreach($buildAttribs as $type => $attribs)
560 $key .= $type.
'='.join(
',', $attribs).
':';
561 $key .= join(
',', $buildTypes);
592 $type = $object->getType();
593 if (!isset($this->_createdOIDs[$type]))
594 $this->_createdOIDs[$type] = array();
595 array_push($this->_createdOIDs[$type], $object->getOID());
ChangeListener defines an interface for classes that want to be notified when a value of an persisten...
error($message, $category)
debug($message, $category)
getClassFile($parser, $className)
propertyChanged(&$object, $name, $oldValue, $newValue)
getOIDsEx($type, $where=null, $orderby=null, &$pagingInfo)
getFirstOID($type, $criteria=null, $orderby=null, &$pagingInfo)
& loadFirstObject($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
setMapper($type, &$mapper)
throwEx($message, $file='', $line='')
PersistenceFacadeImpl delegates persistence operations to the type-specific PersistenceMappers.
const BUILDDEPTH_INFINITE
decomposeOID($oid, $validate=true)
& load($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
enableLogging($logStrategy)
loadObjects($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
stateChanged(&$object, $oldValue, $newValue)
const BUILDDEPTH_REQUIRED
storeConnection($initParams, &$connection)
getCacheKey($oid, $buildDepth, $buildAttribs, $buildTypes)
& create($type, $buildDepth, $buildAttribs=null)
getFirstOIDEx($type, $where=null, $orderby=null, &$pagingInfo)
valueChanged(&$object, $name, $type, $oldValue, $newValue)
getOIDs($type, $criteria=null, $orderby=null, &$pagingInfo)