Fetchable: Add method fetch() which returns an iterator

This commit is contained in:
Johannes Meyer 2015-05-18 13:59:16 +02:00
parent 524c449649
commit 7a6837de0e
3 changed files with 35 additions and 5 deletions

View File

@ -3,11 +3,20 @@
namespace Icinga\Data; namespace Icinga\Data;
use Iterator;
/** /**
* Interface for retrieving data * Interface for retrieving data
*/ */
interface Fetchable 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 * Retrieve an array containing all rows of the result set
* *

View File

@ -4,6 +4,7 @@
namespace Icinga\Data; namespace Icinga\Data;
use ArrayIterator; use ArrayIterator;
use Iterator;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
@ -103,11 +104,11 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
/** /**
* Return a iterable for this query's result * Return a iterable for this query's result
* *
* @return ArrayIterator * @return Iterator
*/ */
public function getIterator() public function getIterator()
{ {
return new ArrayIterator($this->fetchAll()); return $this->fetch();
} }
/** /**
@ -351,6 +352,16 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
return $this->limitOffset; 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 * Retrieve an array containing all rows of the result set
* *

View File

@ -3,7 +3,7 @@
namespace Icinga\Module\Monitoring\DataView; namespace Icinga\Module\Monitoring\DataView;
use ArrayIterator; use Iterator;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Data\QueryInterface; use Icinga\Data\QueryInterface;
use Icinga\Data\Filter\Filter; 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 a iterator for all rows of the result set
* *
* @return ArrayIterator * @return Iterator
*/ */
public function getIterator() 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(); 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 * Retrieve an array containing all rows of the result set
* *