示例#1
0
 /**
  * Delete a graph.
  * @param  string                $name The name of the graph.
  * @throws GraphManagerException
  */
 public function deleteGraph($name)
 {
     try {
         $graphHandler = $this->_toolbox->getGraphHandler();
         return $graphHandler->dropGraph($name);
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new GraphManagerException($normalised['message'], $normalised['code']);
     }
 }
示例#2
0
文件: Finder.php 项目: f21/paradox
 /**
  * Search for one document/vertex/edge using a full-text search on an attribute of the documents with filtering. If no results are found, null is returned.
  * A LIMIT 1 is automatically set, so you do not need to set the LIMIT yourself: doc.name = "john"
  * @param  string      $type        The collection to search in. For graphs, only "vertex" and "edge" are allowed.
  * @param  string      $attribute   The attribute to search on.
  * @param  string      $query       The full-text query.
  * @param  string      $aql         An AQL fragment that will be inserted after the FILTER keyword.
  * @param  array       $params      An optional associative array containing parameters to bind to the query.
  * @param  string      $placeholder Set this to something else if you do not wish to use "doc" to refer to documents in your query.
  * @return null|AModel
  */
 public function searchForOne($type, $attribute, $query, $aql, $params = array(), $placeholder = "doc")
 {
     $collectionParameter = $this->_toolbox->generateBindingParameter('@collection', $params);
     $attributeParameter = $this->_toolbox->generateBindingParameter('attribute', $params);
     $queryParameter = $this->_toolbox->generateBindingParameter('query', $params);
     $aqlStatement = "FOR {$placeholder} in FULLTEXT(@{$collectionParameter}, @{$attributeParameter}, @{$queryParameter}) FILTER " . $aql . " LIMIT 1 return {$placeholder}";
     $params[$collectionParameter] = $this->getCollectionName($type);
     $params[$attributeParameter] = $attribute;
     $params[$queryParameter] = $query;
     if ($this->_toolbox->getTransactionManager()->hasTransaction()) {
         $this->_toolbox->getTransactionManager()->addReadCollection($type);
         $statement = json_encode(array('query' => $aqlStatement, 'bindVars' => $params), JSON_FORCE_OBJECT);
         $this->_toolbox->getTransactionManager()->addCommand("function () {var elements = db._createStatement({$statement}).execute().elements(); return elements[0] ? elements[0] : null}();", "Finder:searchForOne", null, false, array('type' => $type));
     } else {
         try {
             $result = $this->_toolbox->getQuery()->getOne($aqlStatement, $params);
         } catch (\Exception $e) {
             $normalised = $this->_toolbox->normaliseDriverExceptions($e);
             throw new FinderException($normalised['message'], $normalised['code']);
         }
         if (!$result) {
             return null;
         } else {
             $converted = $this->convertToPods($type, array($result));
             return reset($converted);
         }
     }
 }
示例#3
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']);
 }
示例#4
0
文件: Server.php 项目: f21/paradox
 /**
  * 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']);
     }
 }
示例#5
0
文件: Query.php 项目: f21/paradox
 /**
  * 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']);
     }
 }
示例#6
0
 /**
  * Lists all databases availiable.
  * @throws DatabaseManagerException
  * @return array
  */
 public function listDatabases()
 {
     try {
         $connection = $this->getConnection();
         $result = Database::listDatabases($connection);
         if (empty($result['result'])) {
             return array();
         } else {
             return $result['result'];
         }
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new DatabaseManagerException($normalised['message'], $normalised['code']);
     }
 }
示例#7
0
 /**
  * List the indices on a collection.
  * @param  string                     $collection  The name of the collection.
  * @param  boolean                    $includeInfo Whether we want information on each index. If false, only an array of index ids will be returned.
  * @throws CollectionManagerException
  * @return array
  */
 public function listIndices($collection, $includeInfo = false)
 {
     if (isset($this->_indexInfoCache[$collection])) {
         return $this->_indexInfoCache[$collection];
     }
     try {
         $result = $this->_toolbox->getCollectionHandler()->getIndexes($collection);
         $this->_indexInfoCache[$collection] = $result['identifiers'];
         if ($includeInfo) {
             return $this->_indexInfoCache[$collection];
         } else {
             return array_keys($this->_indexInfoCache[$collection]);
         }
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new CollectionManagerException($normalised['message'], $normalised['code']);
     }
 }
示例#8
0
 /**
  * Send a raw transaction to the server and return the result.
  * @param  string                      $action           The javascript function for the transaction.
  * @param  array                       $readCollections  An array of collections to be locked for reading.
  * @param  array                       $writeCollections An array of collections to be locked for writing.
  * @param  array                       $parameters       An array of parameters for executing the transaction multiple times.
  * @throws TransactionManagerException
  * @return mixed
  */
 public function executeTransaction($action, $readCollections = array(), $writeCollections = array(), $parameters = array())
 {
     $transaction = $this->_toolbox->getTransactionObject();
     $transaction->setAction($action);
     $transaction->setReadCollections($readCollections);
     $transaction->setWriteCollections($writeCollections);
     if (!empty($parameters)) {
         $transaction->setParams($parameters);
     }
     //Send
     try {
         $result = $transaction->execute();
         return $result;
     } catch (\Exception $e) {
         $normalised = $this->_toolbox->normaliseDriverExceptions($e);
         throw new TransactionManagerException($normalised['message'], $normalised['code']);
     }
 }