1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package edu.internet2.middleware.grouper.internal.dao;
21
22 import org.apache.commons.lang.StringUtils;
23
24 import edu.internet2.middleware.grouper.util.GrouperUtil;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class QueryOptions {
53
54
55
56
57
58
59
60 public static boolean needsCountQuery(QueryOptions queryOptions, int maxResults) {
61
62 if (queryOptions == null) {
63 return true;
64 }
65
66 QueryPaging queryPaging = queryOptions.getQueryPaging();
67 if (queryPaging == null) {
68 return true;
69 }
70
71 return queryPaging.getPageSize() > maxResults;
72 }
73
74
75
76
77
78 public static void initTotalCount(QueryOptions queryOptions) {
79 if (queryOptions == null) {
80 return;
81 }
82 if (queryOptions.getQueryPaging() != null && queryOptions.getQueryPaging().isDoTotalCount()) {
83 queryOptions.getQueryPaging().setTotalRecordCount(0);
84 }
85 if (queryOptions.isRetrieveCount()) {
86 queryOptions.setCount(0L);
87 }
88 }
89
90
91
92
93 public QueryOptions() {
94
95 }
96
97
98
99
100
101
102
103
104
105 public static QueryOptions create(String sortString, Boolean ascending, Integer pageNumber, Integer pageSize) {
106 QueryOptions queryOptions = null;
107
108 if (ascending != null || !StringUtils.isBlank(sortString)
109 || pageNumber != null || pageSize != null) {
110
111 queryOptions = new QueryOptions();
112
113 if (ascending != null || !StringUtils.isBlank(sortString)) {
114
115 QuerySortuper/internal/dao/QuerySort.html#QuerySort">QuerySort querySort = new QuerySort(sortString, GrouperUtil.defaultIfNull(ascending, Boolean.TRUE));
116 queryOptions.sort(querySort);
117
118 }
119
120 if (pageNumber != null || pageSize != null) {
121
122 QueryPaging/internal/dao/QueryPaging.html#QueryPaging">QueryPaging queryPaging = new QueryPaging();
123 queryPaging.setPageNumber(pageNumber);
124 queryPaging.setPageSize(pageSize);
125 queryOptions.paging(queryPaging);
126 }
127
128 }
129 return queryOptions;
130 }
131
132
133
134
135 private QuerySort querySort;
136
137
138
139
140 private QueryPaging queryPaging;
141
142
143
144
145
146 private Boolean retrieveResults;
147
148
149
150
151
152
153 private Boolean retrieveCount;
154
155
156
157
158 private Boolean secondLevelCache;
159
160
161
162
163 private String secondLevelCacheRegion;
164
165
166
167
168
169
170 public QueryOptions secondLevelCache(boolean secondLevelCache1) {
171 this.secondLevelCache = secondLevelCache1;
172 return this;
173 }
174
175
176
177
178
179 public Boolean getSecondLevelCache() {
180 return this.secondLevelCache;
181 }
182
183
184
185
186
187
188 public QueryOptions secondLevelCacheRegion(String secondLevelCacheRegion1) {
189 this.secondLevelCacheRegion = secondLevelCacheRegion1;
190 return this;
191 }
192
193
194
195
196
197 public String getSecondLevelCacheRegion() {
198 return this.secondLevelCacheRegion;
199 }
200
201
202
203
204
205 private Long count = null;
206
207
208
209
210
211 @Override
212 public String toString() {
213 StringBuilder result = new StringBuilder("QueryOptions: ");
214 if (this.queryPaging != null) {
215 result.append("queryPaging: ").append(queryPaging.toString()).append(", ");
216 }
217 if (this.querySort != null) {
218 result.append("querySort: ").append(querySort.sortString(false)).append(", ");
219 }
220 if (this.secondLevelCache != null) {
221 result.append("secondLevelCache: ").append(this.getSecondLevelCache()).append(", ");
222 }
223 if (this.retrieveResults != null) {
224 result.append("retrieveResults: ").append(this.retrieveResults).append(", ");
225 }
226 if (this.retrieveCount != null) {
227 result.append("retrieveCount: ").append(retrieveCount).append(", ");
228 }
229 if (this.count != null) {
230 result.append("count: ").append(this.count).append(", ");
231 }
232 return result.toString();
233 }
234
235
236
237
238
239 public QuerySort getQuerySort() {
240 return this.querySort;
241 }
242
243
244
245
246
247
248 public QueryOptions sort(QuerySort querySort1) {
249 this.querySort = querySort1;
250 return this;
251 }
252
253
254
255
256
257 public QueryPaging getQueryPaging() {
258 return this.queryPaging;
259 }
260
261
262
263
264
265
266 public QueryOptions sortAsc(String field) {
267 if (this.querySort == null) {
268 this.querySort = new QuerySort(field, true);
269 } else {
270 this.querySort.insertSortToBeginning(field, true);
271 }
272 return this;
273 }
274
275
276
277
278
279
280
281
282 public QueryOptions paging(int pageSize, int pageNumber, boolean doTotalCount) {
283 this.queryPaging = QueryPaging.page(pageSize, pageNumber, doTotalCount);
284 return this;
285 }
286
287
288
289
290
291
292
293
294
295 public QueryOptions pagingCursor(int pageSize, Object lastCursorField, boolean cursorFieldIncludesLastRetrieved, boolean doTotalCount) {
296 this.queryPaging = QueryPaging.pageCursor(pageSize, lastCursorField, cursorFieldIncludesLastRetrieved, doTotalCount);
297 return this;
298 }
299
300
301
302
303
304
305 public QueryOptions sortDesc(String field) {
306 if (this.querySort == null) {
307 this.querySort = new QuerySort(field, false);
308 } else {
309 this.querySort.insertSortToBeginning(field, false);
310 }
311 return this;
312 }
313
314
315
316
317
318
319 public QueryOptions paging(QueryPaging queryPaging1) {
320 this.queryPaging = queryPaging1;
321 return this;
322 }
323
324
325
326
327
328
329 public boolean isRetrieveResults() {
330 return this.retrieveResults == null ? true : this.retrieveResults;
331 }
332
333
334
335
336
337
338
339 public QueryOptions retrieveResults(boolean retrieveResults1) {
340 this.retrieveResults = retrieveResults1;
341 return this;
342 }
343
344
345
346
347
348
349
350 public boolean isRetrieveCount() {
351 return this.retrieveCount == null ? false : this.retrieveCount;
352 }
353
354
355
356
357
358
359
360
361 public QueryOptions retrieveCount(boolean retrieveCount1) {
362 this.retrieveCount = retrieveCount1;
363 return this;
364 }
365
366
367
368
369
370
371 public Long getCount() {
372 return this.count;
373 }
374
375
376
377
378
379
380 public void setCount(Long count1) {
381 this.count = count1;
382 }
383
384 }