Merge branch 'master' of git@github.com:jOOQ/jOOQ.git
This commit is contained in:
commit
05c4f7063a
@ -76,6 +76,7 @@ import org.jooq.Select;
|
||||
import org.jooq.SelectQuery;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.UpdatableRecord;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.InvalidResultException;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.test.BaseTest;
|
||||
@ -1775,4 +1776,37 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchWithMaxRows() throws Exception {
|
||||
Result<B> books =
|
||||
create().selectFrom(TBook())
|
||||
.orderBy(TBook_ID())
|
||||
.maxRows(2)
|
||||
.fetch();
|
||||
|
||||
assertEquals(2, books.size());
|
||||
assertEquals(Arrays.asList(1, 2), books.getValues(TBook_ID()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchWithTimeout() throws Exception {
|
||||
try {
|
||||
|
||||
// [#1856] The below query is *likely* to run into a timeout
|
||||
create().selectOne()
|
||||
.from(
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook(),
|
||||
TBook(), TBook(), TBook(), TBook())
|
||||
.queryTimeout(1)
|
||||
.fetch();
|
||||
fail();
|
||||
}
|
||||
catch (DataAccessException expected) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -837,6 +837,16 @@ public abstract class jOOQAbstractTest<
|
||||
new FetchTests(this).testFetchGroupsPOJO();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchWithMaxRows() throws Exception {
|
||||
new FetchTests(this).testFetchWithMaxRows();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchWithTimeout() throws Exception {
|
||||
new FetchTests(this).testFetchWithTimeout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDAOMethods() throws Exception {
|
||||
new DaoTests(this).testDAOMethods();
|
||||
|
||||
@ -191,4 +191,15 @@ public interface Query extends QueryPart, Attachable {
|
||||
*/
|
||||
Query bind(int index, Object value) throws IllegalArgumentException, DataTypeException;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// JDBC methods
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Specify the query timeout for the underlying JDBC {@link Statement}
|
||||
*
|
||||
* @see Statement#setQueryTimeout(int)
|
||||
*/
|
||||
Query queryTimeout(int timeout);
|
||||
|
||||
}
|
||||
|
||||
@ -880,4 +880,26 @@ public interface ResultQuery<R extends Record> extends Query {
|
||||
@Override
|
||||
ResultQuery<R> bind(int index, Object value) throws IllegalArgumentException, DataTypeException;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// JDBC methods
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
ResultQuery<R> queryTimeout(int timeout);
|
||||
|
||||
/**
|
||||
* Specify the maximum number of rows returned by the underlying
|
||||
* {@link Statement}
|
||||
* <p>
|
||||
* This is not the same as setting a <code>LIMIT .. OFFSET</code> clause
|
||||
* onto the statement, where the result set is restricted within the
|
||||
* database.
|
||||
*
|
||||
* @see Statement#setMaxRows(int)
|
||||
*/
|
||||
ResultQuery<R> maxRows(int rows);
|
||||
|
||||
}
|
||||
|
||||
@ -84,6 +84,16 @@ abstract class AbstractDelegatingSelect<R extends Record>
|
||||
return getDelegate().bind(index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> queryTimeout(int timeout) {
|
||||
return getDelegate().queryTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> maxRows(int rows) {
|
||||
return getDelegate().maxRows(rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<? extends R> getRecordType() {
|
||||
return getDelegate().getRecordType();
|
||||
|
||||
@ -62,6 +62,7 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractQuery.class);
|
||||
|
||||
private Configuration configuration;
|
||||
private int timeout;
|
||||
|
||||
AbstractQuery(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
@ -130,6 +131,17 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override this for covariant result types
|
||||
* <p>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Query queryTimeout(int t) {
|
||||
this.timeout = t;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public final int execute() {
|
||||
@ -160,6 +172,12 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
|
||||
|
||||
listener.prepareStart(ctx);
|
||||
prepare(ctx);
|
||||
|
||||
// [#1856] Set the query timeout onto the Statement
|
||||
if (timeout != 0) {
|
||||
ctx.statement().setQueryTimeout(timeout);
|
||||
}
|
||||
|
||||
listener.prepareEnd(ctx);
|
||||
|
||||
// [#1145] Bind variables only for true prepared statements
|
||||
|
||||
@ -88,6 +88,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
private static final long serialVersionUID = -5588344253566055707L;
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractResultQuery.class);
|
||||
|
||||
private int maxRows;
|
||||
private transient boolean lazy;
|
||||
private transient int size;
|
||||
private transient boolean many;
|
||||
@ -116,6 +117,18 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
return (ResultQuery<R>) super.bind(index, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final ResultQuery<R> queryTimeout(int timeout) {
|
||||
return (ResultQuery<R>) super.queryTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> maxRows(int rows) {
|
||||
this.maxRows = rows;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void prepare(ExecuteContext ctx) throws SQLException {
|
||||
|
||||
@ -138,6 +151,11 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
|
||||
ctx.statement().setFetchSize(size);
|
||||
}
|
||||
|
||||
// [#1854] Set the max number of rows for this result query
|
||||
if (maxRows != 0) {
|
||||
ctx.statement().setMaxRows(maxRows);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -301,6 +301,7 @@ public abstract class AbstractRoutine<T> extends AbstractSchemaProviderQueryPart
|
||||
|
||||
listener.prepareStart(ctx);
|
||||
ctx.statement(connection.prepareCall(ctx.sql()));
|
||||
// [#1856] TODO: Add Statement flags like timeout here
|
||||
listener.prepareEnd(ctx);
|
||||
|
||||
listener.bindStart(ctx);
|
||||
|
||||
@ -92,6 +92,11 @@ class DeleteImpl<R extends Record>
|
||||
return getDelegate().bind(index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Query queryTimeout(int timeout) {
|
||||
return getDelegate().queryTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DeleteImpl<R> where(Condition... conditions) {
|
||||
getDelegate().addConditions(conditions);
|
||||
|
||||
@ -110,6 +110,11 @@ class InsertImpl<R extends Record>
|
||||
return getDelegate().bind(index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Query queryTimeout(int timeout) {
|
||||
return getDelegate().queryTimeout(timeout);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The DSL API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -97,6 +97,11 @@ final class UpdateImpl<R extends Record>
|
||||
return getDelegate().bind(index, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Query queryTimeout(int timeout) {
|
||||
return getDelegate().queryTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> UpdateImpl<R> set(Field<T> field, T value) {
|
||||
getDelegate().addValue(field, value);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user