io.vertx.rxjava.ext.sql.SQLClient Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.rxjava.ext.sql;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
* A common asynchronous client interface for interacting with SQL compliant database
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.ext.sql.SQLClient original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.ext.sql.SQLClient.class)
public class SQLClient implements io.vertx.rxjava.ext.sql.SQLOperations {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SQLClient that = (SQLClient) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new SQLClient((io.vertx.ext.sql.SQLClient) obj),
SQLClient::getDelegate
);
private final io.vertx.ext.sql.SQLClient delegate;
public SQLClient(io.vertx.ext.sql.SQLClient delegate) {
this.delegate = delegate;
}
public SQLClient(Object delegate) {
this.delegate = (io.vertx.ext.sql.SQLClient)delegate;
}
public io.vertx.ext.sql.SQLClient getDelegate() {
return delegate;
}
/**
* 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
*/
public io.vertx.rxjava.ext.sql.SQLOperations querySingle(String sql, Handler> handler) {
delegate.querySingle(sql, 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
* @return self
*/
public io.vertx.rxjava.ext.sql.SQLOperations querySingle(String sql) {
return
querySingle(sql, ar -> { });
}
/**
* 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
* @return self
*/
public Single rxQuerySingle(String sql) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
querySingle(sql, fut);
}));
}
/**
* 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
*/
public io.vertx.rxjava.ext.sql.SQLOperations querySingleWithParams(String sql, JsonArray arguments, Handler> handler) {
delegate.querySingleWithParams(sql, arguments, handler);
return this;
}
/**
* 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
* @return self
*/
public io.vertx.rxjava.ext.sql.SQLOperations querySingleWithParams(String sql, JsonArray arguments) {
return
querySingleWithParams(sql, arguments, ar -> { });
}
/**
* 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
* @return self
*/
public Single rxQuerySingleWithParams(String sql, JsonArray arguments) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
querySingleWithParams(sql, arguments, fut);
}));
}
/**
* Returns a connection that can be used to perform SQL operations on. It's important to remember
* to close the connection when you are done, so it is returned to the pool.
* @param handler the handler which is called when the JdbcConnection
object is ready for use.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient getConnection(Handler> handler) {
delegate.getConnection(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.sql.SQLConnection.newInstance((io.vertx.ext.sql.SQLConnection)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Returns a connection that can be used to perform SQL operations on. It's important to remember
* to close the connection when you are done, so it is returned to the pool.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient getConnection() {
return
getConnection(ar -> { });
}
/**
* Returns a connection that can be used to perform SQL operations on. It's important to remember
* to close the connection when you are done, so it is returned to the pool.
* @return
*/
public Single rxGetConnection() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
getConnection(fut);
}));
}
/**
* Close the client and release all resources.
* Call the handler when close is complete.
* @param handler the handler that will be called when close is complete
*/
public void close(Handler> handler) {
delegate.close(handler);
}
/**
* Close the client and release all resources.
* Call the handler when close is complete.
* @return
*/
public Single rxClose() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
close(fut);
}));
}
/**
* Close the client
*/
public void close() {
delegate.close();
}
/**
* Execute a single SQL statement, this method acquires a connection from the the pool and executes the SQL
* statement and returns it back after the execution.
* @param sql the statement to execute
* @param handler the result handler
* @return self
*/
public io.vertx.rxjava.ext.sql.SQLClient query(String sql, Handler> handler) {
delegate.query(sql, handler);
return this;
}
/**
* Execute a single SQL statement, this method acquires a connection from the the pool and executes the SQL
* statement and returns it back after the execution.
* @param sql the statement to execute
* @return self
*/
public io.vertx.rxjava.ext.sql.SQLClient query(String sql) {
return
query(sql, ar -> { });
}
/**
* Execute a single SQL statement, this method acquires a connection from the the pool and executes the SQL
* statement and returns it back after the execution.
* @param sql the statement to execute
* @return self
*/
public Single rxQuery(String sql) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
query(sql, fut);
}));
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @param handler the handler which is called once the operation completes. It will return a SQLRowStream
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient queryStream(String sql, Handler> handler) {
delegate.queryStream(sql, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.sql.SQLRowStream.newInstance((io.vertx.ext.sql.SQLRowStream)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient queryStream(String sql) {
return
queryStream(sql, ar -> { });
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @return
*/
public Single rxQueryStream(String sql) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
queryStream(sql, fut);
}));
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @param params these are the parameters to fill the statement.
* @param handler the handler which is called once the operation completes. It will return a SQLRowStream
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient queryStreamWithParams(String sql, JsonArray params, Handler> handler) {
delegate.queryStreamWithParams(sql, params, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.sql.SQLRowStream.newInstance((io.vertx.ext.sql.SQLRowStream)ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @param params these are the parameters to fill the statement.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient queryStreamWithParams(String sql, JsonArray params) {
return
queryStreamWithParams(sql, params, ar -> { });
}
/**
* Executes the given SQL SELECT
statement which returns the results of the query as a read stream.
* @param sql the SQL to execute. For example SELECT * FROM table ...
.
* @param params these are the parameters to fill the statement.
* @return
*/
public Single rxQueryStreamWithParams(String sql, JsonArray params) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
queryStreamWithParams(sql, params, fut);
}));
}
/**
* 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
*/
public io.vertx.rxjava.ext.sql.SQLClient queryWithParams(String sql, JsonArray arguments, Handler> handler) {
delegate.queryWithParams(sql, arguments, handler);
return this;
}
/**
* 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
* @return self
*/
public io.vertx.rxjava.ext.sql.SQLClient queryWithParams(String sql, JsonArray arguments) {
return
queryWithParams(sql, arguments, ar -> { });
}
/**
* 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
* @return self
*/
public Single rxQueryWithParams(String sql, JsonArray arguments) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
queryWithParams(sql, arguments, fut);
}));
}
/**
* Executes the given SQL statement which may be an INSERT
, UPDATE
, or DELETE
* statement.
* @param sql the SQL to execute. For example INSERT INTO table ...
* @param handler the handler which is called once the operation completes.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient update(String sql, Handler> handler) {
delegate.update(sql, handler);
return this;
}
/**
* Executes the given SQL statement which may be an INSERT
, UPDATE
, or DELETE
* statement.
* @param sql the SQL to execute. For example INSERT INTO table ...
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient update(String sql) {
return
update(sql, ar -> { });
}
/**
* Executes the given SQL statement which may be an INSERT
, UPDATE
, or DELETE
* statement.
* @param sql the SQL to execute. For example INSERT INTO table ...
* @return
*/
public Single rxUpdate(String sql) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
update(sql, fut);
}));
}
/**
* Executes the given prepared statement which may be an INSERT
, UPDATE
, or DELETE
* statement with the given parameters
* @param sql the SQL to execute. For example INSERT INTO table ...
* @param params these are the parameters to fill the statement.
* @param handler the handler which is called once the operation completes.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient updateWithParams(String sql, JsonArray params, Handler> handler) {
delegate.updateWithParams(sql, params, handler);
return this;
}
/**
* Executes the given prepared statement which may be an INSERT
, UPDATE
, or DELETE
* statement with the given parameters
* @param sql the SQL to execute. For example INSERT INTO table ...
* @param params these are the parameters to fill the statement.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient updateWithParams(String sql, JsonArray params) {
return
updateWithParams(sql, params, ar -> { });
}
/**
* Executes the given prepared statement which may be an INSERT
, UPDATE
, or DELETE
* statement with the given parameters
* @param sql the SQL to execute. For example INSERT INTO table ...
* @param params these are the parameters to fill the statement.
* @return
*/
public Single rxUpdateWithParams(String sql, JsonArray params) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
updateWithParams(sql, params, fut);
}));
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
* @param sql the SQL to execute. For example {call getEmpName}
.
* @param handler the handler which is called once the operation completes. It will return a ResultSet
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient call(String sql, Handler> handler) {
delegate.call(sql, handler);
return this;
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
* @param sql the SQL to execute. For example {call getEmpName}
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient call(String sql) {
return
call(sql, ar -> { });
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
* @param sql the SQL to execute. For example {call getEmpName}
.
* @return
*/
public Single rxCall(String sql) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
call(sql, fut);
}));
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
*
* The index of params and outputs are important for both arrays, for example when dealing with a prodecure that
* takes the first 2 arguments as input values and the 3 arg as an output then the arrays should be like:
*
*
* params = [VALUE1, VALUE2, null]
* outputs = [null, null, "VARCHAR"]
*
* @param sql the SQL to execute. For example {call getEmpName (?, ?)}
.
* @param params these are the parameters to fill the statement.
* @param outputs these are the outputs to fill the statement.
* @param handler the handler which is called once the operation completes. It will return a ResultSet
.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs, Handler> handler) {
delegate.callWithParams(sql, params, outputs, handler);
return this;
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
*
* The index of params and outputs are important for both arrays, for example when dealing with a prodecure that
* takes the first 2 arguments as input values and the 3 arg as an output then the arrays should be like:
*
*
* params = [VALUE1, VALUE2, null]
* outputs = [null, null, "VARCHAR"]
*
* @param sql the SQL to execute. For example {call getEmpName (?, ?)}
.
* @param params these are the parameters to fill the statement.
* @param outputs these are the outputs to fill the statement.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLClient callWithParams(String sql, JsonArray params, JsonArray outputs) {
return
callWithParams(sql, params, outputs, ar -> { });
}
/**
* Calls the given SQL PROCEDURE
which returns the result from the procedure.
*
* The index of params and outputs are important for both arrays, for example when dealing with a prodecure that
* takes the first 2 arguments as input values and the 3 arg as an output then the arrays should be like:
*
*
* params = [VALUE1, VALUE2, null]
* outputs = [null, null, "VARCHAR"]
*
* @param sql the SQL to execute. For example {call getEmpName (?, ?)}
.
* @param params these are the parameters to fill the statement.
* @param outputs these are the outputs to fill the statement.
* @return
*/
public Single rxCallWithParams(String sql, JsonArray params, JsonArray outputs) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
callWithParams(sql, params, outputs, fut);
}));
}
public static SQLClient newInstance(io.vertx.ext.sql.SQLClient arg) {
return arg != null ? new SQLClient(arg) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy