22
22
import java .util .function .Function ;
23
23
24
24
import org .apache .ibatis .annotations .SelectProvider ;
25
+ import org .jspecify .annotations .Nullable ;
25
26
import org .mybatis .dynamic .sql .select .render .SelectStatementProvider ;
26
27
import org .mybatis .dynamic .sql .util .SqlProviderAdapter ;
27
28
@@ -58,7 +59,7 @@ public interface CommonSelectMapper {
58
59
* @return A Map containing the row values.
59
60
*/
60
61
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
61
- Map <String , Object > selectOneMappedRow (SelectStatementProvider selectStatement );
62
+ @ Nullable Map <String , Object > selectOneMappedRow (SelectStatementProvider selectStatement );
62
63
63
64
/**
64
65
* Select a single row of values and then convert the values to a custom type. This is similar
@@ -74,9 +75,10 @@ public interface CommonSelectMapper {
74
75
* @param <R> the datatype of the converted object
75
76
* @return the converted object
76
77
*/
77
- default <R > R selectOne (SelectStatementProvider selectStatement ,
78
+ default <R > @ Nullable R selectOne (SelectStatementProvider selectStatement ,
78
79
Function <Map <String , Object >, R > rowMapper ) {
79
- return rowMapper .apply (selectOneMappedRow (selectStatement ));
80
+ var result = selectOneMappedRow (selectStatement );
81
+ return result == null ? null : rowMapper .apply (result );
80
82
}
81
83
82
84
/**
@@ -122,7 +124,7 @@ default <R> List<R> selectMany(SelectStatementProvider selectStatement,
122
124
* column is null
123
125
*/
124
126
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
125
- BigDecimal selectOneBigDecimal (SelectStatementProvider selectStatement );
127
+ @ Nullable BigDecimal selectOneBigDecimal (SelectStatementProvider selectStatement );
126
128
127
129
/**
128
130
* Retrieve a single {@link java.math.BigDecimal} from a result set. The result set must have
@@ -157,7 +159,7 @@ default <R> List<R> selectMany(SelectStatementProvider selectStatement,
157
159
* column is null
158
160
*/
159
161
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
160
- Double selectOneDouble (SelectStatementProvider selectStatement );
162
+ @ Nullable Double selectOneDouble (SelectStatementProvider selectStatement );
161
163
162
164
/**
163
165
* Retrieve a single {@link java.lang.Double} from a result set. The result set must have
@@ -192,7 +194,7 @@ default <R> List<R> selectMany(SelectStatementProvider selectStatement,
192
194
* column is null
193
195
*/
194
196
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
195
- Integer selectOneInteger (SelectStatementProvider selectStatement );
197
+ @ Nullable Integer selectOneInteger (SelectStatementProvider selectStatement );
196
198
197
199
/**
198
200
* Retrieve a single {@link java.lang.Integer} from a result set. The result set must have
@@ -227,7 +229,7 @@ default <R> List<R> selectMany(SelectStatementProvider selectStatement,
227
229
* column is null
228
230
*/
229
231
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
230
- Long selectOneLong (SelectStatementProvider selectStatement );
232
+ @ Nullable Long selectOneLong (SelectStatementProvider selectStatement );
231
233
232
234
/**
233
235
* Retrieve a single {@link java.lang.Long} from a result set. The result set must have
@@ -262,7 +264,7 @@ default <R> List<R> selectMany(SelectStatementProvider selectStatement,
262
264
* column is null
263
265
*/
264
266
@ SelectProvider (type = SqlProviderAdapter .class , method = "select" )
265
- String selectOneString (SelectStatementProvider selectStatement );
267
+ @ Nullable String selectOneString (SelectStatementProvider selectStatement );
266
268
267
269
/**
268
270
* Retrieve a single {@link java.lang.String} from a result set. The result set must have
0 commit comments