From 7a6837de0e331e19d09a22a8565ab0ea2e11a0cf Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 18 May 2015 13:59:16 +0200 Subject: [PATCH] Fetchable: Add method fetch() which returns an iterator --- library/Icinga/Data/Fetchable.php | 9 +++++++++ library/Icinga/Data/SimpleQuery.php | 15 +++++++++++++-- .../library/Monitoring/DataView/DataView.php | 16 +++++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Data/Fetchable.php b/library/Icinga/Data/Fetchable.php index 0992be933..2164bb1b2 100644 --- a/library/Icinga/Data/Fetchable.php +++ b/library/Icinga/Data/Fetchable.php @@ -3,11 +3,20 @@ namespace Icinga\Data; +use Iterator; + /** * Interface for retrieving data */ interface Fetchable { + /** + * Fetch and return all rows of the result set using an iterator + * + * @return Iterator + */ + public function fetch(); + /** * Retrieve an array containing all rows of the result set * diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 8da712598..ebcaa61a2 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -4,6 +4,7 @@ namespace Icinga\Data; use ArrayIterator; +use Iterator; use IteratorAggregate; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; @@ -103,11 +104,11 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate /** * Return a iterable for this query's result * - * @return ArrayIterator + * @return Iterator */ public function getIterator() { - return new ArrayIterator($this->fetchAll()); + return $this->fetch(); } /** @@ -351,6 +352,16 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate return $this->limitOffset; } + /** + * Fetch and return all rows of the result set using an iterator + * + * @return ArrayIterator + */ + public function fetch() + { + return new ArrayIterator($this->fetchAll()); + } + /** * Retrieve an array containing all rows of the result set * diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php index 6bed36fe1..dfbdd8a14 100644 --- a/modules/monitoring/library/Monitoring/DataView/DataView.php +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -3,7 +3,7 @@ namespace Icinga\Module\Monitoring\DataView; -use ArrayIterator; +use Iterator; use IteratorAggregate; use Icinga\Data\QueryInterface; use Icinga\Data\Filter\Filter; @@ -61,11 +61,11 @@ abstract class DataView implements QueryInterface, IteratorAggregate /** * Return a iterator for all rows of the result set * - * @return ArrayIterator + * @return Iterator */ public function getIterator() { - return new ArrayIterator($this->fetchAll()); + return $this->fetch(); } /** @@ -469,6 +469,16 @@ abstract class DataView implements QueryInterface, IteratorAggregate return $this->query->hasOffset(); } + /** + * Fetch and return all rows of the result set using an iterator + * + * @return Iterator + */ + public function fetch() + { + return $this->getQuery()->fetch(); + } + /** * Retrieve an array containing all rows of the result set *