JpaPagination.java

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
    public JpaPagination() {
55
        this.pageSize = 0;
56
        this.sorting = ORDER_ASC;
57
        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
    public JpaPagination(final String primaryKey) {
68
        this.primaryKey = primaryKey;
69
        this.pageSize = 0;
70
        this.sorting = ORDER_ASC;
71
        this.paging = PAGING_FOREWARD;
72
    }
73
74
    @Override
75
    public String toString() {
76 1 1. toString : replaced return value with "" for org/europa/together/domain/JpaPagination::toString → KILLED
        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
    public int getPageSize() {
98 1 1. getPageSize : replaced int return with 0 for org/europa/together/domain/JpaPagination::getPageSize → KILLED
        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
    public void setPageSize(final int limit) {
107
        this.pageSize = limit;
108
    }
109
110
    /**
111
     * Get if the sorting is DESC or ASC.
112
     *
113
     * @return sorting as String
114
     */
115
    public String getSorting() {
116 1 1. getSorting : replaced return value with "" for org/europa/together/domain/JpaPagination::getSorting → KILLED
        return sorting;
117
    }
118
119
    /**
120
     * Define if the sorting is DESC or ASC.
121
     *
122
     * @param ordering as String
123
     */
124
    public void setSorting(final String ordering) {
125
        this.sorting = ordering;
126
    }
127
128
    /**
129
     * Get the direction (forward or backward) of the paging.
130
     *
131
     * @return paging as String
132
     */
133
    public String getPaging() {
134 1 1. getPaging : replaced return value with "" for org/europa/together/domain/JpaPagination::getPaging → KILLED
        return paging;
135
    }
136
137
    /**
138
     * Define the direction (forward or backward) of the paging.
139
     *
140
     * @param direction as String
141
     */
142
    public void setPaging(final String direction) {
143
        this.paging = direction;
144
    }
145
146
    /**
147
     * Get the defined primarey key of the Domain Object.
148
     *
149
     * @return primaryKey as String
150
     */
151
    public String getPrimaryKey() {
152 1 1. getPrimaryKey : replaced return value with "" for org/europa/together/domain/JpaPagination::getPrimaryKey → KILLED
        return primaryKey;
153
    }
154
155
    /**
156
     * Set the primarey key of the Domain Object.
157
     *
158
     * @param primaryKey as String
159
     */
160
    public void setPrimaryKey(final String primaryKey) {
161
        this.primaryKey = primaryKey;
162
    }
163
164
    /**
165
     * Get the pivot element, where the page break occur.
166
     *
167
     * @return peageBreak as String
168
     */
169
    public String getPageBreak() {
170 1 1. getPageBreak : replaced return value with "" for org/europa/together/domain/JpaPagination::getPageBreak → KILLED
        return pageBreak;
171
    }
172
173
    /**
174
     * Define the pivot element, where the page break occur.
175
     *
176
     * @param pageBreak as String
177
     */
178
    public void setPageBreak(final String pageBreak) {
179
        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
    public String getAdditionalOrdering() {
189 1 1. getAdditionalOrdering : replaced return value with "" for org/europa/together/domain/JpaPagination::getAdditionalOrdering → KILLED
        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
    public void setAdditionalOrdering(final String additionalOrdering) {
199
        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
    public Map<String, String> getFilterStringCriteria() {
209 1 1. getFilterStringCriteria : replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterStringCriteria → KILLED
        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
    public void setFilterStringCriteria(final Map<String, String> filterStringCriteria) {
219 1 1. setFilterStringCriteria : removed call to java/util/Map::putAll → KILLED
        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
    public Map<String, Boolean> getFilterBooleanCriteria() {
229 1 1. getFilterBooleanCriteria : replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterBooleanCriteria → KILLED
        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
    public void setFilterBooleanCriteria(final Map<String, Boolean> filterBooleanCriteria) {
239 1 1. setFilterBooleanCriteria : removed call to java/util/Map::putAll → KILLED
        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
    public Map<String, Integer> getFilterIntegerCriteria() {
249 1 1. getFilterIntegerCriteria : replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterIntegerCriteria → KILLED
        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
    public void setFilterIntegerCriteria(final Map<String, Integer> filterIntegerCriteria) {
259 1 1. setFilterIntegerCriteria : removed call to java/util/Map::putAll → KILLED
        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
    public Map<String, Float> getFilterFloatCriteria() {
269 1 1. getFilterFloatCriteria : replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterFloatCriteria → KILLED
        return Map.copyOf(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
    public void setFilterFloatCriteria(final Map<String, Float> filterFloatCriteria) {
279 1 1. setFilterFloatCriteria : removed call to java/util/Map::putAll → KILLED
        this.filterFloatCriteria.putAll(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
    public Map<String, Date> getFilterDateCriteria() {
289 1 1. getFilterDateCriteria : replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterDateCriteria → KILLED
        return Map.copyOf(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
    public void setFilterDateCriteria(final Map<String, Date> filterDateCriteria) {
299 1 1. setFilterDateCriteria : removed call to java/util/Map::putAll → KILLED
        this.filterDateCriteria.putAll(filterDateCriteria);
300
    }
301
    //</editor-fold>
302
}

Mutations

76

1.1
Location : toString
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::toString → KILLED

98

1.1
Location : getPageSize
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced int return with 0 for org/europa/together/domain/JpaPagination::getPageSize → KILLED

116

1.1
Location : getSorting
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::getSorting → KILLED

134

1.1
Location : getPaging
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::getPaging → KILLED

152

1.1
Location : getPrimaryKey
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::getPrimaryKey → KILLED

170

1.1
Location : getPageBreak
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::getPageBreak → KILLED

189

1.1
Location : getAdditionalOrdering
Killed by : org.europa.together.domain.JpaPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.domain.JpaPaginationTest]/[method:domainObject()]
replaced return value with "" for org/europa/together/domain/JpaPagination::getAdditionalOrdering → KILLED

209

1.1
Location : getFilterStringCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultFilterWhitoutPagination()]
replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterStringCriteria → KILLED

219

1.1
Location : setFilterStringCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultFilterWhitoutPagination()]
removed call to java/util/Map::putAll → KILLED

229

1.1
Location : getFilterBooleanCriteria
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getDeprecatedEntries()]
replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterBooleanCriteria → KILLED

239

1.1
Location : setFilterBooleanCriteria
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getDeprecatedEntries()]
removed call to java/util/Map::putAll → KILLED

249

1.1
Location : getFilterIntegerCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultIntegerEqualFilterWithPagination()]
replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterIntegerCriteria → KILLED

259

1.1
Location : setFilterIntegerCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultIntegerEqualFilterWithPagination()]
removed call to java/util/Map::putAll → KILLED

269

1.1
Location : getFilterFloatCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultFloatEqualFilterWithPagination()]
replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterFloatCriteria → KILLED

279

1.1
Location : setFilterFloatCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultFloatEqualFilterWithPagination()]
removed call to java/util/Map::putAll → KILLED

289

1.1
Location : getFilterDateCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultDateEqualFilterWithPagination()]
replaced return value with Collections.emptyMap for org/europa/together/domain/JpaPagination::getFilterDateCriteria → KILLED

299

1.1
Location : setFilterDateCriteria
Killed by : org.europa.together.application.DaoPaginationTest.[engine:junit-jupiter]/[class:org.europa.together.application.DaoPaginationTest]/[method:simpleResultDateEqualFilterWithPagination()]
removed call to java/util/Map::putAll → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0