@Override public SQLClient getConnection(Handler<AsyncResult<SQLConnection>> handler) { return client.getConnection(handler); } }
@Override public SQLClient getConnection(Handler<AsyncResult<SQLConnection>> handler) { return client.getConnection(handler); } }
@Override public SQLClient getConnection(Handler<AsyncResult<SQLConnection>> handler) { return client.getConnection(handler); } }
/** * @return a Future that returns a SQLConnection or an Exception. */ private Future<SQLConnection> getConnection(){ Future<SQLConnection> future = Future.future(); delegate.getConnection(future); return future; }
/** * @return a Future that returns a SQLConnection or an Exception. */ private Future<SQLConnection> getConnection(){ Future<SQLConnection> future = Future.future(); delegate.getConnection(future); return future; }
/** * @return a Future that returns a SQLConnection or an Exception. */ protected Future<SQLConnection> getConnection(){ Future<SQLConnection> future = Future.future(); delegate.getConnection(future); return future; }
/** * @return a Future that returns a SQLConnection or an Exception. */ protected Future<SQLConnection> getConnection(){ Future<SQLConnection> future = Future.future(); delegate.getConnection(future); return future; }
/** * @return a CompletableFuture that returns a SQLConnection or an Exception. */ protected CompletableFuture<SQLConnection> getConnection(){ CompletableFuture<SQLConnection> cf = new VertxCompletableFuture<>(vertx); delegate.getConnection(h -> { if (h.succeeded()) { cf.complete(h.result()); } else { cf.completeExceptionally(h.cause()); } }); return cf; }
public void getConnection(Handler<ExtendedAsyncResult<SQLConnection>> fut) { cli.getConnection(res -> { if (res.failed()) { fut.handle(new Failure<>(INTERNAL, res.cause())); } else { SQLConnection con = res.result(); fut.handle(new Success<>(con)); } }); }
/** * @return a CompletableFuture that returns a SQLConnection or an Exception. */ private CompletableFuture<SQLConnection> getConnection(){ CompletableFuture<SQLConnection> cf = new VertxCompletableFuture<>(vertx); delegate.getConnection(h -> { if (h.succeeded()) { cf.complete(h.result()); } else { cf.completeExceptionally(h.cause()); } }); return cf; }
/** * @return a CompletableFuture that returns a SQLConnection or an Exception. */ private CompletableFuture<SQLConnection> getConnection(){ CompletableFuture<SQLConnection> cf = new VertxCompletableFuture<>(vertx); delegate.getConnection(h -> { if (h.succeeded()) { cf.complete(h.result()); } else { cf.completeExceptionally(h.cause()); } }); return cf; }
/** * Executes the given query and returns the {@link ResultSet} to the {@link Handler} * * @param sqlClient * the sqlClient to obtain the connection from * @param command * the command to be executed * @param resultHandler * a resulthandler to be informed */ public static void queryWithParams(AsyncSQLClient sqlClient, String command, JsonArray params, Handler<AsyncResult<ResultSet>> resultHandler) { LOGGER.debug("queryWithParams: " + command + " | " + params); sqlClient.getConnection(cr -> { if (cr.failed()) { Exception sqlEx = new SqlException(ERROR_GAINING_CONNECTION, cr.cause()); LOGGER.error("", sqlEx); resultHandler.handle(Future.failedFuture(sqlEx)); return; } SQLConnection connection = cr.result(); LOGGER.debug(GAINED_SUCCESSFULLY_A_CONNECTION); doQueryWithParams(command, params, resultHandler, connection); }); }
/** * Executes the given query and returns the {@link ResultSet} to the {@link Handler} * * @param sqlClient * the sqlClient to obtain the connection from * @param command * the command to be executed * @param resultHandler * a resulthandler to be informed */ public static void query(AsyncSQLClient sqlClient, String command, Handler<AsyncResult<ResultSet>> resultHandler) { LOGGER.debug("query: " + command); sqlClient.getConnection(cr -> { if (cr.failed()) { Exception sqlEx = new SqlException(ERROR_GAINING_CONNECTION, cr.cause()); LOGGER.error("", sqlEx); resultHandler.handle(Future.failedFuture(sqlEx)); return; } SQLConnection connection = cr.result(); LOGGER.debug(GAINED_SUCCESSFULLY_A_CONNECTION); doQuery(command, resultHandler, connection); }); }
/** * Executes the given command and informs the {@link Handler} * * @param sqlClient * the sqlClient to obtain the connection from * @param command * the command to be executed * @param resultHandler * a resulthandler to be informed */ public static void updateWithParams(AsyncSQLClient sqlClient, String command, JsonArray params, Handler<AsyncResult<UpdateResult>> resultHandler) { LOGGER.debug("updateWithParams: " + command + " | " + params); sqlClient.getConnection(cr -> { if (cr.failed()) { Exception sqlEx = new SqlException(ERROR_GAINING_CONNECTION, cr.cause()); LOGGER.error("", sqlEx); resultHandler.handle(Future.failedFuture(sqlEx)); } else { SQLConnection connection = cr.result(); LOGGER.debug(GAINED_SUCCESSFULLY_A_CONNECTION); executeUpdateWithParams(connection, command, params, resultHandler); } }); }
/** * Executes the given command and informs the {@link Handler} * * @param sqlClient * the sqlClient to obtain the connection from * @param command * the command to be executed * @param resultHandler * a resulthandler to be informed */ public static void execute(AsyncSQLClient sqlClient, String command, Handler<AsyncResult<Void>> resultHandler) { LOGGER.debug("execute: " + command); sqlClient.getConnection(cr -> { if (cr.failed()) { Exception sqlEx = new SqlException(ERROR_GAINING_CONNECTION, cr.cause()); LOGGER.error("", sqlEx); resultHandler.handle(Future.failedFuture(sqlEx)); return; } SQLConnection connection = cr.result(); LOGGER.debug(GAINED_SUCCESSFULLY_A_CONNECTION); doExecute(command, resultHandler, connection); }); }
/** * Executes the given command and informs the {@link Handler} * * @param sqlClient * the sqlClient to obtain the connection from * @param command * the command to be executed * @param resultHandler * a resulthandler to be informed */ public static void update(AsyncSQLClient sqlClient, String command, Handler<AsyncResult<UpdateResult>> resultHandler) { LOGGER.debug("update: " + command); sqlClient.getConnection(cr -> { if (cr.failed()) { Exception sqlEx = new SqlException(ERROR_GAINING_CONNECTION, cr.cause()); LOGGER.error("", sqlEx); resultHandler.handle(Future.failedFuture(sqlEx)); return; } SQLConnection connection = cr.result(); LOGGER.debug(GAINED_SUCCESSFULLY_A_CONNECTION); executeUpdate(connection, command, resultHandler); }); }
@Test public void testConnection(TestContext context) { Vertx vertx = Vertx.vertx(); String host = System.getProperty("MySqlDataStoreContainer.host", null); if (host == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.host'"); } String username = System.getProperty("MySqlDataStoreContainer.username", null); if (username == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.username'"); } String password = System.getProperty("MySqlDataStoreContainer.password", null); if (password == null) { throw new ParameterRequiredException("you must set the property 'MySqlDataStoreContainer.password'"); } JsonObject mySQLClientConfig = new JsonObject().put("host", host).put("username", username) .put("password", password).put("database", "test").put("port", 3306); AsyncSQLClient client = MySQLClient.createNonShared(vertx, mySQLClientConfig); client.getConnection(res -> { if (res.succeeded()) { SQLConnection connection = res.result(); // Got a connection LOGGER.info("succeeded connection"); } else { LOGGER.error("", res.cause()); context.fail(res.cause()); } }); }