/**
  * Executes the query.
  *
  * @param string $params Any additional query parameters.
  * @param integer $hydrationMode Processing mode to be used during the hydration process.
  * @return mixed
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     // If there are still pending insertions in the UnitOfWork we need to flush
     // in order to guarantee a correct result.
     //TODO: Think this over. Its tricky. Not doing this can lead to strange results
     //      potentially, but doing it could result in endless loops when querying during
     //      a flush, i.e. inside an event listener.
     if ($this->_em->getUnitOfWork()->hasPendingInsertions()) {
         $this->_em->flush();
     }
     if ($hydrationMode !== null) {
         $this->setHydrationMode($hydrationMode);
     }
     if ($params) {
         $this->setParameters($params);
     }
     if (isset($this->_params[0])) {
         throw QueryException::invalidParameterPosition(0);
     }
     // Check result cache
     if ($this->_useResultCache && ($cacheDriver = $this->getResultCacheDriver())) {
         $id = $this->_getResultCacheId();
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
         if ($cached === false) {
             // Cache miss.
             $stmt = $this->_doExecute();
             $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
             $cacheDriver->save($id, $result, $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             return $cached;
         }
     }
     $stmt = $this->_doExecute();
     if (is_numeric($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
 }
示例#2
0
 /**
  * Executes the query.
  *
  * @param string $params Any additional query parameters.
  * @param integer $hydrationMode Processing mode to be used during the hydration process.
  * @return mixed
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     // If there are still pending insertions in the UnitOfWork we need to flush
     // in order to guarantee a correct result.
     if ($this->_em->getUnitOfWork()->hasPendingInsertions()) {
         $this->_em->flush();
     }
     if ($hydrationMode !== null) {
         $this->_hydrationMode = $hydrationMode;
     }
     $params = $this->getParameters($params);
     if (isset($params[0])) {
         throw QueryException::invalidParameterPosition(0);
     }
     // Check result cache
     if ($this->_useResultCache && ($cacheDriver = $this->getResultCacheDriver())) {
         $id = $this->getResultCacheId($params);
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
         if ($cached === false) {
             // Cache miss.
             $stmt = $this->_doExecute($params);
             $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
             $cacheDriver->save($id, $result, $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             return $cached;
         }
     }
     $stmt = $this->_doExecute($params);
     if (is_numeric($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
 }
示例#3
0
 /**
  * Executes the query.
  *
  * @param array $params Any additional query parameters.
  * @param integer $hydrationMode Processing mode to be used during the hydration process.
  * @return mixed
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     if ($hydrationMode !== null) {
         $this->setHydrationMode($hydrationMode);
     }
     if ($params) {
         $this->setParameters($params);
     }
     if (isset($this->_params[0])) {
         throw QueryException::invalidParameterPosition(0);
     }
     // Check result cache
     if ($this->_useResultCache && ($cacheDriver = $this->getResultCacheDriver())) {
         list($key, $hash) = $this->getResultCacheId();
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($hash);
         if ($cached === false || !isset($cached[$key])) {
             // Cache miss.
             $stmt = $this->_doExecute();
             $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
             $cacheDriver->save($hash, array($key => $result), $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             return $cached[$key];
         }
     }
     $stmt = $this->_doExecute();
     if (is_numeric($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
 }