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

com.julienviet.reactivex.pgclient.PgConnection Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
/*
 * 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.reactivex.pgclient;

import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import com.julienviet.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 {@link com.julienviet.pgclient.PgConnection original} non RX-ified interface using Vert.x codegen. */ @io.vertx.lang.reactivex.RxGen(com.julienviet.pgclient.PgConnection.class) public class PgConnection 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; PgConnection that = (PgConnection) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final io.vertx.lang.reactivex.TypeArg __TYPE_ARG = new io.vertx.lang.reactivex.TypeArg<>( obj -> new PgConnection((com.julienviet.pgclient.PgConnection) obj), PgConnection::getDelegate ); private final com.julienviet.pgclient.PgConnection delegate; public PgConnection(com.julienviet.pgclient.PgConnection delegate) { super(delegate); this.delegate = delegate; } public com.julienviet.pgclient.PgConnection getDelegate() { return delegate; } /** * Create a prepared query. * @param sql the sql * @param handler the handler notified with the prepared query asynchronously * @return */ public PgConnection prepare(String sql, Handler> handler) { delegate.prepare(sql, new Handler>() { public void handle(AsyncResult ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(PgPreparedQuery.newInstance(ar.result()))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } /** * Create a prepared query. * @param sql the sql * @return */ public Single rxPrepare(String sql) { return new io.vertx.reactivex.core.impl.AsyncResultSingle(handler -> { prepare(sql, handler); }); } /** * Set an handler called with connection errors. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public PgConnection exceptionHandler(Handler handler) { delegate.exceptionHandler(handler); return this; } /** * 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 PgConnection closeHandler(Handler handler) { delegate.closeHandler(handler); return this; } /** * Begin a transaction and returns a {@link com.julienviet.reactivex.pgclient.PgTransaction} for controlling and tracking * this transaction. *

* When the connection is explicitely closed, any inflight transaction is rollbacked. * @return the transaction instance */ public PgTransaction begin() { PgTransaction ret = PgTransaction.newInstance(delegate.begin()); return ret; } /** * Set an handler called when the connection receives notification on a channel. *

* The handler is called with the {@link com.julienviet.pgclient.PgNotification} and has access to the channel name * and the notification payload. * @param handler the handler * @return the transaction instance */ public PgConnection notificationHandler(Handler handler) { delegate.notificationHandler(handler); return this; } /** * @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. */ public void close() { delegate.close(); } public PgConnection 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.reactivex.pgclient.Row.__TYPE_ARG))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single> rxPreparedQuery(String sql) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedQuery(sql, handler); }); } public PgConnection 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.reactivex.pgclient.Row.__TYPE_ARG))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single> rxQuery(String sql) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { query(sql, handler); }); } public PgConnection 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.reactivex.pgclient.Row.__TYPE_ARG))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single> rxPreparedQuery(String sql, Tuple arguments) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedQuery(sql, arguments, handler); }); } public PgConnection 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.reactivex.pgclient.Row.__TYPE_ARG))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; } public Single> rxPreparedBatch(String sql, List batch) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedBatch(sql, batch, handler); }); } public static PgConnection newInstance(com.julienviet.pgclient.PgConnection arg) { return arg != null ? new PgConnection(arg) : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy