summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--framework/Data/TDataFieldAccessor.php2
-rw-r--r--framework/DataAccess/TAdodbProvider.php33
-rw-r--r--framework/DataAccess/TSQLMap.php77
4 files changed, 97 insertions, 16 deletions
diff --git a/.gitattributes b/.gitattributes
index 7d1573b9..33f5442b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -294,6 +294,7 @@ framework/Data/TXmlDocument.php -text
framework/DataAccess/TAdodbProvider.php -text
framework/DataAccess/TCreoleProvider.php -text
framework/DataAccess/TDatabaseProvider.php -text
+framework/DataAccess/TSQLMap.php -text
framework/Exceptions/TErrorHandler.php -text
framework/Exceptions/TException.php -text
framework/Exceptions/messages.txt -text
diff --git a/framework/Data/TDataFieldAccessor.php b/framework/Data/TDataFieldAccessor.php
index af4d6ac0..e0c87add 100644
--- a/framework/Data/TDataFieldAccessor.php
+++ b/framework/Data/TDataFieldAccessor.php
@@ -85,6 +85,8 @@ class TDataFieldAccessor
$getter='get'.$field;
if(is_callable(array($data,$getter)))
return call_user_func(array($data,$getter));
+ else if(in_array($field, array_keys(get_object_vars($data))))
+ return $data->{$field};
}
else // field in the format of xxx.yyy.zzz
{
diff --git a/framework/DataAccess/TAdodbProvider.php b/framework/DataAccess/TAdodbProvider.php
index 65e336a9..53eead61 100644
--- a/framework/DataAccess/TAdodbProvider.php
+++ b/framework/DataAccess/TAdodbProvider.php
@@ -35,7 +35,7 @@ class TAdodbProvider extends TDatabaseProvider
public function getConnection()
{
- if(is_null($this->_connection))
+ if(is_null($this->_connection) || is_null($this->_connection->getProvider()))
{
$this->importAdodbLibrary();
$this->_connection = new TAdodbConnection($this);
@@ -148,28 +148,15 @@ class TAdodbConnection extends TDbConnection
}
/**
- * PHP magic function.
- * This method will pass all method calls to ADOConnection class
- * provided in the ADODB library.
- * @param mixed method name
- * @param mixed method call parameters
- * @param mixed return value of the method call
- */
- public function __call($method, $params)
- {
- if(is_null($this->_connection) || !$this->_connection->IsConnected())
- $this->open();
- return call_user_func_array(array($this->_connection,$method),$params);
- }
-
- /**
* Cleanup work before serializing.
* This is a PHP defined magic method.
* @return array the names of instance-variables to serialize.
*/
public function __sleep()
{
+ //close any open connections before serializing.
$this->close();
+ $this->_connection = null;
return array_keys(get_object_vars($this));
}
@@ -181,6 +168,20 @@ class TAdodbConnection extends TDbConnection
{
}
+ /**
+ * PHP magic function.
+ * This method will pass all method calls to ADOConnection class
+ * provided in the ADODB library.
+ * @param mixed method name
+ * @param mixed method call parameters
+ * @param mixed return value of the method call
+ */
+ public function __call($method, $params)
+ {
+ if(is_null($this->_connection) || !$this->_connection->IsConnected())
+ $this->open();
+ return call_user_func_array(array($this->_connection,$method),$params);
+ }
public function getIsClosed()
{
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 @@
+<?php
+
+class TSQLMap extends TModule
+{
+ private $_SQLMapLibrary='';
+ private $_configFile;
+ private $_sqlmap;
+ private $_provider;
+
+ /**
+ * File extension of external configuration file
+ */
+ const CONFIG_FILE_EXT='.config';
+
+ public function getSQLMapLibrary()
+ {
+ if(strlen($this->_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