diff options
| author | wei <> | 2006-04-14 06:22:09 +0000 | 
|---|---|---|
| committer | wei <> | 2006-04-14 06:22:09 +0000 | 
| commit | 3d3f8d3832921f99daf8ce1953304763c2e76c62 (patch) | |
| tree | e1b0a9bc3a13fccd253770fb452ac96cc6315121 /framework/DataAccess/SQLMap/Statements/TCachingStatement.php | |
| parent | 373d8acc503b94ea09823f49e2ab5e395eccc584 (diff) | |
Importing SQLMap + sample + docs.
Diffstat (limited to 'framework/DataAccess/SQLMap/Statements/TCachingStatement.php')
| -rw-r--r-- | framework/DataAccess/SQLMap/Statements/TCachingStatement.php | 102 | 
1 files changed, 102 insertions, 0 deletions
diff --git a/framework/DataAccess/SQLMap/Statements/TCachingStatement.php b/framework/DataAccess/SQLMap/Statements/TCachingStatement.php new file mode 100644 index 00000000..8e4e2a3d --- /dev/null +++ b/framework/DataAccess/SQLMap/Statements/TCachingStatement.php @@ -0,0 +1,102 @@ +<?php
 +
 +/**
 + * 
 + *
 + * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 + * @version $Revision: $  $Date: $
 + * @package System.Web.UI.WebControls
 + * @since 3.0
 + */
 +class TCachingStatement implements IMappedStatement
 +{
 +	private $_mappedStatement;
 +
 +	public function __construct(TMappedStatement $statement)
 +	{
 +		$this->_mappedStatement = $statement;
 +	}
 +
 +	public function getID()
 +	{
 +		return $this->_mappedStatement->getID();
 +	}
 +
 +	public function getStatement()
 +	{
 +		return $this->_mappedStatement->getStatement();
 +	}
 +
 +	public function getSqlMap()
 +	{
 +		return $this->_mappedStatement->getSqlMap();
 +	}
 +
 +	public function executeQueryForMap($connection, $parameter, 
 +								$keyProperty, $valueProperty=null, $delegate=null)
 +	{
 +		$sql = $this->createCommand($connection, $parameter);
 +		$key = $this->getCacheKey(array($sql, $keyProperty, $valueProperty));
 +		$map = $this->getStatement()->getCache()->get($key);
 +		if(is_null($map))
 +		{
 +			$map = $this->_mappedStatement->runQueryForMap(
 +							$connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
 +			$this->getStatement()->getCache()->set($key, $map);
 +		}
 +		return $map;
 +	}
 +
 +	public function executeUpdate($connection, $parameter)
 +	{
 +		return $this->_mappedStatement->executeUpdate($connection, $parameter);
 +	}
 +
 +	public function executeInsert($connection, $parameter)
 +	{
 +		return $this->executeInsert($connection, $parameter);
 +	}
 +
 +	public function executeQueryForList($connection, $parameter, 
 +								$result, $skip=-1, $max=-1, $delegate=null)
 +	{
 +		$sql = $this->createCommand($connection, $parameter);
 +		$key = $this->getCacheKey(array($sql, $skip, $max));
 +		$list = $this->getStatement()->getCache()->get($key);
 +		if(is_null($list))
 +		{
 +			$list = $this->_mappedStatement->runQueryForList(
 +							$connection, $parameter, $sql, $result, $skip, $max, $delegate);
 +			$this->getStatement()->getCache()->set($key, $list);
 +		}
 +		return $list;
 +	}
 +
 +	public function executeQueryForObject($connection, $parameter, $result)
 +	{
 +		$sql = $this->createCommand($connection, $parameter);
 +		$key = $this->getCacheKey($sql);
 +		$object = $this->getStatement()->getCache()->get($key);
 +		if(is_null($object))
 +		{
 +			$object = $this->_mappedStatement->runQueryForObject(
 +							$connection, $sql, $result);
 +			$this->getStatement()->getCache()->set($key, $object);
 +		}
 +		return $object;
 +	}
 +	
 +	protected function getCacheKey($object)
 +	{
 +		$cacheKey = new TSqlMapCacheKey($object);
 +		return $cacheKey->getHash();
 +	}
 +
 +	protected function createCommand($connection, $parameter)
 +	{
 +		return $this->_mappedStatement->getCommand()->create(
 +					$connection, $this->getStatement(), $parameter);
 +	}
 +}
 +
 +?>
\ No newline at end of file  | 
