Synchronize vertexes and edges with related OrientDb database

@param string $connectionName
19733
public function synchronize($connectionName)
    {
        $configuration = $this->getConfiguration($connectionName);
        $database = $this->getDatabase($connectionName);

        foreach ($configuration->getVertexes() as $vertex) {
            try {
                $database->query(sprintf('CREATE CLASS %s EXTENDS V',
                    $vertex->getName()
                ));
                $database->query(sprintf('DISPLAY RECORD 0',
                    $vertex->getName()
                ));
                dump($res); die;
            } catch (\Exception $e) {
                if (preg_match(sprintf('/Class %s already exists in current database$/', $vertex->getName()), $e->getMessage())) {
                    continue;
                }

                throw $e;
            }
        }
    }
1345120
public function init(ConnectionInterface $conn = null, $runlevel = ApplicationServerInterface::FULL)
    {

        // switch to the new runlevel
        $this->synchronized(function ($self, $newRunlevel) {
            // wait till the previous commands has been finished
            while ($self->locked === true) {
                sleep(1);
            }

            // set the command name
            $self->command = InitCommand::COMMAND;

            // lock process
            $self->locked = true;
            $self->params = $newRunlevel;

            // notify the AS to execute the command
            $self->notify();

        }, $this, $runlevel);
    }
89844
public static function getConnection($connectionName = '')
    {
        if (!$connectionName) {
            $connectionName = static::$defaultConnection;
        }
        if (isset(static::$connections[$connectionName])) {
            return static::$connections[$connectionName];
        }
    }
649894
private function _getJunctionTableColumns($relationName, $model)
    {
        $junctionTableColumns = [];
        if (array_key_exists($relationName, $this->_relationsExtraColumns)) {
            if (is_callable($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName]($model);
            } elseif (is_array($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName];
            }
            if (!is_array($junctionTableColumns)) {
                throw new RuntimeException(
                    'Junction table columns definition must return an array, got ' . gettype($junctionTableColumns)
                );
            }
        }
        return $junctionTableColumns;
    }
87303
public function setActiveConnections($connections)
    {
        if (!is_array($connections)) {
            $connections = explode(',', $connections);
        }

        // Sanitize and set connections
        $filtered = array_filter($connections, [$this, 'isValidConnection']);
        if (!$filtered) {
            throw new ConnectionException('Invalid connection(s): '.implode(', ', $connections));
        }

        $this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connections) {
            $connectionKey = $connection->getConnectionKey();
            $handle = $connectionKey->toHandle();

            $connection->setActive(in_array($handle, $connections, true) || in_array($connectionKey->name, $connections, true));
            $connection->setCurrent(false);

            return $connection;
        });
    }
79568
protected static function initSessionStorage(string $dbName) : void
    {
        if (!isset($_SESSION['databases']) || !\is_array($_SESSION['databases'])) {
            $_SESSION['databases'] = [];
        }

        if (!isset($_SESSION['databases'][$dbName]) || !\is_array($_SESSION['databases'][$dbName])) {
            $_SESSION['databases'][$dbName] = ['tables' => []];
        }
    }
487595
public function commit()
    {
        if ($this->transactionNestingLevel === 0) {
            throw ConnectionException::noActiveTransaction();
        }
        if ($this->isRollbackOnly) {
            throw ConnectionException::commitFailedRollbackOnly();
        }

        $connection = $this->getWrappedConnection();

        $logger = $this->_config->getSQLLogger();

        if ($this->transactionNestingLevel === 1) {
            if ($logger) {
                $logger->startQuery('"COMMIT"');
            }

            $connection->commit();

            if ($logger) {
                $logger->stopQuery();
            }
        } elseif ($this->nestTransactionsWithSavepoints) {
            if ($logger) {
                $logger->startQuery('"RELEASE SAVEPOINT"');
            }
            $this->releaseSavepoint($this->_getNestedTransactionSavePointName());
            if ($logger) {
                $logger->stopQuery();
            }
        }

        --$this->transactionNestingLevel;

        if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) {
            return true;
        }

        $this->beginTransaction();

        return true;
    }
462049
public function getTableColumns($tableName = null, $connectionName = null)
    {
        $tableName = $this->validateTableName($tableName);

        return $this->getSchema($connectionName)->listTableColumns($tableName);
    }
