From 5f66433898f89865a6682ad9aebfeef14b596dea Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 12 Mar 2006 10:38:37 +0000 Subject: adding TSQLMap module --- framework/DataAccess/TSQLMap.php | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 framework/DataAccess/TSQLMap.php (limited to 'framework/DataAccess/TSQLMap.php') diff --git a/framework/DataAccess/TSQLMap.php b/framework/DataAccess/TSQLMap.php new file mode 100644 index 00000000..bc9ba1fb --- /dev/null +++ b/framework/DataAccess/TSQLMap.php @@ -0,0 +1,77 @@ +_SQLMapLibrary) < 1) + return dirname(__FILE__).'/SQLMap'; + else + return $this->_SQLMapLibrary; + } + + public function setSQLMapLibrary($path) + { + $this->_SQLMapLibrary = Prado::getPathOfNamespace($path); + } + + /** + * @return string external configuration file. Defaults to null. + */ + public function getConfigFile() + { + return $this->_configFile; + } + + public function init($xml) + { + $config = $xml->getElementByTagName('provider'); + $class = $config->getAttribute('class'); + $provider = Prado::createComponent($class); + $datasource = $config->getElementByTagName('datasource'); + $properties = $datasource->getAttributes(); + foreach($properties as $name=>$value) + $provider->setSubproperty($name,$value); + $this->_provider = $provider; + } + + /** + * @param string external configuration file in namespace format. The file + * must be suffixed with '.xml'. + * @throws TInvalidDataValueException if the file is invalid. + */ + public function setConfigFile($value) + { + if(($this->_configFile=Prado::getPathOfNamespace( + $value,self::CONFIG_FILE_EXT))===null) + throw new TConfigurationException('sqlmap_configfile_invalid',$value); + } + + protected function configure($configFile) + { + include($this->getSQLMapLibrary().'/TSqlMapper.php'); + $builder = new TDomSqlMapBuilder(); + $this->_sqlmap = $builder->configure($configFile); + if(!is_null($this->_provider)) + $this->_sqlmap->setDataProvider($this->_provider); + } + + public function getClient() + { + if(is_null($this->_sqlmap)) + $this->configure($this->getConfigFile()); + return $this->_sqlmap; + } +} + +?> \ No newline at end of file -- cgit v1.2.3