/*
 * 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.reactiverse.rxjava.pgclient;

import java.util.Map;
import rx.Observable;
import rx.Single;
import io.reactiverse.pgclient.PgNotification;
import java.util.List;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

A connection to Postgres.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * A connection to Postgres. * * <p/> * NOTE: This class has been automatically generated from the {@link io.reactiverse.pgclient.PgConnection original} non RX-ified interface using Vert.x codegen. */
@io.vertx.lang.rx.RxGen(io.reactiverse.pgclient.PgConnection.class) public class PgConnection extends io.reactiverse.rxjava.pgclient.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; PgConnection that = (PgConnection) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final io.vertx.lang.rx.TypeArg<PgConnection> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new PgConnection((io.reactiverse.pgclient.PgConnection) obj), PgConnection::getDelegate ); private final io.reactiverse.pgclient.PgConnection delegate; public PgConnection(io.reactiverse.pgclient.PgConnection delegate) { super(delegate); this.delegate = delegate; } public io.reactiverse.pgclient.PgConnection getDelegate() { return delegate; }
Create a prepared query.
Params:
  • sql – the sql
  • handler – the handler notified with the prepared query asynchronously
Returns:
/** * Create a prepared query. * @param sql the sql * @param handler the handler notified with the prepared query asynchronously * @return */
public io.reactiverse.rxjava.pgclient.PgConnection prepare(String sql, Handler<AsyncResult<io.reactiverse.rxjava.pgclient.PgPreparedQuery>> handler) { delegate.prepare(sql, new Handler<AsyncResult<io.reactiverse.pgclient.PgPreparedQuery>>() { public void handle(AsyncResult<io.reactiverse.pgclient.PgPreparedQuery> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.rxjava.pgclient.PgPreparedQuery.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
Create a prepared query.
Params:
  • sql – the sql
Returns:
/** * Create a prepared query. * @param sql the sql * @return */
public Single<io.reactiverse.rxjava.pgclient.PgPreparedQuery> rxPrepare(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { prepare(sql, fut); })); }
Set an handler called with connection errors.
Params:
  • handler – the handler
Returns:a reference to this, so the API can be used fluently
/** * Set an handler called with connection errors. * @param handler the handler * @return a reference to this, so the API can be used fluently */
public io.reactiverse.rxjava.pgclient.PgConnection exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
Set an handler called when the connection is closed.
Params:
  • handler – the handler
Returns:a reference to this, so the API can be used fluently
/** * Set an handler called when the connection is closed. * @param handler the handler * @return a reference to this, so the API can be used fluently */
public io.reactiverse.rxjava.pgclient.PgConnection closeHandler(Handler<Void> handler) { delegate.closeHandler(handler); return this; }
Begin a transaction and returns a PgTransaction for controlling and tracking this transaction.

When the connection is explicitely closed, any inflight transaction is rollbacked.
Returns:the transaction instance
/** * Begin a transaction and returns a {@link io.reactiverse.rxjava.pgclient.PgTransaction} for controlling and tracking * this transaction. * <p/> * When the connection is explicitely closed, any inflight transaction is rollbacked. * @return the transaction instance */
public io.reactiverse.rxjava.pgclient.PgTransaction begin() { io.reactiverse.rxjava.pgclient.PgTransaction ret = io.reactiverse.rxjava.pgclient.PgTransaction.newInstance(delegate.begin()); return ret; }
Set an handler called when the connection receives notification on a channel.

The handler is called with the PgNotification and has access to the channel name and the notification payload.
Params:
  • handler – the handler
Returns:the transaction instance
/** * Set an handler called when the connection receives notification on a channel. * <p/> * The handler is called with the {@link io.reactiverse.pgclient.PgNotification} and has access to the channel name * and the notification payload. * @param handler the handler * @return the transaction instance */
public io.reactiverse.rxjava.pgclient.PgConnection notificationHandler(Handler<PgNotification> handler) { delegate.notificationHandler(handler); return this; }
Returns:The process ID of the target backend
/** * @return The process ID of the target backend */
public int processId() { int ret = delegate.processId(); return ret; }
Returns:The secret key for the target backend
/** * @return The secret key for the target backend */
public int secretKey() { int ret = delegate.secretKey(); return ret; }
Send a request cancellation message to tell the server to cancel processing request in this connection.
Note: Use this with caution because the cancellation signal may or may not have any effect.
Params:
  • handler – the handler notified if cancelling request is sent
Returns:a reference to this, so the API can be used fluently
/** * Send a request cancellation message to tell the server to cancel processing request in this connection. * <br>Note: Use this with caution because the cancellation signal may or may not have any effect. * @param handler the handler notified if cancelling request is sent * @return a reference to this, so the API can be used fluently */
public io.reactiverse.rxjava.pgclient.PgConnection cancelRequest(Handler<AsyncResult<Void>> handler) { io.reactiverse.rxjava.pgclient.PgConnection ret = io.reactiverse.rxjava.pgclient.PgConnection.newInstance(delegate.cancelRequest(handler)); return ret; }
Returns:whether the connection uses SSL
/** * @return whether the connection uses SSL */
public boolean isSSL() { boolean ret = delegate.isSSL(); return ret; }
Close the current connection after all the pending commands have been processed.
/** * Close the current connection after all the pending commands have been processed. */
public void close() { delegate.close(); } public io.reactiverse.rxjava.pgclient.PgConnection preparedQuery(String sql, Handler<AsyncResult<io.reactiverse.rxjava.pgclient.PgRowSet>> handler) { delegate.preparedQuery(sql, new Handler<AsyncResult<io.reactiverse.pgclient.PgRowSet>>() { public void handle(AsyncResult<io.reactiverse.pgclient.PgRowSet> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.rxjava.pgclient.PgRowSet.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, fut); })); } public io.reactiverse.rxjava.pgclient.PgConnection query(String sql, Handler<AsyncResult<io.reactiverse.rxjava.pgclient.PgRowSet>> handler) { delegate.query(sql, new Handler<AsyncResult<io.reactiverse.pgclient.PgRowSet>>() { public void handle(AsyncResult<io.reactiverse.pgclient.PgRowSet> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.rxjava.pgclient.PgRowSet.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxQuery(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { query(sql, fut); })); } public io.reactiverse.rxjava.pgclient.PgConnection preparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments, Handler<AsyncResult<io.reactiverse.rxjava.pgclient.PgRowSet>> handler) { delegate.preparedQuery(sql, arguments.getDelegate(), new Handler<AsyncResult<io.reactiverse.pgclient.PgRowSet>>() { public void handle(AsyncResult<io.reactiverse.pgclient.PgRowSet> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.rxjava.pgclient.PgRowSet.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, arguments, fut); })); } public io.reactiverse.rxjava.pgclient.PgConnection preparedBatch(String sql, List<io.reactiverse.rxjava.pgclient.Tuple> batch, Handler<AsyncResult<io.reactiverse.rxjava.pgclient.PgRowSet>> handler) { delegate.preparedBatch(sql, batch.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList()), new Handler<AsyncResult<io.reactiverse.pgclient.PgRowSet>>() { public void handle(AsyncResult<io.reactiverse.pgclient.PgRowSet> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.reactiverse.rxjava.pgclient.PgRowSet.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedBatch(String sql, List<io.reactiverse.rxjava.pgclient.Tuple> batch) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedBatch(sql, batch, fut); })); } public static PgConnection newInstance(io.reactiverse.pgclient.PgConnection arg) { return arg != null ? new PgConnection(arg) : null; } }