Skip to content

Commit

Permalink
[#7659] Support any Number type for LIMIT .. OFFSET
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jul 10, 2018
1 parent 3f76c48 commit af0d8e1
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 44 deletions.
12 changes: 11 additions & 1 deletion jOOQ/src/main/java/org/jooq/SelectLimitAfterOffsetStep.java
Expand Up @@ -130,6 +130,16 @@ public interface SelectLimitAfterOffsetStep<R extends Record> extends SelectForU
@Support @Support
SelectLimitPercentAfterOffsetStep<R> limit(int numberOfRows); SelectLimitPercentAfterOffsetStep<R> limit(int numberOfRows);


/**
* Add a <code>LIMIT</code> clause to the query
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, this may be emulated with a <code>ROW_NUMBER()</code> window
* function and nested <code>SELECT</code> statements.
*/
@Support
SelectLimitPercentAfterOffsetStep<R> limit(Number numberOfRows);

/** /**
* Add a <code>LIMIT</code> clause to the query using named parameters * Add a <code>LIMIT</code> clause to the query using named parameters
* <p> * <p>
Expand All @@ -143,6 +153,6 @@ public interface SelectLimitAfterOffsetStep<R extends Record> extends SelectForU
* statements. * statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentAfterOffsetStep<R> limit(Param<Integer> numberOfRows); SelectLimitPercentAfterOffsetStep<R> limit(Param<? extends Number> numberOfRows);


} }
74 changes: 71 additions & 3 deletions jOOQ/src/main/java/org/jooq/SelectLimitStep.java
Expand Up @@ -134,6 +134,19 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
@Support @Support
SelectLimitPercentStep<R> limit(int numberOfRows); SelectLimitPercentStep<R> limit(int numberOfRows);


/**
* Add a <code>LIMIT</code> clause to the query
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, this may be emulated with a <code>ROW_NUMBER()</code> window
* function and nested <code>SELECT</code> statements.
* <p>
* This is the same as calling {@link #limit(int, int)} with offset = 0, or
* calling <code>.limit(numberOfRows).offset(0)</code>
*/
@Support
SelectLimitPercentStep<R> limit(Number numberOfRows);

/** /**
* Add a <code>LIMIT</code> clause to the query using named parameters * Add a <code>LIMIT</code> clause to the query using named parameters
* <p> * <p>
Expand All @@ -150,7 +163,7 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
* calling <code>.limit(numberOfRows).offset(0)</code> * calling <code>.limit(numberOfRows).offset(0)</code>
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentStep<R> limit(Param<Integer> numberOfRows); SelectLimitPercentStep<R> limit(Param<? extends Number> numberOfRows);


/** /**
* Add a <code>LIMIT</code> clause to the query * Add a <code>LIMIT</code> clause to the query
Expand All @@ -166,6 +179,20 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectWithTiesAfterOffsetStep<R> limit(int offset, int numberOfRows); SelectWithTiesAfterOffsetStep<R> limit(int offset, int numberOfRows);


/**
* Add a <code>LIMIT</code> clause to the query
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or if your RDBMS does not natively support offsets, this is
* emulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectWithTiesAfterOffsetStep<R> limit(Number offset, Number numberOfRows);

/** /**
* Add a <code>LIMIT</code> clause to the query using named parameters * Add a <code>LIMIT</code> clause to the query using named parameters
* <p> * <p>
Expand All @@ -181,6 +208,21 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentAfterOffsetStep<R> limit(int offset, Param<Integer> numberOfRows); SelectLimitPercentAfterOffsetStep<R> limit(int offset, Param<Integer> numberOfRows);


/**
* Add a <code>LIMIT</code> clause to the query using named parameters
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or the <code>LIMIT</code> or <code>TOP</code> clause does not
* support bind values, or if your RDBMS does not natively support offsets,
* this may be emulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentAfterOffsetStep<R> limit(Number offset, Param<? extends Number> numberOfRows);

/** /**
* Add a <code>LIMIT</code> clause to the query using named parameters * Add a <code>LIMIT</code> clause to the query using named parameters
* <p> * <p>
Expand Down Expand Up @@ -209,7 +251,22 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
* and nested <code>SELECT</code> statements. * and nested <code>SELECT</code> statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentAfterOffsetStep<R> limit(Param<Integer> offset, Param<Integer> numberOfRows); SelectLimitPercentAfterOffsetStep<R> limit(Param<? extends Number> offset, Number numberOfRows);

/**
* Add a <code>LIMIT</code> clause to the query using named parameters
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or the <code>LIMIT</code> or <code>TOP</code> clause does not
* support bind values, or if your RDBMS does not natively support offsets,
* this may be emulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitPercentAfterOffsetStep<R> limit(Param<? extends Number> offset, Param<? extends Number> numberOfRows);


/** /**
* Add an <code>OFFSET</code> clause to the query * Add an <code>OFFSET</code> clause to the query
Expand All @@ -222,6 +279,17 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitAfterOffsetStep<R> offset(int offset); SelectLimitAfterOffsetStep<R> offset(int offset);


/**
* Add an <code>OFFSET</code> clause to the query
* <p>
* If there is no <code>LIMIT .. OFFSET</code> or <code>TOP</code> clause in
* your RDBMS, or if your RDBMS does not natively support offsets, this is
* emulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitAfterOffsetStep<R> offset(Number offset);

/** /**
* Add an <code>OFFSET</code> clause to the query using a named parameter * Add an <code>OFFSET</code> clause to the query using a named parameter
* <p> * <p>
Expand All @@ -231,5 +299,5 @@ public interface SelectLimitStep<R extends Record> extends SelectForUpdateStep<R
* <code>SELECT</code> statements. * <code>SELECT</code> statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectLimitAfterOffsetStep<R> offset(Param<Integer> offset); SelectLimitAfterOffsetStep<R> offset(Param<? extends Number> offset);
} }
13 changes: 12 additions & 1 deletion jOOQ/src/main/java/org/jooq/SelectOffsetStep.java
Expand Up @@ -132,6 +132,17 @@ public interface SelectOffsetStep<R extends Record> extends SelectForUpdateStep<
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectForUpdateStep<R> offset(int offset); SelectForUpdateStep<R> offset(int offset);


/**
* Add an <code>OFFSET</code> clause to the query.
* <p>
* If there is no <code>LIMIT .. OFFSET</code> or <code>TOP</code> clause in
* your RDBMS, or if your RDBMS does not natively support offsets, this is
* emulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectForUpdateStep<R> offset(Number offset);

/** /**
* Add an <code>OFFSET</code> clause to the query using a named parameter. * Add an <code>OFFSET</code> clause to the query using a named parameter.
* <p> * <p>
Expand All @@ -141,5 +152,5 @@ public interface SelectOffsetStep<R extends Record> extends SelectForUpdateStep<
* <code>SELECT</code> statements. * <code>SELECT</code> statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectForUpdateStep<R> offset(Param<Integer> offset); SelectForUpdateStep<R> offset(Param<? extends Number> offset);
} }
80 changes: 77 additions & 3 deletions jOOQ/src/main/java/org/jooq/SelectQuery.java
Expand Up @@ -606,6 +606,17 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addOffset(int offset); void addOffset(int offset);


/**
* Add an <code>OFFSET</code> clause to the query.
* <p>
* If there is no <code>LIMIT .. OFFSET</code> or <code>TOP</code> clause in
* your RDBMS, or if your RDBMS does not natively support offsets, this is
* emulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addOffset(Number offset);

/** /**
* Add an <code>OFFSET</code> clause to the query using a named parameter. * Add an <code>OFFSET</code> clause to the query using a named parameter.
* <p> * <p>
Expand All @@ -615,7 +626,7 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
* <code>SELECT</code> statements. * <code>SELECT</code> statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addOffset(Param<Integer> offset); void addOffset(Param<? extends Number> offset);


/** /**
* Limit the results of this select. * Limit the results of this select.
Expand All @@ -627,6 +638,16 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
@Support @Support
void addLimit(int numberOfRows); void addLimit(int numberOfRows);


/**
* Limit the results of this select.
* <p>
* This is the same as calling {@link #addLimit(int, int)} with offset = 0
*
* @param numberOfRows The number of rows to return
*/
@Support
void addLimit(Number numberOfRows);

/** /**
* Limit the results of this select using named parameters. * Limit the results of this select using named parameters.
* <p> * <p>
Expand All @@ -644,7 +665,7 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
* @param numberOfRows The number of rows to return * @param numberOfRows The number of rows to return
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Param<Integer> numberOfRows); void addLimit(Param<? extends Number> numberOfRows);


/** /**
* Limit the results of this select. * Limit the results of this select.
Expand All @@ -663,6 +684,23 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(int offset, int numberOfRows); void addLimit(int offset, int numberOfRows);


/**
* Limit the results of this select.
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or if your RDBMS does not natively support offsets, this is
* emulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Number offset, Number numberOfRows);

/** /**
* Limit the results of this select. * Limit the results of this select.
* <p> * <p>
Expand All @@ -681,6 +719,24 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Param<Integer> offset, int numberOfRows); void addLimit(Param<Integer> offset, int numberOfRows);


/**
* Limit the results of this select.
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or the <code>LIMIT</code> or <code>TOP</code> clause does not
* support bind values, or if your RDBMS does not natively support offsets,
* this may be emulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Param<? extends Number> offset, Number numberOfRows);

/** /**
* Limit the results of this select using named parameters. * Limit the results of this select using named parameters.
* <p> * <p>
Expand Down Expand Up @@ -715,7 +771,25 @@ public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvi
* @param numberOfRows The number of rows to return * @param numberOfRows The number of rows to return
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Param<Integer> offset, Param<Integer> numberOfRows); void addLimit(Number offset, Param<? extends Number> numberOfRows);

/**
* Limit the results of this select using named parameters.
* <p>
* Note that some dialects do not support bind values at all in
* <code>LIMIT</code> or <code>TOP</code> clauses!
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, or the <code>LIMIT</code> or <code>TOP</code> clause does not
* support bind values, or if your RDBMS does not natively support offsets,
* this may be emulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
void addLimit(Param<? extends Number> offset, Param<? extends Number> numberOfRows);






Expand Down
12 changes: 11 additions & 1 deletion jOOQ/src/main/java/org/jooq/SelectSeekLimitStep.java
Expand Up @@ -127,6 +127,16 @@ public interface SelectSeekLimitStep<R extends Record> extends SelectForUpdateSt
@Support @Support
SelectForUpdateStep<R> limit(int numberOfRows); SelectForUpdateStep<R> limit(int numberOfRows);


/**
* Add a <code>LIMIT</code> clause to the query.
* <p>
* If there is no <code>LIMIT</code> or <code>TOP</code> clause in your
* RDBMS, this may be emulated with a <code>ROW_NUMBER()</code> window
* function and nested <code>SELECT</code> statements.
*/
@Support
SelectForUpdateStep<R> limit(Number numberOfRows);

/** /**
* Add a <code>LIMIT</code> clause to the query using named parameters. * Add a <code>LIMIT</code> clause to the query using named parameters.
* <p> * <p>
Expand All @@ -140,6 +150,6 @@ public interface SelectSeekLimitStep<R extends Record> extends SelectForUpdateSt
* statements. * statements.
*/ */
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
SelectForUpdateStep<R> limit(Param<Integer> numberOfRows); SelectForUpdateStep<R> limit(Param<? extends Number> numberOfRows);


} }

0 comments on commit af0d8e1

Please sign in to comment.