/*
 * 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.sqlclient;

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 connection pool which reuses a number of SQL connections.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * A connection pool which reuses a number of SQL connections. * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.sqlclient.Pool original} non RX-ified interface using Vert.x codegen. */
@RxGen(io.vertx.sqlclient.Pool.class) public class Pool extends io.vertx.rxjava.sqlclient.SqlClient { @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; Pool that = (Pool) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg<Pool> __TYPE_ARG = new TypeArg<>( obj -> new Pool((io.vertx.sqlclient.Pool) obj), Pool::getDelegate ); private final io.vertx.sqlclient.Pool delegate; public Pool(io.vertx.sqlclient.Pool delegate) { super(delegate); this.delegate = delegate; } public Pool(Object delegate) { super((io.vertx.sqlclient.Pool)delegate); this.delegate = (io.vertx.sqlclient.Pool)delegate; } public io.vertx.sqlclient.Pool getDelegate() { return delegate; } private static final TypeArg<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> TYPE_ARG_0 = new TypeArg<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>>(o1 -> io.vertx.rxjava.sqlclient.RowSet.newInstance((io.vertx.sqlclient.RowSet)o1, new TypeArg<io.vertx.rxjava.sqlclient.Row>(o2 -> io.vertx.rxjava.sqlclient.Row.newInstance((io.vertx.sqlclient.Row)o2), o2 -> o2.getDelegate())), o1 -> o1.getDelegate()); private static final TypeArg<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> TYPE_ARG_1 = new TypeArg<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>>(o1 -> io.vertx.rxjava.sqlclient.RowSet.newInstance((io.vertx.sqlclient.RowSet)o1, new TypeArg<io.vertx.rxjava.sqlclient.Row>(o2 -> io.vertx.rxjava.sqlclient.Row.newInstance((io.vertx.sqlclient.Row)o2), o2 -> o2.getDelegate())), o1 -> o1.getDelegate());
Create a connection pool to the database configured with the given connectOptions and default PoolOptions
Params:
  • connectOptions – the options used to create the connection pool, such as database hostname
Returns:the connection pool
/** * Create a connection pool to the database configured with the given <code>connectOptions</code> and default {@link io.vertx.sqlclient.PoolOptions} * @param connectOptions the options used to create the connection pool, such as database hostname * @return the connection pool */
public static io.vertx.rxjava.sqlclient.Pool pool(io.vertx.sqlclient.SqlConnectOptions connectOptions) { io.vertx.rxjava.sqlclient.Pool ret = io.vertx.rxjava.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(connectOptions)); return ret; }
Create a connection pool to the database configured with the given connectOptions and poolOptions.
Params:
  • connectOptions – the options used to create the connection pool, such as database hostname
  • poolOptions – the options for creating the pool
Returns:the connection pool
/** * Create a connection pool to the database configured with the given <code>connectOptions</code> and <code>poolOptions</code>. * @param connectOptions the options used to create the connection pool, such as database hostname * @param poolOptions the options for creating the pool * @return the connection pool */
public static io.vertx.rxjava.sqlclient.Pool pool(io.vertx.sqlclient.SqlConnectOptions connectOptions, io.vertx.sqlclient.PoolOptions poolOptions) { io.vertx.rxjava.sqlclient.Pool ret = io.vertx.rxjava.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(connectOptions, poolOptions)); return ret; }
Create a connection pool to the database configured with the given connectOptions and poolOptions.
Params:
  • vertx – the Vertx instance to be used with the connection pool
  • connectOptions – the options used to create the connection pool, such as database hostname
  • poolOptions – the options for creating the pool
