@noinspection PhpUnusedPrivateMethodInspection
@param Connection              $connection
@param DatabaseSchemaInterface $schema

@throws DBALException

@return void
548082
private function createTokensView(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        $view                = $schema->getTokensView();
        $tokens              = $schema->getTokensTable();
        $intermediate        = $schema->getTokensScopesTable();
        $tokensTokenId       = $schema->getTokensIdentityColumn();
        $intermediateTokenId = $schema->getTokensScopesTokenIdentityColumn();
        $intermediateScopeId = $schema->getTokensScopesScopeIdentityColumn();
        $scopes              = $schema->getTokensViewScopesColumn();

        $sql = <<< EOT
CREATE OR REPLACE VIEW {$view} AS
    SELECT
      t.*,
      GROUP_CONCAT(DISTINCT s.{$intermediateScopeId} ORDER BY s.{$intermediateScopeId} ASC SEPARATOR ' ') AS {$scopes}
    FROM {$tokens} AS t
      LEFT JOIN {$intermediate} AS s ON t.{$tokensTokenId} = s.{$intermediateTokenId}
    GROUP BY t.{$tokensTokenId};
EOT;
        $connection->exec($sql);
    }
40916
protected function checkSlave(Connection $connection)
    {
        $paused = 0;

        while (($lag = $this->getLag($connection)) > $this->options['max_lag']) {
            $this->paused = true;
            $for = $this->options['pause_lag'];

            $this->logger->notice('Chunk detected lag of {lag} on {database}, pausing for {for}', [
                'lag'      => $lag,
                'database' => sprintf('%s/%s', $connection->getHost(), $connection->getDatabase()),
                'for'      => $for
            ]);

            usleep($for);
            $paused += $for;

            if ($paused > $this->options['max_pause_lag']) {
                if ($this->options['continue_lag']) {
                    break;
                } else {
                    throw new RuntimeException('Slave lag did not recover after processing chunk. Aborting.');
                }
            }
        }
    }
701254
public function queryBuilder(ConnectionInterface $connection, String $connectionId=null) : QueryBuilderProvider
	{
		return new PdoQueryBuilder($connection, $connectionId);
	}
1252764
public function build(ConnectionInterface $connection, IlluminateSchemaGrammar $grammar)
    {
        foreach ($this->toCypher($connection, $grammar) as $statement)
        {
            $connection->statement($statement);
        }
    }
886958
private function removeMigration(Connection $connection, int $index): void
    {
        $connection->delete(static::MIGRATIONS_TABLE, [static::MIGRATIONS_COLUMN_ID => $index]);
    }
958182
private function removeInToManyRelationship(
        Connection $connection,
        string $primaryIdentity,
        string $name,
        iterable $secondaryIdentities
    ): int {
        $removeToMany = $this->builderOnRemoveInBelongsToManyRelationship(
            $name,
            $this
                ->createBuilderFromConnection($connection, $this->getModelClass())
                ->prepareDeleteInToManyRelationship($name, $primaryIdentity, $secondaryIdentities)
        );
        $removed = $removeToMany->execute();

        return $removed;
    }
166660
public static function fromConnection(Connection $connection, $table, array $types = [])
    {
        $name = $connection->getDriver()->getName();
        switch ($name) {
        case 'pdo_mysql':
            return new MysqlSelector($connection, $table, $types);
        case 'pdo_sqlite':
            return new SqliteSelector($connection, $table, $types);
        default:
            throw new DBALException("Unsupported database type: $name");
        }
    }
925124
private function removeTokensView(Connection $connection, DatabaseSchemaInterface $schema)
    {
        $view = $schema->getTokensView();
        $sql  = "DROP VIEW IF EXISTS {$view}";
        $connection->exec($sql);
    }
