[#1219] API Bug: Cannot use LIMIT .. OFFSET along with FOR UPDATE

This commit is contained in:
Lukas Eder 2012-03-06 19:07:18 +00:00
parent 9ece8fc8b9
commit 23b92034cd
8 changed files with 62 additions and 26 deletions

View File

@ -489,7 +489,7 @@ extends BaseTest<A, B, S, B2S, BS, L, X, DATE, D, T, U, I, IPK, T658, T725, T639
assertEquals(sequence, schema.getSequence(sequence.getName()));
}
int tables = 18;
int tables = 17;
// The additional T_DIRECTORY table for recursive queries
if (supportsRecursiveQueries()) {
@ -545,7 +545,7 @@ extends BaseTest<A, B, S, B2S, BS, L, X, DATE, D, T, U, I, IPK, T658, T725, T639
// [#610] Collision-prone entities are only available in HSQLDB
else if (getDialect() == HSQLDB) {
assertEquals(tables + 11, schema.getTables().size());
assertEquals(tables + 12, schema.getTables().size());
}
else {

View File

@ -345,10 +345,34 @@ extends BaseTest<A, B, S, B2S, BS, L, X, DATE, D, T, U, I, IPK, T658, T725, T639
.fetch();
assertEquals(2, result.size());
Result<A> result2 = create().selectFrom(TAuthor())
.forUpdate()
.fetch();
.forUpdate()
.fetch();
assertEquals(2, result2.size());
// Check again with limit / offset clauses
switch (getDialect()) {
case INGRES:
case ORACLE:
log.info("SKIPPING", "LIMIT .. OFFSET .. FOR UPDATE");
break;
default: {
Result<Record> result3 = create().select(TAuthor_ID())
.from(TAuthor())
.limit(5)
.offset(0)
.forUpdate()
.fetch();
assertEquals(2, result3.size());
Result<A> result4 = create().selectFrom(TAuthor())
.limit(5)
.offset(0)
.forUpdate()
.fetch();
assertEquals(2, result4.size());
}
}
switch (getDialect()) {
case ASE:
case DB2:

View File

@ -92,10 +92,16 @@ public interface SelectForUpdateStep extends SelectFinalStep {
/**
* Add a <code>FOR UPDATE</code> clause to the end of the query.
* <p>
* Note: not all SQL dialects allow for combining a <code>FOR UPDATE</code>
* clause with <code>LIMIT .. OFFSET</code>, or with <code>GROUP BY</code>.
* This essentially includes {@link SQLDialect#INGRES} and
* {@link SQLDialect#ORACLE}. These incompatibilities are not reflected by
* the jOOQ API.
*
* @see LockProvider#setForUpdate(boolean) see LockProvider for more details
*/
@Support({ASE, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SYBASE})
@Support({ ASE, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SYBASE })
SelectForUpdateOfStep forUpdate();
/**

View File

@ -57,7 +57,7 @@ import static org.jooq.SQLDialect.SYBASE;
* -- more than five books in German in the last three years
* -- (from 2011), and sort those authors by last names
* -- limiting results to the second and third row
*
*
* SELECT T_AUTHOR.FIRST_NAME, T_AUTHOR.LAST_NAME, COUNT(*)
* FROM T_AUTHOR
* JOIN T_BOOK ON T_AUTHOR.ID = T_BOOK.AUTHOR_ID
@ -86,7 +86,7 @@ import static org.jooq.SQLDialect.SYBASE;
* .of(TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
* .noWait();
* </pre></code> Refer to the manual for more details
*
*
* @author Lukas Eder
*/
public interface SelectLimitStep extends SelectForUpdateStep {
@ -134,7 +134,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectFinalStep limit(int offset, int numberOfRows);
SelectForUpdateStep limit(int offset, int numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -149,7 +149,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* and nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectFinalStep limit(int offset, Param<Integer> numberOfRows);
SelectForUpdateStep limit(int offset, Param<Integer> numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -164,7 +164,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* and nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectFinalStep limit(Param<Integer> offset, int numberOfRows);
SelectForUpdateStep limit(Param<Integer> offset, int numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -179,5 +179,5 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* and nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectFinalStep limit(Param<Integer> offset, Param<Integer> numberOfRows);
SelectForUpdateStep limit(Param<Integer> offset, Param<Integer> numberOfRows);
}

View File

@ -57,7 +57,7 @@ import static org.jooq.SQLDialect.SYBASE;
* -- more than five books in German in the last three years
* -- (from 2011), and sort those authors by last names
* -- limiting results to the second and third row
*
*
* SELECT T_AUTHOR.FIRST_NAME, T_AUTHOR.LAST_NAME, COUNT(*)
* FROM T_AUTHOR
* JOIN T_BOOK ON T_AUTHOR.ID = T_BOOK.AUTHOR_ID
@ -86,10 +86,10 @@ import static org.jooq.SQLDialect.SYBASE;
* .of(TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
* .noWait();
* </pre></code> Refer to the manual for more details
*
*
* @author Lukas Eder
*/
public interface SelectOffsetStep extends SelectFinalStep {
public interface SelectOffsetStep extends SelectForUpdateStep {
/**
* Add an <code>OFFSET</code> clause to the query
@ -99,8 +99,8 @@ public interface SelectOffsetStep extends SelectFinalStep {
* simulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE})
SelectFinalStep offset(int offset);
@Support({ DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep offset(int offset);
/**
* Add an <code>OFFSET</code> clause to the query using a named parameter
@ -110,6 +110,6 @@ public interface SelectOffsetStep extends SelectFinalStep {
* simulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE})
SelectFinalStep offset(Param<Integer> offset);
@Support({ DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep offset(Param<Integer> offset);
}

View File

@ -69,10 +69,16 @@ public interface SimpleSelectForUpdateStep<R extends Record> extends SimpleSelec
/**
* Add a <code>FOR UPDATE</code> clause to the end of the query.
* <p>
* Note: not all SQL dialects allow for combining a <code>FOR UPDATE</code>
* clause with <code>LIMIT .. OFFSET</code>, or with <code>GROUP BY</code>.
* This essentially includes {@link SQLDialect#INGRES} and
* {@link SQLDialect#ORACLE}. These incompatibilities are not reflected by
* the jOOQ API.
*
* @see LockProvider#setForUpdate(boolean) see LockProvider for more details
*/
@Support({ASE, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SYBASE})
@Support({ ASE, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SYBASE })
SimpleSelectForUpdateOfStep<R> forUpdate();
/**

View File

@ -110,7 +110,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectFinalStep<R> limit(int offset, int numberOfRows);
SimpleSelectForUpdateStep<R> limit(int offset, int numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -125,7 +125,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectFinalStep<R> limit(int offset, Param<Integer> numberOfRows);
SimpleSelectForUpdateStep<R> limit(int offset, Param<Integer> numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -140,7 +140,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectFinalStep<R> limit(Param<Integer> offset, int numberOfRows);
SimpleSelectForUpdateStep<R> limit(Param<Integer> offset, int numberOfRows);
/**
* Add a <code>LIMIT</code> clause to the query using named parameters
@ -155,5 +155,5 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* and nested <code>SELECT</code> statements.
*/
@Support({ DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectFinalStep<R> limit(Param<Integer> offset, Param<Integer> numberOfRows);
SimpleSelectForUpdateStep<R> limit(Param<Integer> offset, Param<Integer> numberOfRows);
}

View File

@ -66,7 +66,7 @@ import static org.jooq.SQLDialect.SYBASE;
* @param <R> The record type being returned by this query
* @author Lukas Eder
*/
public interface SimpleSelectOffsetStep<R extends Record> extends SimpleSelectFinalStep<R> {
public interface SimpleSelectOffsetStep<R extends Record> extends SimpleSelectForUpdateStep<R> {
/**
* Add an <code>OFFSET</code> clause to the query
@ -77,7 +77,7 @@ public interface SimpleSelectOffsetStep<R extends Record> extends SimpleSelectFi
* <code>SELECT</code> statements.
*/
@Support({DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE})
SimpleSelectFinalStep<R> offset(int offset);
SimpleSelectForUpdateStep<R> offset(int offset);
/**
* Add an <code>OFFSET</code> clause to the query using a named parameter
@ -88,5 +88,5 @@ public interface SimpleSelectOffsetStep<R extends Record> extends SimpleSelectFi
* <code>SELECT</code> statements.
*/
@Support({DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE})
SimpleSelectFinalStep<R> offset(Param<Integer> offset);
SimpleSelectForUpdateStep<R> offset(Param<Integer> offset);
}