connection.close(done -> { if (done.failed()) { resultHandler.handle(Future.failedFuture(done.cause()));
connection.close(done -> { if (done.failed()) { throw new RuntimeException(done.cause());
connection.close(done -> { if (done.failed()) { throw new RuntimeException(done.cause());
conn.result().close(done -> { if (done.failed()) { throw new RuntimeException(done.cause());
conn.result().close(done -> { if (done.failed()) { throw new RuntimeException(done.cause());
.endHandler(v -> { connection.close(done -> { if (done.failed()) { throw new RuntimeException(done.cause());
@Override public void close() throws Exception { connection.close(); closed = true; }
/** * Closes the connection. Important to always close the connection when you are done so it's returned to the pool. * @param handler the handler called when this operation completes. */ public void close(Handler<AsyncResult<Void>> handler) { delegate.close(handler); }
/** * Closes the connection. Important to always close the connection when you are done so it's returned to the pool. */ public void close() { delegate.close(); }
@Override public void close(IAsyncResultHandler<Void> handler) { connection.close(translateVoidHandlers(handler)); closed = true; }
protected <U> Function<SQLConnection,CompletableFuture<U>> safeExecute(Function<SQLConnection,CompletableFuture<U>> action){ return sqlConnection -> { try{ return action.apply(sqlConnection); }catch(Throwable e){ sqlConnection.close(); CompletableFuture<U> cf = new VertxCompletableFuture<>(vertx); cf.completeExceptionally(e); return cf; } }; }
protected void removeAll(String sql, Handler<AsyncResult<Void>> resultHandler) { client.getConnection(connHandler(resultHandler, connection -> { connection.update(sql, r -> { if (r.succeeded()) { resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(r.cause())); } connection.close(); }); })); }
protected <R> void execute(JsonArray params, String sql, R ret, Handler<AsyncResult<R>> resultHandler) { client.getConnection(connHandler(resultHandler, connection -> { connection.updateWithParams(sql, params, r -> { if (r.succeeded()) { resultHandler.handle(Future.succeededFuture(ret)); } else { resultHandler.handle(Future.failedFuture(r.cause())); } connection.close(); }); })); }
@Override public void initializePersistence(Handler<AsyncResult<Void>> resultHandler) { jdbc.getConnection(connHandler(resultHandler, connection -> { connection.execute(CREATE_STATEMENT, r -> { resultHandler.handle(r); connection.close(); }); })); }
@Override public ProductService initializePersistence(Handler<AsyncResult<Void>> resultHandler) { client.getConnection(connHandler(resultHandler, connection -> { connection.execute(CREATE_STATEMENT, r -> { resultHandler.handle(r); connection.close(); }); })); return this; }
@Override public AccountService initializePersistence(Handler<AsyncResult<Void>> resultHandler) { client.getConnection(connHandler(resultHandler, connection -> { connection.execute(CREATE_STATEMENT, r -> { resultHandler.handle(r); connection.close(); }); })); return this; }
@Override public OrderService initializePersistence(Handler<AsyncResult<Void>> resultHandler) { client.getConnection(connHandler(resultHandler, connection -> { connection.execute(CREATE_STATEMENT, r -> { resultHandler.handle(r); connection.close(); }); })); return this; }
@Test public void testCloseThenQuery() throws Exception { client.getConnection(onSuccess(conn -> { conn.close(onSuccess(v -> { conn.query("SELECT 1 FROM select_table", onFailure(t -> { assertNotNull(t); testComplete(); })); })); })); await(); }
@Test public void testClose() throws Exception { client.getConnection(onSuccess(conn -> { conn.query("SELECT 1 FROM select_table", onSuccess(results -> { assertNotNull(results); conn.close(onSuccess(v -> { testComplete(); })); })); })); await(); }