diff --git a/library/Icinga/Data/DataArray/ArrayDatasource.php b/library/Icinga/Data/DataArray/ArrayDatasource.php index 11f8e59e8..ef5b4e3ed 100644 --- a/library/Icinga/Data/DataArray/ArrayDatasource.php +++ b/library/Icinga/Data/DataArray/ArrayDatasource.php @@ -3,6 +3,7 @@ namespace Icinga\Data\DataArray; +use ArrayIterator; use Icinga\Data\Selectable; use Icinga\Data\SimpleQuery; @@ -82,6 +83,18 @@ class ArrayDatasource implements Selectable return new SimpleQuery($this); } + /** + * Fetch and return all rows of the given query's result set using an iterator + * + * @param SimpleQuery $query + * + * @return ArrayIterator + */ + public function query(SimpleQuery $query) + { + return new ArrayIterator($this->fetchAll($query)); + } + /** * Fetch and return a column of all rows of the result set as an array * diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index ebe6e5743..f6398831d 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -4,6 +4,7 @@ namespace Icinga\Data\Db; use PDO; +use Iterator; use Zend_Db; use Icinga\Application\Benchmark; use Icinga\Data\ConfigObject; @@ -87,6 +88,18 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible return new DbQuery($this); } + /** + * Fetch and return all rows of the given query's result set using an iterator + * + * @param DbQuery $query + * + * @return Iterator + */ + public function query(DbQuery $query) + { + return $query->getSelectQuery()->query(); + } + /** * Getter for database type * diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 8da712598..c2dd5c1d9 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -3,7 +3,6 @@ namespace Icinga\Data; -use ArrayIterator; use IteratorAggregate; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; @@ -103,11 +102,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->ds->query($this); } /** diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index 9296c5f88..2f7cccd41 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -3,6 +3,7 @@ namespace Icinga\Protocol\Ldap; +use ArrayIterator; use Icinga\Application\Config; use Icinga\Application\Logger; use Icinga\Application\Platform; @@ -133,6 +134,11 @@ class Connection implements Selectable return new Query($this); } + public function query(Query $query) + { + return new ArrayIterator($this->fetchAll($query)); + } + public function fetchOne($query, $fields = array()) { $row = (array) $this->fetchRow($query, $fields); diff --git a/library/Icinga/Repository/RepositoryQuery.php b/library/Icinga/Repository/RepositoryQuery.php index 2186573f0..220e85632 100644 --- a/library/Icinga/Repository/RepositoryQuery.php +++ b/library/Icinga/Repository/RepositoryQuery.php @@ -372,16 +372,6 @@ class RepositoryQuery implements QueryInterface, Iterator return $this->query->getOffset(); } - /** - * Fetch and return all rows of the result set using an iterator - * - * @return Iterator - */ - public function fetch() - { - return $this; - } - /** * Fetch and return the first column of this query's first row * @@ -533,7 +523,7 @@ class RepositoryQuery implements QueryInterface, Iterator $this->order(); } - $iterator = $this->query->fetch(); + $iterator = $this->repository->getDataSource()->query($this->query); if ($iterator instanceof IteratorAggregate) { $this->iterator = $iterator->getIterator(); } else { diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php index 6bed36fe1..442e1e7c2 100644 --- a/modules/monitoring/library/Monitoring/DataView/DataView.php +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -3,7 +3,6 @@ namespace Icinga\Module\Monitoring\DataView; -use ArrayIterator; use IteratorAggregate; use Icinga\Data\QueryInterface; use Icinga\Data\Filter\Filter; @@ -13,6 +12,7 @@ use Icinga\Data\ConnectionInterface; use Icinga\Exception\QueryException; use Icinga\Web\Request; use Icinga\Web\Url; +use Icinga\Module\Monitoring\Backend\Ido\Query\IdoQuery; use Icinga\Module\Monitoring\Backend\MonitoringBackend; /** @@ -23,7 +23,7 @@ abstract class DataView implements QueryInterface, IteratorAggregate /** * The query used to populate the view * - * @var QueryInterface + * @var IdoQuery */ protected $query; @@ -61,11 +61,11 @@ abstract class DataView implements QueryInterface, IteratorAggregate /** * Return a iterator for all rows of the result set * - * @return ArrayIterator + * @return IdoQuery */ public function getIterator() { - return new ArrayIterator($this->fetchAll()); + return $this->getQuery(); } /**