Ejemplo n.º 1
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 ($this->_em->getUnitOfWork()->hasPendingInsertions()) {
         $this->_em->flush();
     }
     if ($hydrationMode !== null) {
         $this->_hydrationMode = $hydrationMode;
     }
     $params = $this->getParams($params);
     // Check result cache
     if ($cacheDriver = $this->getResultCacheDriver()) {
         // Calculate hash for DQL query.
         $hash = md5($this->getDql() . var_export($params, true));
         $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($hash);
         if ($cached === false) {
             // Cache miss.
             $result = $this->_doExecute($params);
             $queryResult = CacheHandler::fromResultSet($this, $result);
             $cacheDriver->save($hash, $queryResult->toCachedForm(), $this->_resultCacheTTL);
             return $result;
         } else {
             // Cache hit.
             $queryResult = CacheHandler::fromCachedResult($this, $cached);
             return $queryResult->getResultSet();
         }
     }
     $stmt = $this->_doExecute($params);
     if (is_integer($stmt)) {
         return $stmt;
     }
     return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping);
 }