Search in sources :

Example 1 with Connection

use of io.vertx.sqlclient.impl.Connection in project vertx-sql-client by eclipse-vertx.

the class MSSQLConnectionFactory method connectOrRedirect.

private Future<Connection> connectOrRedirect(SocketAddress server, String username, String password, String database, EventLoopContext context, int redirections) {
    if (redirections > 1) {
        return context.failedFuture("The client can be redirected only once");
    }
    return netClient.connect(server).map(so -> createSocketConnection(so, context)).compose(conn -> conn.sendPreLoginMessage(clientConfigSsl).compose(encryptionLevel -> login(conn, username, password, database, encryptionLevel, context))).compose(connBase -> {
        MSSQLSocketConnection conn = (MSSQLSocketConnection) connBase;
        SocketAddress alternateServer = conn.getAlternateServer();
        if (alternateServer == null) {
            return context.succeededFuture(conn);
        }
        Promise<Void> closePromise = context.promise();
        conn.close(null, closePromise);
        return closePromise.future().transform(v -> connectOrRedirect(alternateServer, username, password, database, context, redirections + 1));
    });
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) ConnectionFactoryBase(io.vertx.sqlclient.impl.ConnectionFactoryBase) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) EncryptionLevel(io.vertx.mssqlclient.impl.codec.EncryptionLevel) Promise(io.vertx.core.Promise) ContextInternal(io.vertx.core.impl.ContextInternal) Context(io.vertx.core.Context) Future(io.vertx.core.Future) NetClientOptions(io.vertx.core.net.NetClientOptions) Connection(io.vertx.sqlclient.impl.Connection) EventLoopContext(io.vertx.core.impl.EventLoopContext) SqlConnection(io.vertx.sqlclient.SqlConnection) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal) NetSocket(io.vertx.core.net.NetSocket) SocketAddress(io.vertx.core.net.SocketAddress) SocketAddress(io.vertx.core.net.SocketAddress)

Example 2 with Connection

use of io.vertx.sqlclient.impl.Connection in project vertx-sql-client by eclipse-vertx.

the class OracleDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    OracleConnectOptions baseConnectOptions = OracleConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    Function<Connection, Future<Void>> afterAcquire = conn -> ((CommandHandler) conn).afterAcquire();
    Function<Connection, Future<Void>> beforeRecycle = conn -> ((CommandHandler) conn).beforeRecycle();
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, 1, options, afterAcquire, beforeRecycle, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : OracleConnectOptions(io.vertx.oracleclient.OracleConnectOptions) SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) io.vertx.oracleclient.impl(io.vertx.oracleclient.impl) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) Pool(io.vertx.sqlclient.Pool) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Future(io.vertx.core.Future) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) CloseFuture(io.vertx.core.impl.CloseFuture) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) OracleConnectOptions(io.vertx.oracleclient.OracleConnectOptions) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Connection(io.vertx.sqlclient.impl.Connection) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) Future(io.vertx.core.Future) CloseFuture(io.vertx.core.impl.CloseFuture) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics)

Example 3 with Connection

use of io.vertx.sqlclient.impl.Connection in project vertx-sql-client by eclipse-vertx.

the class InitCommandCodec method handleReadyForQuery.

@Override
public void handleReadyForQuery() {
    // The final phase before returning the connection
    // We should make sure we are supporting only UTF8
    // https://www.postgresql.org/docs/9.5/static/multibyte.html#MULTIBYTE-CHARSET-SUPPORTED
    Charset cs = null;
    try {
        cs = Charset.forName(encoding);
    } catch (Exception ignore) {
    }
    CommandResponse<Connection> fut;
    if (cs == null || !cs.equals(StandardCharsets.UTF_8)) {
        fut = CommandResponse.failure(encoding + " is not supported in the client only UTF8");
    } else {
        fut = CommandResponse.success(cmd.connection());
    }
    completionHandler.handle(fut);
}
Also used : PgSocketConnection(io.vertx.pgclient.impl.PgSocketConnection) Connection(io.vertx.sqlclient.impl.Connection) Charset(java.nio.charset.Charset)

Aggregations

Connection (io.vertx.sqlclient.impl.Connection)3 Future (io.vertx.core.Future)2 ContextInternal (io.vertx.core.impl.ContextInternal)2 VertxInternal (io.vertx.core.impl.VertxInternal)2 SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)2 QueryTracer (io.vertx.sqlclient.impl.tracing.QueryTracer)2 Context (io.vertx.core.Context)1 Promise (io.vertx.core.Promise)1 Vertx (io.vertx.core.Vertx)1 CloseFuture (io.vertx.core.impl.CloseFuture)1 EventLoopContext (io.vertx.core.impl.EventLoopContext)1 JsonObject (io.vertx.core.json.JsonObject)1 NetClientOptions (io.vertx.core.net.NetClientOptions)1 NetSocket (io.vertx.core.net.NetSocket)1 SocketAddress (io.vertx.core.net.SocketAddress)1 NetSocketInternal (io.vertx.core.net.impl.NetSocketInternal)1 ClientMetrics (io.vertx.core.spi.metrics.ClientMetrics)1 VertxMetrics (io.vertx.core.spi.metrics.VertxMetrics)1 MSSQLConnectOptions (io.vertx.mssqlclient.MSSQLConnectOptions)1 EncryptionLevel (io.vertx.mssqlclient.impl.codec.EncryptionLevel)1