1
1
/**
2
- * Copyright 2009-2018 the original author or authors.
2
+ * Copyright 2009-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -262,6 +262,54 @@ public T ORDER_BY(String... columns) {
262
262
return getSelf ();
263
263
}
264
264
265
+ /**
266
+ * Set the limit variable string(e.g. {@code "#{limit}"}).
267
+ *
268
+ * @param variable a limit variable string
269
+ * @return a self instance
270
+ * @since 3.5.2
271
+ */
272
+ public T LIMIT (String variable ) {
273
+ sql ().limit = variable ;
274
+ return getSelf ();
275
+ }
276
+
277
+ /**
278
+ * Set the limit value.
279
+ *
280
+ * @param value an offset value
281
+ * @return a self instance
282
+ * @since 3.5.2
283
+ */
284
+ public T LIMIT (int value ) {
285
+ sql ().limit = String .valueOf (value );
286
+ return getSelf ();
287
+ }
288
+
289
+ /**
290
+ * Set the offset variable string(e.g. {@code "#{offset}"}).
291
+ *
292
+ * @param variable a offset variable string
293
+ * @return a self instance
294
+ * @since 3.5.2
295
+ */
296
+ public T OFFSET (String variable ) {
297
+ sql ().offset = variable ;
298
+ return getSelf ();
299
+ }
300
+
301
+ /**
302
+ * Set the offset value.
303
+ *
304
+ * @param value an offset value
305
+ * @return a self instance
306
+ * @since 3.5.2
307
+ */
308
+ public T OFFSET (long value ) {
309
+ sql ().offset = String .valueOf (value );
310
+ return getSelf ();
311
+ }
312
+
265
313
private SQLStatement sql () {
266
314
return sql ;
267
315
}
@@ -328,6 +376,8 @@ public enum StatementType {
328
376
List <String > columns = new ArrayList <>();
329
377
List <String > values = new ArrayList <>();
330
378
boolean distinct ;
379
+ String offset ;
380
+ String limit ;
331
381
332
382
public SQLStatement () {
333
383
// Prevent Synthetic Access
@@ -368,6 +418,12 @@ private String selectSQL(SafeAppendable builder) {
368
418
sqlClause (builder , "GROUP BY" , groupBy , "" , "" , ", " );
369
419
sqlClause (builder , "HAVING" , having , "(" , ")" , " AND " );
370
420
sqlClause (builder , "ORDER BY" , orderBy , "" , "" , ", " );
421
+ if (limit != null ) {
422
+ builder .append (" LIMIT " ).append (limit );
423
+ }
424
+ if (offset != null ) {
425
+ builder .append (" OFFSET " ).append (offset );
426
+ }
371
427
return builder .toString ();
372
428
}
373
429
@@ -389,6 +445,9 @@ private String insertSQL(SafeAppendable builder) {
389
445
private String deleteSQL (SafeAppendable builder ) {
390
446
sqlClause (builder , "DELETE FROM" , tables , "" , "" , "" );
391
447
sqlClause (builder , "WHERE" , where , "(" , ")" , " AND " );
448
+ if (limit != null ) {
449
+ builder .append (" LIMIT " ).append (limit );
450
+ }
392
451
return builder .toString ();
393
452
}
394
453
@@ -397,6 +456,9 @@ private String updateSQL(SafeAppendable builder) {
397
456
joins (builder );
398
457
sqlClause (builder , "SET" , sets , "" , "" , ", " );
399
458
sqlClause (builder , "WHERE" , where , "(" , ")" , " AND " );
459
+ if (limit != null ) {
460
+ builder .append (" LIMIT " ).append (limit );
461
+ }
400
462
return builder .toString ();
401
463
}
402
464
0 commit comments