/** * Calls the given SQL <code>PROCEDURE</code> which returns the result from the procedure. * * @param sql the SQL to execute. For example <code>{call getEmpName}</code>. * @param handler the handler which is called once the operation completes. It will return a {@code ResultSet}. * * @see java.sql.CallableStatement#execute(String) */ @Fluent @Override default SQLClient call(String sql, Handler<AsyncResult<ResultSet>> handler) { getConnection(getConnection -> { if (getConnection.failed()) { handler.handle(Future.failedFuture(getConnection.cause())); } else { final SQLConnection conn = getConnection.result(); conn.call(sql, HandlerUtil.closeAndHandleResult(conn, handler)); } }); return this; }
/** * Execute a one shot SQL statement that returns a single SQL row. This method will reduce the boilerplate code by * getting a connection from the pool (this object) and return it back after the execution. Only the first result * from the result set is returned. * * @param sql the statement to execute * @param handler the result handler * @return self */ @Fluent default SQLOperations querySingle(String sql, Handler<AsyncResult<@Nullable JsonArray>> handler) { return query(sql, HandlerUtil.handleResultSetSingleRow(handler)); }
/** * Execute a one shot SQL statement with arguments that returns a single SQL row. This method will reduce the * boilerplate code by getting a connection from the pool (this object) and return it back after the execution. * Only the first result from the result set is returned. * * @param sql the statement to execute * @param arguments the arguments * @param handler the result handler * @return self */ @Fluent default SQLOperations querySingleWithParams(String sql, JsonArray arguments, Handler<AsyncResult<@Nullable JsonArray>> handler) { return queryWithParams(sql, arguments, HandlerUtil.handleResultSetSingleRow(handler)); }
/** * Execute a single SQL prepared statement, this method acquires a connection from the the pool and executes the SQL * prepared statement and returns it back after the execution. * * @param sql the statement to execute * @param arguments the arguments to the statement * @param handler the result handler * @return self */ @Fluent @Override default SQLClient queryWithParams(String sql, JsonArray arguments, Handler<AsyncResult<ResultSet>> handler) { getConnection(getConnection -> { if (getConnection.failed()) { handler.handle(Future.failedFuture(getConnection.cause())); } else { final SQLConnection conn = getConnection.result(); conn.queryWithParams(sql, arguments, HandlerUtil.closeAndHandleResult(conn,handler)); } }); return this; }
/** * Executes the given SQL statement which may be an <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> * statement. * * @param sql the SQL to execute. For example <code>INSERT INTO table ...</code> * @param handler the handler which is called once the operation completes. * * @see java.sql.Statement#executeUpdate(String) * @see java.sql.PreparedStatement#executeUpdate(String) */ @Fluent @Override default SQLClient update(String sql, Handler<AsyncResult<UpdateResult>> handler) { getConnection(getConnection -> { if (getConnection.failed()) { handler.handle(Future.failedFuture(getConnection.cause())); } else { final SQLConnection conn = getConnection.result(); conn.update(sql, HandlerUtil.closeAndHandleResult(conn,handler)); } }); return this; }
/** * Executes the given prepared statement which may be an <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> * statement with the given parameters * * @param sql the SQL to execute. For example <code>INSERT INTO table ...</code> * @param params these are the parameters to fill the statement. * @param handler the handler which is called once the operation completes. * * @see java.sql.Statement#executeUpdate(String) * @see java.sql.PreparedStatement#executeUpdate(String) */ @Fluent @Override default SQLClient updateWithParams(String sql, JsonArray params, Handler<AsyncResult<UpdateResult>> handler) { getConnection(getConnection -> { if (getConnection.failed()) { handler.handle(Future.failedFuture(getConnection.cause())); } else { final SQLConnection conn = getConnection.result(); conn.updateWithParams(sql, params, HandlerUtil.closeAndHandleResult(conn,handler)); } }); return this; }
} else { final SQLConnection conn = getConnection.result(); conn.callWithParams(sql, params, outputs, HandlerUtil.closeAndHandleResult(conn, handler));