19 require_once(BASE.
"wcmf/lib/util/class.Message.php");
20 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceMapper.php");
21 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
22 require_once(BASE.
"wcmf/lib/persistence/converter/class.DataConverter.php");
23 require_once(BASE.
"wcmf/lib/model/class.Node.php");
24 require_once(BASE.
"wcmf/lib/util/class.XMLUtil.php");
25 require_once(BASE.
"wcmf/lib/util/class.Log.php");
30 define(
"DATATYPE_DONTCARE", 0);
31 define(
"DATATYPE_ATTRIBUTE", 1);
32 define(
"DATATYPE_ELEMENT", 2);
33 define(
"DATATYPE_IGNORE", 3);
37 define(
"BUILDDEPTH_INFINITE", -1);
38 define(
"BUILDDEPTH_SINGLE", -2);
39 define(
"BUILDDEPTH_GROUPED", -3);
71 if (isset($params[
'filename']) && isset($params[
'doctype']) && isset($params[
'dtd']))
73 $this->_filename = $params[
'filename'];
74 $this->_doctype = $params[
'doctype'];
75 $this->_dtd = $params[
'dtd'];
79 $this->_db->SetOptions(array(
'TimeStampFlag' => 0,
'XmlOptions' => array(XML_OPTION_SKIP_WHITE => 1)));
82 $this->aDbPermissions = array(
83 'GetNodeData' => XMLDB_PERMISSION_ENABLE,
84 'GetChildData' => XMLDB_PERMISSION_ENABLE,
85 'InsertNode' => XMLDB_PERMISSION_ENABLE,
86 'UpdateNode' => XMLDB_PERMISSION_ENABLE,
87 'RemoveNode' => XMLDB_PERMISSION_ENABLE
90 $this->_db->bSecureMode = TRUE;
91 foreach ($this->aDbPermissions as $MethodName => $Permission)
92 $this->_db->aPermissions[$MethodName] = $Permission;
100 register_shutdown_function(array(&$this,
'commitTransaction'));
109 if (array_key_exists(
'filename', $params) && array_key_exists(
'doctype', $params) && array_key_exists(
'dtd', $params))
111 if ($params[
'filename'] == $this->_filename)
117 $this->_filename = $params[
'filename'];
118 $this->_doctype = $params[
'doctype'];
119 $this->_dtd = $params[
'dtd'];
134 function &
loadImpl($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
147 if (is_array($buildTypes) && !in_array($nodeDef[
'type'], $buildTypes))
154 foreach ($nodeData[
'_datadef'] as $dataDef)
157 $elementName = $dataDef[
'name'];
162 if (strlen($elementName) > 0)
164 $nodeData[
'_data'] = $this->_db->GetNodeData($oid, $elementName);
165 if ($nodeData[
'_data'] == null)
173 foreach($nodeData[
'_properties'] as $property)
174 $node->setProperty($property[
'name'], $property[
'value']);
176 $parentoids = array();
177 while (array_key_exists(
'pid'+$i, $nodeData[
'_data']))
180 array_push($parentoids, $parentoid);
183 $node->setProperty(
'parentoids', $parentoids);
187 if ($buildAttribs != null && isset($buildAttribs[$nodeDef[
'type']]))
188 $attribs = $buildAttribs[$nodeDef[
'type']];
191 foreach($nodeData[
'_datadef'] as $dataItem)
193 if ($attribs == null || in_array($dataItem[
'name'], $attribs))
195 $value = $this->_dataConverter->convertStorageToApplication($nodeData[
'_data'][$dataItem[
'name']], $dataItem[
'db_data_type'], $dataItem[
'name']);
196 $node->setValue($dataItem[
'name'], $value, $dataItem[
'app_data_type']);
197 $valueProperties = array();
198 foreach($dataItem as $key => $value)
199 if ($key !=
'name' && $key !=
'app_data_type')
200 $valueProperties[$key] = $value;
201 $node->setValueProperties($dataItem[
'name'], $valueProperties, $dataItem[
'app_data_type']);
207 $newBuildDepth = $buildDepth-1;
209 $newBuildDepth = $buildDepth;
212 $childoids = array();
213 $childrenData = $this->_db->GetChildData($oid);
214 foreach($childrenData as $childData)
217 array_push($childoids, $childoid);
220 $childNode = &$persistenceFacade->load($childoid, $newBuildDepth, $buildAttribs, $buildTypes);
221 if ($childNode != null)
222 $node->addChild($childNode);
225 $node->setProperty(
'childoids', $childoids);
246 foreach($nodeData[
'_properties'] as $property)
247 $node->setProperty($property[
'name'], $property[
'value']);
252 if ($buildAttribs != null && isset($buildAttribs[$type]))
253 $attribs = $buildAttribs[$type];
256 foreach($nodeData[
'_datadef'] as $dataItem)
258 if ($attribs == null || in_array($dataItem[
'name'], $attribs))
260 $value = $this->_dataConverter->convertStorageToApplication($dataItem[
'default'], $dataItem[
'db_data_type'], $dataItem[
'name']);
261 $node->setValue($dataItem[
'name'], $value, $dataItem[
'app_data_type']);
262 $valueProperties = array();
263 foreach($dataItem as $key => $value)
264 if ($key !=
'name' && $key !=
'app_data_type')
265 $valueProperties[$key] = $value;
266 $node->setValueProperties($dataItem[
'name'], $valueProperties, $dataItem[
'app_data_type']);
272 $newBuildDepth = $buildDepth-1;
274 $newBuildDepth = $buildDepth;
280 foreach ($nodeData[
'_children'] as $childData)
283 if (!isset($childData[
'minOccurs']))
284 $childData[
'minOccurs'] = 0;
285 if (!isset($childData[
'maxOccurs']))
286 $childData[
'maxOccurs'] = 1;
289 (($buildDepth ==
BUILDDEPTH_REQUIRED) && $childData[
'minOccurs'] > 0 && $childData[
'aggregation'] ==
true)) )
291 $childNode = &$persistenceFacade->create($childData[
'type'], $newBuildDepth, $buildAttribs);
292 $childNode->setProperty(
'minOccurs', $childData[
'minOccurs']);
293 $childNode->setProperty(
'maxOccurs', $childData[
'maxOccurs']);
294 $childNode->setProperty(
'aggregation', $childData[
'aggregation']);
295 $childNode->setProperty(
'composition', $childData[
'composition']);
296 $node->addChild($childNode);
307 if ($node->getType() == $this->_db->getRootNodeName())
316 $appValues = array();
317 foreach ($node->getDataTypes() as $type)
318 foreach ($node->getValueNames($type) as $valueName)
320 $properties = $node->getValueProperties($valueName, $type);
321 $appValues[$type][$valueName] = $node->getValue($valueName, $type);
323 $value = str_replace(array(
"\'",
"\\\""), array(
"'",
"\""), $appValues[$type][$valueName]);
324 $node->setValue($valueName, $this->_dataConverter->convertApplicationToStorage($value, $properties[
'db_data_type'], $valueName), $type);
332 $parent = $node->getParent();
334 $parentOID = $parent->getOID();
335 else if (
sizeof($node->getProperty(
'parentoids')) > 0)
337 $poids = $node->getProperty(
'parentoids');
338 $parentOID = $poids[0];
345 $newID = $this->_db->InsertNode($node, $parentOID);
347 WCMFException::throwEx(
"Error inserting node ".$node->getType().
": ".$this->_db->getErrorMsg(), __FILE__, __LINE__);
361 if(!$this->_db->UpdateNode($node))
362 WCMFException::throwEx(
"Error updating node ".$node->getType().
": ".$this->_db->getErrorMsg(), __FILE__, __LINE__);
366 foreach ($node->getDataTypes() as $type)
367 foreach ($node->getValueNames($type) as $valueName)
368 $node->setValue($valueName, $appValues[$type][$valueName], $type);
398 if(!$this->_db->RemoveNode($oid))
404 $childrenData = $this->_db->GetChildData($oid);
405 foreach($childrenData as $childData)
408 $persistenceFacade->delete($childoid, $recursive);
418 function getOIDs($type, $criteria=null, $orderby=null, &$pagingInfo)
422 if ($criteria != null)
424 $attribCondStr =
"[@";
425 foreach($criteria as $name => $value)
426 $attribCondStr .= $name.
"='".$value.
"'][@";
427 $attribCondStr = substr($attribCondStr, 0, strlen($attribCondStr)-strlen(
"[@"));
435 $nodeQuery =
"descendant::".$type.$attribCondStr;
437 $oids = $this->_db->GetOIDs($nodeQuery);
444 function loadObjects($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
460 Log::debug(
"start read transaction on ".$this->_filename, __CLASS__);
470 if (!$this->_inTransaction)
472 Log::debug(
"start transaction on ".$this->_filename, __CLASS__);
474 $this->_inTransaction =
true;
483 if ($this->_inTransaction)
485 Log::debug(
"end transaction on ".$this->_filename, __CLASS__);
487 $this->_inTransaction =
false;
504 if ($this->_db->DbFileName != $this->_filename)
506 if (!$this->_db->Open($this->_filename, TRUE, $lock))
511 chmod($this->_filename, 0775);
512 $this->_db->XmlDb->setVerbose(0);
513 Log::debug(
"opened ".$this->_filename, __CLASS__);
521 $result = $this->_db->Close();
522 Log::debug(
"closed ".$this->_filename.
" with result ".$result, __CLASS__);
539 WCMFException::throwEx(
"createObject() must be implemented by derived class: ".get_class($this), __FILE__, __LINE__);
& createObject($type, $oid=null)
debug($message, $category)
loadObjects($type, $buildDepth, $criteria=null, $orderby=null, &$pagingInfo, $buildAttribs=null, $buildTypes=null)
& loadImpl($oid, $buildDepth, $buildAttribs=null, $buildTypes=null)
deleteImpl($oid, $recursive=true)
throwEx($message, $file='', $line='')
XMLUtil helps in using XML files as storage. XMLUtil is a subclass of CXmlDb that is customized for u...
const BUILDDEPTH_INFINITE
decomposeOID($oid, $validate=true)
const BUILDDEPTH_REQUIRED
getOIDs($type, $criteria=null, $orderby=null, &$pagingInfo)
DataConverter is the base class for all converter classes. It defines the interface for converting da...
& createImpl($type, $buildDepth, $buildAttribs)
PersistenceMapper is the base class for all mapper classes.
NodeXMLDBMapper maps Node objects to a xml file using the CXmlDb class. http://sourceforge.net/projects/phpxmldb.