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

com.julienviet.reactivex.pgclient.PgClient 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 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 io.vertx.reactivex.core.Vertx;
import java.util.List;
import com.julienviet.pgclient.PgConnectOptions;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import com.julienviet.pgclient.PgPoolOptions;

/**
 * Defines the client operations with a Postgres Database.
 *
 * 

* NOTE: This class has been automatically generated from the {@link com.julienviet.pgclient.PgClient original} non RX-ified interface using Vert.x codegen. */ @io.vertx.lang.reactivex.RxGen(com.julienviet.pgclient.PgClient.class) public class 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; PgClient that = (PgClient) 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 PgClient((com.julienviet.pgclient.PgClient) obj), PgClient::getDelegate ); private final com.julienviet.pgclient.PgClient delegate; public PgClient(com.julienviet.pgclient.PgClient delegate) { this.delegate = delegate; } public com.julienviet.pgclient.PgClient getDelegate() { return delegate; } /** * Create a connection pool to the database configured with the given options. * @param options the options for creating the pool * @return the connection pool */ public static PgPool pool(PgPoolOptions options) { PgPool ret = PgPool.newInstance(com.julienviet.pgclient.PgClient.pool(options)); return ret; } /** * Like {@link com.julienviet.reactivex.pgclient.PgClient#pool} with a specific instance. * @param vertx * @param options * @return */ public static PgPool pool(Vertx vertx, PgPoolOptions options) { PgPool ret = PgPool.newInstance(com.julienviet.pgclient.PgClient.pool(vertx.getDelegate(), options)); return ret; } /** * Connects to the database and returns the connection if that succeeds. *

* The connection interracts directly with the database is not a proxy, so closing the * connection will close the underlying connection to the database. * @param vertx the vertx instance * @param options the connect options * @param handler the handler called with the connection or the failure */ public static void connect(Vertx vertx, PgConnectOptions options, Handler> handler) { com.julienviet.pgclient.PgClient.connect(vertx.getDelegate(), options, 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())); } } }); } /** * Connects to the database and returns the connection if that succeeds. *

* The connection interracts directly with the database is not a proxy, so closing the * connection will close the underlying connection to the database. * @param vertx the vertx instance * @param options the connect options * @return */ public static Single rxConnect(Vertx vertx, PgConnectOptions options) { return new io.vertx.reactivex.core.impl.AsyncResultSingle(handler -> { connect(vertx, options, handler); }); } /** * Execute a simple query. * @param sql the query SQL * @param handler the handler notified with the execution result * @return a reference to this, so the API can be used fluently */ public PgClient 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; } /** * Execute a simple query. * @param sql the query SQL * @return */ public Single> rxQuery(String sql) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { query(sql, handler); }); } /** * Prepare and execute a query. * @param sql the prepared query SQL * @param handler the handler notified with the execution result * @return a reference to this, so the API can be used fluently */ public PgClient 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; } /** * Prepare and execute a query. * @param sql the prepared query SQL * @return */ public Single> rxPreparedQuery(String sql) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedQuery(sql, handler); }); } /** * Prepare and execute a query. * @param sql the prepared query SQL * @param arguments the list of arguments * @param handler the handler notified with the execution result * @return a reference to this, so the API can be used fluently */ public PgClient 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; } /** * Prepare and execute a query. * @param sql the prepared query SQL * @param arguments the list of arguments * @return */ public Single> rxPreparedQuery(String sql, Tuple arguments) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedQuery(sql, arguments, handler); }); } /** * Prepare and execute a createBatch. * @param sql the prepared query SQL * @param batch the batch of tuples * @param handler the handler notified with the execution result * @return a reference to this, so the API can be used fluently */ public PgClient 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; } /** * Prepare and execute a createBatch. * @param sql the prepared query SQL * @param batch the batch of tuples * @return */ public Single> rxPreparedBatch(String sql, List batch) { return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> { preparedBatch(sql, batch, handler); }); } public static PgClient newInstance(com.julienviet.pgclient.PgClient arg) { return arg != null ? new PgClient(arg) : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy