/**
  * listClasses returns a list of available OrientDB classes for the current database
  *
  * @return OClass[]
  */
 public function listClasses()
 {
     $res = $this->_cn->getDatabaseInfo();
     /** @var OClass[] $hasSuper */
     $hasSuper = [];
     /** @var OClass[] $classes */
     $classes = [];
     foreach ($res['classes'] as $meta) {
         $classes[$meta['name']] = $c = new OClass($meta);
         if (!empty($meta->superClass)) {
             $hasSuper[] = $c;
         }
     }
     foreach ($hasSuper as $c) {
         $c->setSuperClass($classes[$c->getSuperClassName()]);
     }
     return $classes;
 }
 /**
  * @param array $queries
  *
  * @return array
  * @throws SQLBatchException
  */
 private function executeQueries(array $queries)
 {
     $results = $this->binding->sqlBatch($queries)['result'];
     if (!is_array($results) || count($results) !== 1) {
         throw new SQLBatchException('unexpected response from server when executing batch request');
     }
     $res = [];
     foreach ($results[0] as $k => $v) {
         if ($k[0] === 'n') {
             $res[substr($k, 1)] = $v;
         }
     }
     return $res;
 }
 private function loadIndirectReferenceCollection(PersistentCollection $collection)
 {
     $rows = $collection->getData();
     if (count($rows) === 0) {
         return;
     }
     $mapping = $collection->getMapping();
     $prop = $mapping['direction'] === 'in' ? 'out' : 'in';
     $rids = [];
     $results = [];
     $edgeRids = [];
     foreach ($rows as $row) {
         if (is_string($row)) {
             // edge RID
             $edgeRids[] = $row;
             continue;
         }
         // edge is loaded, so we
         $edgeRid = $row['@rid'];
         if (is_string($row[$prop])) {
             $rids[$row[$prop]][] = $edgeRid;
         } else {
             $results[$edgeRid] = $rows[$prop];
         }
     }
     // load edges and their immediate children (*:1)
     if ($edgeRids) {
         $loaded = $this->binding->query(sprintf('SELECT FROM [%s]', implode(',', $edgeRids)), -1, '*:1');
         $results = array_merge($results, self::extractVertexes($loaded, $prop));
     }
     if ($rids) {
         $loaded = $this->binding->query(sprintf('SELECT FROM [%s]', implode(',', array_keys($rids))));
         foreach ($loaded as $row) {
             $rid = $row['@rid'];
             foreach ($rids[$rid] as $edge) {
                 $results[$edge] = $row;
             }
         }
     }
     foreach ($results as $key => $data) {
         $document = $this->uow->getOrCreateDocument($data);
         $collection->set($key, $document);
     }
 }
Example #4
0
 public function __construct(BindingInterface $binding, Cache $cache)
 {
     $this->binding = $binding;
     $this->cache = $cache;
     $this->databaseName = $binding->getDatabaseName();
 }