• 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

30.43
/src/main/java/com/github/wz2cool/dynamic/mybatis/mapper/SelectMinByDynamicQueryMapper.java
1
package com.github.wz2cool.dynamic.mybatis.mapper;
2

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

14
import java.math.BigDecimal;
15
import java.util.Date;
16
import java.util.Optional;
17

18
/**
19
 * @author Frank
20
 */
21
@RegisterMapper
22
@SuppressWarnings("squid:S1214")
23
public interface SelectMinByDynamicQueryMapper<T> {
24

25
    QueryHelper QUERY_HELPER = new QueryHelper();
1✔
26

27
    /**
28
     * Select min value of column by dynamic query.
29
     *
30
     * @param column       the column need get min value
31
     * @param dynamicQuery dynamic query
32
     * @return min value of column.
33
     */
34
    @SelectProvider(type = DynamicQueryProvider.class, method = "dynamicSQL")
35
    Object selectMinByDynamicQuery(
36
            @Param(MapperConstants.COLUMN) String column, @Param(MapperConstants.DYNAMIC_QUERY) DynamicQuery<T> dynamicQuery);
37

38
    /**
39
     * Select min value of property by dynamic query.
40
     *
41
     * @param getPropertyFunction the property need get min value
42
     * @param dynamicQuery        dynamic query.
43
     * @return min value of property.
44
     */
45
    default <R extends Comparable> Object selectMinByDynamicQueryInternal(
46
            GetPropertyFunction<T, R> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
47
        String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
1✔
48
        Class entityClass = dynamicQuery.getEntityClass();
1✔
49
        String queryColumn = QUERY_HELPER.getQueryColumnByProperty(entityClass, propertyName);
1✔
50
        return selectMinByDynamicQuery(queryColumn, dynamicQuery);
1✔
51
    }
52

53
    /**
54
     * Select min value of property by dynamic query.
55
     *
56
     * @param getPropertyFunction the property need get min value
57
     * @param dynamicQuery        dynamic query.
58
     * @return min value of property.
59
     */
60
    default Optional<BigDecimal> selectMinByDynamicQuery(
61
            GetBigDecimalPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
62
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
1✔
63
        return Optional.ofNullable(TypeHelper.getBigDecimal(result));
1✔
64
    }
65

66
    /**
67
     * Select min value of property by dynamic query.
68
     *
69
     * @param getPropertyFunction the property need get min value
70
     * @param dynamicQuery        dynamic query.
71
     * @return min value of property.
72
     */
73
    default Optional<Byte> selectMinByDynamicQuery(
74
            GetBytePropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
75
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
76
        return Optional.ofNullable(TypeHelper.getByte(result));
×
77
    }
78

79
    /**
80
     * Select min value of property by dynamic query.
81
     *
82
     * @param getPropertyFunction the property need get min value
83
     * @param dynamicQuery        dynamic query.
84
     * @return min value of property.
85
     */
86
    default Optional<Date> selectMinByDynamicQuery(
87
            GetDatePropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
88
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
89
        return Optional.ofNullable(TypeHelper.getDate(result));
×
90
    }
91

92
    /**
93
     * Select min value of property by dynamic query.
94
     *
95
     * @param getPropertyFunction the property need get min value
96
     * @param dynamicQuery        dynamic query.
97
     * @return min value of property.
98
     */
99
    default Optional<Double> selectMinByDynamicQuery(
100
            GetDoublePropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
101
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
102
        return Optional.ofNullable(TypeHelper.getDouble(result));
×
103
    }
104

105
    /**
106
     * Select min value of property by dynamic query.
107
     *
108
     * @param getPropertyFunction the property need get min value
109
     * @param dynamicQuery        dynamic query.
110
     * @return min value of property.
111
     */
112
    default Optional<Float> selectMinByDynamicQuery(
113
            GetFloatPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
114
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
115
        return Optional.ofNullable(TypeHelper.getFloat(result));
×
116
    }
117

118
    /**
119
     * Select min value of property by dynamic query.
120
     *
121
     * @param getPropertyFunction the property need get min value
122
     * @param dynamicQuery        dynamic query.
123
     * @return min value of property.
124
     */
125
    default Optional<Integer> selectMinByDynamicQuery(
126
            GetIntegerPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
127
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
128
        return Optional.ofNullable(TypeHelper.getInteger(result));
×
129
    }
130

131
    /**
132
     * Select min value of property by dynamic query.
133
     *
134
     * @param getPropertyFunction the property need get min value
135
     * @param dynamicQuery        dynamic query.
136
     * @return min value of property.
137
     */
138
    default Optional<Long> selectMinByDynamicQuery(
139
            GetLongPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
140
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
141
        return Optional.ofNullable(TypeHelper.getLong(result));
×
142
    }
143

144
    /**
145
     * Select min value of property by dynamic query.
146
     *
147
     * @param getPropertyFunction the property need get min value
148
     * @param dynamicQuery        dynamic query.
149
     * @return min value of property.
150
     */
151
    default Optional<Short> selectMinByDynamicQuery(
152
            GetShortPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
153
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
154
        return Optional.ofNullable(TypeHelper.getShort(result));
×
155
    }
156

157
    /**
158
     * Select min value of property by dynamic query.
159
     *
160
     * @param getPropertyFunction the property need get min value
161
     * @param dynamicQuery        dynamic query.
162
     * @return min value of property.
163
     */
164
    default Optional<String> selectMinByDynamicQuery(
165
            GetStringPropertyFunction<T> getPropertyFunction, DynamicQuery<T> dynamicQuery) {
166
        Object result = selectMinByDynamicQueryInternal(getPropertyFunction, dynamicQuery);
×
167
        return Optional.ofNullable(TypeHelper.getString(result));
×
168
    }
169
}
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