use of org.davidmoten.rx.jdbc.callable.internal.ParameterPlaceholder in project rxjava2-jdbc by davidmoten.
the class Call method execute.
private static List<PlaceAndType> execute(NamedCallableStatement stmt, List<Object> parameters, List<ParameterPlaceholder> parameterPlaceholders, int outCount, CallableStatement st) throws SQLException {
Util.incrementCounter(st.getConnection());
setParameters(st, parameters, parameterPlaceholders, stmt.names);
int initialSize = outCount == Integer.MAX_VALUE ? 16 : outCount;
List<PlaceAndType> outs = new ArrayList<PlaceAndType>(initialSize);
for (int j = 0; j < parameterPlaceholders.size(); j++) {
ParameterPlaceholder p = parameterPlaceholders.get(j);
if (p instanceof OutParameterPlaceholder) {
outs.add(new PlaceAndType(j + 1, ((OutParameterPlaceholder) p).type()));
if (outs.size() == outCount) {
break;
}
}
}
st.execute();
return outs;
}
use of org.davidmoten.rx.jdbc.callable.internal.ParameterPlaceholder in project rxjava2-jdbc by davidmoten.
the class Call method createWithNResultSets.
private static Flowable<Notification<CallableResultSetN>> createWithNResultSets(Connection con, String sql, Flowable<List<Object>> parameterGroups, List<ParameterPlaceholder> parameterPlaceholders, List<Function<? super ResultSet, ?>> functions, int fetchSize) {
Callable<NamedCallableStatement> resourceFactory = () -> Util.prepareCall(con, sql, parameterPlaceholders);
final //
Function<NamedCallableStatement, Flowable<Notification<CallableResultSetN>>> flowableFactory = stmt -> //
parameterGroups.flatMap(parameters -> {
List<Object> outputValues = executeAndReturnOutputValues(parameterPlaceholders, stmt, parameters);
List<Flowable<?>> flowables = Lists.newArrayList();
int i = 0;
do {
Function<? super ResultSet, ?> f = functions.get(i);
flowables.add(createFlowable(stmt, f));
i++;
} while (stmt.stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
return Single.just(new CallableResultSetN(outputValues, flowables)).toFlowable();
}).materialize().doOnComplete(//
() -> Util.commit(stmt.stmt)).doOnError(e -> Util.rollback(stmt.stmt));
Consumer<NamedCallableStatement> disposer = Util::closeCallableStatementAndConnection;
return Flowable.using(resourceFactory, flowableFactory, disposer, true);
}
use of org.davidmoten.rx.jdbc.callable.internal.ParameterPlaceholder in project rxjava2-jdbc by davidmoten.
the class Call method setParameters.
static PreparedStatement setParameters(PreparedStatement ps, List<Object> parameters, List<ParameterPlaceholder> parameterPlaceholders, List<String> names) throws SQLException {
// TODO handle Parameter objects (named)
if (names.isEmpty()) {
int i = 0;
for (int j = 0; j < parameterPlaceholders.size() && i < parameters.size(); j++) {
ParameterPlaceholder p = parameterPlaceholders.get(j);
if (p instanceof InParameterPlaceholder) {
Util.setParameter(ps, j + 1, parameters.get(i));
i++;
}
}
} else {
// TODO
throw new RuntimeException("named paramters not implemented yet for CallableStatement yet");
// Util.setNamedParameters(ps, params, names);
}
return ps;
}
Aggregations