summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/DataMapper
diff options
context:
space:
mode:
authorwei <>2006-04-14 11:23:56 +0000
committerwei <>2006-04-14 11:23:56 +0000
commitf6a5e7589396854e10e023c25237b47e512ff047 (patch)
tree2b313bb8b66869235ee06b9cae2af2f7645cf5c9 /framework/DataAccess/SQLMap/DataMapper
parent3d3f8d3832921f99daf8ce1953304763c2e76c62 (diff)
Adding SQLMap unit tests. Allow sqlmap to use Prado's caching module to cache records.
Diffstat (limited to 'framework/DataAccess/SQLMap/DataMapper')
-rw-r--r--framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php73
-rw-r--r--framework/DataAccess/SQLMap/DataMapper/messages.txt3
2 files changed, 72 insertions, 4 deletions
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