コード例 #1
0
ファイル: Manager.php プロジェクト: Reinmar/Orient
    /**
     * Executes a query against OrientDB, via the protocolAdapter, specifying
     * a $fetchPlan (which is optional) and a $rid to look for.
     * Then, it finalizes the hydration result.
     *
     * @param   type        $rid
     * @param   mixed       $fetchPlan
     * @return  object|null 
     */
    protected function doFind($rid, $fetchPlan = null)
    {
        $query      = new Query(array($rid));
        $adapter    = $this->getProtocolAdapter();
        $execution  = $adapter->execute($query->getRaw(), true, $fetchPlan);

        if ($execution && $result = $adapter->getResult()) {
          $record       = is_array($result) ? array_shift($result) : $result;
          $result       = $this->getMapper()->hydrate($record);

          return $this->finalize($result);
        }

        return null;
    }
コード例 #2
0
ファイル: Repository.php プロジェクト: Reinmar/Orient
    /**
     * Finds objects by a set of criteria.
     *
     * Optionally sorting and limiting details can be passed. An implementation may throw
     * an UnexpectedValueException if certain values of the sorting or limiting details are
     * not supported.
     *
     * @param array $criteria
     * @param array|null $orderBy
     * @param int|null $limit
     * @param int|null $offset
     * @return mixed The objects.
     */
    public function findBy(array $criteria, array $orderBy = array(), $limit = null, $offset = null)
    {
        $results = array();
        
        foreach ($this->getOrientClasses() as $mappedClass) {
            $query      = new Query(array($mappedClass));
            
            foreach ($criteria as $key => $value) {
                $query->where("$key = ?", $value);
            }
            
            foreach ($orderBy as $key => $order) {
                $query->orderBy("$key $order");
            }
            
            if ($limit) {
                $query->limit($limit);
            }

            $collection = $this->getManager()->execute($query);

            if (!is_array($collection)) {
                $message = <<<EOT
Problems executing the query "{$query->getRaw()}".
The server returned $collection, while it should be an Array.
EOT;
              
                throw new Exception($message);
            }
            
            $results = array_merge($results, $collection);
        }

        return $results;
    }
コード例 #3
0
ファイル: ManagerTest.php プロジェクト: Reinmar/Orient
 /**
  * @expectedException \Congow\Orient\Exception\Query\SQL\Invalid
  */
 public function testAnExceptionGetsRaisedWhenExecutingAWrongQuery()
 {
     $query      = new Query(array('Address'));
     $query->update('Address')->set(array())->where('@rid = ?', '1:10000');
     $result  = $this->manager->execute($query);
 }