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