summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'framework/DataAccess/SQLMap/Configuration')
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php1
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php52
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TParameterMap.php2
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TResultMap.php22
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php8
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);
}
}