diff options
author | wei <> | 2006-07-16 06:19:36 +0000 |
---|---|---|
committer | wei <> | 2006-07-16 06:19:36 +0000 |
commit | c7d41e5bea4a5f96979a08da9cc9f79355edfe70 (patch) | |
tree | 8f21cba052c1eae7c7204ac272dd8c5e9d6fe110 /framework/DataAccess/SQLMap/Configuration | |
parent | af68030fcf0c266300feb2c100149ecadef7d364 (diff) |
Update Time Tracker demo.
Diffstat (limited to 'framework/DataAccess/SQLMap/Configuration')
5 files changed, 72 insertions, 13 deletions
diff --git a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php index ee8f1744..2441dedf 100644 --- a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php +++ b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php @@ -104,6 +104,7 @@ class TConfigDeserialize public function resultMap($node, $sqlMap, $file)
{
$resultMap = new TResultMap;
+ $resultMap->initialize($sqlMap);
$this->loadConfiguration($resultMap, $node, $file);
foreach($node->result as $result)
{
diff --git a/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php b/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php index d3059dd7..ba8323cc 100644 --- a/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php +++ b/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php @@ -63,6 +63,9 @@ class TDomSqlMapBuilder if(isset($document->settings) && isset($document->settings->setting))
$this->configureSettings($document->settings);
+
+ if(isset($document->typeHandler))
+ $this->loadTypeHandler($document, $this->_configFile);
//load database provider
if(isset($document->provider) && isset($document->provider->datasource))
@@ -157,11 +160,19 @@ class TDomSqlMapBuilder {
//$id = (string)$node['id'];
$class = (string)$providerNode['class'];
- if(strlen($class) > 0 && class_exists($class,false))
+ if(strlen($class) > 0)
{
- $provider = new $class;
- $this->_deserialize->loadConfiguration($provider, $node,$file);
- $this->_sqlMapper->setDataProvider($provider);
+ if(class_exists($class,false))
+ {
+ $provider = new $class;
+ $this->_deserialize->loadConfiguration($provider, $node,$file);
+ $this->_sqlMapper->setDataProvider($provider);
+ }
+ else
+ {
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_unable_find_provider_class_def', $file, $class);
+ }
}
else
{
@@ -170,11 +181,38 @@ class TDomSqlMapBuilder }
//var_dump($node);
}
-/*
- protected function loadTypeHandlers()
+
+ protected function loadTypeHandler($nodes, $file)
{
+ foreach($nodes->typeHandler as $node)
+ {
+ if(!is_null($node['type']) && !is_null($node['callback']))
+ {
+ $type = (string)$node['type'];
+ $class = (string)$node['callback'];
+ if(class_exists('Prado', false))
+ {
+ $handler = Prado::createComponent($class);
+ }
+ else
+ {
+ if(class_exists($class,false))
+ $handler = new $class;
+ else
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_type_handler_class_undef', $file, $class);
+ }
+ $factory = $this->_sqlMapper->getTypeHandlerFactory();
+ $factory->register($type, $handler);
+ }
+ else
+ {
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_type_handler_callback_undef', $file);
+ }
+ }
}
-*/
+
protected function loadSqlMappingFiles($sqlmappings)
{
foreach($sqlmappings->sqlMap as $node)
diff --git a/framework/DataAccess/SQLMap/Configuration/TParameterMap.php b/framework/DataAccess/SQLMap/Configuration/TParameterMap.php index 8e1c757d..b3c6ed6e 100644 --- a/framework/DataAccess/SQLMap/Configuration/TParameterMap.php +++ b/framework/DataAccess/SQLMap/Configuration/TParameterMap.php @@ -56,7 +56,7 @@ class TParameterMap extends TComponent $typeHandler = $mapping->getTypeHandler();
try
{
- $value = TPropertyAccess::get($parameterValue, $mapping->getProperty());
+ $value = TPropertyAccess::get($parameterValue, $mapping->getProperty());
}
catch (TInvalidPropertyException $e)
{
diff --git a/framework/DataAccess/SQLMap/Configuration/TResultMap.php b/framework/DataAccess/SQLMap/Configuration/TResultMap.php index 0f09a1ba..b8032c81 100644 --- a/framework/DataAccess/SQLMap/Configuration/TResultMap.php +++ b/framework/DataAccess/SQLMap/Configuration/TResultMap.php @@ -8,6 +8,7 @@ class TResultMap extends TComponent private $_extendMap='';
private $_groupBy='';
private $_discriminator=null;
+ private $_typeHandlerFactory=null;
public function __construct()
{
@@ -32,6 +33,11 @@ class TResultMap extends TComponent public function getDiscriminator(){ return $this->_discriminator; }
public function setDiscriminator($value){ $this->_discriminator = $value; }
+ public function initialize($sqlMap, $resultMap=null)
+ {
+ $this->_typeHandlerFactory = $sqlMap->getTypeHandlerFactory();
+ }
+
public function addResultProperty(TResultProperty $property)
{
$this->_columns->add($property->getProperty(), $property);
@@ -39,7 +45,21 @@ class TResultMap extends TComponent public function createInstanceOfResult()
{
- return TTypeHandlerFactory::createInstanceOf($this->getClass());
+ $handler = $this->_typeHandlerFactory->getTypeHandler($this->getClass());
+
+ try
+ {
+ if(!is_null($handler))
+ return $handler->createNewInstance();
+ else
+ return TTypeHandlerFactory::createInstanceOf($this->getClass());
+ }
+ catch (TDataMapperException $e)
+ {
+ throw new TSqlMapExecutionException(
+ 'sqlmap_unable_to_create_new_instance',
+ $this->getClass(), get_class($handler), $this->getID());
+ }
}
public function resolveSubMap($row)
diff --git a/framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php b/framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php index 228b37d6..414ad2f1 100644 --- a/framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php +++ b/framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php @@ -79,14 +79,14 @@ class TSqlMapStatement extends TComponent return array(); //new TList;
}
- protected function createInstanceOf($type)
+ protected function createInstanceOf($type,$row=null)
{
$handler = $this->_typeHandler->getTypeHandler($type);
try
{
if(!is_null($handler))
- return $handler->createNewInstance();
+ return $handler->createNewInstance($row);
else
return TTypeHandlerFactory::createInstanceOf($type);
}
@@ -99,10 +99,10 @@ class TSqlMapStatement extends TComponent }
- public function createInstanceOfResultClass()
+ public function createInstanceOfResultClass($row)
{
if(strlen($type= $this->getResultClass()) > 0)
- return $this->createInstanceOf($type);
+ return $this->createInstanceOf($type,$row);
}
}
|