1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.select;
17
18 import java.util.Optional;
19
20 import org.jspecify.annotations.Nullable;
21
22 public class PagingModel {
23
24 private final @Nullable Long limit;
25 private final @Nullable Long offset;
26 private final @Nullable Long fetchFirstRows;
27
28 private PagingModel(Builder builder) {
29 super();
30 limit = builder.limit;
31 offset = builder.offset;
32 fetchFirstRows = builder.fetchFirstRows;
33 }
34
35 public Optional<Long> limit() {
36 return Optional.ofNullable(limit);
37 }
38
39 public Optional<Long> offset() {
40 return Optional.ofNullable(offset);
41 }
42
43 public Optional<Long> fetchFirstRows() {
44 return Optional.ofNullable(fetchFirstRows);
45 }
46
47 public static class Builder {
48 private @Nullable Long limit;
49 private @Nullable Long offset;
50 private @Nullable Long fetchFirstRows;
51
52 public Builder withLimit(@Nullable Long limit) {
53 this.limit = limit;
54 return this;
55 }
56
57 public Builder withOffset(@Nullable Long offset) {
58 this.offset = offset;
59 return this;
60 }
61
62 public Builder withFetchFirstRows(@Nullable Long fetchFirstRows) {
63 this.fetchFirstRows = fetchFirstRows;
64 return this;
65 }
66
67 public Optional<PagingModel> build() {
68 if (limit == null && offset == null && fetchFirstRows == null) {
69 return Optional.empty();
70 }
71
72 return Optional.of(new PagingModel(this));
73 }
74 }
75 }