diff options
Diffstat (limited to 'framework/Data/SqlMap/Configuration')
-rw-r--r-- | framework/Data/SqlMap/Configuration/TDiscriminator.php | 54 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php | 49 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php | 58 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php | 26 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapDelete.php | 22 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapInsert.php | 42 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapSelect.php | 26 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php | 72 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapStatement.php | 132 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapUpdate.php | 22 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php | 111 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapXmlMappingConfiguration.php (renamed from framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php) | 286 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSubMap.php | 61 |
13 files changed, 435 insertions, 526 deletions
diff --git a/framework/Data/SqlMap/Configuration/TDiscriminator.php b/framework/Data/SqlMap/Configuration/TDiscriminator.php index 1f7347ae..1c7f679f 100644 --- a/framework/Data/SqlMap/Configuration/TDiscriminator.php +++ b/framework/Data/SqlMap/Configuration/TDiscriminator.php @@ -174,56 +174,4 @@ class TDiscriminator extends TComponent $manager->getResultMap($subMap->getResultMapping()); } } -} - -/** - * TSubMap class defines a submapping value and the corresponding <resultMap> - * - * The {@link Value setValue()} property is used for comparison with the - * discriminator column value. When the {@link Value setValue()} matches - * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping} - * is used inplace of the current result map. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSubMap extends TComponent -{ - private $_value; - private $_resultMapping; - - /** - * @return string value for comparison with discriminator column value. - */ - public function getValue() - { - return $this->_value; - } - - /** - * @param string value for comparison with discriminator column value. - */ - public function setValue($value) - { - $this->_value = $value; - } - - /** - * The result map to use when the Value matches the discriminator column value. - * @return string ID of a result map - */ - public function getResultMapping() - { - return $this->_resultMapping; - } - - /** - * @param string ID of a result map - */ - public function setResultMapping($value) - { - $this->_resultMapping = $value; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php new file mode 100644 index 00000000..095f24d4 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php @@ -0,0 +1,49 @@ +<?php +/** + * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapCacheKey class. + * + * Provides a hash of the object to be cached. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapCacheKey +{ + private $_key; + + /** + * @param mixed object to be cached. + */ + public function __construct($object) + { + $this->_key = $this->generateKey(serialize($object)); + } + + /** + * @param string serialized object + * @return string crc32 hash of the serialized object. + */ + protected function generateKey($string) + { + return sprintf('%x',crc32($string)); + } + + /** + * @return string object hash. + */ + public function getHash() + { + return $this->_key; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php index 271db675..0021cad8 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php @@ -183,60 +183,4 @@ class TSqlMapCacheModel extends TComponent else return 0; } -} - -/** - * TSqlMapCacheTypes enumerable class. - * - * Implemented cache are 'Basic', 'FIFO' and 'LRU'. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapCacheTypes extends TEnumerable -{ - const Basic='Basic'; - const FIFO='FIFO'; - const LRU='LRU'; -} - -/** - * TSqlMapCacheKey class. - * - * Provides a hash of the object to be cached. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapCacheKey -{ - private $_key; - - /** - * @param mixed object to be cached. - */ - public function __construct($object) - { - $this->_key = $this->generateKey(serialize($object)); - } - - /** - * @param string serialized object - * @return string crc32 hash of the serialized object. - */ - protected function generateKey($string) - { - return sprintf('%x',crc32($string)); - } - - /** - * @return string object hash. - */ - public function getHash() - { - return $this->_key; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php new file mode 100644 index 00000000..c252151c --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php @@ -0,0 +1,26 @@ +<?php +/** + * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapCacheTypes enumerable class. + * + * Implemented cache are 'Basic', 'FIFO' and 'LRU'. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapCacheTypes extends TEnumerable +{ + const Basic='Basic'; + const FIFO='FIFO'; + const LRU='LRU'; +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapDelete.php b/framework/Data/SqlMap/Configuration/TSqlMapDelete.php new file mode 100644 index 00000000..90e1ab21 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapDelete.php @@ -0,0 +1,22 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapDelete class corresponds to the <delete> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapDelete extends TSqlMapUpdate +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapInsert.php b/framework/Data/SqlMap/Configuration/TSqlMapInsert.php new file mode 100644 index 00000000..f269386f --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapInsert.php @@ -0,0 +1,42 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapInsert class corresponds to the <insert> element. + * + * The <insert> element allows <selectKey> child elements that can be used + * to generate a key to be used for the insert command. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapInsert extends TSqlMapStatement +{ + private $_selectKey=null; + + /** + * @return TSqlMapSelectKey select key element. + */ + public function getSelectKey() + { + return $this->_selectKey; + } + + /** + * @param TSqlMapSelectKey select key. + */ + public function setSelectKey($value) + { + $this->_selectKey = $value; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapSelect.php b/framework/Data/SqlMap/Configuration/TSqlMapSelect.php new file mode 100644 index 00000000..098be9fb --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapSelect.php @@ -0,0 +1,26 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapSelect class file. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TSqlMapSelect extends TSqlMapStatement +{ + private $_generate; + + public function getGenerate(){ return $this->_generate; } + public function setGenerate($value){ $this->_generate = $value; } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php b/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php new file mode 100644 index 00000000..51299097 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php @@ -0,0 +1,72 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapSelect corresponds to the <selectKey> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapSelectKey extends TSqlMapStatement +{ + private $_type = 'post'; + private $_property; + + /** + * @return string select generated key type, 'post' or 'pre'. + */ + public function getType() + { + return $this->_type; + } + + /** + * @param string select generated key type, 'post' or 'pre'. + */ + public function setType($value) + { + $this->_type = strtolower($value) == 'post' ? 'post' : 'pre'; + } + + /** + * @return string property name for the generated key. + */ + public function getProperty() + { + return $this->_property; + } + + /** + * @param string property name for the generated key. + */ + public function setProperty($value) + { + $this->_property = $value; + } + + /** + * @throws TSqlMapConfigurationException extends is unsupported. + */ + public function setExtends($value) + { + throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key'); + } + + /** + * @return boolean true if key is generated after insert command, false otherwise. + */ + public function getIsAfter() + { + return $this->_type == 'post'; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php index 0efcc5b6..3477e9cf 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php @@ -311,134 +311,4 @@ class TSqlMapStatement extends TComponent return array_diff(parent::__sleep(),$exprops); } -} - -/** - * TSqlMapSelect class file. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TSqlMapSelect extends TSqlMapStatement -{ - private $_generate; - - public function getGenerate(){ return $this->_generate; } - public function setGenerate($value){ $this->_generate = $value; } -} - -/** - * TSqlMapInsert class corresponds to the <insert> element. - * - * The <insert> element allows <selectKey> child elements that can be used - * to generate a key to be used for the insert command. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapInsert extends TSqlMapStatement -{ - private $_selectKey=null; - - /** - * @return TSqlMapSelectKey select key element. - */ - public function getSelectKey() - { - return $this->_selectKey; - } - - /** - * @param TSqlMapSelectKey select key. - */ - public function setSelectKey($value) - { - $this->_selectKey = $value; - } -} - -/** - * TSqlMapUpdate class corresponds to <update> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapUpdate extends TSqlMapStatement -{ -} - -/** - * TSqlMapDelete class corresponds to the <delete> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapDelete extends TSqlMapUpdate -{ -} - -/** - * TSqlMapSelect corresponds to the <selectKey> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapSelectKey extends TSqlMapStatement -{ - private $_type = 'post'; - private $_property; - - /** - * @return string select generated key type, 'post' or 'pre'. - */ - public function getType() - { - return $this->_type; - } - - /** - * @param string select generated key type, 'post' or 'pre'. - */ - public function setType($value) - { - $this->_type = strtolower($value) == 'post' ? 'post' : 'pre'; - } - - /** - * @return string property name for the generated key. - */ - public function getProperty() - { - return $this->_property; - } - - /** - * @param string property name for the generated key. - */ - public function setProperty($value) - { - $this->_property = $value; - } - - /** - * @throws TSqlMapConfigurationException extends is unsupported. - */ - public function setExtends($value) - { - throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key'); - } - - /** - * @return boolean true if key is generated after insert command, false otherwise. - */ - public function getIsAfter() - { - return $this->_type == 'post'; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php b/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php new file mode 100644 index 00000000..853e7e2a --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php @@ -0,0 +1,22 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapUpdate class corresponds to <update> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapUpdate extends TSqlMapStatement +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php new file mode 100644 index 00000000..47982fca --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php @@ -0,0 +1,111 @@ +<?php +/** + * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement'); + +/** + * TSqlMapXmlConfig class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + */ +abstract class TSqlMapXmlConfigBuilder +{ + /** + * Create an instance of an object give by the attribute named 'class' in the + * node and set the properties on the object given by attribute names and values. + * @param SimpleXmlNode property node + * @return Object new instance of class with class name given by 'class' attribute value. + */ + protected function createObjectFromNode($node) + { + if(isset($node['class'])) + { + $obj = Prado::createComponent((string)$node['class']); + $this->setObjectPropFromNode($obj,$node,array('class')); + return $obj; + } + throw new TSqlMapConfigurationException( + 'sqlmap_node_class_undef', $node, $this->getConfigFile()); + } + + /** + * For each attributes (excluding attribute named in $except) set the + * property of the $obj given by the name of the attribute with the value + * of the attribute. + * @param Object object instance + * @param SimpleXmlNode property node + * @param array exception property name + */ + protected function setObjectPropFromNode($obj,$node,$except=array()) + { + foreach($node->attributes() as $name=>$value) + { + if(!in_array($name,$except)) + { + if($obj->canSetProperty($name)) + $obj->{$name} = (string)$value; + else + throw new TSqlMapConfigurationException( + 'sqlmap_invalid_property', $name, get_class($obj), + $node, $this->getConfigFile()); + } + } + } + + /** + * Gets the filename relative to the basefile. + * @param string base filename + * @param string relative filename + * @return string absolute filename. + */ + protected function getAbsoluteFilePath($basefile,$resource) + { + $basedir = dirname($basefile); + $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); + if(!is_string($file) || !is_file($file)) + $file = realpath($resource); + if(is_string($file) && is_file($file)) + return $file; + else + throw new TSqlMapConfigurationException( + 'sqlmap_unable_to_find_resource', $resource); + } + + /** + * Load document using simple xml. + * @param string filename. + * @return SimpleXmlElement xml document. + */ + protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config) + { + if( strpos($filename, '${') !== false) + $filename = $config->replaceProperties($filename); + + if(!is_file($filename)) + throw new TSqlMapConfigurationException( + 'sqlmap_unable_to_find_config', $filename); + return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); + } + + /** + * Get element node by ID value (try for attribute name ID as case insensitive). + * @param SimpleXmlDocument $document + * @param string tag name. + * @param string id value. + * @return SimpleXmlElement node if found, null otherwise. + */ + protected function getElementByIdValue($document, $tag, $value) + { + //hack to allow upper case and lower case attribute names. + foreach(array('id','ID','Id', 'iD') as $id) + { + $xpath = "//{$tag}[@{$id}='{$value}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlMappingConfiguration.php index db178f70..d677f6cd 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlMappingConfiguration.php @@ -9,289 +9,6 @@ * @package System.Data.SqlMap.Configuration */ -Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement'); - -/** - * TSqlMapXmlConfig class file. - * - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - */ -abstract class TSqlMapXmlConfigBuilder -{ - /** - * Create an instance of an object give by the attribute named 'class' in the - * node and set the properties on the object given by attribute names and values. - * @param SimpleXmlNode property node - * @return Object new instance of class with class name given by 'class' attribute value. - */ - protected function createObjectFromNode($node) - { - if(isset($node['class'])) - { - $obj = Prado::createComponent((string)$node['class']); - $this->setObjectPropFromNode($obj,$node,array('class')); - return $obj; - } - throw new TSqlMapConfigurationException( - 'sqlmap_node_class_undef', $node, $this->getConfigFile()); - } - - /** - * For each attributes (excluding attribute named in $except) set the - * property of the $obj given by the name of the attribute with the value - * of the attribute. - * @param Object object instance - * @param SimpleXmlNode property node - * @param array exception property name - */ - protected function setObjectPropFromNode($obj,$node,$except=array()) - { - foreach($node->attributes() as $name=>$value) - { - if(!in_array($name,$except)) - { - if($obj->canSetProperty($name)) - $obj->{$name} = (string)$value; - else - throw new TSqlMapConfigurationException( - 'sqlmap_invalid_property', $name, get_class($obj), - $node, $this->getConfigFile()); - } - } - } - - /** - * Gets the filename relative to the basefile. - * @param string base filename - * @param string relative filename - * @return string absolute filename. - */ - protected function getAbsoluteFilePath($basefile,$resource) - { - $basedir = dirname($basefile); - $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); - if(!is_string($file) || !is_file($file)) - $file = realpath($resource); - if(is_string($file) && is_file($file)) - return $file; - else - throw new TSqlMapConfigurationException( - 'sqlmap_unable_to_find_resource', $resource); - } - - /** - * Load document using simple xml. - * @param string filename. - * @return SimpleXmlElement xml document. - */ - protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config) - { - if( strpos($filename, '${') !== false) - $filename = $config->replaceProperties($filename); - - if(!is_file($filename)) - throw new TSqlMapConfigurationException( - 'sqlmap_unable_to_find_config', $filename); - return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); - } - - /** - * Get element node by ID value (try for attribute name ID as case insensitive). - * @param SimpleXmlDocument $document - * @param string tag name. - * @param string id value. - * @return SimpleXmlElement node if found, null otherwise. - */ - protected function getElementByIdValue($document, $tag, $value) - { - //hack to allow upper case and lower case attribute names. - foreach(array('id','ID','Id', 'iD') as $id) - { - $xpath = "//{$tag}[@{$id}='{$value}']"; - foreach($document->xpath($xpath) as $node) - return $node; - } - } - - /** - * @return string configuration file. - */ - protected abstract function getConfigFile(); -} - -/** - * TSqlMapXmlConfig class. - * - * Configures the TSqlMapManager using xml configuration file. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder -{ - /** - * @var TSqlMapManager manager - */ - private $_manager; - /** - * @var string configuration file. - */ - private $_configFile; - /** - * @var array global properties. - */ - private $_properties=array(); - - /** - * @param TSqlMapManager manager instance. - */ - public function __construct($manager) - { - $this->_manager=$manager; - } - - public function getManager() - { - return $this->_manager; - } - - protected function getConfigFile() - { - return $this->_configFile; - } - - /** - * Configure the TSqlMapManager using the given xml file. - * @param string SqlMap configuration xml file. - */ - public function configure($filename=null) - { - $this->_configFile=$filename; - $document = $this->loadXmlDocument($filename,$this); - - foreach($document->xpath('//property') as $property) - $this->loadGlobalProperty($property); - - foreach($document->xpath('//typeHandler') as $handler) - $this->loadTypeHandler($handler); - - foreach($document->xpath('//connection[last()]') as $conn) - $this->loadDatabaseConnection($conn); - - //try to load configuration in the current config file. - $mapping = new TSqlMapXmlMappingConfiguration($this); - $mapping->configure($filename); - - foreach($document->xpath('//sqlMap') as $sqlmap) - $this->loadSqlMappingFiles($sqlmap); - - $this->resolveResultMapping(); - $this->attachCacheModels(); - } - - /** - * Load global replacement property. - * @param SimpleXmlElement property node. - */ - protected function loadGlobalProperty($node) - { - $this->_properties[(string)$node['name']] = (string)$node['value']; - } - - /** - * Load the type handler configurations. - * @param SimpleXmlElement type handler node - */ - protected function loadTypeHandler($node) - { - $handler = $this->createObjectFromNode($node); - $this->_manager->getTypeHandlers()->registerTypeHandler($handler); - } - - /** - * Load the database connection tag. - * @param SimpleXmlElement connection node. - */ - protected function loadDatabaseConnection($node) - { - $conn = $this->createObjectFromNode($node); - $this->_manager->setDbConnection($conn); - } - - /** - * Load SqlMap mapping configuration. - * @param unknown_type $node - */ - protected function loadSqlMappingFiles($node) - { - if(strlen($resource = (string)$node['resource']) > 0) - { - if( strpos($resource, '${') !== false) - $resource = $this->replaceProperties($resource); - - $mapping = new TSqlMapXmlMappingConfiguration($this); - $filename = $this->getAbsoluteFilePath($this->_configFile, $resource); - $mapping->configure($filename); - } - } - - /** - * Resolve nest result mappings. - */ - protected function resolveResultMapping() - { - $maps = $this->_manager->getResultMaps(); - foreach($maps as $entry) - { - foreach($entry->getColumns() as $item) - { - $resultMap = $item->getResultMapping(); - if(strlen($resultMap) > 0) - { - if($maps->contains($resultMap)) - $item->setNestedResultMap($maps[$resultMap]); - else - throw new TSqlMapConfigurationException( - 'sqlmap_unable_to_find_result_mapping', - $resultMap, $this->_configFile, $entry->getID()); - } - } - if($entry->getDiscriminator()!==null) - $entry->getDiscriminator()->initialize($this->_manager); - } - } - - /** - * Set the cache for each statement having a cache model property. - */ - protected function attachCacheModels() - { - foreach($this->_manager->getMappedStatements() as $mappedStatement) - { - if(strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0) - { - $cache = $this->_manager->getCacheModel($model); - $mappedStatement->getStatement()->setCache($cache); - } - } - } - - /** - * Replace the place holders ${name} in text with properties the - * corresponding global property value. - * @param string original string. - * @return string string with global property replacement. - */ - public function replaceProperties($string) - { - foreach($this->_properties as $find => $replace) - $string = str_replace('${'.$find.'}', $replace, $string); - return $string; - } -} - /** * Loads the statements, result maps, parameters maps from xml configuration. * @@ -797,5 +514,4 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder } } } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSubMap.php b/framework/Data/SqlMap/Configuration/TSubMap.php new file mode 100644 index 00000000..0a2e7614 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSubMap.php @@ -0,0 +1,61 @@ +<?php +/** + * TDiscriminator and TSubMap classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSubMap class defines a submapping value and the corresponding <resultMap> + * + * The {@link Value setValue()} property is used for comparison with the + * discriminator column value. When the {@link Value setValue()} matches + * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping} + * is used inplace of the current result map. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSubMap extends TComponent +{ + private $_value; + private $_resultMapping; + + /** + * @return string value for comparison with discriminator column value. + */ + public function getValue() + { + return $this->_value; + } + + /** + * @param string value for comparison with discriminator column value. + */ + public function setValue($value) + { + $this->_value = $value; + } + + /** + * The result map to use when the Value matches the discriminator column value. + * @return string ID of a result map + */ + public function getResultMapping() + { + return $this->_resultMapping; + } + + /** + * @param string ID of a result map + */ + public function setResultMapping($value) + { + $this->_resultMapping = $value; + } +}
\ No newline at end of file |