io.reactiverse.pgclient.impl.PgPreparedQueryImpl 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 (C) 2017 Julien Viet
*
* Licensed 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.pgclient.impl;
import io.reactiverse.pgclient.*;
import io.vertx.core.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collector;
/**
* @author Julien Viet
*/
class PgPreparedQueryImpl implements PgPreparedQuery {
private final Connection conn;
private final Context context;
private final PreparedStatement ps;
private final AtomicBoolean closed = new AtomicBoolean();
PgPreparedQueryImpl(Connection conn, Context context, PreparedStatement ps) {
this.conn = conn;
this.context = context;
this.ps = ps;
}
@Override
public PgPreparedQuery execute(Tuple args, Handler> handler) {
return execute(args, false, PgRowSetImpl.FACTORY, PgRowSetImpl.COLLECTOR, handler);
}
@Override
public PgPreparedQuery execute(Tuple args, Collector collector, Handler>> handler) {
return execute(args, true, PgResultImpl::new, collector, handler);
}
private , R3 extends PgResult> PgPreparedQuery execute(
Tuple args,
boolean singleton,
Function factory,
Collector collector,
Handler> handler) {
PgResultBuilder b = new PgResultBuilder<>(factory, handler);
return execute(args, 0, null, false, singleton, collector, b, b);
}
PgPreparedQuery execute(Tuple args,
int fetch,
String portal,
boolean suspended,
boolean singleton,
Collector collector,
QueryResultHandler resultHandler,
Handler> handler) {
if (context == Vertx.currentContext()) {
String msg = ps.prepare((List