com.julienviet.rxjava.pgclient.PgPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reactive-pg-client Show documentation
Show all versions of reactive-pg-client Show documentation
The reactive Postgres client
/*
* 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 com.julienviet.rxjava.pgclient;
import java.util.Map;
import rx.Observable;
import rx.Single;
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 com.julienviet.pgclient.PgPool original} non RX-ified interface using Vert.x codegen.
*/
@io.vertx.lang.rxjava.RxGen(com.julienviet.pgclient.PgPool.class)
public class PgPool extends PgClient {
@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();
}
public static final io.vertx.lang.rxjava.TypeArg __TYPE_ARG = new io.vertx.lang.rxjava.TypeArg<>(
obj -> new PgPool((com.julienviet.pgclient.PgPool) obj),
PgPool::getDelegate
);
private final com.julienviet.pgclient.PgPool delegate;
public PgPool(com.julienviet.pgclient.PgPool delegate) {
super(delegate);
this.delegate = delegate;
}
public com.julienviet.pgclient.PgPool getDelegate() {
return delegate;
}
public 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(PgResult.newInstance(ar.result(), com.julienviet.rxjava.pgclient.Row.__TYPE_ARG)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Single> rxPreparedQuery(String sql) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
preparedQuery(sql, fut);
}));
}
public 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(PgResult.newInstance(ar.result(), com.julienviet.rxjava.pgclient.Row.__TYPE_ARG)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Single> rxQuery(String sql) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
query(sql, fut);
}));
}
public PgPool preparedQuery(String sql, 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(PgResult.newInstance(ar.result(), com.julienviet.rxjava.pgclient.Row.__TYPE_ARG)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Single> rxPreparedQuery(String sql, Tuple arguments) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
preparedQuery(sql, arguments, fut);
}));
}
public 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(PgResult.newInstance(ar.result(), com.julienviet.rxjava.pgclient.Row.__TYPE_ARG)));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
public Single> rxPreparedBatch(String sql, List batch) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
preparedBatch(sql, batch, fut);
}));
}
/**
* Get a connection from the pool.
* @param handler the handler that will get the connection result
*/
public void getConnection(Handler> handler) {
delegate.getConnection(new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(PgConnection.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Get a connection from the pool.
* @return
*/
public Single rxGetConnection() {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
getConnection(fut);
}));
}
/**
* Close the pool and release the associated resources.
*/
public void close() {
delegate.close();
}
public static PgPool newInstance(com.julienviet.pgclient.PgPool arg) {
return arg != null ? new PgPool(arg) : null;
}
}