summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php4
-rw-r--r--framework/DataAccess/SQLMap/Configuration/TSqlMapCacheModel.php12
-rw-r--r--framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php73
-rw-r--r--framework/DataAccess/SQLMap/DataMapper/messages.txt3
-rw-r--r--framework/DataAccess/SQLMap/TSqlMapClient.php3
-rw-r--r--framework/DataAccess/SQLMap/TSqlMapper.php3
6 files changed, 82 insertions, 16 deletions
diff --git a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php
index 250133b9..9a44d1ec 100644
--- a/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php
+++ b/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php
@@ -144,7 +144,7 @@ class TConfigDeserialize
{
$cacheModel = new TSqlMapCacheModel;
$this->loadConfiguration($cacheModel, $node, $file);
- if(isset($node->flushInterval))
+/* if(isset($node->flushInterval))
{
$interval = $node->flushInterval;
$span = 0; //span in seconds
@@ -156,7 +156,7 @@ class TConfigDeserialize
$span += intval($interval['seconds']);
if($span > 0)
$cacheModel->setFlushInterval($span);
- }
+ }*/
if(isset($node->property))
{
foreach($node->property as $property)
diff --git a/framework/DataAccess/SQLMap/Configuration/TSqlMapCacheModel.php b/framework/DataAccess/SQLMap/Configuration/TSqlMapCacheModel.php
index 6c945155..3bd20933 100644
--- a/framework/DataAccess/SQLMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/DataAccess/SQLMap/Configuration/TSqlMapCacheModel.php
@@ -3,11 +3,11 @@
class TSqlMapCacheModel extends TComponent
{
private $_cache;
- private $_flushInterval = -1;
+// private $_flushInterval = -1;
private $_hits = 0;
private $_requests = 0;
private $_id;
- private $_lastFlush;
+// private $_lastFlush;
private $_implementation;
private $_properties = array();
@@ -18,15 +18,15 @@ class TSqlMapCacheModel extends TComponent
public function getImplementation(){ return $this->_implementation; }
public function setImplementation($value){ $this->_implementation = $value; }
- public function getFlushInterval(){ return $this->_flushInterval; }
- public function setFlushInterval($value){ $this->_flushInterval = $value; }
+// public function getFlushInterval(){ return $this->_flushInterval; }
+// public function setFlushInterval($value){ $this->_flushInterval = $value; }
public function initialize($sqlMap)
{
$implementation = $this->getImplementationClass(
$sqlMap->getTypeHandlerFactory());
$this->_cache = new $implementation;
- $this->_cache->configure($this->_properties);
+ $this->_cache->configure($this, $this->_properties);
}
protected function getImplementationClass($typeFactory)
@@ -35,6 +35,7 @@ class TSqlMapCacheModel extends TComponent
{
case 'fifo': return 'TSqlMapFifoCache';
case 'lru' : return 'TSqlMapLruCache';
+ case 'basic' : return 'TSqlMapApplicationCache';
}
if(class_exists($this->_implementation, false))
@@ -66,7 +67,6 @@ class TSqlMapCacheModel extends TComponent
public function flush()
{
- var_dump("flush!");
$this->_cache->flush();
}
diff --git a/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php b/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
index 8571d46d..a62a7432 100644
--- a/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
+++ b/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
@@ -1,6 +1,6 @@
<?php
/**
- * TSqlMapCache class file contains FIFO and LRU cache implementations.
+ * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
@@ -20,7 +20,7 @@ interface ISqLMapCache
public function set($key, $value);
- public function configure($properties);
+ public function configure($model, $properties);
}
/**
@@ -54,7 +54,7 @@ abstract class TSqlMapCache implements ISqlMapCache
* Configures the Cache Size.
* @param array list of properties
*/
- public function configure($properties)
+ public function configure($model, $properties)
{
if(isset($properties['size']))
$this->_cacheSize = intval($properties['size']);
@@ -161,5 +161,72 @@ class TSqlMapLruCache extends TSqlMapCache
}
}
+class TSqlMapApplicationCache implements ISqlMapCache
+{
+ private $_cache;
+ private $_expiry=0;
+ private $_property=array();
+ private $_cacheModelID;
+
+ public function __sleep()
+ {
+ $this->_cache = null;
+ return array_keys(get_object_vars($this));
+ }
+
+ public function remove($key)
+ {
+ $this->getCache()->delete($key);
+ }
+
+ public function flush()
+ {
+ $this->getCache()->flush();
+ }
+
+ public function get($key)
+ {
+ $result = $this->getCache()->get($key);
+ return $result === false ? null : $result;
+ }
+
+ public function set($key, $value)
+ {
+ $this->getCache()->set($key, $value, $this->_expiry);
+ }
+
+ public function configure($model, $properties)
+ {
+ $this->_property = $properties;
+ $this->_cacheModelID = $model->getID();
+ }
+
+ protected function getCache()
+ {
+ if(is_null($this->_cache))
+ $this->initialize();
+ return $this->_cache;
+ }
+
+ protected function initialize()
+ {
+ if(isset($this->_property['expiry']))
+ $this->_expiry = intval($this->_property['expiry']);
+
+ if(isset($this->_property['cacheModule']))
+ {
+ $id = $this->_property['cacheModule'];
+ $this->_cache = Prado::getApplication()->getModule($id);
+ }
+ else
+ {
+ $this->_cache = Prado::getApplication()->getCache();
+ }
+
+ if(!($this->_cache instanceof ICache))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_invalid_prado_cache', $this->_cacheModelID);
+ }
+}
?> \ No newline at end of file
diff --git a/framework/DataAccess/SQLMap/DataMapper/messages.txt b/framework/DataAccess/SQLMap/DataMapper/messages.txt
index 79c80ad5..6bf5f396 100644
--- a/framework/DataAccess/SQLMap/DataMapper/messages.txt
+++ b/framework/DataAccess/SQLMap/DataMapper/messages.txt
@@ -58,4 +58,5 @@ sqlmap_invalid_lazyload_list = Invalid type to lazy load, must specify a valid
sqlmap_unable_to_find_resource = 'Unable to find SQLMap configuration file '{0}'.
sqlmap_query_execution_error = Error in executing SQLMap statement '{0}' : '{1}'.
sqlmap_undefined_discriminator = The discriminator is null, but somehow a subMap was reached in ResultMap '{0}' in file '{1}'.
-sqlmap_invalid_delegate = Invalid callback row delegate '{1}' in mapped statement '{0}'. \ No newline at end of file
+sqlmap_invalid_delegate = Invalid callback row delegate '{1}' in mapped statement '{0}'.
+sqlmap_invalid_prado_cache = Unable to find Prado cache module for SQLMap cache '{0}'. \ No newline at end of file
diff --git a/framework/DataAccess/SQLMap/TSqlMapClient.php b/framework/DataAccess/SQLMap/TSqlMapClient.php
index 7662d83e..5f531f64 100644
--- a/framework/DataAccess/SQLMap/TSqlMapClient.php
+++ b/framework/DataAccess/SQLMap/TSqlMapClient.php
@@ -44,7 +44,6 @@ class TSqlMapClient
{
if(!is_file($this->_cache))
{
- var_dump('saving cache to file', $this->_cache);
file_put_contents($this->_cache,serialize($this->_mapper));
return true;
}
@@ -57,12 +56,10 @@ class TSqlMapClient
$this->_cache = $this->getCacheFile($file);
if($loadFromCache && $this->_cache !== false && is_file($this->_cache))
{
- var_dump('loading from cache: '.$this->_cache);
$this->_mapper = unserialize(file_get_contents($this->_cache));
}
else
{
-// var_dump('build from *.xml');
$builder = new TDomSqlMapBuilder();
$this->_mapper = $builder->configure($file);
}
diff --git a/framework/DataAccess/SQLMap/TSqlMapper.php b/framework/DataAccess/SQLMap/TSqlMapper.php
index 602b83ea..26e6c115 100644
--- a/framework/DataAccess/SQLMap/TSqlMapper.php
+++ b/framework/DataAccess/SQLMap/TSqlMapper.php
@@ -3,6 +3,7 @@
Prado::using('System.DataAccess.SQLMap.DataMapper.*');
Prado::using('System.DataAccess.SQLMap.Configuration.*');
Prado::using('System.DataAccess.SQLMap.Statements.*');
+Prado::using('System.Collections.*');
Prado::using('System.DataAccess.SQLMap.DataMapper.TTypeHandlerFactory');
Prado::using('System.DataAccess.SQLMap.DataMapper.TSqlMapCache');
Prado::using('System.DataAccess.SQLMap.DataMapper.TDataMapperException');
@@ -39,7 +40,7 @@ class TSqlMapper extends TComponent
private $_resultMaps;
private $_parameterMaps;
private $_typeHandlerFactory;
- private $_cacheModelsEnabled = false;
+ private $_cacheModelsEnabled = true;
private $_cacheMaps;
/**