Ejemplo n.º 1
0
 /**
  * @covers Paradox\Toolbox::normaliseDriverExceptions
  */
 public function testNormaliseDriverExceptionsWithNormalExceptions()
 {
     $exception = new \Exception("some error message", 123456);
     $result = $this->toolbox->normaliseDriverExceptions($exception);
     $this->assertEquals(123456, $result['code']);
     $this->assertEquals("some error message", $result['message']);
 }
Ejemplo n.º 2
0
 /**
  * Converts the an array of associative arrays (each representing a document) received from the server into pods.
  * @param  string $type   The collection type. For graphs, only "vertex" or "edge" is valid.
  * @param  array  $result The array of documents to convert.
  * @return array
  */
 public function convertToPods($type, $result)
 {
     $converted = $this->_toolbox->getPodManager()->convertToPods($type, $result);
     foreach ($converted as $model) {
         $model->getPod()->setSaved();
     }
     return $converted;
 }
Ejemplo n.º 3
0
 /**
  * Get the unix timestamp of the server with microsecond precision
  * @throws ServerException
  * @return float
  */
 public function getTime()
 {
     try {
         return $this->_toolbox->getAdminHandler()->getServerTime();
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new ServerException($normalised['message'], $normalised['code']);
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the fields that are used to store geo coordinates for the first index for this collection.
  * @param  string          $collection The name of the collection
  * @throws FinderException
  * @return array|null
  */
 public function getGeoFieldsForAQL($collection)
 {
     $indices = $this->_toolbox->getCollectionManager()->listIndices($collection, true);
     foreach ($indices as $index => $info) {
         //If this is the first geo index we encounter
         if ($info['type'] == "geo1" || $info['type'] == "geo2") {
             return $info['fields'];
         }
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * Returns the execution plan for a query. This will not execute the query.
  * @param  string         $query      The AQL query to run.
  * @param  array          $parameters An optional associative array containing parameters to bind to the query.
  * @throws QueryException
  * @return array
  */
 public function explain($query, array $parameters = array())
 {
     $data = array('query' => $query, 'bindVars' => $parameters);
     $statement = new Statement($this->_toolbox->getConnection(), $data);
     try {
         $result = $statement->explain();
         return $result['plan'];
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new QueryException($normalised['message'], $normalised['code']);
     }
 }
Ejemplo n.º 6
0
 /**
  * Determines the collection name to use. For graphs, it converts "vertex" and "edge" into the appropriate collection names on the server.
  * @param  string          $type The collection name.
  * @throws FinderException
  * @return string
  */
 private function getCollectionName($type)
 {
     if ($this->_toolbox->isGraph()) {
         if (!$this->_toolbox->getPodManager()->validateType($type)) {
             throw new FinderException("When finding documents in graphs, only the types 'vertex' and 'edge' are allowed.");
         }
         //Is a vertex
         if (strtolower($type) == "vertex") {
             return $this->_toolbox->getVertexCollectionName();
             //Is an edge
         } else {
             return $this->_toolbox->getEdgeCollectionName();
         }
     } else {
         return $type;
     }
 }
Ejemplo n.º 7
0
 /**
  * Given the id in ArangoDB format (mycollection/123456) parse it and return the key (123456).
  * @param  string $id
  * @return string
  */
 protected function parseIdForKey($id)
 {
     return $this->_toolbox->parseIdForKey($id);
 }
Ejemplo n.º 8
0
 /**
  * Get a cloned connection with targetting a database.
  * @param  string                        $database The optional name of the database. Defaults to _system.
  * @return \triagens\ArangoDb\Connection
  */
 private function getConnection($database = '_system')
 {
     $connection = clone $this->_toolbox->getConnection();
     $connection->setDatabase($database);
     return $connection;
 }
Ejemplo n.º 9
0
 /**
  * Processes the transaction result after committing.
  * @param  array                       $results The results array from the server.
  * @throws TransactionManagerException
  * @return array
  */
 private function processResult($results)
 {
     $processedResults = array();
     foreach ($results as $id => $result) {
         $command = $this->_commands[$id];
         switch ($command['action']) {
             case "PodManager:store":
                 $processed = $this->_toolbox->getPodManager()->processStoreResult($command['object']->getPod(), $result['_rev'], $result['_id']);
                 break;
             case "PodManager:delete":
                 $this->_toolbox->getPodManager()->processDeleteResult($command['object']->getPod());
                 $processed = true;
                 break;
             case "PodManager:load":
                 $parsedId = $this->_toolbox->parseId($result['_id']);
                 if (!$result) {
                     $processed = null;
                     break;
                 }
                 $processed = $this->_toolbox->getPodManager()->convertArrayToPod($command['data']['type'], $result);
                 break;
             case "Query:getOne":
             case "Query:getAll":
                 $processed = $result;
                 break;
             case "Finder:find":
             case "Finder:findAll":
             case "Finder:findNear":
             case "Finder:findAllNear":
             case "Finder:findWithin":
             case "Finder:findAllWithin":
             case "Finder:search":
             case "Finder:searchAll":
                 if (isset($command['data']['coordinates'])) {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], $result, $command['data']['coordinates']);
                 } else {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], $result);
                 }
                 break;
             case "Finder:findOne":
             case "Finder:any":
             case "Finder:findOneNear":
             case "Finder:findOneWithin":
             case "Finder:searchForOne":
                 if ($result == null) {
                     $processed = null;
                     break;
                 }
                 if (isset($command['data']['coordinates'])) {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], array($result), $command['data']['coordinates']);
                 } else {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], array($result));
                 }
                 $processed = reset($processed);
                 break;
             case "GraphManager:getInboundEdges":
             case "GraphManager:getOutboundEdges":
             case "GraphManager:getEdges":
                 $processed = $this->_toolbox->getGraphManager()->convertToPods("edge", $result);
                 break;
             case "GraphManager:getNeighbours":
                 $processed = $this->_toolbox->getGraphManager()->convertToPods("vertex", $result);
                 break;
             default:
                 throw new TransactionManagerException("Invalid or unimplemented action ({$command['action']}) while processing the transaction results.");
         }
         if (array_key_exists($id, $this->_registeredResults)) {
             $processedResults[$this->_registeredResults[$id]] = $processed;
         }
     }
     return $processedResults;
 }