Skip to content

Commit 20d1758

Browse files
committed
Docs
1 parent f691cd3 commit 20d1758

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/test/java/examples/paging/LimitAndOffsetDecorator.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
import org.jspecify.annotations.NullMarked;
2222
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
2323

24+
/**
25+
* This decorator modifies the generated SQL by adding a LIMIT and OFFSET clause at the end
26+
* of the generated SQL. This can be used to create a paginated query.
27+
*
28+
* <p>LIMIT and OFFSET has limited support in relational databases, so this cannot be considered
29+
* a general solution for all paginated queries (and that is why this adapter lives only in the
30+
* test source tree and is not packaged with the core library code).
31+
*
32+
* <p>I believe it works in MySQL, HSQLDB, and Postgres.
33+
*
34+
* <p><b>Important Note: </b> this decorator is no longer required for limit and offset support as the
35+
* library now supports limit and offset natively. However, this remains a good example of altering the generated
36+
* SQL before it is executed.
37+
*
38+
* @author Jeff Butler
39+
*/
2440
@NullMarked
2541
public class LimitAndOffsetDecorator implements SelectStatementProvider {
2642
private final Map<String, Object> parameters = new HashMap<>();
@@ -31,8 +47,7 @@ public LimitAndOffsetDecorator(int limit, int offset, SelectStatementProvider de
3147
parameters.put("limit", limit);
3248
parameters.put("offset", offset);
3349

34-
selectStatement = delegate.getSelectStatement() +
35-
" LIMIT #{parameters.limit} OFFSET #{parameters.offset}";
50+
selectStatement = delegate.getSelectStatement() + " LIMIT #{parameters.limit} OFFSET #{parameters.offset}";
3651
}
3752

3853
@Override

0 commit comments

Comments
 (0)