389412
private function saveSeed(Connection $connection, string $class): void
    {
        $format = $connection->getSchemaManager()->getDatabasePlatform()->getDateTimeFormatString();
        $now    = (new DateTimeImmutable())->format($format);
        $connection->insert($this->getSeedsTable(), [
            static::SEEDS_COLUMN_CLASS     => $class,
            static::SEEDS_COLUMN_SEEDED_AT => $now,
        ]);
    }
1080119
protected function addActiveConnection(ConnectionInterface $connection)
    {
        if (!$this->activeConnections) {
            $this->activeConnections = new \SplObjectStorage;
        }
        $this->activeConnections->attach($connection);
    }
490395
public function onHandshakeRequest(
        Connection $connection,
        string $path,
        string $origin,
        string $key,
        array $extensions
    ): void {
        if (!$this->isAllowed($origin)) {
            $connection->close(Protocol::CLOSE_NORMAL, 'Not allowed origin during handshake request');
        }
    }
1366977
protected void setSchema(final String schema) throws DatabaseEngineException {
        try {
            this.conn.setSchema(schema);
        } catch (final Exception e) {
            throw new DatabaseEngineException(String.format("Could not set current schema to '%s'", schema), e);
        }
    }
1203138
public function disconnect(Connection $connection = null) {
		if(!isset($connection)) {
			$this->connection->close();
		} else {
			$connection->close();
		}
	}
312041
protected function createClientsScopesTable(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        $manager = $connection->getSchemaManager();

        $table = new Table($schema->getClientsScopesTable());
        $table->addColumn($schema->getClientsScopesIdentityColumn(), Type::INTEGER)
            ->setNotnull(true)->setAutoincrement(true)->setUnsigned(true);
        $table->addColumn($schema->getClientsScopesClientIdentityColumn(), Type::STRING)->setNotnull(true);
        $table->addColumn($schema->getClientsScopesScopeIdentityColumn(), Type::STRING)->setNotnull(true);
        $table->setPrimaryKey([$schema->getClientsScopesIdentityColumn()]);
        $table->addUniqueIndex([
            $schema->getClientsScopesClientIdentityColumn(),
            $schema->getClientsScopesScopeIdentityColumn()
        ]);

        $table->addForeignKeyConstraint(
            $schema->getClientsTable(),
            [$schema->getClientsScopesClientIdentityColumn()],
            [$schema->getClientsIdentityColumn()],
            $this->getOnDeleteCascadeConstraint()
        );

        $table->addForeignKeyConstraint(
            $schema->getScopesTable(),
            [$schema->getClientsScopesScopeIdentityColumn()],
            [$schema->getScopesIdentityColumn()],
            $this->getOnDeleteCascadeConstraint()
        );

        $manager->dropAndCreateTable($table);
    }
420054
private function saveMigration(Connection $connection, string $class): void
    {
        $format = $connection->getSchemaManager()->getDatabasePlatform()->getDateTimeFormatString();
        $now    = (new DateTimeImmutable())->format($format);
        $connection->insert(static::MIGRATIONS_TABLE, [
            static::MIGRATIONS_COLUMN_CLASS       => $class,
            static::MIGRATIONS_COLUMN_MIGRATED_AT => $now,
        ]);
    }
1325656
public function onSocketConnect($socket, Connection $connection): void
    {
        $this->checkConnections($connection);
        $this->checkConnectionsPerIp($connection);
    }
662596
protected function createScopesTable(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        $manager = $connection->getSchemaManager();

        $table = new Table($schema->getScopesTable());
        $table->addColumn($schema->getScopesIdentityColumn(), Type::STRING)->setNotnull(true);
        $table->addColumn($schema->getScopesDescriptionColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getScopesCreatedAtColumn(), Type::DATETIME)->setNotnull(true);
        $table->addColumn($schema->getScopesUpdatedAtColumn(), Type::DATETIME)->setNotnull(false);
        $table->setPrimaryKey([$schema->getScopesIdentityColumn()]);

        $manager->dropAndCreateTable($table);
    }