1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.domain

File JpaPagination.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
30
25
1
302
114
25
0.83
1.2
25
1

Classes

Class Line # Actions
JpaPagination 20 30 0% 25 0
1.0100%
 

Contributing tests

This file is covered by 44 tests. .

Source view

1    package org.europa.together.domain;
2   
3    import java.util.Date;
4    import java.util.HashMap;
5    import java.util.Map;
6   
7    /**
8    * Be always aware, when using listAll() because some database tables with a
9    * giant amount of rows will slow down your application dramatically. The
10    * JpaPagination is designed to limit your result set. It avoid a slow
11    * performing OFFSET and implement instead the seek method.
12    * <br>
13    * To secure a correct result set, the results aer by default sorted by the
14    * primary key of the database table in an ascending manner. This behavior can
15    * be changed.
16    * <br>
17    * Its necessary to define the Primary Key from the Domain Object and not from
18    * the database table name.
19    */
 
20    public class JpaPagination {
21   
22    /**
23    * Ascending sorting order of the whole result set.
24    */
25    public static final String ORDER_ASC = "ASC";
26    /**
27    * Descending sorting order of the whole result set.
28    */
29    public static final String ORDER_DESC = "DESC";
30    /**
31    * Define if the pagination goes ahead.
32    */
33    public static final String PAGING_FOREWARD = "FW";
34    /**
35    * Define if the pgination goes backwards.
36    */
37    public static final String PAGING_BACKWARD = "BW";
38   
39    private String sorting;
40    private String paging;
41    private int pageSize;
42    private String primaryKey;
43    private String pageBreak;
44    private String additionalOrdering;
45    private Map<String, String> filterStringCriteria = new HashMap<>();
46    private Map<String, Boolean> filterBooleanCriteria = new HashMap<>();
47    private Map<String, Integer> filterIntegerCriteria = new HashMap<>();
48    private Map<String, Float> filterFloatCriteria = new HashMap<>();
49    private Map<String, Date> filterDateCriteria = new HashMap<>();
50   
51    /**
52    * Default Constructor.
53    */
 
54  10 toggle public JpaPagination() {
55  10 this.pageSize = 0;
56  10 this.sorting = ORDER_ASC;
57  10 this.paging = PAGING_FOREWARD;
58    }
59   
60    /**
61    * Allow to set the PrimaryKey (PK) of the database table. Be aware, that
62    * the PK is not the colum name of the table. The PK is defined by Domain
63    * Object is used.
64    *
65    * @param primaryKey as String
66    */
 
67  47 toggle public JpaPagination(final String primaryKey) {
68  47 this.primaryKey = primaryKey;
69  47 this.pageSize = 0;
70  47 this.sorting = ORDER_ASC;
71  47 this.paging = PAGING_FOREWARD;
72    }
73   
 
74  56 toggle @Override
75    public String toString() {
76  56 return "JpaPagination{"
77    + "sorting=" + sorting
78    + ", paging=" + paging
79    + ", pageSize=" + pageSize
80    + ", primaryKey=" + primaryKey
81    + ", pageBreak=" + pageBreak
82    + ", additionalOrdering=" + additionalOrdering
83    + ", filterStringCriteria=" + this.filterStringCriteria
84    + ", filterBooleanCriteria=" + this.filterBooleanCriteria
85    + ", filterIntegerCriteria=" + this.filterIntegerCriteria
86    + ", filterFloatCriteria=" + this.filterFloatCriteria
87    + ", filterDateCriteria=" + this.filterDateCriteria
88    + '}';
89    }
90   
91    //<editor-fold defaultstate="collapsed" desc="Getter / Setter">
92    /**
93    * get the amount of elements will be placed on a page.
94    *
95    * @return pageSize as Integer
96    */
 
97  48 toggle public int getPageSize() {
98  48 return pageSize;
99    }
100   
101    /**
102    * Define the amount of elements will be placed on a page.
103    *
104    * @param limit as Integer
105    */
 
106  15 toggle public void setPageSize(final int limit) {
107  15 this.pageSize = limit;
108    }
109   
110    /**
111    * Get if the sorting is DESC or ASC.
112    *
113    * @return sorting as String
114    */
 
115  48 toggle public String getSorting() {
116  48 return sorting;
117    }
118   
119    /**
120    * Define if the sorting is DESC or ASC.
121    *
122    * @param ordering as String
123    */
 
124  5 toggle public void setSorting(final String ordering) {
125  5 this.sorting = ordering;
126    }
127   
128    /**
129    * Get the direction (forward or backward) of the paging.
130    *
131    * @return paging as String
132    */
 
133  10 toggle public String getPaging() {
134  10 return paging;
135    }
136   
137    /**
138    * Define the direction (forward or backward) of the paging.
139    *
140    * @param direction as String
141    */
 
142  3 toggle public void setPaging(final String direction) {
143  3 this.paging = direction;
144    }
145   
146    /**
147    * Get the defined primarey key of the Domain Object.
148    *
149    * @return primaryKey as String
150    */
 
151  57 toggle public String getPrimaryKey() {
152  57 return primaryKey;
153    }
154   
155    /**
156    * Set the primarey key of the Domain Object.
157    *
158    * @param primaryKey as String
159    */
 
160  2 toggle public void setPrimaryKey(final String primaryKey) {
161  2 this.primaryKey = primaryKey;
162    }
163   
164    /**
165    * Get the pivot element, where the page break occur.
166    *
167    * @return peageBreak as String
168    */
 
169  57 toggle public String getPageBreak() {
170  57 return pageBreak;
171    }
172   
173    /**
174    * Define the pivot element, where the page break occur.
175    *
176    * @param pageBreak as String
177    */
 
178  11 toggle public void setPageBreak(final String pageBreak) {
179  11 this.pageBreak = pageBreak;
180    }
181   
182    /**
183    * Get the 2 nd parameter, besides the primarey key for ordering the result
184    * set.
185    *
186    * @return additionalOrdering as String
187    */
 
188  53 toggle public String getAdditionalOrdering() {
189  53 return additionalOrdering;
190    }
191   
192    /**
193    * Set the 2 nd parameter, besides the primarey key for ordering the result
194    * set.
195    *
196    * @param additionalOrdering as String
197    */
 
198  7 toggle public void setAdditionalOrdering(final String additionalOrdering) {
199  7 this.additionalOrdering = additionalOrdering;
200    }
201   
202    /**
203    * Get all <b>String</b> based filters &gt;KEY, Value&lt; to reduce the
204    * result set.
205    *
206    * @return filterStringCriteria as Map
207    */
 
208  79 toggle public Map<String, String> getFilterStringCriteria() {
209  79 return Map.copyOf(filterStringCriteria);
210    }
211   
212    /**
213    * Set all <b>String</b> based filters &gt;KEY, Value&lt; to reduce the
214    * result set.
215    *
216    * @param filterStringCriteria as Map
217    */
 
218  32 toggle public void setFilterStringCriteria(final Map<String, String> filterStringCriteria) {
219  32 this.filterStringCriteria.putAll(filterStringCriteria);
220    }
221   
222    /**
223    * Get all <b>Boolean</b> based filters &gt;KEY, Value&lt; to reduce the
224    * result set.
225    *
226    * @return filterBooleanCriteria as Map
227    */
 
228  50 toggle public Map<String, Boolean> getFilterBooleanCriteria() {
229  50 return Map.copyOf(filterBooleanCriteria);
230    }
231   
232    /**
233    * Set all <b>Boolean</b> based filters &gt;KEY, Value&lt; to reduce the
234    * result set.
235    *
236    * @param filterBooleanCriteria as Map
237    */
 
238  3 toggle public void setFilterBooleanCriteria(final Map<String, Boolean> filterBooleanCriteria) {
239  3 this.filterBooleanCriteria.putAll(filterBooleanCriteria);
240    }
241   
242    /**
243    * Get all <b>Integer</b> based filters &gt;KEY, Value&lt; to reduce the
244    * result set.
245    *
246    * @return filterIntegerCriteria as Map
247    */
 
248  49 toggle public Map<String, Integer> getFilterIntegerCriteria() {
249  49 return Map.copyOf(filterIntegerCriteria);
250    }
251   
252    /**
253    * Set all <b>Integer</b> based filters &gt;KEY, Value&lt; to reduce the
254    * result set.
255    *
256    * @param filterIntegerCriteria as Map
257    */
 
258  2 toggle public void setFilterIntegerCriteria(final Map<String, Integer> filterIntegerCriteria) {
259  2 this.filterIntegerCriteria.putAll(filterIntegerCriteria);
260    }
261   
262    /**
263    * Get all <b>Float</b> based filters &gt;KEY, Value&lt; to reduce the
264    * result set.
265    *
266    * @return filterFloatCriteria as Map
267    */
 
268  50 toggle public Map<String, Float> getFilterFloatCriteria() {
269  50 return filterFloatCriteria;
270    }
271   
272    /**
273    * Set all <b>Float</b> based filters &gt;KEY, Value&lt; to reduce the
274    * result set.
275    *
276    * @param filterFloatCriteria as Map
277    */
 
278  4 toggle public void setFilterFloatCriteria(final Map<String, Float> filterFloatCriteria) {
279  4 this.filterFloatCriteria = filterFloatCriteria;
280    }
281   
282    /**
283    * Get all <b>Date</b> based filters &gt;KEY, Value&lt; to reduce the result
284    * set.
285    *
286    * @return filterDateCriteria as Map
287    */
 
288  50 toggle public Map<String, Date> getFilterDateCriteria() {
289  50 return filterDateCriteria;
290    }
291   
292    /**
293    * Set all <b>Date</b> based filters &gt;KEY, Value&lt; to reduce the result
294    * set.
295    *
296    * @param filterDateCriteria as Map
297    */
 
298  4 toggle public void setFilterDateCriteria(final Map<String, Date> filterDateCriteria) {
299  4 this.filterDateCriteria = filterDateCriteria;
300    }
301    //</editor-fold>
302    }