772770
function (connectionName, callback) {
        var self = this,
            _db = Transaction.databases[connectionName],
            transactionId;

        // validate db setup prior to every connection. this ensures nothing goes forward post teardown
        if (!_db) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_SETUP));
        }

        // validate connection name
        if (!connectionName) {
            callback(new AdapterError(AdapterError.TRANSACTION_NOT_IDENTIFIED));
        }

        // if this transaction is already connected, then continue
        if (self.connection()) {
            // @todo implement error check when multi-db conn is attempted
            // // callback with error if connection name and current connection mismatch
            // if (connectionName !== self.connection().identity) {
            //     callback(new AdapterError(AdapterError.TRANSACTION_MULTI_DB_CONNECTION_ATTEMPTED));
            // }
            callback(undefined, self.connection());
            return;
        }

        // at this point, it seems like the connection has not been setup yet, so we setup one and then move forward
        transactionId = self.id(); // this will return and cache a new transaction ID if not already present

        // set the actual connection name
        self._connectionName = connectionName;

        _db.getConnection(function (error, conn) {
            if (!error) {
                self._connection = conn; // save reference
                Transaction.associateConnection(conn, transactionId, _db.transactionConfig); // @note disassociate on dc
            }

            callback(error, self._connection);
        });
    }
1161492
public static function build(string $connectionName = null) : Connection
    {
        $configs = Application::current()->config('database');
        $connectionName = $connectionName ?: $configs['default'];

        if (!isset($configs[$connectionName])) {
            throw new \Exception("Unknown database connection: '$connectionName'");
        }

        if (!isset(self::$connections[$connectionName])) {
            $connectionClass = $configs[$connectionName]['driver'];
            $options = $configs[$connectionName]['options'];
            self::$connections[$connectionName] = new $connectionClass($options);
        }

        return self::$connections[$connectionName];
    }
65214
public static function syncSchema($database1,$database2) {
		if (!isset(RedBean_Facade::$toolboxes[$database1])) throw new RedBean_Exception_Security('No database for this key: '.$database1);
		if (!isset(RedBean_Facade::$toolboxes[$database2])) throw new RedBean_Exception_Security('No database for this key: '.$database2);
		$db1 = RedBean_Facade::$toolboxes[$database1];
		$db2 = RedBean_Facade::$toolboxes[$database2];
		$sync = new self;
		$sync->doSync($db1, $db2);
	}
1190736
public function makeRaw(string $connectionName = ''): RawQueryBuilder
    {
        $connection = $this->provideConnection($connectionName);
        $statementBuilder = new RawStatementBuider;
        return new RawQueryBuilder($connection, $statementBuilder);
    }
723840
public function getSingleAssociationReferencedJoinColumnName($fieldName)
    {
        if ( ! $this->isAssociationWithSingleJoinColumn($fieldName)) {
            throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName);
        }
        return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName'];
    }
635670
protected function filename($connectionName)
    {
        $directory = $this->argument('directory');

        if (! empty($directory) &&
            ! is_dir(storage_path($directory))
        ) {
            $dirLoop = '';
            foreach(explode('/', $directory) as $dir) {
                if (! is_dir(storage_path($dirLoop . $dir))) {
                    mkdir(storage_path($dirLoop . $dir));
                }
                $dirLoop .= $dir . DIRECTORY_SEPARATOR;
            }

        }

        $filename = str_slug($connectionName) . '-' . Carbon::now()->format('Y-m-d-H-i-s') . '.sql';

        return storage_path($directory . DIRECTORY_SEPARATOR . $filename);
    }
1137012
public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null/*, bool $lazy = false, bool $weak = false*/)
    {
        $lazy = func_num_args() >= 6 ? func_get_arg(5) : false;
        $weak = func_num_args() >= 7 ? func_get_arg(6) : false;

        if (null === $sourceId || null === $destId) {
            return;
        }

        $sourceNode = $this->createNode($sourceId, $sourceValue);
        $destNode = $this->createNode($destId, $destValue);
        $edge = new ServiceReferenceGraphEdge($sourceNode, $destNode, $reference, $lazy, $weak);

        $sourceNode->addOutEdge($edge);
        $destNode->addInEdge($edge);
    }
1025067
public static function setConnectionString( $connectionString, $userName = null, $password = null, $pdoOptions = array() )
    {
        self::setConnection( null );

        //	If you set a connection string a new connection one is created for you
        if ( !empty( $connectionString ) )
        {
            self::$_connectionString = $connectionString;

            self::$_connection = new \PDO(
                self::$_connectionString, $userName, $password, array_merge(
                    array(
                        \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                    ),
                    $pdoOptions
                )
            );
        }

        return self::$_connection;
    }
987423
final protected function loadChoicesFromQuery(string $query, string $columnName, string $connectionName = null)
    {
        $connection = $connectionName
            ? $this->connectionRegistry->getHttpConnection($connectionName)
            : $this->connectionRegistry->getDefaultHttpConnection()
        ;
        $measurements = array_map(function ($point) use ($columnName) {
            return $point[$columnName];
        }, $connection->query($query)->getPoints());

        return array_combine(array_values($measurements), $measurements);
    }