com.julienviet.rxjava.pgclient.PgPreparedQuery 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.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 prepared query.
*
*
* NOTE: This class has been automatically generated from the {@link com.julienviet.pgclient.PgPreparedQuery original} non RX-ified interface using Vert.x codegen.
*/
@io.vertx.lang.rxjava.RxGen(com.julienviet.pgclient.PgPreparedQuery.class)
public class PgPreparedQuery {
@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;
PgPreparedQuery that = (PgPreparedQuery) 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 PgPreparedQuery((com.julienviet.pgclient.PgPreparedQuery) obj),
PgPreparedQuery::getDelegate
);
private final com.julienviet.pgclient.PgPreparedQuery delegate;
public PgPreparedQuery(com.julienviet.pgclient.PgPreparedQuery delegate) {
this.delegate = delegate;
}
public com.julienviet.pgclient.PgPreparedQuery getDelegate() {
return delegate;
}
/**
* @param handler
* @return create a query with no arguments
*/
public PgPreparedQuery execute(Handler>> handler) {
PgPreparedQuery ret = PgPreparedQuery.newInstance(delegate.execute(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 ret;
}
/**
* Create a cursor with the provided arguments
.
* @param args the list of arguments
* @param handler
* @return the query
*/
public PgPreparedQuery execute(Tuple args, Handler>> handler) {
PgPreparedQuery ret = PgPreparedQuery.newInstance(delegate.execute(args.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 ret;
}
/**
* @return create a query cursor with a fetch
size and empty arguments
*/
public PgCursor cursor() {
PgCursor ret = PgCursor.newInstance(delegate.cursor());
return ret;
}
/**
* Create a cursor with the provided arguments
.
* @param args the list of arguments
* @return the query
*/
public PgCursor cursor(Tuple args) {
PgCursor ret = PgCursor.newInstance(delegate.cursor(args.getDelegate()));
return ret;
}
/**
* Execute the prepared query with a cursor and createStream the result. The createStream opens a cursor
* with a fetch
size to fetch the results.
*
* Note: this requires to be in a transaction, since cursors require it.
* @param fetch the cursor fetch size
* @param args the prepared query arguments
* @return the createStream
*/
public PgStream createStream(int fetch, Tuple args) {
PgStream ret = PgStream.newInstance(delegate.createStream(fetch, args.getDelegate()), com.julienviet.rxjava.pgclient.Row.__TYPE_ARG);
return ret;
}
/**
* Execute a batch.
* @param argsList the list of tuple for the batch
* @param handler
* @return the createBatch
*/
public PgPreparedQuery batch(List argsList, Handler>> handler) {
delegate.batch(argsList.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;
}
/**
* Execute a batch.
* @param argsList the list of tuple for the batch
* @return
*/
public Single> rxBatch(List argsList) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
batch(argsList, fut);
}));
}
/**
* Close the prepared query and release its resources.
*/
public void close() {
delegate.close();
}
/**
* Like {@link com.julienviet.rxjava.pgclient.PgPreparedQuery#close} but notifies the completionHandler
when it's closed.
* @param completionHandler
*/
public void close(Handler> completionHandler) {
delegate.close(completionHandler);
}
/**
* Like {@link com.julienviet.rxjava.pgclient.PgPreparedQuery#close} but notifies the completionHandler
when it's closed.
* @return
*/
public Single rxClose() {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
close(fut);
}));
}
public static PgPreparedQuery newInstance(com.julienviet.pgclient.PgPreparedQuery arg) {
return arg != null ? new PgPreparedQuery(arg) : null;
}
}