Search in sources :

Example 1 with SqlConnectOptions

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

the class OracleDriver method newPool.

@Override
public Pool newPool(Vertx vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    VertxInternal vx = (VertxInternal) vertx;
    PoolImpl pool;
    if (options.isShared()) {
        pool = vx.createSharedClient(SHARED_CLIENT_KEY, options.getName(), closeFuture, cf -> newPoolImpl(vx, databases, options, cf));
    } else {
        pool = newPoolImpl(vx, databases, options, closeFuture);
    }
    return new OraclePoolImpl(vx, closeFuture, 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) VertxInternal(io.vertx.core.impl.VertxInternal) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Example 2 with SqlConnectOptions

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

the class MySQLConnectionAutoRetryTest method initialConnector.

@Override
protected void initialConnector(int proxyPort) {
    SqlConnectOptions proxyOptions = new MySQLConnectOptions(options);
    proxyOptions.setPort(proxyPort);
    proxyOptions.setHost("localhost");
    connectionConnector = ClientConfig.CONNECT.connect(vertx, proxyOptions);
    poolConnector = ClientConfig.POOLED.connect(vertx, proxyOptions);
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions)

Example 3 with SqlConnectOptions

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

the class MySQLDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    MySQLConnectOptions baseConnectOptions = MySQLConnectOptions.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;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, 1, options, null, null, 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 : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MySQLConnectionImpl(io.vertx.mysqlclient.impl.MySQLConnectionImpl) Driver(io.vertx.sqlclient.spi.Driver) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MySQLConnectionFactory(io.vertx.mysqlclient.impl.MySQLConnectionFactory) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) MySQLPool(io.vertx.mysqlclient.MySQLPool) CloseFuture(io.vertx.core.impl.CloseFuture) MySQLConnectionUriParser(io.vertx.mysqlclient.impl.MySQLConnectionUriParser) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) MySQLConnectionFactory(io.vertx.mysqlclient.impl.MySQLConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Example 4 with SqlConnectOptions

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

the class MSSQLDriver method newPool.

@Override
public MSSQLPool newPool(Vertx vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    VertxInternal vx = (VertxInternal) vertx;
    PoolImpl pool;
    if (options.isShared()) {
        pool = vx.createSharedClient(SHARED_CLIENT_KEY, options.getName(), closeFuture, cf -> newPoolImpl(vx, databases, options, cf));
    } else {
        pool = newPoolImpl(vx, databases, options, closeFuture);
    }
    return new MSSQLPoolImpl(vx, closeFuture, pool);
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) MSSQLConnectionUriParser(io.vertx.mssqlclient.impl.MSSQLConnectionUriParser) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MSSQLConnectionFactory(io.vertx.mssqlclient.impl.MSSQLConnectionFactory) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MSSQLConnectionImpl(io.vertx.mssqlclient.impl.MSSQLConnectionImpl) 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) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) MSSQLPool(io.vertx.mssqlclient.MSSQLPool) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl) VertxInternal(io.vertx.core.impl.VertxInternal) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl)

Example 5 with SqlConnectOptions

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

the class Driver method createPool.

/**
 * Create a connection pool to the database configured with the given {@code connectOptions} and {@code poolOptions}.
 *
 * <p> The returned pool will automatically closed when {@code vertx} is not {@code null} and is closed or when the creating
 * context is closed (e.g verticle undeployment).
 *
 * @param vertx the Vertx instance to be used with the connection pool or {@code null} to create an auto closed Vertx instance
 * @param databases the list of databases
 * @param options the options for creating the pool
 * @return the connection pool
 */
default Pool createPool(Vertx vertx, List<? extends SqlConnectOptions> databases, PoolOptions options) {
    VertxInternal vx;
    if (vertx == null) {
        if (Vertx.currentContext() != null) {
            throw new IllegalStateException("Running in a Vertx context => use Pool#pool(Vertx, SqlConnectOptions, PoolOptions) instead");
        }
        VertxOptions vertxOptions = new VertxOptions();
        SqlConnectOptions database = databases.get(0);
        if (database.isUsingDomainSocket()) {
            vertxOptions.setPreferNativeTransport(true);
        }
        vx = (VertxInternal) Vertx.vertx(vertxOptions);
    } else {
        vx = (VertxInternal) vertx;
    }
    CloseFuture closeFuture = new CloseFuture();
    Pool pool;
    try {
        pool = newPool(vx, databases, options, closeFuture);
    } catch (Exception e) {
        if (vertx == null) {
            vx.close();
        }
        throw e;
    }
    vx.addCloseHook(closeFuture);
    if (vertx == null) {
        closeFuture.future().onComplete(ar -> vx.close());
    } else {
        ContextInternal ctx = vx.getContext();
        if (ctx != null) {
            ctx.addCloseHook(closeFuture);
        } else {
            vx.addCloseHook(closeFuture);
        }
    }
    return pool;
}
Also used : CloseFuture(io.vertx.core.impl.CloseFuture) VertxInternal(io.vertx.core.impl.VertxInternal) SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) Pool(io.vertx.sqlclient.Pool) ContextInternal(io.vertx.core.impl.ContextInternal) VertxOptions(io.vertx.core.VertxOptions)

Aggregations

SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)20 CloseFuture (io.vertx.core.impl.CloseFuture)11 ContextInternal (io.vertx.core.impl.ContextInternal)11 VertxInternal (io.vertx.core.impl.VertxInternal)11 Vertx (io.vertx.core.Vertx)10 JsonObject (io.vertx.core.json.JsonObject)10 ClientMetrics (io.vertx.core.spi.metrics.ClientMetrics)10 VertxMetrics (io.vertx.core.spi.metrics.VertxMetrics)10 PoolOptions (io.vertx.sqlclient.PoolOptions)10 Connection (io.vertx.sqlclient.impl.Connection)10 PoolImpl (io.vertx.sqlclient.impl.PoolImpl)10 SqlConnectionInternal (io.vertx.sqlclient.impl.SqlConnectionInternal)10 QueryTracer (io.vertx.sqlclient.impl.tracing.QueryTracer)10 ConnectionFactory (io.vertx.sqlclient.spi.ConnectionFactory)10 Driver (io.vertx.sqlclient.spi.Driver)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)3 MSSQLConnectOptions (io.vertx.mssqlclient.MSSQLConnectOptions)3 MySQLConnectOptions (io.vertx.mysqlclient.MySQLConnectOptions)3