Ejemplo n.º 1
0
 public function testRefreshCacheOnUpdate()
 {
     $childrenQuery = $this->connection->createQuery()->select('*')->from('children')->setCache(true);
     $childrenResult = $childrenQuery->execute();
     $this->cache->cacheQuery($childrenQuery, $childrenResult);
     $parentsQuery = $this->connection->createQuery()->select('*')->from('parents')->setCache(true);
     $parentsResult = $parentsQuery->execute();
     $this->cache->cacheQuery($parentsQuery, $parentsResult);
     $refreshQuery = $this->connection->createQuery()->update()->table('children')->set(array('child_id' => 123456))->whereEqual('child_id', 12345);
     $this->cache->refreshCache($refreshQuery);
     $this->assertTrue(is_null($this->cache->getCachedResult($childrenQuery)));
     $this->assertSame($parentsResult, $this->cache->getCachedResult($parentsQuery));
 }
Ejemplo n.º 2
0
 /**
  * query function.
  *
  * @access public
  * @todo implement cache
  *
  * @param string $query
  * @param array  $data (default: array())
  * @param string|callable $entity (default: null)
  *
  * @return DatabaseResult
  */
 public function query($query, $data = array(), $entity = null)
 {
     if ($this->cache->isCached($query)) {
         return $this->cache->getCachedResult($query);
     } else {
         try {
             $statement = $this->database->prepare((string) $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
             $result = $statement->execute($data);
             $this->lastQuery = $statement->queryString;
             if (!$result) {
                 throw new DatabaseException(implode(': ', $statement->errorInfo()) . PHP_EOL . PHP_EOL . $query);
             }
         } catch (PDOException $e) {
             throw new DatabaseException($e->getMessage() . PHP_EOL . PHP_EOL . $query);
         }
         $databaseResult = $this->createResult($statement, $entity);
         if ($query instanceof DatabaseQuery && $databaseResult instanceof DatabaseResult) {
             $this->cache->cacheQuery($query, $databaseResult);
         }
         if ($query instanceof DatabaseQuery) {
             $this->cache->refreshCache($query);
         }
         if ($databaseResult instanceof DatabaseResult) {
             return $databaseResult;
         } else {
             if ($query instanceof DatabaseQuery && $query->getType() == DatabaseQuery::QUERY_TYPE_INSERT) {
                 return $this->insertId($query->getTable());
             } else {
                 return $databaseResult;
             }
         }
     }
 }