Returns:the connection pool
/** * Create a connection pool to the database configured with the given <code>connectOptions</code> and <code>poolOptions</code>. * @param vertx the Vertx instance to be used with the connection pool * @param connectOptions the options used to create the connection pool, such as database hostname * @param poolOptions the options for creating the pool * @return the connection pool */
public static io.vertx.rxjava.sqlclient.Pool pool(io.vertx.rxjava.core.Vertx vertx, io.vertx.sqlclient.SqlConnectOptions connectOptions, io.vertx.sqlclient.PoolOptions poolOptions) { io.vertx.rxjava.sqlclient.Pool ret = io.vertx.rxjava.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(vertx.getDelegate(), connectOptions, poolOptions)); return ret; }
Get a connection from the pool.
Params:
  • handler – the handler that will get the connection result
/** * Get a connection from the pool. * @param handler the handler that will get the connection result */
public void getConnection(Handler<AsyncResult<io.vertx.rxjava.sqlclient.SqlConnection>> handler) { delegate.getConnection(new Handler<AsyncResult<io.vertx.sqlclient.SqlConnection>>() { public void handle(AsyncResult<io.vertx.sqlclient.SqlConnection> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
Get a connection from the pool.
/** * Get a connection from the pool. */
public void getConnection() { getConnection(ar -> { }); }
Get a connection from the pool.
Returns:
/** * Get a connection from the pool. * @return */
public Single<io.vertx.rxjava.sqlclient.SqlConnection> rxGetConnection() { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { getConnection(fut); })); }
A connection is borrowed from the connection pool when the query is executed and then immediately returned to the pool after it completes.
Params:
  • sql –
Returns:
/** * * * A connection is borrowed from the connection pool when the query is executed and then immediately returned * to the pool after it completes. * @param sql * @return */
public io.vertx.rxjava.sqlclient.Query<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> query(String sql) { io.vertx.rxjava.sqlclient.Query<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> ret = io.vertx.rxjava.sqlclient.Query.newInstance((io.vertx.sqlclient.Query)delegate.query(sql), TYPE_ARG_0); return ret; }
A connection is borrowed from the connection pool when the query is executed and then immediately returned to the pool after it completes.
Params:
  • sql –
Returns:
/** * * * A connection is borrowed from the connection pool when the query is executed and then immediately returned * to the pool after it completes. * @param sql * @return */
public io.vertx.rxjava.sqlclient.PreparedQuery<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> preparedQuery(String sql) { io.vertx.rxjava.sqlclient.PreparedQuery<io.vertx.rxjava.sqlclient.RowSet<io.vertx.rxjava.sqlclient.Row>> ret = io.vertx.rxjava.sqlclient.PreparedQuery.newInstance((io.vertx.sqlclient.PreparedQuery)delegate.preparedQuery(sql), TYPE_ARG_1); return ret; }
Execute the given function within a transaction.

The function is passed a client executing all operations within a transaction. When the future returned by the function

  • succeeds the transaction commits
  • fails the transaction rollbacks

The handler is given a success result when the function returns a succeeded futures and the transaction commits. Otherwise it is given a failure result.

Params:
  • function – the code to execute
  • handler – the result handler
/** * Execute the given <code>function</code> within a transaction. * * <p>The <code>function</code> is passed a client executing all operations within a transaction. * When the future returned by the function * <ul> * <li>succeeds the transaction commits</li> * <li>fails the transaction rollbacks</li> * </ul> * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures and the transaction commits. * Otherwise it is given a failure result. * @param function the code to execute * @param handler the result handler */
public <T> void withTransaction(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function, Handler<AsyncResult<T>> handler) { delegate.withTransaction(new Function<io.vertx.sqlclient.SqlConnection,io.vertx.core.Future<T>>() { public io.vertx.core.Future<T> apply(io.vertx.sqlclient.SqlConnection arg) { io.vertx.core.Future<T> ret = function.apply(io.vertx.rxjava.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); return ret; } }, handler); }
Execute the given function within a transaction.

The function is passed a client executing all operations within a transaction. When the future returned by the function

  • succeeds the transaction commits
  • fails the transaction rollbacks

The handler is given a success result when the function returns a succeeded futures and the transaction commits. Otherwise it is given a failure result.

Params:
  • function – the code to execute
/** * Execute the given <code>function</code> within a transaction. * * <p>The <code>function</code> is passed a client executing all operations within a transaction. * When the future returned by the function * <ul> * <li>succeeds the transaction commits</li> * <li>fails the transaction rollbacks</li> * </ul> * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures and the transaction commits. * Otherwise it is given a failure result. * @param function the code to execute */
public <T> void withTransaction(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function) { withTransaction(function, ar -> { }); }
Execute the given function within a transaction.

The function is passed a client executing all operations within a transaction. When the future returned by the function

  • succeeds the transaction commits
  • fails the transaction rollbacks

The handler is given a success result when the function returns a succeeded futures and the transaction commits. Otherwise it is given a failure result.

Params:
  • function – the code to execute
Returns:
/** * Execute the given <code>function</code> within a transaction. * * <p>The <code>function</code> is passed a client executing all operations within a transaction. * When the future returned by the function * <ul> * <li>succeeds the transaction commits</li> * <li>fails the transaction rollbacks</li> * </ul> * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures and the transaction commits. * Otherwise it is given a failure result. * @param function the code to execute * @return */
public <T> Single<T> rxWithTransaction(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { withTransaction(function, fut); })); }
Get a connection from the pool and execute the given function.

