Search in sources :

Example 1 with MockResultSet

use of org.jooq.tools.jdbc.MockResultSet in project jOOQ by jOOQ.

the class AbstractResultQuery method execute.

@Override
protected final int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException {
    listener.executeStart(ctx);
    // [#4511] [#4753] PostgreSQL doesn't like fetchSize with autoCommit == true
    int f = SettingsTools.getFetchSize(fetchSize, ctx.settings());
    if (REPORT_FETCH_SIZE_WITH_AUTOCOMMIT.contains(ctx.dialect()) && f != 0 && ctx.connection().getAutoCommit())
        log.info("Fetch Size", "A fetch size of " + f + " was set on a auto-commit PostgreSQL connection, which is not recommended. See http://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor");
    SQLException e = executeStatementAndGetFirstResultSet(ctx, rendered.skipUpdateCounts);
    listener.executeEnd(ctx);
    // Fetch a single result set
    notManyIf: if (!many) {
        // and that exception is not thrown because of Settings.throwExceptions == THROW_NONE, we can stop
        if (e != null)
            break notManyIf;
        // not a result set.
        if (ctx.resultSet() == null) {
            DSLContext dsl = DSL.using(ctx.configuration());
            Field<Integer> c = DSL.field(name("UPDATE_COUNT"), int.class);
            Result<Record1<Integer>> r = dsl.newResult(c);
            r.add(dsl.newRecord(c).values(ctx.rows()));
            ctx.resultSet(new MockResultSet(r));
        }
        Field<?>[] fields = getFields(ctx.resultSet().getMetaData());
        cursor = new CursorImpl<>(ctx, listener, fields, intern.internIndexes(fields), keepStatement(), keepResultSet(), getRecordType(), SettingsTools.getMaxRows(maxRows, ctx.settings()), autoclosing);
        if (!lazy) {
            result = cursor.fetch();
            cursor = null;
        }
    } else // Fetch several result sets
    {
        results = new ResultsImpl(ctx.configuration());
        consumeResultSets(ctx, listener, results, intern, e);
    }
    return result != null ? result.size() : 0;
}
Also used : Field(org.jooq.Field) SQLException(java.sql.SQLException) DSLContext(org.jooq.DSLContext) MockResultSet(org.jooq.tools.jdbc.MockResultSet) Result(org.jooq.Result)

Aggregations

SQLException (java.sql.SQLException)1 DSLContext (org.jooq.DSLContext)1 Field (org.jooq.Field)1 Result (org.jooq.Result)1 MockResultSet (org.jooq.tools.jdbc.MockResultSet)1