Browse Source

Moving bufferResults from the ORM to Database Query

Jose Lorenzo Rodriguez 11 years ago
parent
commit
6ce5609874
2 changed files with 35 additions and 35 deletions
  1. 35 0
      src/Database/Query.php
  2. 0 35
      src/ORM/Query.php

+ 35 - 0
src/Database/Query.php

@@ -114,6 +114,14 @@ class Query implements ExpressionInterface, IteratorAggregate
     protected $_functionsBuilder;
 
     /**
+     * Boolean for tracking whether or not buffered results
+     * are enabled.
+     *
+     * @var bool
+     */
+    protected $_useBufferedResults = true;
+
+    /**
      * Constructor.
      *
      * @param \Cake\Database\Connection $connection The connection
@@ -1582,6 +1590,33 @@ class Query implements ExpressionInterface, IteratorAggregate
     }
 
     /**
+     * Enable/Disable buffered results.
+     *
+     * When enabled the results returned by this Query will be
+     * buffered. This enables you to iterate a result set multiple times, or
+     * both cache and iterate it.
+     *
+     * When disabled it will consume less memory as fetched results are not
+     * remembered for future iterations.
+     *
+     * If called with no arguments, it will return whether or not buffering is
+     * enabled.
+     *
+     * @param bool $enable whether or not to enable buffering
+     * @return bool|$this
+     */
+    public function bufferResults($enable = null)
+    {
+        if ($enable === null) {
+            return $this->_useBufferedResults;
+        }
+
+        $this->_dirty();
+        $this->_useBufferedResults = (bool)$enable;
+        return $this;
+    }
+
+    /**
      * Auxiliary function used to wrap the original statement from the driver with
      * any registered callbacks.
      *

+ 0 - 35
src/ORM/Query.php

@@ -77,14 +77,6 @@ class Query extends DatabaseQuery implements JsonSerializable
     protected $_autoFields;
 
     /**
-     * Boolean for tracking whether or not buffered results
-     * are enabled.
-     *
-     * @var bool
-     */
-    protected $_useBufferedResults = true;
-
-    /**
      * Whether to hydrate results into entity objects
      *
      * @var bool
@@ -344,33 +336,6 @@ class Query extends DatabaseQuery implements JsonSerializable
     }
 
     /**
-     * Enable/Disable buffered results.
-     *
-     * When enabled the ResultSet returned by this Query will be
-     * buffered. This enables you to iterate a ResultSet multiple times, or
-     * both cache and iterate the ResultSet.
-     *
-     * When disabled it will consume less memory as fetched results are not
-     * remembered in the ResultSet.
-     *
-     * If called with no arguments, it will return whether or not buffering is
-     * enabled.
-     *
-     * @param bool $enable whether or not to enable buffering
-     * @return bool|$this
-     */
-    public function bufferResults($enable = null)
-    {
-        if ($enable === null) {
-            return $this->_useBufferedResults;
-        }
-
-        $this->_dirty();
-        $this->_useBufferedResults = (bool)$enable;
-        return $this;
-    }
-
-    /**
      * Returns a key => value array representing a single aliased field
      * that can be passed directly to the select() method.
      * The key will contain the alias and the value the actual field name.