Search in sources :

Example 1 with ResultOrRowsImpl

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;
}
Also used : Configuration(org.jooq.Configuration) IgnoreQuery(org.jooq.impl.DefaultParseContext.IgnoreQuery) ResultQuery(org.jooq.ResultQuery) Query(org.jooq.Query) ResultOrRowsImpl(org.jooq.impl.ResultsImpl.ResultOrRowsImpl) DSLContext(org.jooq.DSLContext) ResultQuery(org.jooq.ResultQuery)

Example 2 with ResultOrRowsImpl

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;
            }
        }
    }
}
Also used : TableField(org.jooq.TableField) Field(org.jooq.Field) SortField(org.jooq.SortField) OrderField(org.jooq.OrderField) SQLException(java.sql.SQLException) ResultOrRowsImpl(org.jooq.impl.ResultsImpl.ResultOrRowsImpl) UpdatableRecord(org.jooq.UpdatableRecord) QualifiedRecord(org.jooq.QualifiedRecord) Record(org.jooq.Record) EmbeddableRecord(org.jooq.EmbeddableRecord) TableRecord(org.jooq.TableRecord) ResultOrRows(org.jooq.ResultOrRows) DataAccessException(org.jooq.exception.DataAccessException)

Example 3 with ResultOrRowsImpl

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;
}
Also used : SQLException(java.sql.SQLException) ResultOrRowsImpl(org.jooq.impl.ResultsImpl.ResultOrRowsImpl)

Aggregations

ResultOrRowsImpl (org.jooq.impl.ResultsImpl.ResultOrRowsImpl)3 SQLException (java.sql.SQLException)2 Configuration (org.jooq.Configuration)1 DSLContext (org.jooq.DSLContext)1 EmbeddableRecord (org.jooq.EmbeddableRecord)1 Field (org.jooq.Field)1 OrderField (org.jooq.OrderField)1 QualifiedRecord (org.jooq.QualifiedRecord)1 Query (org.jooq.Query)1 Record (org.jooq.Record)1 ResultOrRows (org.jooq.ResultOrRows)1 ResultQuery (org.jooq.ResultQuery)1 SortField (org.jooq.SortField)1 TableField (org.jooq.TableField)1 TableRecord (org.jooq.TableRecord)1 UpdatableRecord (org.jooq.UpdatableRecord)1 DataAccessException (org.jooq.exception.DataAccessException)1 IgnoreQuery (org.jooq.impl.DefaultParseContext.IgnoreQuery)1