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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations