io.reactiverse.mutiny.pgclient.PgPool Maven / Gradle / Ivy
package io.reactiverse.mutiny.pgclient;
import java.util.Map;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import java.util.function.Consumer;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Publisher;
import java.util.List;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
/**
* A pool of connection.
*
*
* NOTE: This class has been automatically generated from the {@link io.reactiverse.pgclient.PgPool original} non Mutiny-ified interface using Vert.x codegen.
*/
@io.smallrye.mutiny.vertx.MutinyGen(io.reactiverse.pgclient.PgPool.class)
public class PgPool extends io.reactiverse.mutiny.pgclient.PgClient {
public static final io.smallrye.mutiny.vertx.TypeArg __TYPE_ARG = new io.smallrye.mutiny.vertx.TypeArg<>( obj -> new PgPool((io.reactiverse.pgclient.PgPool) obj),
PgPool::getDelegate
);
private final io.reactiverse.pgclient.PgPool delegate;
public PgPool(io.reactiverse.pgclient.PgPool delegate) {
super(delegate);
this.delegate = delegate;
}
/**
* Empty constructor used by CDI, do not use this constructor directly.
**/
PgPool() { super(null);
this.delegate = null;
}
public io.reactiverse.pgclient.PgPool getDelegate() {
return delegate;
}
@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;
PgPool that = (PgPool) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
private io.reactiverse.mutiny.pgclient.PgPool __preparedQuery(String sql, Handler> handler) {
delegate.preparedQuery(sql, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgRowSet.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Uni preparedQuery(String sql) {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__preparedQuery(sql, handler);
});
}
public io.reactiverse.mutiny.pgclient.PgRowSet preparedQueryAndAwait(String sql) {
return (io.reactiverse.mutiny.pgclient.PgRowSet) preparedQuery(sql).await().indefinitely();
}
private io.reactiverse.mutiny.pgclient.PgPool __query(String sql, Handler> handler) {
delegate.query(sql, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgRowSet.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Uni query(String sql) {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__query(sql, handler);
});
}
public io.reactiverse.mutiny.pgclient.PgRowSet queryAndAwait(String sql) {
return (io.reactiverse.mutiny.pgclient.PgRowSet) query(sql).await().indefinitely();
}
private io.reactiverse.mutiny.pgclient.PgPool __preparedQuery(String sql, io.reactiverse.mutiny.pgclient.Tuple arguments, Handler> handler) {
delegate.preparedQuery(sql, arguments.getDelegate(), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgRowSet.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Uni preparedQuery(String sql, io.reactiverse.mutiny.pgclient.Tuple arguments) {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__preparedQuery(sql, arguments, handler);
});
}
public io.reactiverse.mutiny.pgclient.PgRowSet preparedQueryAndAwait(String sql, io.reactiverse.mutiny.pgclient.Tuple arguments) {
return (io.reactiverse.mutiny.pgclient.PgRowSet) preparedQuery(sql, arguments).await().indefinitely();
}
private io.reactiverse.mutiny.pgclient.PgPool __preparedBatch(String sql, List batch, Handler> handler) {
delegate.preparedBatch(sql, batch.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList()), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgRowSet.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Uni preparedBatch(String sql, List batch) {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__preparedBatch(sql, batch, handler);
});
}
public io.reactiverse.mutiny.pgclient.PgRowSet preparedBatchAndAwait(String sql, List batch) {
return (io.reactiverse.mutiny.pgclient.PgRowSet) preparedBatch(sql, batch).await().indefinitely();
}
/**
* Get a connection from the pool.
* @param handler the handler that will get the connection result
*/
private void __getConnection(Handler> handler) {
delegate.getConnection(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgConnection.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Get a connection from the pool.
* @return
*/
public Uni getConnection() {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__getConnection(handler);
});
}
/**
* Get a connection from the pool.
* @return
*/
public io.reactiverse.mutiny.pgclient.PgConnection getConnectionAndAwait() {
return (io.reactiverse.mutiny.pgclient.PgConnection) getConnection().await().indefinitely();
}
/**
* Borrow a connection from the pool and begin a transaction, the underlying connection will be returned
* to the pool when the transaction ends.
* @param handler
*/
private void __begin(Handler> handler) {
delegate.begin(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.mutiny.pgclient.PgTransaction.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Borrow a connection from the pool and begin a transaction, the underlying connection will be returned
* to the pool when the transaction ends.
* @return the transaction
*/
public Uni begin() {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
__begin(handler);
});
}
/**
* Borrow a connection from the pool and begin a transaction, the underlying connection will be returned
* to the pool when the transaction ends.
* @return the transaction
*/
public io.reactiverse.mutiny.pgclient.PgTransaction beginAndAwait() {
return (io.reactiverse.mutiny.pgclient.PgTransaction) begin().await().indefinitely();
}
/**
* Close the pool and release the associated resources.
*/
public void close() {
delegate.close();
}
public static PgPool newInstance(io.reactiverse.pgclient.PgPool arg) {
return arg != null ? new PgPool(arg) : null;
}
}