When the future returned by the function completes, the connection is returned to the pool.

The handler is given a success result when the function returns a succeeded futures. Otherwise it is given a failure result.

Params:
  • function – the code to execute
  • handler – the result handler
/** * Get a connection from the pool and execute the given <code>function</code>. * * <p> When the future returned by the <code>function</code> completes, the connection is returned to the pool. * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures. * Otherwise it is given a failure result. * @param function the code to execute * @param handler the result handler */
public <T> void withConnection(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function, Handler<AsyncResult<T>> handler) { delegate.withConnection(new Function<io.vertx.sqlclient.SqlConnection,io.vertx.core.Future<T>>() { public io.vertx.core.Future<T> apply(io.vertx.sqlclient.SqlConnection arg) { io.vertx.core.Future<T> ret = function.apply(io.vertx.rxjava.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); return ret; } }, handler); }
Get a connection from the pool and execute the given function.

When the future returned by the function completes, the connection is returned to the pool.

The handler is given a success result when the function returns a succeeded futures. Otherwise it is given a failure result.

Params:
  • function – the code to execute
/** * Get a connection from the pool and execute the given <code>function</code>. * * <p> When the future returned by the <code>function</code> completes, the connection is returned to the pool. * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures. * Otherwise it is given a failure result. * @param function the code to execute */
public <T> void withConnection(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function) { withConnection(function, ar -> { }); }
Get a connection from the pool and execute the given function.

When the future returned by the function completes, the connection is returned to the pool.

The handler is given a success result when the function returns a succeeded futures. Otherwise it is given a failure result.

Params:
  • function – the code to execute
Returns:
/** * Get a connection from the pool and execute the given <code>function</code>. * * <p> When the future returned by the <code>function</code> completes, the connection is returned to the pool. * * <p>The <code>handler</code> is given a success result when the function returns a succeeded futures. * Otherwise it is given a failure result. * @param function the code to execute * @return */
public <T> Single<T> rxWithConnection(Function<io.vertx.rxjava.sqlclient.SqlConnection, io.vertx.core.Future<T>> function) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { withConnection(function, fut); })); }
Close the pool and release the associated resources.
Params:
  • handler – the completion handler
/** * Close the pool and release the associated resources. * @param handler the completion handler */
public void close(Handler<AsyncResult<Void>> handler) { delegate.close(handler); }
Close the pool and release the associated resources.
/** * Close the pool and release the associated resources. */
public void close() { close(ar -> { }); }
Close the pool and release the associated resources.
Returns:
/** * Close the pool and release the associated resources. * @return */
public Single<Void> rxClose() { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { close(fut); })); } public static Pool newInstance(io.vertx.sqlclient.Pool arg) { return arg != null ? new Pool(arg) : null; } }