summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data/SqlMap/Configuration')
-rw-r--r--framework/Data/SqlMap/Configuration/TParameterMap.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TResultMap.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TResultProperty.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php29
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapStatement.php4
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php91
6 files changed, 108 insertions, 40 deletions
diff --git a/framework/Data/SqlMap/Configuration/TParameterMap.php b/framework/Data/SqlMap/Configuration/TParameterMap.php
index f4fbbe1c..4b5ee144 100644
--- a/framework/Data/SqlMap/Configuration/TParameterMap.php
+++ b/framework/Data/SqlMap/Configuration/TParameterMap.php
@@ -4,7 +4,7 @@
*
* @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
@@ -140,12 +140,12 @@ class TParameterMap extends TComponent
{
$value = $this->getObjectValue($parameterValue,$property);
- if(!is_null($handler=$this->createTypeHandler($property, $registry)))
+ if(($handler=$this->createTypeHandler($property, $registry))!==null)
$value = $handler->getParameter($value);
$value = $this->nullifyDefaultValue($property,$value);
- if(!is_null($type = $property->getType()))
+ if(($type = $property->getType())!==null)
$value = $registry->convertToType($type, $value);
return $value;
@@ -197,7 +197,7 @@ class TParameterMap extends TComponent
*/
protected function nullifyDefaultValue($property,$value)
{
- if(!is_null($nullValue = $property->getNullValue()))
+ if(($nullValue = $property->getNullValue())!==null)
{
if($nullValue === $value)
$value = null;
diff --git a/framework/Data/SqlMap/Configuration/TResultMap.php b/framework/Data/SqlMap/Configuration/TResultMap.php
index d59d9522..e85dc1aa 100644
--- a/framework/Data/SqlMap/Configuration/TResultMap.php
+++ b/framework/Data/SqlMap/Configuration/TResultMap.php
@@ -4,7 +4,7 @@
*
* @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
@@ -162,7 +162,7 @@ class TResultMap extends TComponent
$handler = $registry->getTypeHandler($this->getClass());
try
{
- if(!is_null($handler))
+ if($handler!==null)
return $handler->createNewInstance();
else
return $registry->createInstanceOf($this->getClass());
@@ -184,12 +184,12 @@ class TResultMap extends TComponent
public function resolveSubMap($registry,$row)
{
$subMap = $this;
- if(!is_null($disc = $this->getDiscriminator()))
+ if(($disc = $this->getDiscriminator())!==null)
{
$value = $disc->getMapping()->getPropertyValue($registry,$row);
$subMap = $disc->getSubMap((string)$value);
- if(is_null($subMap))
+ if($subMap===null)
$subMap = $this;
else if($subMap !== $this)
$subMap = $subMap->resolveSubMap($registry,$row);
diff --git a/framework/Data/SqlMap/Configuration/TResultProperty.php b/framework/Data/SqlMap/Configuration/TResultProperty.php
index 8e20d5e4..7316ef0b 100644
--- a/framework/Data/SqlMap/Configuration/TResultProperty.php
+++ b/framework/Data/SqlMap/Configuration/TResultProperty.php
@@ -4,7 +4,7 @@
*
* @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
@@ -242,7 +242,7 @@ class TResultProperty extends TComponent
$value = $this->getTypedValue($registry,$row[$index]);
else if(isset($row[$name]))
$value = $this->getTypedValue($registry,$row[$name]);
- if(is_null($value) && !is_null($this->getNullValue()))
+ if(($value===null) && ($this->getNullValue()!==null))
$value = $this->getTypedValue($registry,$this->getNullValue());
return $value;
}
@@ -302,7 +302,7 @@ class TResultProperty extends TComponent
*/
public function instanceOfListType($target)
{
- if(is_null($this->getType()))
+ if($this->getType()===null)
return TPropertyAccess::get($target,$this->getProperty()) instanceof TList;
return $this->getPropertyValueType() == self::LIST_TYPE;
}
@@ -315,7 +315,7 @@ class TResultProperty extends TComponent
*/
public function instanceOfArrayType($target)
{
- if(is_null($this->getType()))
+ if($this->getType()===null)
{
$prop = TPropertyAccess::get($target,$this->getProperty());
if(is_object($prop))
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index d7984dc4..d85148eb 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -4,7 +4,7 @@
*
* @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
@@ -38,8 +38,9 @@ class TSqlMapCacheModel extends TComponent
private $_hits = 0;
private $_requests = 0;
private $_id;
- private $_implementation='basic';
+ private $_implementation=TSqlMapCacheTypes::Basic;
private $_properties = array();
+ private $_flushInterval = 0;
/**
* @return string unique cache model identifier.
@@ -74,12 +75,28 @@ class TSqlMapCacheModel extends TComponent
}
/**
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ */
+ public function setFlushInterval($value)
+ {
+ $this->_flushInterval=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer cache duration.
+ */
+ public function getFlushInterval()
+ {
+ return $this->_flushInterval;
+ }
+
+ /**
* Initialize the cache implementation, sets the actual cache contain if supplied.
* @param ISqLMapCache cache implementation instance.
*/
public function initialize($cache=null)
{
- if(is_null($cache))
+ if($cache===null)
$this->_cache= Prado::createComponent($this->getImplementationClass());
else
$this->_cache=$cache;
@@ -127,7 +144,7 @@ class TSqlMapCacheModel extends TComponent
//if flush ?
$value = $this->_cache->get($key);
$this->_requests++;
- if(!is_null($value))
+ if($value!==null)
$this->_hits++;
return $value;
}
@@ -141,8 +158,8 @@ class TSqlMapCacheModel extends TComponent
if($key instanceof TSqlMapCacheKey)
$key = $key->getHash();
- if(!is_null($value))
- $this->_cache->set($key, $value);
+ if($value!==null)
+ $this->_cache->set($key, $value, $this->_flushInterval);
}
/**
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
index 3afcc75f..7e1783a3 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
@@ -5,7 +5,7 @@
*
* @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
@@ -275,7 +275,7 @@ class TSqlMapStatement extends TComponent
protected function createInstanceOf($registry,$type,$row=null)
{
$handler = $registry->getTypeHandler($type);
- if(!is_null($handler))
+ if($handler!==null)
return $handler->createNewInstance($row);
else
return $registry->createInstanceOf($type);
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
}
}
}
-
+