• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wz2cool / mybatis-dynamic-query / #393

19 May 2024 12:06PM CUT coverage: 72.18% (-17.3%) from 89.44%
#393

push

wz2cool
add ci

1977 of 2739 relevant lines covered (72.18%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.93
/src/main/java/com/github/wz2cool/dynamic/mybatis/mapper/SelectMaxByGroupedQueryMapper.java
1
package com.github.wz2cool.dynamic.mybatis.mapper;
2

3
import com.github.wz2cool.dynamic.GroupedQuery;
4
import com.github.wz2cool.dynamic.helper.CommonsHelper;
5
import com.github.wz2cool.dynamic.lambda.*;
6
import com.github.wz2cool.dynamic.mybatis.QueryHelper;
7
import com.github.wz2cool.dynamic.mybatis.TypeHelper;
8
import com.github.wz2cool.dynamic.mybatis.mapper.constant.MapperConstants;
9
import com.github.wz2cool.dynamic.mybatis.mapper.provider.GroupedQueryProvider;
10
import org.apache.ibatis.annotations.Param;
11
import org.apache.ibatis.annotations.SelectProvider;
12
import org.apache.ibatis.session.RowBounds;
13
import tk.mybatis.mapper.annotation.RegisterMapper;
14

15
import java.math.BigDecimal;
16
import java.util.ArrayList;
17
import java.util.Date;
18
import java.util.List;
19
import java.util.Optional;
20

21
/**
22
 * @author Frank
23
 **/
24
@RegisterMapper
25
@SuppressWarnings("java:S119")
26
public interface SelectMaxByGroupedQueryMapper<T> {
27

28
    QueryHelper QUERY_HELPER = new QueryHelper();
1✔
29

30
    /**
31
     * Select max value of column by dynamic query.
32
     *
33
     * @param column       the column need get max value
34
     * @param groupedQuery grouped query
35
     * @return max value of column.
36
     */
37
    @SelectProvider(type = GroupedQueryProvider.class, method = "dynamicSQL")
38
    <TSelect extends Comparable> List<Object> selectMaxByGroupedQuery(
39
            @Param(MapperConstants.COLUMN) String column,
40
            @Param(MapperConstants.GROUPED_QUERY) GroupedQuery<T, TSelect> groupedQuery);
41

42

43
    /**
44
     * Select max value of column by dynamic query.
45
     *
46
     * @param column       the column need get max value
47
     * @param groupedQuery grouped query
48
     * @return max value of column.
49
     */
50
    @SelectProvider(type = GroupedQueryProvider.class, method = "dynamicSQL")
51
    <TSelect extends Comparable> List<Object> selectMaxRowBoundsByGroupedQuery(
52
            @Param(MapperConstants.COLUMN) String column,
53
            @Param(MapperConstants.GROUPED_QUERY) GroupedQuery<T, TSelect> groupedQuery,
54
            RowBounds rowBounds);
55

56

57
    default <TSelect extends Comparable> List<Object> selectMaxByGroupedQueryInternal(
58
            GetPropertyFunction<T, TSelect> getPropertyFunction, GroupedQuery<T, TSelect> groupedQuery) {
59
        String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
×
60
        Class<T> queryClass = groupedQuery.getQueryClass();
×
61
        String queryColumn = QUERY_HELPER.getQueryColumnByProperty(queryClass, propertyName);
×
62
        return selectMaxByGroupedQuery(queryColumn, groupedQuery);
×
63
    }
64

65
    default <TSelect extends Comparable> List<Object> selectMaxByGroupedQueryInternal(
66
            GetPropertyFunction<T, TSelect> getPropertyFunction, GroupedQuery<T, TSelect> groupedQuery,
67
            RowBounds rowBounds) {
68
        String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
1✔
69
        Class<T> queryClass = groupedQuery.getQueryClass();
1✔
70
        String queryColumn = QUERY_HELPER.getQueryColumnByProperty(queryClass, propertyName);
1✔
71
        return selectMaxRowBoundsByGroupedQuery(queryColumn, groupedQuery, rowBounds);
1✔
72
    }
73

74
    /**
75
     * Select max value of property by dynamic query.
76
     *
77
     * @param getPropertyFunction the property need get max value
78
     * @param groupedQuery        grouped query.
79
     * @param rowBounds           row bounds
80
     * @return max value of property.
81
     */
82
    default List<BigDecimal> selectMaxByGroupedQuery(
83
            GetBigDecimalPropertyFunction<T> getPropertyFunction,
84
            GroupedQuery<T, BigDecimal> groupedQuery,
85
            RowBounds rowBounds) {
86
        List<Object> objects = rowBounds == null ?
×
87
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
88
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
89
        List<BigDecimal> result = new ArrayList<>();
×
90
        if (objects.isEmpty()) {
×
91
            return result;
×
92
        }
93
        for (Object object : objects) {
×
94
            Optional.ofNullable(TypeHelper.getBigDecimal(object))
×
95
                    .ifPresent(result::add);
×
96
        }
×
97
        return result;
×
98
    }
99

100
    /**
101
     * Select max value of property by dynamic query.
102
     *
103
     * @param getPropertyFunction the property need get max value
104
     * @param groupedQuery        grouped query.
105
     * @return max value of property.
106
     */
107
    default List<Byte> selectMaxByGroupedQuery(
108
            GetBytePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Byte> groupedQuery,
109
            RowBounds rowBounds) {
110
        List<Object> objects = rowBounds == null ?
×
111
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
112
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
113
        List<Byte> result = new ArrayList<>();
×
114
        if (objects.isEmpty()) {
×
115
            return result;
×
116
        }
117
        for (Object object : objects) {
×
118
            Optional.ofNullable(TypeHelper.getByte(object))
×
119
                    .ifPresent(result::add);
×
120
        }
×
121
        return result;
×
122
    }
123

124
    /**
125
     * Select max value of property by dynamic query.
126
     *
127
     * @param getPropertyFunction the property need get max value
128
     * @param groupedQuery        grouped query.
129
     * @return max value of property.
130
     */
131
    default List<Byte> selectMaxByGroupedQuery(
132
            GetBytePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Byte> groupedQuery) {
133
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
134
    }
135

136
    /**
137
     * Select max value of property by dynamic query.
138
     *
139
     * @param getPropertyFunction the property need get max value
140
     * @param groupedQuery        grouped query.
141
     * @param rowBounds           row bounds
142
     * @return max value of property.
143
     */
144
    default List<Date> selectMaxByGroupedQuery(
145
            GetDatePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Date> groupedQuery,
146
            RowBounds rowBounds) {
147
        List<Object> objects = rowBounds == null ?
×
148
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
149
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
150
        List<Date> result = new ArrayList<>();
×
151
        if (objects.isEmpty()) {
×
152
            return result;
×
153
        }
154
        for (Object object : objects) {
×
155
            Optional.ofNullable(TypeHelper.getDate(object))
×
156
                    .ifPresent(result::add);
×
157
        }
×
158
        return result;
×
159
    }
160

161
    /**
162
     * Select max value of property by dynamic query.
163
     *
164
     * @param getPropertyFunction the property need get max value
165
     * @param groupedQuery        grouped query.
166
     * @return max value of property.
167
     */
168
    default List<Date> selectMaxByGroupedQuery(
169
            GetDatePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Date> groupedQuery) {
170
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
171
    }
172

173
    /**
174
     * Select max value of property by dynamic query.
175
     *
176
     * @param getPropertyFunction the property need get max value
177
     * @param groupedQuery        grouped query.
178
     * @param rowBounds           row bounds
179
     * @return max value of property.
180
     */
181
    default List<Double> selectMaxByGroupedQuery(
182
            GetDoublePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Double> groupedQuery,
183
            RowBounds rowBounds) {
184
        List<Object> objects = rowBounds == null ?
×
185
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
186
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
187
        List<Double> result = new ArrayList<>();
×
188
        if (objects.isEmpty()) {
×
189
            return result;
×
190
        }
191
        for (Object object : objects) {
×
192
            Optional.ofNullable(TypeHelper.getDouble(object))
×
193
                    .ifPresent(result::add);
×
194
        }
×
195
        return result;
×
196
    }
197

198
    /**
199
     * Select max value of property by dynamic query.
200
     *
201
     * @param getPropertyFunction the property need get max value
202
     * @param groupedQuery        grouped query.
203
     * @return max value of property.
204
     */
205
    default List<Double> selectMaxByGroupedQuery(
206
            GetDoublePropertyFunction<T> getPropertyFunction, GroupedQuery<T, Double> groupedQuery) {
207
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery);
×
208
    }
209

210
    /**
211
     * Select max value of property by dynamic query.
212
     *
213
     * @param getPropertyFunction the property need get max value
214
     * @param groupedQuery        grouped query.
215
     * @param rowBounds           row bounds
216
     * @return max value of property.
217
     */
218
    default List<Float> selectMaxByGroupedQuery(
219
            GetFloatPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Float> groupedQuery,
220
            RowBounds rowBounds) {
221
        List<Object> objects = rowBounds == null ?
×
222
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
223
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
224
        List<Float> result = new ArrayList<>();
×
225
        if (objects.isEmpty()) {
×
226
            return result;
×
227
        }
228
        for (Object object : objects) {
×
229
            Optional.ofNullable(TypeHelper.getFloat(object))
×
230
                    .ifPresent(result::add);
×
231
        }
×
232
        return result;
×
233
    }
234

235
    /**
236
     * Select max value of property by dynamic query.
237
     *
238
     * @param getPropertyFunction the property need get max value
239
     * @param groupedQuery        grouped query.
240
     * @return max value of property.
241
     */
242
    default List<Float> selectMaxByGroupedQuery(
243
            GetFloatPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Float> groupedQuery) {
244
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
245
    }
246

247
    /**
248
     * Select max value of property by dynamic query.
249
     *
250
     * @param getPropertyFunction the property need get max value
251
     * @param groupedQuery        grouped query.
252
     * @return max value of property.
253
     */
254
    default List<Integer> selectMaxByGroupedQuery(
255
            GetIntegerPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Integer> groupedQuery,
256
            RowBounds rowBounds) {
257
        List<Object> objects = rowBounds == null ?
×
258
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
259
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
260
        List<Integer> result = new ArrayList<>();
×
261
        if (objects.isEmpty()) {
×
262
            return result;
×
263
        }
264
        for (Object object : objects) {
×
265
            Optional.ofNullable(TypeHelper.getInteger(object))
×
266
                    .ifPresent(result::add);
×
267
        }
×
268
        return result;
×
269
    }
270

271
    /**
272
     * Select max value of property by dynamic query.
273
     *
274
     * @param getPropertyFunction the property need get max value
275
     * @param groupedQuery        grouped query.
276
     * @return max value of property.
277
     */
278
    default List<Integer> selectMaxByGroupedQuery(
279
            GetIntegerPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Integer> groupedQuery) {
280
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
281
    }
282

283
    /**
284
     * Select max value of property by dynamic query.
285
     *
286
     * @param getPropertyFunction the property need get max value
287
     * @param groupedQuery        grouped query.
288
     * @return max value of property.
289
     */
290
    default List<Long> selectMaxByGroupedQuery(
291
            GetLongPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Long> groupedQuery,
292
            RowBounds rowBounds) {
293
        List<Object> objects = rowBounds == null ?
1✔
294
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
1✔
295
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
1✔
296
        List<Long> result = new ArrayList<>();
1✔
297
        if (objects.isEmpty()) {
1✔
298
            return result;
×
299
        }
300
        for (Object object : objects) {
1✔
301
            Optional.ofNullable(TypeHelper.getLong(object))
1✔
302
                    .ifPresent(result::add);
1✔
303
        }
1✔
304
        return result;
1✔
305
    }
306

307
    /**
308
     * Select max value of property by dynamic query.
309
     *
310
     * @param getPropertyFunction the property need get max value
311
     * @param groupedQuery        grouped query.
312
     * @return max value of property.
313
     */
314
    default List<Long> selectMaxByGroupedQuery(
315
            GetLongPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Long> groupedQuery) {
316
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
317
    }
318

319
    /**
320
     * Select max value of property by dynamic query.
321
     *
322
     * @param getPropertyFunction the property need get max value
323
     * @param groupedQuery        grouped query.
324
     * @param rowBounds           row bonds
325
     * @return max value of property.
326
     */
327
    default List<Short> selectMaxByGroupedQuery(
328
            GetShortPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Short> groupedQuery,
329
            RowBounds rowBounds) {
330
        List<Object> objects = rowBounds == null ?
×
331
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
332
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
333
        List<Short> result = new ArrayList<>();
×
334
        if (objects.isEmpty()) {
×
335
            return result;
×
336
        }
337
        for (Object object : objects) {
×
338
            Optional.ofNullable(TypeHelper.getShort(object))
×
339
                    .ifPresent(result::add);
×
340
        }
×
341
        return result;
×
342
    }
343

344
    /**
345
     * Select max value of property by dynamic query.
346
     *
347
     * @param getPropertyFunction the property need get max value
348
     * @param groupedQuery        grouped query.
349
     * @return max value of property.
350
     */
351
    default List<Short> selectMaxByGroupedQuery(
352
            GetShortPropertyFunction<T> getPropertyFunction, GroupedQuery<T, Short> groupedQuery) {
353
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
354
    }
355

356
    /**
357
     * Select max value of property by dynamic query.
358
     *
359
     * @param getPropertyFunction the property need get max value
360
     * @param groupedQuery        grouped query.
361
     * @param rowBounds           row bounds
362
     * @return max value of property.
363
     */
364
    default List<String> selectMaxByGroupedQuery(
365
            GetStringPropertyFunction<T> getPropertyFunction, GroupedQuery<T, String> groupedQuery,
366
            RowBounds rowBounds) {
367
        List<Object> objects = rowBounds == null ?
×
368
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery) :
×
369
                selectMaxByGroupedQueryInternal(getPropertyFunction, groupedQuery, rowBounds);
×
370
        List<String> result = new ArrayList<>();
×
371
        if (objects.isEmpty()) {
×
372
            return result;
×
373
        }
374
        for (Object object : objects) {
×
375
            Optional.ofNullable(TypeHelper.getString(object))
×
376
                    .ifPresent(result::add);
×
377
        }
×
378
        return result;
×
379
    }
380

381
    /**
382
     * Select max value of property by dynamic query.
383
     *
384
     * @param getPropertyFunction the property need get max value
385
     * @param groupedQuery        grouped query.
386
     * @return max value of property.
387
     */
388
    default List<String> selectMaxByGroupedQuery(
389
            GetStringPropertyFunction<T> getPropertyFunction, GroupedQuery<T, String> groupedQuery) {
390
        return selectMaxByGroupedQuery(getPropertyFunction, groupedQuery, null);
×
391
    }
392
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc