예제 #1
0
 /**
  * Executes a caching query.
  *
  * @param string                                 $query  The SQL query to execute.
  * @param array                                  $params The parameters to bind to the query, if any.
  * @param array                                  $types  The types the previous parameters are in.
  * @param \Doctrine\DBAL\Cache\QueryCacheProfile $qcp    The query cache profile.
  *
  * @return \Doctrine\DBAL\Driver\ResultStatement
  *
  * @throws \Doctrine\DBAL\Cache\CacheException
  */
 public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp)
 {
     $resultCache = $qcp->getResultCacheDriver() ?: $this->_config->getResultCacheImpl();
     if (!$resultCache) {
         throw CacheException::noResultDriverConfigured();
     }
     list($cacheKey, $realKey) = $qcp->generateCacheKeys($query, $params, $types);
     // fetch the row pointers entry
     if ($data = $resultCache->fetch($cacheKey)) {
         // is the real key part of this row pointers map or is the cache only pointing to other cache keys?
         if (isset($data[$realKey])) {
             $stmt = new ArrayStatement($data[$realKey]);
         } else {
             if (array_key_exists($realKey, $data)) {
                 $stmt = new ArrayStatement(array());
             }
         }
     }
     if (!isset($stmt)) {
         $stmt = new ResultCacheStatement($this->executeQuery($query, $params, $types), $resultCache, $cacheKey, $realKey, $qcp->getLifetime());
     }
     $stmt->setFetchMode($this->defaultFetchMode);
     return $stmt;
 }
예제 #2
0
 /**
  * Set a cache profile for the result cache.
  *
  * If no result cache driver is set in the QueryCacheProfile, the default
  * result cache driver is used from the configuration.
  *
  * @param \Doctrine\DBAL\Cache\QueryCacheProfile $profile
  * @return \Doctrine\ORM\AbstractQuery
  */
 public function setResultCacheProfile(QueryCacheProfile $profile = null)
 {
     if (!$profile->getResultCacheDriver()) {
         $resultCacheDriver = $this->_em->getConfiguration()->getResultCacheImpl();
         $profile = $profile->setResultCacheDriver($resultCacheDriver);
     }
     $this->_queryCacheProfile = $profile;
     return $this;
 }
예제 #3
0
 /**
  * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
  * and returns the number of affected rows.
  *
  * This method supports PDO binding types as well as DBAL mapping types.
  *
  * @param string $query  The SQL query.
  * @param array  $params The query parameters.
  * @param array  $types  The parameter types.
  *
  * @throws \Doctrine\DBAL\DBALException
  *
  * @return integer The number of affected rows.
  */
 public function executeUpdate($query, array $params = [], array $types = [])
 {
     $result = parent::executeUpdate($query, $params, $types);
     $this->_queryCacheProfile->getResultCacheDriver()->flushAll();
     return $result;
 }