Ejemplo n.º 1
0
 /**
  * Perform cursor fetching.
  *
  * @param string $name Property name.
  * @param array $options Cursor ResultSet configuration options.
  * @return ResultSet
  */
 public function fetchCursor($name, $options = [])
 {
     $options += ['entityClass' => 'Cake\\ORM\\Entity'];
     if ($this->isNew()) {
         throw new InvalidArgumentException('Cannot fetch cursor on not executed request');
     }
     $parameter = $this->_repository->schema()->parameter($name);
     if (empty($parameter)) {
         throw new InvalidArgumentException('Cannot fetch cursor for not declared parameter');
     }
     if ($parameter['type'] !== 'cursor') {
         throw new InvalidArgumentException('Cannot fetch cursor for parameter that have wrong type');
     }
     $property = $this->get($name);
     $statement = $this->_repository->connection()->prepareMethod($property);
     $statement->queryString = __('fetch {0} cursor', $name);
     $statement->execute();
     return new ResultSet($this->_repository, $statement, $options);
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param Method $repository Method object instance.
  * @param \Cake\Database\StatementInterface $statement The statement to fetch from
  * @param array $options Additional resultset options that setup result entity.
  * @internal param \Cake\ORM\Query $query Query from where results come
  */
 public function __construct($repository, $statement, $options = [])
 {
     $options += ['entityClass' => 'Cake\\ORM\\Entity', 'hydrate' => true, 'useBuffering' => false, 'schema' => []];
     $this->_statement = $statement;
     $this->_driver = $repository->connection()->driver();
     $this->_hydrate = $options['hydrate'];
     $this->_entityClass = $options['entityClass'];
     $this->_useBuffering = $options['useBuffering'];
     $this->_schema = $options['schema'];
     $this->_types = $this->_getTypes(array_keys($this->_schema));
     if ($this->_useBuffering) {
         $count = $this->count();
         $this->_results = new SplFixedArray($count);
     }
 }