All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.reactivex.sqlclient.Pool 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.reactivex.sqlclient;

import io.vertx.reactivex.RxHelper;
import io.vertx.reactivex.ObservableHelper;
import io.vertx.reactivex.FlowableHelper;
import io.vertx.reactivex.impl.AsyncResultMaybe;
import io.vertx.reactivex.impl.AsyncResultSingle;
import io.vertx.reactivex.impl.AsyncResultCompletable;
import io.vertx.reactivex.WriteStreamObserver;
import io.vertx.reactivex.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Supplier;
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 {@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.reactivex.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 __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 TYPE_ARG_0 = new TypeArg(o1 -> io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)o1), o1 -> o1.getDelegate()); private static final TypeArg> TYPE_ARG_1 = new TypeArg>(o1 -> io.vertx.reactivex.sqlclient.RowSet.newInstance((io.vertx.sqlclient.RowSet)o1, new TypeArg(o2 -> io.vertx.reactivex.sqlclient.Row.newInstance((io.vertx.sqlclient.Row)o2), o2 -> o2.getDelegate())), o1 -> o1.getDelegate()); private static final TypeArg> TYPE_ARG_2 = new TypeArg>(o1 -> io.vertx.reactivex.sqlclient.RowSet.newInstance((io.vertx.sqlclient.RowSet)o1, new TypeArg(o2 -> io.vertx.reactivex.sqlclient.Row.newInstance((io.vertx.sqlclient.Row)o2), o2 -> o2.getDelegate())), o1 -> o1.getDelegate()); /** * Like {@link io.vertx.reactivex.sqlclient.Pool#pool} with default options. * @param connectOptions * @return */ public static io.vertx.reactivex.sqlclient.Pool pool(io.vertx.sqlclient.SqlConnectOptions connectOptions) { io.vertx.reactivex.sqlclient.Pool ret = io.vertx.reactivex.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(connectOptions)); return ret; } /** * Like {@link io.vertx.reactivex.sqlclient.Pool#pool} with a Vert.x instance created automatically. * @param database * @param options * @return */ public static io.vertx.reactivex.sqlclient.Pool pool(io.vertx.sqlclient.SqlConnectOptions database, io.vertx.sqlclient.PoolOptions options) { io.vertx.reactivex.sqlclient.Pool ret = io.vertx.reactivex.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(database, options)); return ret; } /** * Create a connection pool to the database with the given options. * *

A will be selected among the drivers found on the classpath returning * true when applied to the first options * of the list. * @param vertx the Vertx instance to be used with the connection pool * @param database the options used to create the connection pool, such as database hostname * @param options the options for creating the pool * @return the connection pool */ public static io.vertx.reactivex.sqlclient.Pool pool(io.vertx.reactivex.core.Vertx vertx, io.vertx.sqlclient.SqlConnectOptions database, io.vertx.sqlclient.PoolOptions options) { io.vertx.reactivex.sqlclient.Pool ret = io.vertx.reactivex.sqlclient.Pool.newInstance((io.vertx.sqlclient.Pool)io.vertx.sqlclient.Pool.pool(vertx.getDelegate(), database, options)); return ret; } /** * Get a connection from the pool. * @return a future notified with the {@link io.vertx.reactivex.sqlclient.SqlConnection} */ public io.vertx.core.Future getConnection() { io.vertx.core.Future ret = delegate.getConnection().map(val -> io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)val)); return ret; } /** * Get a connection from the pool. * @return a future notified with the {@link io.vertx.reactivex.sqlclient.SqlConnection} */ public io.reactivex.Single rxGetConnection() { return AsyncResultSingle.toSingle($handler -> { this.getConnection().onComplete($handler); }); } /** * * * 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.reactivex.sqlclient.Query> query(java.lang.String sql) { io.vertx.reactivex.sqlclient.Query> ret = io.vertx.reactivex.sqlclient.Query.newInstance((io.vertx.sqlclient.Query)delegate.query(sql), TYPE_ARG_1); 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. * @param sql * @return */ public io.vertx.reactivex.sqlclient.PreparedQuery> preparedQuery(java.lang.String sql) { io.vertx.reactivex.sqlclient.PreparedQuery> ret = io.vertx.reactivex.sqlclient.PreparedQuery.newInstance((io.vertx.sqlclient.PreparedQuery)delegate.preparedQuery(sql), TYPE_ARG_2); 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. * @param function the code to execute * @return a future notified with the result */ public io.vertx.core.Future withTransaction(java.util.function.Function> function) { io.vertx.core.Future ret = delegate.withTransaction(new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.vertx.core.Future ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); return ret.map(val -> val); } }).map(val -> (T) val); 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. * @param function the code to execute * @return a future notified with the result */ public io.reactivex.Maybe rxWithTransaction(java.util.function.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withTransaction(function).onComplete($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. * @param function the code to execute * @return a future notified with the result */ public io.vertx.core.Future withTransaction(io.reactivex.functions.Function> function) { io.vertx.core.Future ret = delegate.withTransaction(new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.reactivex.Maybe ret; try { ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); } catch (Exception e) { return io.vertx.core.Future.failedFuture(e); } return io.vertx.reactivex.MaybeHelper.toFuture(ret, obj -> obj); } }).map(val -> (T) val); 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. * @param function the code to execute * @return a future notified with the result */ public io.reactivex.Maybe rxWithTransaction(io.reactivex.functions.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withTransaction(function).onComplete($handler); }); } /** * Like {@link io.vertx.reactivex.sqlclient.Pool#withTransaction} but allows for setting the mode, defining how the acquired * connection is managed during the execution of the function. * @param txPropagation * @param function * @return */ public io.vertx.core.Future withTransaction(io.vertx.sqlclient.TransactionPropagation txPropagation, java.util.function.Function> function) { io.vertx.core.Future ret = delegate.withTransaction(txPropagation, new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.vertx.core.Future ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); return ret.map(val -> val); } }).map(val -> (T) val); return ret; } /** * Like {@link io.vertx.reactivex.sqlclient.Pool#withTransaction} but allows for setting the mode, defining how the acquired * connection is managed during the execution of the function. * @param txPropagation * @param function * @return */ public io.reactivex.Maybe rxWithTransaction(io.vertx.sqlclient.TransactionPropagation txPropagation, java.util.function.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withTransaction(txPropagation, function).onComplete($handler); }); } /** * Like {@link io.vertx.reactivex.sqlclient.Pool#withTransaction} but allows for setting the mode, defining how the acquired * connection is managed during the execution of the function. * @param txPropagation * @param function * @return */ public io.vertx.core.Future withTransaction(io.vertx.sqlclient.TransactionPropagation txPropagation, io.reactivex.functions.Function> function) { io.vertx.core.Future ret = delegate.withTransaction(txPropagation, new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.reactivex.Maybe ret; try { ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); } catch (Exception e) { return io.vertx.core.Future.failedFuture(e); } return io.vertx.reactivex.MaybeHelper.toFuture(ret, obj -> obj); } }).map(val -> (T) val); return ret; } /** * Like {@link io.vertx.reactivex.sqlclient.Pool#withTransaction} but allows for setting the mode, defining how the acquired * connection is managed during the execution of the function. * @param txPropagation * @param function * @return */ public io.reactivex.Maybe rxWithTransaction(io.vertx.sqlclient.TransactionPropagation txPropagation, io.reactivex.functions.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withTransaction(txPropagation, function).onComplete($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. * @param function the code to execute * @return a future notified with the result */ public io.vertx.core.Future withConnection(java.util.function.Function> function) { io.vertx.core.Future ret = delegate.withConnection(new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.vertx.core.Future ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); return ret.map(val -> val); } }).map(val -> (T) val); return ret; } /** * 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. * @param function the code to execute * @return a future notified with the result */ public io.reactivex.Maybe rxWithConnection(java.util.function.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withConnection(function).onComplete($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. * @param function the code to execute * @return a future notified with the result */ public io.vertx.core.Future withConnection(io.reactivex.functions.Function> function) { io.vertx.core.Future ret = delegate.withConnection(new Function>() { public io.vertx.core.Future apply(io.vertx.sqlclient.SqlConnection arg) { io.reactivex.Maybe ret; try { ret = function.apply(io.vertx.reactivex.sqlclient.SqlConnection.newInstance((io.vertx.sqlclient.SqlConnection)arg)); } catch (Exception e) { return io.vertx.core.Future.failedFuture(e); } return io.vertx.reactivex.MaybeHelper.toFuture(ret, obj -> obj); } }).map(val -> (T) val); return ret; } /** * 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. * @param function the code to execute * @return a future notified with the result */ public io.reactivex.Maybe rxWithConnection(io.reactivex.functions.Function> function) { return AsyncResultMaybe.toMaybe($handler -> { this.withConnection(function).onComplete($handler); }); } /** * @return the current pool size approximation */ public int size() { int ret = delegate.size(); return ret; } public static Pool newInstance(io.vertx.sqlclient.Pool arg) { return arg != null ? new Pool(arg) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy