Example #1
0
 /**
  * getNativeQuery 
  * 
  * @param Query $query 
  * @access public
  * @return void
  */
 public function getNativeQuery(Query $query, array $options = array())
 {
     // Clone the original SimpleExpression
     $statement = clone $query->getStatement();
     // Apply CustomVisitors to modify SimpleExpression
     $customVisitors = $this->getCustomVisitors();
     if ($customVisitors) {
         $statement->dispatch($customVisitors);
     }
     // Apply OuterVisitor to output the nativeQuery from SimpleExpression
     $outerVisitor = $this->getOuterVisitor();
     $statement->dispatch($outerVisitor);
     // Get NativeQuery from the Visitor
     return $outerVisitor->getNativeQuery($options);
 }
Example #2
0
 public function testExecute()
 {
     $statement = new Statement();
     $persister = new TestPersister(new TestVisitor('test'));
     $persister->results = 'results';
     $query = new Query($statement, $persister);
     $results = $query->execute();
     $this->assertEquals('results', $results);
     $query = new Query($statement);
     try {
         $query->execute();
         $this->fail('Expect exception is occured.');
     } catch (\RuntimeException $ex) {
         $this->assertTrue(true);
     }
 }
Example #3
0
 /**
  * findByQuery 
  * 
  * @param Query $query 
  * @access public
  * @return void
  */
 public function findByQuery($query)
 {
     if ($query instanceof Query) {
         $query->setPersister($this->getPersister());
         return $query->getNativeQUERY->getResult();
     } else {
         if (is_string($query)) {
             // parse the query string
             $queryParser = $this->getInterfaceQueryParser();
             if ($queryParser) {
                 return $queryParser->parse($query)->getNativeQuery()->getResult();
             }
         }
     }
     throw new \InvalidArgumentException('Unsupported query is given.');
 }