diff options
author | wei <> | 2006-07-23 11:11:21 +0000 |
---|---|---|
committer | wei <> | 2006-07-23 11:11:21 +0000 |
commit | cbb7a11179b9c1c46e35f04d07d6386a44e400b2 (patch) | |
tree | dacfc2a5fdbcce3973e228eaca8002ff799e45d1 /framework/DataAccess/SQLMap/Configuration | |
parent | c0d9d27f16bae2e428225302da144e9cc6d4adc8 (diff) |
Update time-tracker demo and add simple dynamic SQLMap
Diffstat (limited to 'framework/DataAccess/SQLMap/Configuration')
5 files changed, 96 insertions, 65 deletions
diff --git a/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php b/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php index ba8323cc..0d1172b0 100644 --- a/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php +++ b/framework/DataAccess/SQLMap/Configuration/TDomSqlMapBuilder.php @@ -64,8 +64,8 @@ class TDomSqlMapBuilder if(isset($document->settings) && isset($document->settings->setting))
$this->configureSettings($document->settings);
- if(isset($document->typeHandler))
- $this->loadTypeHandler($document, $this->_configFile);
+ foreach($document->xpath('//typeHandler') as $handler)
+ $this->loadTypeHandler($handler, $this->_configFile);
//load database provider
if(isset($document->provider) && isset($document->provider->datasource))
@@ -79,8 +79,8 @@ class TDomSqlMapBuilder 'sqlmap_unable_to_find_db_config', $this->_configFile);
}
- if(isset($document->sqlMaps) && isset($document->sqlMaps->sqlMap))
- $this->loadSqlMappingFiles($document->sqlMaps);
+ foreach($document->xpath('//sqlMap') as $sqlmap)
+ $this->loadSqlMappingFiles($sqlmap);
if($this->_sqlMapper->getIsCacheModelsEnabled())
$this->attachCacheModel();
@@ -182,46 +182,40 @@ class TDomSqlMapBuilder //var_dump($node);
}
- protected function loadTypeHandler($nodes, $file)
+ protected function loadTypeHandler($node, $file)
{
- foreach($nodes->typeHandler as $node)
+ if(!is_null($node['type']) && !is_null($node['callback']))
{
- if(!is_null($node['type']) && !is_null($node['callback']))
+ $type = (string)$node['type'];
+ $dbType = (string)$node['dbType'];
+ $class = (string)$node['callback'];
+ if(class_exists('Prado', false))
{
- $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);
+ $handler = Prado::createComponent($class);
}
else
{
+ if(class_exists($class,false))
+ $handler = new $class;
+ else
throw new TSqlMapConfigurationException(
- 'sqlmap_type_handler_callback_undef', $file);
+ 'sqlmap_type_handler_class_undef', $file, $class);
}
+ $factory = $this->_sqlMapper->getTypeHandlerFactory();
+ $factory->register($type, $handler, $dbType);
}
- }
-
- protected function loadSqlMappingFiles($sqlmappings)
- {
- foreach($sqlmappings->sqlMap as $node)
+ else
{
- $resource = $this->getResourceFromPath((string)$node['resource']);
- $sqlmap = $this->getConfigAsXmlDocument($resource);
- $this->configureSqlMap($sqlmap,$resource);
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_type_handler_callback_undef', $file);
}
+ }
+ protected function loadSqlMappingFiles($node)
+ {
+ $resource = $this->getResourceFromPath((string)$node['resource']);
+ $sqlmap = $this->getConfigAsXmlDocument($resource);
+ $this->configureSqlMap($sqlmap,$resource);
$this->resolveResultMapping();
}
@@ -243,27 +237,26 @@ class TDomSqlMapBuilder // if(isset($document->typeAlias))
// foreach($document->typeAlias as $node)
// TTypeAliasDeSerializer::Deserialize($node, $this->_sqlMapper);
- if(isset($document->resultMap))
- foreach($document->resultMap as $node)
- $this->loadResultMap($node,$document,$file);
- if(isset($document->parameterMap))
- foreach($document->parameterMap as $node)
- $this->loadParameterMap($node, $document, $file);
- if(isset($document->statement))
- foreach($document->statement as $node)
- $this->loadStatementTag($node, $document,$file);
- if(isset($document->select))
- foreach($document->select as $node)
- $this->loadSelectTag($node, $document, $file);
- if(isset($document->insert))
- foreach($document->insert as $node)
- $this->loadInsertTag($node, $document, $file);
- if(isset($document->update))
- foreach($document->update as $node)
- $this->loadUpdateTag($node, $document, $file);
- if(isset($document->delete))
- foreach($document->delete as $node)
- $this->loadDeleteTag($node, $document, $file);
+ foreach($document->xpath('//resultMap') as $node)
+ $this->loadResultMap($node,$document,$file);
+
+ foreach($document->xpath('//parameterMap') as $node)
+ $this->loadParameterMap($node, $document, $file);
+
+ foreach($document->xpath('//statement') as $node)
+ $this->loadStatementTag($node, $document,$file);
+
+ foreach($document->xpath('//select') as $node)
+ $this->loadSelectTag($node, $document, $file);
+
+ foreach($document->xpath('//insert') as $node)
+ $this->loadInsertTag($node, $document, $file);
+
+ foreach($document->xpath('//update') as $node)
+ $this->loadUpdateTag($node, $document, $file);
+
+ foreach($document->xpath('//delete') as $node)
+ $this->loadDeleteTag($node, $document, $file);
/* if(isset($document->procedure))
foreach($document->procedure as $node)
$this->loadProcedureTag($node);
@@ -391,7 +384,7 @@ class TDomSqlMapBuilder if(isset($superNodes[0]))
$commandText = (string)$superNodes[0] . $commandText;
else
- throw TSqlMapConfigurationException(
+ throw new TSqlMapConfigurationException(
'sqlmap_unable_to_find_parent_sql', $extend, $file);
}
@@ -404,15 +397,15 @@ class TDomSqlMapBuilder protected function applyInlineParameterMap($statement, $sqlStatement, $node, $file)
{
+ $scope['statement'] = $statement->getID();
+ $scope['file'] = $file;
+
if($statement->parameterMap() == null)
{
- $scope['statement'] = $statement->getID();
- $scope['file'] = $file;
-
// Build a Parametermap with the inline parameters.
// if they exist. Then delete inline infos from sqltext.
$parameterParser = new TInlineParameterMapParser;
- $sqlText = $parameterParser->parseInlineParameterMap(
+ $sqlText = $parameterParser->parse(
$this->_sqlMapper, $statement, $sqlStatement, $scope);
if(count($sqlText['parameters']) > 0)
{
@@ -424,7 +417,16 @@ class TDomSqlMapBuilder }
$sqlStatement = $sqlText['sql'];
}
- $sql = new TStaticSql();
+
+ $simpleDynamic = new TSimpleDynamicParser;
+ $dynamics = $simpleDynamic->parse($this->_sqlMapper, $statement, $sqlStatement, $scope);
+ if(count($dynamics['parameters']) > 0)
+ {
+ $sql = new TSimpleDynamicSql($dynamics['parameters']);
+ $sqlStatement = $dynamics['sql'];
+ }
+ else
+ $sql = new TStaticSql();
$sql->buildPreparedStatement($statement, $sqlStatement);
$statement->setSql($sql);
}
diff --git a/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php b/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php index 8b1ecf04..bc633b2c 100644 --- a/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php +++ b/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php @@ -4,7 +4,7 @@ class TInlineParameterMapParser {
private $PARAMETER_TOKEN_REGEXP = '/#(#?[^#]+#?)#/';
- public function parseInlineParameterMap($sqlMap, $statement, $sqlText, $scope)
+ public function parse($sqlMap, $statement, $sqlText, $scope)
{
$parameterClass = !is_null($statement)
? $statement->getParameterClass() : null;
diff --git a/framework/DataAccess/SQLMap/Configuration/TParameterProperty.php b/framework/DataAccess/SQLMap/Configuration/TParameterProperty.php index 2ff55f73..196f27f5 100644 --- a/framework/DataAccess/SQLMap/Configuration/TParameterProperty.php +++ b/framework/DataAccess/SQLMap/Configuration/TParameterProperty.php @@ -19,9 +19,13 @@ class TParameterProperty extends TComponent {
if(is_null($this->_typeHandlerFactory)) return null;
if(!is_null($this->_typeHandler))
- return $this->_typeHandlerFactory->getTypeHandler($this->_typeHandler);
- else if(!is_null($this->getType()))
- return $this->_typeHandlerFactory->getTypeHandler($this->getType());
+ {
+ return $this->_typeHandlerFactory->getTypeHandler(
+ $this->_typeHandler, $this->_dbType);
+ }
+ else if(!is_null($this->getType()))
+ return $this->_typeHandlerFactory->getTypeHandler(
+ $this->getType(), $this->_dbType);
else
return null;
}
diff --git a/framework/DataAccess/SQLMap/Configuration/TResultProperty.php b/framework/DataAccess/SQLMap/Configuration/TResultProperty.php index 9cc0df3a..29ee366e 100644 --- a/framework/DataAccess/SQLMap/Configuration/TResultProperty.php +++ b/framework/DataAccess/SQLMap/Configuration/TResultProperty.php @@ -45,9 +45,11 @@ class TResultProperty extends TComponent {
if(is_null($this->_typeHandlerFactory)) return null;
if(!is_null($this->_typeHandler))
- return $this->_typeHandlerFactory->getTypeHandler($this->_typeHandler);
+ return $this->_typeHandlerFactory->getTypeHandler(
+ $this->_typeHandler, $this->_dbType);
else if(!is_null($this->getType()))
- return $this->_typeHandlerFactory->getTypeHandler($this->getType());
+ return $this->_typeHandlerFactory->getTypeHandler(
+ $this->getType(), $this->_dbType);
else
return null;
}
diff --git a/framework/DataAccess/SQLMap/Configuration/TSimpleDynamicParser.php b/framework/DataAccess/SQLMap/Configuration/TSimpleDynamicParser.php new file mode 100644 index 00000000..e58d8af8 --- /dev/null +++ b/framework/DataAccess/SQLMap/Configuration/TSimpleDynamicParser.php @@ -0,0 +1,23 @@ +<?php
+
+class TSimpleDynamicParser
+{
+ private $PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/';
+
+ const DYNAMIC_TOKEN = '`!`';
+
+ public function parse($sqlMap, $statement, $sqlText, $scope)
+ {
+ $matches = array();
+ $mappings = array();
+ preg_match_all($this->PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
+ for($i = 0, $k=count($matches[1]); $i<$k; $i++)
+ {
+ $mappings[] = $matches[1][$i];
+ $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText);
+ }
+ return array('sql'=>$sqlText, 'parameters'=>$mappings);
+ }
+}
+
+?>
\ No newline at end of file |