summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php')
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php91
1 files changed, 71 insertions, 20 deletions
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
index f2d13966..462b356f 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
@@ -4,14 +4,14 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
*/
Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
-
+
/**
* TSqlMapXmlConfig class file.
*
@@ -89,6 +89,9 @@ abstract class TSqlMapXmlConfigBuilder
*/
protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config)
{
+ if( strpos($filename, '${') !== false)
+ $filename = $config->replaceProperties($filename);
+
if(!is_file($filename))
throw new TSqlMapConfigurationException(
'sqlmap_unable_to_find_config', $filename);
@@ -228,6 +231,9 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
{
if(strlen($resource = (string)$node['resource']) > 0)
{
+ if( strpos($resource, '${') !== false)
+ $resource = $this->replaceProperties($resource);
+
$mapping = new TSqlMapXmlMappingConfiguration($this);
$filename = $this->getAbsoluteFilePath($this->_configFile, $resource);
$mapping->configure($filename);
@@ -255,7 +261,7 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
$resultMap, $this->_configFile, $entry->getID());
}
}
- if(!is_null($entry->getDiscriminator()))
+ if($entry->getDiscriminator()!==null)
$entry->getDiscriminator()->initialize($this->_manager);
}
}
@@ -309,16 +315,16 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
private $_FlushOnExecuteStatements=array();
- /**
- * Regular expressions for escaping simple/inline parameter symbols
- */
- const SIMPLE_MARK='$';
- const INLINE_SYMBOL='#';
- const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
- const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
- const SIMPLE_PLACEHOLDER='`!!`';
- const INLINE_PLACEHOLDER='`!!!`';
-
+ /**
+ * Regular expressions for escaping simple/inline parameter symbols
+ */
+ const SIMPLE_MARK='$';
+ const INLINE_SYMBOL='#';
+ const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
+ const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
+ const SIMPLE_PLACEHOLDER='`!!`';
+ const INLINE_PLACEHOLDER='`!!!`';
+
/**
* @param TSqlMapXmlConfiguration parent xml configuration.
*/
@@ -343,6 +349,15 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$document = $this->loadXmlDocument($filename,$this->_xmlConfig);
$this->_document=$document;
+ static $bCacheDependencies;
+ if($bCacheDependencies === null)
+ $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance;
+
+ if($bCacheDependencies)
+ $this->_manager->getCacheDependencies()
+ ->getDependencies()
+ ->add(new TFileCacheDependency($filename));
+
foreach($document->xpath('//resultMap') as $node)
$this->loadResultMap($node);
@@ -434,7 +449,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
foreach($node->xpath('subMap') as $subMapNode)
{
- if(is_null($discriminator))
+ if($discriminator===null)
throw new TSqlMapConfigurationException(
'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode);
$subMap = new TSubMap;
@@ -442,7 +457,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$discriminator->addSubMap($subMap);
}
- if(!is_null($discriminator))
+ if($discriminator!==null)
$resultMap->setDiscriminator($discriminator);
return $resultMap;
@@ -542,7 +557,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$scope['file'] = $this->_configFile;
$scope['node'] = $node;
- $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
+ $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
if($statement->parameterMap() === null)
{
// Build a Parametermap with the inline parameters.
@@ -559,7 +574,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
$sqlStatement = $sqlText['sql'];
}
- $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
+ $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
$this->prepareSql($statement, $sqlStatement, $node);
}
@@ -574,7 +589,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
protected function prepareSql($statement,$sqlStatement, $node)
{
$simpleDynamic = new TSimpleDynamicParser;
- $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
+ $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
$dynamics = $simpleDynamic->parse($sqlStatement);
if(count($dynamics['parameters']) > 0)
{
@@ -583,7 +598,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
else
$sql = new TStaticSql();
- $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
+ $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
$sql->buildPreparedStatement($statement, $sqlStatement);
$statement->setSqlText($sql);
}
@@ -697,6 +712,8 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
$cache = Prado::createComponent($cacheModel->getImplementationClass());
$this->setObjectPropFromNode($cache,$node,$properties);
+ $this->loadFlushInterval($cacheModel,$node);
+
$cacheModel->initialize($cache);
$this->_manager->addCacheModel($cacheModel);
foreach($node->xpath('flushOnExecute') as $flush)
@@ -704,6 +721,40 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
/**
+ * Load the flush interval
+ * @param TSqlMapCacheModel cache model
+ * @param SimpleXmlElement cache node
+ */
+ protected function loadFlushInterval($cacheModel, $node)
+ {
+ $flushInterval = $node->xpath('flushInterval');
+ if($flushInterval === null || count($flushInterval) === 0) return;
+ $duration = 0;
+ foreach($flushInterval[0]->attributes() as $name=>$value)
+ {
+ switch(strToLower($name))
+ {
+ case 'seconds':
+ $duration += (integer)$value;
+ break;
+ case 'minutes':
+ $duration += 60 * (integer)$value;
+ break;
+ case 'hours':
+ $duration += 3600 * (integer)$value;
+ break;
+ case 'days':
+ $duration += 86400 * (integer)$value;
+ break;
+ case 'duration':
+ $duration = (integer)$value;
+ break 2; // switch, foreach
+ }
+ }
+ $cacheModel->setFlushInterval($duration);
+ }
+
+ /**
* Load the flush on cache properties.
* @param TSqlMapCacheModel cache model
* @param SimpleXmlElement parent node.
@@ -737,4 +788,4 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
}
}
-
+