summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/Statements
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 22:02:33 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 22:02:33 +0100
commit90b5141367db5fcac9ba72042278556612b5dc3f (patch)
tree369112fd85eab39d36f4726f4f763828e6c560a4 /framework/Data/SqlMap/Statements
parentf6c4b70070a8e4378a37f750d53920e44bcc5857 (diff)
One class per file: framework/Data
Diffstat (limited to 'framework/Data/SqlMap/Statements')
-rw-r--r--framework/Data/SqlMap/Statements/TMappedStatement.php304
-rw-r--r--framework/Data/SqlMap/Statements/TPostSelectBinding.php41
-rw-r--r--framework/Data/SqlMap/Statements/TResultSetListItemParameter.php46
-rw-r--r--framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php53
-rw-r--r--framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php201
5 files changed, 342 insertions, 303 deletions
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php
index 4d3b6355..517127d3 100644
--- a/framework/Data/SqlMap/Statements/TMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TMappedStatement.php
@@ -931,306 +931,4 @@ class TMappedStatement extends TComponent implements IMappedStatement
if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound";
return array_diff(parent::__sleep(),$exprops);
}
-}
-
-/**
- * TPostSelectBinding class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TPostSelectBinding
-{
- private $_statement=null;
- private $_property=null;
- private $_resultObject=null;
- private $_keys=null;
- private $_method=TMappedStatement::QUERY_FOR_LIST;
-
- public function getStatement(){ return $this->_statement; }
- public function setStatement($value){ $this->_statement = $value; }
-
- public function getResultProperty(){ return $this->_property; }
- public function setResultProperty($value){ $this->_property = $value; }
-
- public function getResultObject(){ return $this->_resultObject; }
- public function setResultObject($value){ $this->_resultObject = $value; }
-
- public function getKeys(){ return $this->_keys; }
- public function setKeys($value){ $this->_keys = $value; }
-
- public function getMethod(){ return $this->_method; }
- public function setMethod($value){ $this->_method = $value; }
-}
-
-/**
- * TSQLMapObjectCollectionTree class.
- *
- * Maps object collection graphs as trees. Nodes in the collection can
- * be {@link add} using parent relationships. The object collections can be
- * build using the {@link collect} method.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TSqlMapObjectCollectionTree extends TComponent
-{
- /**
- * @var array object graph as tree
- */
- private $_tree = array();
- /**
- * @var array tree node values
- */
- private $_entries = array();
- /**
- * @var array resulting object collection
- */
- private $_list = array();
-
- /**
- * @return boolean true if the graph is empty
- */
- public function isEmpty()
- {
- return count($this->_entries) == 0;
- }
-
- /**
- * Add a new node to the object tree graph.
- * @param string parent node id
- * @param string new node id
- * @param mixed node value
- */
- public function add($parent, $node, $object='')
- {
- if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null)
- && isset($this->_entries[$node]) && ($this->_entries[$node]!==null))
- {
- $this->_entries[$node] = $object;
- return;
- }
- $this->_entries[$node] = $object;
- if(empty($parent))
- {
- if(isset($this->_entries[$node]))
- return;
- $this->_tree[$node] = array();
- }
- $found = $this->addNode($this->_tree, $parent, $node);
- if(!$found && !empty($parent))
- {
- $this->_tree[$parent] = array();
- if(!isset($this->_entries[$parent]) || $object !== '')
- $this->_entries[$parent] = $object;
- $this->addNode($this->_tree, $parent, $node);
- }
- }
-
- /**
- * Find the parent node and add the new node as its child.
- * @param array list of nodes to check
- * @param string parent node id
- * @param string new node id
- * @return boolean true if parent node is found.
- */
- protected function addNode(&$childs, $parent, $node)
- {
- $found = false;
- reset($childs);
- for($i = 0, $k = count($childs); $i < $k; $i++)
- {
- $key = key($childs);
- next($childs);
- if($key == $parent)
- {
- $found = true;
- $childs[$key][$node] = array();
- }
- else
- {
- $found = $found || $this->addNode($childs[$key], $parent, $node);
- }
- }
- return $found;
- }
-
- /**
- * @return array object collection
- */
- public function collect()
- {
- while(count($this->_tree) > 0)
- $this->collectChildren(null, $this->_tree);
- return $this->getCollection();
- }
-
- /**
- * @param array list of nodes to check
- * @return boolean true if all nodes are leaf nodes, false otherwise
- */
- protected function hasChildren(&$nodes)
- {
- $hasChildren = false;
- foreach($nodes as $node)
- if(count($node) != 0)
- return true;
- return $hasChildren;
- }
-
- /**
- * Visit all the child nodes and collect them by removing.
- * @param string parent node id
- * @param array list of child nodes.
- */
- protected function collectChildren($parent, &$nodes)
- {
- $noChildren = !$this->hasChildren($nodes);
- $childs = array();
- for(reset($nodes); $key = key($nodes);)
- {
- next($nodes);
- if($noChildren)
- {
- $childs[] = $key;
- unset($nodes[$key]);
- }
- else
- $this->collectChildren($key, $nodes[$key]);
- }
- if(count($childs) > 0)
- $this->onChildNodesVisited($parent, $childs);
- }
-
- /**
- * Set the object properties for all the child nodes visited.
- * @param string parent node id
- * @param array list of child nodes visited.
- */
- protected function onChildNodesVisited($parent, $nodes)
- {
- if(empty($parent) || empty($this->_entries[$parent]))
- return;
-
- $parentObject = $this->_entries[$parent]['object'];
- $property = $this->_entries[$nodes[0]]['property'];
-
- $list = TPropertyAccess::get($parentObject, $property);
-
- foreach($nodes as $node)
- {
- if($list instanceof TList)
- $parentObject->{$property}[] = $this->_entries[$node]['object'];
- else if(is_array($list))
- $list[] = $this->_entries[$node]['object'];
- else
- throw new TSqlMapExecutionException(
- 'sqlmap_property_must_be_list');
- }
-
- if(is_array($list))
- TPropertyAccess::set($parentObject, $property, $list);
-
- if($this->_entries[$parent]['property'] === null)
- $this->_list[] = $parentObject;
- }
-
- /**
- * @return array object collection.
- */
- protected function getCollection()
- {
- return $this->_list;
- }
-
- public function __sleep()
- {
- $exprops = array(); $cn = __CLASS__;
- if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree";
- if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries";
- if (!count($this->_list)) $exprops[] = "\0$cn\0_list";
- return array_diff(parent::__sleep(),$exprops);
- }
-}
-
-/**
- * TResultSetListItemParameter class
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TResultSetListItemParameter extends TComponent
-{
- private $_resultObject;
- private $_parameterObject;
- private $_list;
-
- public function __construct($result, $parameter, &$list)
- {
- $this->_resultObject = $result;
- $this->_parameterObject = $parameter;
- $this->_list = &$list;
- }
-
- public function getResult()
- {
- return $this->_resultObject;
- }
-
- public function getParameter()
- {
- return $this->_parameterObject;
- }
-
- public function &getList()
- {
- return $this->_list;
- }
-}
-
-/**
- * TResultSetMapItemParameter class.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @package System.Data.SqlMap.Statements
- * @since 3.1
- */
-class TResultSetMapItemParameter extends TComponent
-{
- private $_key;
- private $_value;
- private $_parameterObject;
- private $_map;
-
- public function __construct($key, $value, $parameter, &$map)
- {
- $this->_key = $key;
- $this->_value = $value;
- $this->_parameterObject = $parameter;
- $this->_map = &$map;
- }
-
- public function getKey()
- {
- return $this->_key;
- }
-
- public function getValue()
- {
- return $this->_value;
- }
-
- public function getParameter()
- {
- return $this->_parameterObject;
- }
-
- public function &getMap()
- {
- return $this->_map;
- }
-}
-
+} \ No newline at end of file
diff --git a/framework/Data/SqlMap/Statements/TPostSelectBinding.php b/framework/Data/SqlMap/Statements/TPostSelectBinding.php
new file mode 100644
index 00000000..8180e73d
--- /dev/null
+++ b/framework/Data/SqlMap/Statements/TPostSelectBinding.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * TMappedStatement and related classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TPostSelectBinding class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TPostSelectBinding
+{
+ private $_statement=null;
+ private $_property=null;
+ private $_resultObject=null;
+ private $_keys=null;
+ private $_method=TMappedStatement::QUERY_FOR_LIST;
+
+ public function getStatement(){ return $this->_statement; }
+ public function setStatement($value){ $this->_statement = $value; }
+
+ public function getResultProperty(){ return $this->_property; }
+ public function setResultProperty($value){ $this->_property = $value; }
+
+ public function getResultObject(){ return $this->_resultObject; }
+ public function setResultObject($value){ $this->_resultObject = $value; }
+
+ public function getKeys(){ return $this->_keys; }
+ public function setKeys($value){ $this->_keys = $value; }
+
+ public function getMethod(){ return $this->_method; }
+ public function setMethod($value){ $this->_method = $value; }
+} \ No newline at end of file
diff --git a/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php b/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php
new file mode 100644
index 00000000..e330a5ae
--- /dev/null
+++ b/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * TMappedStatement and related classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TResultSetListItemParameter class
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TResultSetListItemParameter extends TComponent
+{
+ private $_resultObject;
+ private $_parameterObject;
+ private $_list;
+
+ public function __construct($result, $parameter, &$list)
+ {
+ $this->_resultObject = $result;
+ $this->_parameterObject = $parameter;
+ $this->_list = &$list;
+ }
+
+ public function getResult()
+ {
+ return $this->_resultObject;
+ }
+
+ public function getParameter()
+ {
+ return $this->_parameterObject;
+ }
+
+ public function &getList()
+ {
+ return $this->_list;
+ }
+} \ No newline at end of file
diff --git a/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php b/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php
new file mode 100644
index 00000000..363edb55
--- /dev/null
+++ b/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * TMappedStatement and related classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TResultSetMapItemParameter class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TResultSetMapItemParameter extends TComponent
+{
+ private $_key;
+ private $_value;
+ private $_parameterObject;
+ private $_map;
+
+ public function __construct($key, $value, $parameter, &$map)
+ {
+ $this->_key = $key;
+ $this->_value = $value;
+ $this->_parameterObject = $parameter;
+ $this->_map = &$map;
+ }
+
+ public function getKey()
+ {
+ return $this->_key;
+ }
+
+ public function getValue()
+ {
+ return $this->_value;
+ }
+
+ public function getParameter()
+ {
+ return $this->_parameterObject;
+ }
+
+ public function &getMap()
+ {
+ return $this->_map;
+ }
+} \ No newline at end of file
diff --git a/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php b/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php
new file mode 100644
index 00000000..91fe3882
--- /dev/null
+++ b/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php
@@ -0,0 +1,201 @@
+<?php
+/**
+ * TMappedStatement and related classes.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Data.SqlMap.Statements
+ */
+
+/**
+ * TSQLMapObjectCollectionTree class.
+ *
+ * Maps object collection graphs as trees. Nodes in the collection can
+ * be {@link add} using parent relationships. The object collections can be
+ * build using the {@link collect} method.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @package System.Data.SqlMap.Statements
+ * @since 3.1
+ */
+class TSqlMapObjectCollectionTree extends TComponent
+{
+ /**
+ * @var array object graph as tree
+ */
+ private $_tree = array();
+ /**
+ * @var array tree node values
+ */
+ private $_entries = array();
+ /**
+ * @var array resulting object collection
+ */
+ private $_list = array();
+
+ /**
+ * @return boolean true if the graph is empty
+ */
+ public function isEmpty()
+ {
+ return count($this->_entries) == 0;
+ }
+
+ /**
+ * Add a new node to the object tree graph.
+ * @param string parent node id
+ * @param string new node id
+ * @param mixed node value
+ */
+ public function add($parent, $node, $object='')
+ {
+ if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null)
+ && isset($this->_entries[$node]) && ($this->_entries[$node]!==null))
+ {
+ $this->_entries[$node] = $object;
+ return;
+ }
+ $this->_entries[$node] = $object;
+ if(empty($parent))
+ {
+ if(isset($this->_entries[$node]))
+ return;
+ $this->_tree[$node] = array();
+ }
+ $found = $this->addNode($this->_tree, $parent, $node);
+ if(!$found && !empty($parent))
+ {
+ $this->_tree[$parent] = array();
+ if(!isset($this->_entries[$parent]) || $object !== '')
+ $this->_entries[$parent] = $object;
+ $this->addNode($this->_tree, $parent, $node);
+ }
+ }
+
+ /**
+ * Find the parent node and add the new node as its child.
+ * @param array list of nodes to check
+ * @param string parent node id
+ * @param string new node id
+ * @return boolean true if parent node is found.
+ */
+ protected function addNode(&$childs, $parent, $node)
+ {
+ $found = false;
+ reset($childs);
+ for($i = 0, $k = count($childs); $i < $k; $i++)
+ {
+ $key = key($childs);
+ next($childs);
+ if($key == $parent)
+ {
+ $found = true;
+ $childs[$key][$node] = array();
+ }
+ else
+ {
+ $found = $found || $this->addNode($childs[$key], $parent, $node);
+ }
+ }
+ return $found;
+ }
+
+ /**
+ * @return array object collection
+ */
+ public function collect()
+ {
+ while(count($this->_tree) > 0)
+ $this->collectChildren(null, $this->_tree);
+ return $this->getCollection();
+ }
+
+ /**
+ * @param array list of nodes to check
+ * @return boolean true if all nodes are leaf nodes, false otherwise
+ */
+ protected function hasChildren(&$nodes)
+ {
+ $hasChildren = false;
+ foreach($nodes as $node)
+ if(count($node) != 0)
+ return true;
+ return $hasChildren;
+ }
+
+ /**
+ * Visit all the child nodes and collect them by removing.
+ * @param string parent node id
+ * @param array list of child nodes.
+ */
+ protected function collectChildren($parent, &$nodes)
+ {
+ $noChildren = !$this->hasChildren($nodes);
+ $childs = array();
+ for(reset($nodes); $key = key($nodes);)
+ {
+ next($nodes);
+ if($noChildren)
+ {
+ $childs[] = $key;
+ unset($nodes[$key]);
+ }
+ else
+ $this->collectChildren($key, $nodes[$key]);
+ }
+ if(count($childs) > 0)
+ $this->onChildNodesVisited($parent, $childs);
+ }
+
+ /**
+ * Set the object properties for all the child nodes visited.
+ * @param string parent node id
+ * @param array list of child nodes visited.
+ */
+ protected function onChildNodesVisited($parent, $nodes)
+ {
+ if(empty($parent) || empty($this->_entries[$parent]))
+ return;
+
+ $parentObject = $this->_entries[$parent]['object'];
+ $property = $this->_entries[$nodes[0]]['property'];
+
+ $list = TPropertyAccess::get($parentObject, $property);
+
+ foreach($nodes as $node)
+ {
+ if($list instanceof TList)
+ $parentObject->{$property}[] = $this->_entries[$node]['object'];
+ else if(is_array($list))
+ $list[] = $this->_entries[$node]['object'];
+ else
+ throw new TSqlMapExecutionException(
+ 'sqlmap_property_must_be_list');
+ }
+
+ if(is_array($list))
+ TPropertyAccess::set($parentObject, $property, $list);
+
+ if($this->_entries[$parent]['property'] === null)
+ $this->_list[] = $parentObject;
+ }
+
+ /**
+ * @return array object collection.
+ */
+ protected function getCollection()
+ {
+ return $this->_list;
+ }
+
+ public function __sleep()
+ {
+ $exprops = array(); $cn = __CLASS__;
+ if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree";
+ if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries";
+ if (!count($this->_list)) $exprops[] = "\0$cn\0_list";
+ return array_diff(parent::__sleep(),$exprops);
+ }
+} \ No newline at end of file