Skip to content
Permalink
Browse files

Removing ORM specific code out of QueryTrait

  • Loading branch information...
lorenzo committed Feb 20, 2014
1 parent 06d6343 commit f2cd735b24c4ed4a1b4db64a427f30756ec70329
Showing with 38 additions and 17 deletions.
  1. +2 −2 src/Datasource/QueryCacher.php
  2. +5 −14 src/Datasource/QueryTrait.php
  3. +31 −1 src/ORM/Query.php
@@ -22,9 +22,9 @@
/**
* Handles caching queries and loading results from the cache.
*
* Used by Cake\ORM\Query internally.
* Used by Cake\Datasource\QueryTrait internally.
*
* @see Cake\ORM\Query::cache() for the public interface.
* @see Cake\Datasource\QueryTrait::cache() for the public interface.
*/
class QueryCacher {
@@ -40,7 +40,7 @@ trait QueryTrait {
*
* When set, query execution will be bypassed.
*
* @var Cake\ORM\ResultSet
* @var \Cake\Datasource\ResultSetDecorator
* @see setResult()
*/
protected $_results;
@@ -186,13 +186,9 @@ public function getResults() {
* When using a function, this query instance will be supplied as an argument.
* @param string|CacheEngine $config Either the name of the cache config to use, or
* a cache config instance.
* @return Query The query instance.
* @throws \RuntimeException When you attempt to cache a non-select query.
* @return QueryTrait This same object
*/
public function cache($key, $config = 'default') {
if ($this->_type !== 'select' && $this->_type !== null) {
throw new \RuntimeException('You cannot cache the results of non-select queries.');
}
if ($key === false) {
$this->_cache = null;
return $this;
@@ -205,20 +201,15 @@ public function cache($key, $config = 'default') {
* Fetch the results for this query.
*
* Compiles the SQL representation of this query and executes it using the
* provided connection object. Returns a ResultSet iterator object.
* provided connection object. Returns a ResultSetDecorator iterator object.
*
* ResultSet is a travesable object that implements the methods found
* ResultSetDecorator is a travesable object that implements the methods found
* on Cake\Collection\Collection.
*
* @return Cake\ORM\ResultCollectionTrait
* @return Cake\ORM\ResultSetDecorator
* @throws RuntimeException if this method is called on a non-select Query.
*/
public function all() {
if ($this->_type !== 'select' && $this->_type !== null) {
throw new \RuntimeException(
'You cannot call all() on a non-select query. Use execute() instead.'
);
}
return $this->getResults();
}
@@ -28,7 +28,10 @@
*/
class Query extends DatabaseQuery {
use QueryTrait;
use QueryTrait {
cache as private _cache;
all as private _all;
}
/**
* Indicates that the operation should append to the list
@@ -553,6 +556,33 @@ public function hydrate($enable = null) {
return $this;
}
/**
* {@inheritdoc}
*
* @return Query The query instance.
* @throws \RuntimeException When you attempt to cache a non-select query.
*/
public function cache($key, $config = 'default') {
if ($this->_type !== 'select' && $this->_type !== null) {
throw new \RuntimeException('You cannot cache the results of non-select queries.');
}
return $this->_cache($key, $config);
}
/**
* {@inheritdoc}
*
* @throws RuntimeException if this method is called on a non-select Query.
*/
public function all() {
if ($this->_type !== 'select' && $this->_type !== null) {
throw new \RuntimeException(
'You cannot call all() on a non-select query. Use execute() instead.'
);
}
return $this->_all();
}
/**
* Auxiliary function used to wrap the original statement from the driver with
* any registered callbacks. This will also setup the correct statement class

0 comments on commit f2cd735

Please sign in to comment.
You can’t perform that action at this time.