use of org.jooq.impl.ResultsImpl.ResultOrRowsImpl in project jOOQ by jOOQ.
the class QueriesImpl method fetchMany.
// ------------------------------------------------------------------------
// Execution API
// ------------------------------------------------------------------------
@Override
public final Results fetchMany() {
Configuration c = configurationOrThrow();
ResultsImpl results = new ResultsImpl(c);
DSLContext ctx = c.dsl();
for (Query query : this) if (query instanceof ResultQuery)
results.resultsOrRows.addAll(ctx.fetchMany((ResultQuery<?>) query).resultsOrRows());
else
results.resultsOrRows.add(new ResultOrRowsImpl(ctx.execute(query)));
return results;
}
use of org.jooq.impl.ResultsImpl.ResultOrRowsImpl in project jOOQ by jOOQ.
the class Tools method consumeResultSets.
/**
* [#3681] Consume all {@link ResultSet}s from a JDBC {@link Statement}.
*/
static final void consumeResultSets(ExecuteContext ctx, ExecuteListener listener, Results results, Intern intern, SQLException prev) throws SQLException {
boolean anyResults = false;
int i;
int rows = (ctx.resultSet() == null) ? ctx.rows() : 0;
for (i = 0; i < maxConsumedResults; i++) {
try {
if (ctx.resultSet() != null) {
anyResults = true;
Field<?>[] fields = new MetaDataFieldProvider(ctx.configuration(), ctx.resultSet().getMetaData()).getFields();
Cursor<Record> c = new CursorImpl<>(ctx, listener, fields, intern != null ? intern.internIndexes(fields) : null, true, false);
results.resultsOrRows().add(new ResultOrRowsImpl(c.fetch()));
} else if (prev == null) {
if (rows != -1)
results.resultsOrRows().add(new ResultOrRowsImpl(rows));
else
break;
}
if (ctx.statement().getMoreResults()) {
ctx.resultSet(ctx.statement().getResultSet());
} else {
rows = ctx.statement().getUpdateCount();
ctx.rows(rows);
if (rows != -1)
ctx.resultSet(null);
else
break;
}
prev = null;
}// [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any
catch (SQLException e) {
prev = e;
if (ctx.settings().getThrowExceptions() == THROW_NONE) {
ctx.sqlException(e);
results.resultsOrRows().add(new ResultOrRowsImpl(Tools.translate(ctx.sql(), e)));
} else {
consumeExceptions(ctx.configuration(), ctx.statement(), e);
throw e;
}
}
}
if (i == maxConsumedResults)
log.warn("Maximum consumed results reached: " + maxConsumedResults + ". This is probably a bug. Please report to https://github.com/jOOQ/jOOQ/issues/new");
// Call this only when there was at least one ResultSet.
if (anyResults) {
ctx.statement().getMoreResults(Statement.CLOSE_ALL_RESULTS);
}
// be linked, just as if they were collected using ThrowExceptions == THROW_ALL
if (ctx.settings().getThrowExceptions() == THROW_NONE) {
SQLException s1 = null;
for (ResultOrRows r : results.resultsOrRows()) {
DataAccessException d = r.exception();
if (d != null && d.getCause() instanceof SQLException) {
SQLException s2 = (SQLException) d.getCause();
if (s1 != null)
s1.setNextException(s2);
s1 = s2;
}
}
}
}
use of org.jooq.impl.ResultsImpl.ResultOrRowsImpl in project jOOQ by jOOQ.
the class AbstractRoutine method execute0.
private final SQLException execute0(ExecuteContext ctx, ExecuteListener listener) throws SQLException {
listener.executeStart(ctx);
SQLException e = executeStatementAndGetFirstResultSet(ctx, 0);
listener.executeEnd(ctx);
if (e != null)
results.resultsOrRows().add(new ResultOrRowsImpl(Tools.translate(ctx.sql(), e)));
return e;
}
Aggregations