1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package examples.animal.data;
17
18 import static examples.animal.data.AnimalDataDynamicSqlSupport.animalData;
19 import static examples.animal.data.AnimalDataDynamicSqlSupport.animalName;
20 import static examples.animal.data.AnimalDataDynamicSqlSupport.bodyWeight;
21 import static examples.animal.data.AnimalDataDynamicSqlSupport.brainWeight;
22 import static examples.animal.data.AnimalDataDynamicSqlSupport.id;
23 import static java.util.function.Predicate.not;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertAll;
26 import static org.mybatis.dynamic.sql.SqlBuilder.*;
27
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
30 import java.sql.Connection;
31 import java.sql.DriverManager;
32 import java.util.List;
33
34 import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
35 import org.apache.ibatis.jdbc.ScriptRunner;
36 import org.apache.ibatis.mapping.Environment;
37 import org.apache.ibatis.session.Configuration;
38 import org.apache.ibatis.session.SqlSession;
39 import org.apache.ibatis.session.SqlSessionFactory;
40 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
41 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
42 import org.jspecify.annotations.Nullable;
43 import org.junit.jupiter.api.BeforeEach;
44 import org.junit.jupiter.api.Test;
45 import org.mybatis.dynamic.sql.render.RenderingStrategies;
46 import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
47 import org.mybatis.dynamic.sql.util.Predicates;
48
49 class OptionalConditionsWithPredicatesAnimalDataTest {
50
51 private static final String JDBC_URL = "jdbc:hsqldb:mem:aname";
52 private static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver";
53 private static final @Nullable Integer NULL_INTEGER = null;
54
55 private SqlSessionFactory sqlSessionFactory;
56
57 @BeforeEach
58 void setup() throws Exception {
59 Class.forName(JDBC_DRIVER);
60 try (InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql")) {
61 assert is != null;
62 try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "");
63 InputStreamReader isr = new InputStreamReader(is)) {
64 ScriptRunner sr = new ScriptRunner(connection);
65 sr.setLogWriter(null);
66 sr.runScript(isr);
67 }
68 }
69
70 UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
71 Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
72 Configuration config = new Configuration(environment);
73 config.addMapper(AnimalDataMapper.class);
74 sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
75 }
76
77 @Test
78 void testAllIgnored() {
79 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
80 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
81 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
82 .from(animalData)
83 .where(id, isGreaterThanWhenPresent(NULL_INTEGER))
84 .orderBy(id)
85 .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
86 .build()
87 .render(RenderingStrategies.MYBATIS3);
88 List<AnimalData> animals = mapper.selectMany(selectStatement);
89 assertAll(
90 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"),
91 () -> assertThat(animals).hasSize(65),
92 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1),
93 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(2)
94 );
95 }
96 }
97
98 @Test
99 void testIgnoredBetweenRendered() {
100 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
101 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
102 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
103 .from(animalData)
104 .where(id, isEqualTo(3))
105 .and(id, isNotEqualToWhenPresent(NULL_INTEGER))
106 .or(id, isEqualTo(4))
107 .orderBy(id)
108 .build()
109 .render(RenderingStrategies.MYBATIS3);
110 List<AnimalData> animals = mapper.selectMany(selectStatement);
111 assertAll(
112 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
113 () -> assertThat(animals).hasSize(2),
114 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
115 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
116 );
117 }
118 }
119
120 @Test
121 void testIgnoredInWhere() {
122 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
123 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
124 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
125 .from(animalData)
126 .where(id, isLessThanWhenPresent(NULL_INTEGER))
127 .and(id, isEqualTo(3))
128 .or(id, isEqualTo(4))
129 .orderBy(id)
130 .build()
131 .render(RenderingStrategies.MYBATIS3);
132 List<AnimalData> animals = mapper.selectMany(selectStatement);
133 assertAll(
134 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
135 () -> assertThat(animals).hasSize(2),
136 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
137 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
138 );
139 }
140 }
141
142 @Test
143 void testManyIgnored() {
144 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
145 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
146 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
147 .from(animalData)
148 .where(id, isLessThanWhenPresent(NULL_INTEGER), and(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER)))
149 .and(id, isEqualToWhenPresent(NULL_INTEGER), or(id, isEqualTo(3), and(id, isLessThanWhenPresent(NULL_INTEGER))))
150 .or(id, isEqualToWhenPresent(4), and(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER)))
151 .and(id, isNotEqualToWhenPresent(NULL_INTEGER))
152 .orderBy(id)
153 .build()
154 .render(RenderingStrategies.MYBATIS3);
155 List<AnimalData> animals = mapper.selectMany(selectStatement);
156 assertAll(
157 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
158 () -> assertThat(animals).hasSize(2),
159 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
160 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
161 );
162 }
163 }
164
165 @Test
166 void testIgnoredInitialWhere() {
167 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
168 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
169 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
170 .from(animalData)
171 .where(id, isLessThanWhenPresent(NULL_INTEGER), and(id, isEqualTo(3)))
172 .or(id, isEqualTo(4))
173 .orderBy(id)
174 .build()
175 .render(RenderingStrategies.MYBATIS3);
176 List<AnimalData> animals = mapper.selectMany(selectStatement);
177 assertAll(
178 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
179 () -> assertThat(animals).hasSize(2),
180 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
181 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
182 );
183 }
184 }
185
186 @Test
187 void testEqualWhenWithValue() {
188 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
189 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
190 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
191 .from(animalData)
192 .where(id, isEqualTo(4))
193 .orderBy(id)
194 .build()
195 .render(RenderingStrategies.MYBATIS3);
196 List<AnimalData> animals = mapper.selectMany(selectStatement);
197 assertAll(
198 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"),
199 () -> assertThat(animals).hasSize(1),
200 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
201 );
202 }
203 }
204
205 @Test
206 void testEqualWhenWithoutValue() {
207 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
208 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
209 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
210 .from(animalData)
211 .where(id, isEqualToWhenPresent(NULL_INTEGER))
212 .and(id, isLessThanOrEqualTo(10))
213 .orderBy(id)
214 .build()
215 .render(RenderingStrategies.MYBATIS3);
216 List<AnimalData> animals = mapper.selectMany(selectStatement);
217 assertAll(
218 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
219 () -> assertThat(animals).hasSize(10),
220 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
221 );
222 }
223 }
224
225 @Test
226 void testNotEqualWhenWithValue() {
227 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
228 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
229 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
230 .from(animalData)
231 .where(id, isNotEqualTo(4))
232 .and(id, isLessThanOrEqualTo(10))
233 .orderBy(id)
234 .build()
235 .render(RenderingStrategies.MYBATIS3);
236 List<AnimalData> animals = mapper.selectMany(selectStatement);
237 assertAll(
238 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
239 () -> assertThat(animals).hasSize(9),
240 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
241 );
242 }
243 }
244
245 @Test
246 void testNotEqualWhenWithoutValue() {
247 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
248 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
249 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
250 .from(animalData)
251 .where(id, isNotEqualToWhenPresent(NULL_INTEGER))
252 .and(id, isLessThanOrEqualTo(10))
253 .orderBy(id)
254 .build()
255 .render(RenderingStrategies.MYBATIS3);
256 List<AnimalData> animals = mapper.selectMany(selectStatement);
257 assertAll(
258 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
259 () -> assertThat(animals).hasSize(10),
260 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
261 );
262 }
263 }
264
265 @Test
266 void testGreaterThanWhenWithValue() {
267 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
268 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
269 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
270 .from(animalData)
271 .where(id, isGreaterThan(4))
272 .and(id, isLessThanOrEqualTo(10))
273 .orderBy(id)
274 .build()
275 .render(RenderingStrategies.MYBATIS3);
276 List<AnimalData> animals = mapper.selectMany(selectStatement);
277 assertAll(
278 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
279 () -> assertThat(animals).hasSize(6),
280 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(5)
281 );
282 }
283 }
284
285 @Test
286 void testGreaterThanWhenWithoutValue() {
287 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
288 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
289 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
290 .from(animalData)
291 .where(id, isGreaterThanWhenPresent(NULL_INTEGER))
292 .and(id, isLessThanOrEqualTo(10))
293 .orderBy(id)
294 .build()
295 .render(RenderingStrategies.MYBATIS3);
296 List<AnimalData> animals = mapper.selectMany(selectStatement);
297 assertAll(
298 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
299 () -> assertThat(animals).hasSize(10),
300 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
301 );
302 }
303 }
304
305 @Test
306 void testGreaterThanOrEqualToWhenWithValue() {
307 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
308 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
309 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
310 .from(animalData)
311 .where(id, isGreaterThanOrEqualTo(4))
312 .and(id, isLessThanOrEqualTo(10))
313 .orderBy(id)
314 .build()
315 .render(RenderingStrategies.MYBATIS3);
316 List<AnimalData> animals = mapper.selectMany(selectStatement);
317 assertAll(
318 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
319 () -> assertThat(animals).hasSize(7),
320 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
321 );
322 }
323 }
324
325 @Test
326 void testGreaterThanOrEqualToWhenWithoutValue() {
327 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
328 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
329 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
330 .from(animalData)
331 .where(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER))
332 .and(id, isLessThanOrEqualTo(10))
333 .orderBy(id)
334 .build()
335 .render(RenderingStrategies.MYBATIS3);
336 List<AnimalData> animals = mapper.selectMany(selectStatement);
337 assertAll(
338 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
339 () -> assertThat(animals).hasSize(10),
340 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
341 );
342 }
343 }
344
345 @Test
346 void testLessThanWhenWithValue() {
347 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
348 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
349 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
350 .from(animalData)
351 .where(id, isLessThan(4))
352 .orderBy(id)
353 .build()
354 .render(RenderingStrategies.MYBATIS3);
355 List<AnimalData> animals = mapper.selectMany(selectStatement);
356 assertAll(
357 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"),
358 () -> assertThat(animals).hasSize(3),
359 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
360 );
361 }
362 }
363
364 @Test
365 void testLessThanWhenWithoutValue() {
366 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
367 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
368 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
369 .from(animalData)
370 .where(id, isLessThanWhenPresent(NULL_INTEGER))
371 .and(id, isLessThanOrEqualTo(10))
372 .orderBy(id)
373 .build()
374 .render(RenderingStrategies.MYBATIS3);
375 List<AnimalData> animals = mapper.selectMany(selectStatement);
376 assertAll(
377 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
378 () -> assertThat(animals).hasSize(10),
379 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
380 );
381 }
382 }
383
384 @Test
385 void testLessThanOrEqualToWhenWithValue() {
386 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
387 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
388 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
389 .from(animalData)
390 .where(id, isLessThanOrEqualTo(4))
391 .orderBy(id)
392 .build()
393 .render(RenderingStrategies.MYBATIS3);
394 List<AnimalData> animals = mapper.selectMany(selectStatement);
395 assertAll(
396 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
397 () -> assertThat(animals).hasSize(4),
398 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
399 );
400 }
401 }
402
403 @Test
404 void testLessThanOrEqualToWhenWithoutValue() {
405 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
406 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
407 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
408 .from(animalData)
409 .where(id, isLessThanOrEqualToWhenPresent(NULL_INTEGER))
410 .and(id, isLessThanOrEqualTo(10))
411 .orderBy(id)
412 .build()
413 .render(RenderingStrategies.MYBATIS3);
414 List<AnimalData> animals = mapper.selectMany(selectStatement);
415 assertAll(
416 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
417 () -> assertThat(animals).hasSize(10),
418 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
419 );
420 }
421 }
422
423 @Test
424 void testIsInWhenWithValue() {
425 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
426 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
427 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
428 .from(animalData)
429 .where(id, isIn(4, 5, 6))
430 .orderBy(id)
431 .build()
432 .render(RenderingStrategies.MYBATIS3);
433 List<AnimalData> animals = mapper.selectMany(selectStatement);
434 assertAll(
435 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"),
436 () -> assertThat(animals).hasSize(3),
437 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
438 );
439 }
440 }
441
442 @Test
443 void testIsInWhenWithSomeValues() {
444 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
445 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
446 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
447 .from(animalData)
448 .where(id, isInWhenPresent(3, NULL_INTEGER, 5).map(i -> i + 3))
449 .orderBy(id)
450 .build()
451 .render(RenderingStrategies.MYBATIS3);
452 List<AnimalData> animals = mapper.selectMany(selectStatement);
453 assertAll(
454 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"),
455 () -> assertThat(animals).hasSize(2),
456 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(6),
457 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(8)
458 );
459 }
460 }
461
462 @Test
463 void testIsInCaseInsensitiveWhenWithValue() {
464 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
465 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
466 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
467 .from(animalData)
468 .where(animalName, isInCaseInsensitive("mouse", "musk shrew"))
469 .orderBy(id)
470 .build()
471 .render(RenderingStrategies.MYBATIS3);
472 List<AnimalData> animals = mapper.selectMany(selectStatement);
473 assertAll(
474 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
475 () -> assertThat(animals).hasSize(2),
476 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
477 );
478 }
479 }
480
481 @Test
482 void testValueStreamTransformer() {
483 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
484 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
485 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
486 .from(animalData)
487 .where(animalName, isInWhenPresent(" Mouse", " ", null, "", "Musk shrew ")
488 .map(String::trim)
489 .filter(not(String::isEmpty)))
490 .orderBy(id)
491 .build()
492 .render(RenderingStrategies.MYBATIS3);
493 List<AnimalData> animals = mapper.selectMany(selectStatement);
494 assertAll(
495 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
496 () -> assertThat(animals).hasSize(2),
497 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
498 );
499 }
500 }
501
502 @Test
503 void testValueStreamTransformerWithCustomCondition() {
504 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
505 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
506 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
507 .from(animalData)
508 .where(animalName, MyInCondition.isIn(" Mouse", " ", null, "", "Musk shrew "))
509 .orderBy(id)
510 .build()
511 .render(RenderingStrategies.MYBATIS3);
512 List<AnimalData> animals = mapper.selectMany(selectStatement);
513 assertAll(
514 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
515 () -> assertThat(animals).hasSize(2),
516 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
517 );
518 }
519 }
520
521 @Test
522 void testIsInCaseInsensitiveWhenWithNoValues() {
523 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
524 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
525 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
526 .from(animalData)
527 .where(animalName, isInCaseInsensitiveWhenPresent())
528 .and(id, isLessThanOrEqualTo(10))
529 .orderBy(id)
530 .build()
531 .render(RenderingStrategies.MYBATIS3);
532 List<AnimalData> animals = mapper.selectMany(selectStatement);
533 assertAll(
534 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
535 () -> assertThat(animals).hasSize(10),
536 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
537 );
538 }
539 }
540
541 @Test
542 void testIsNotInWhenWithValue() {
543 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
544 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
545 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
546 .from(animalData)
547 .where(id, isNotIn(4, 5, 6))
548 .and(id, isLessThanOrEqualTo(10))
549 .orderBy(id)
550 .build()
551 .render(RenderingStrategies.MYBATIS3);
552 List<AnimalData> animals = mapper.selectMany(selectStatement);
553 assertAll(
554 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"),
555 () -> assertThat(animals).hasSize(7),
556 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
557 );
558 }
559 }
560
561 @Test
562 void testIsNotInWhenWithSomeValues() {
563 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
564 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
565 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
566 .from(animalData)
567 .where(id, isNotInWhenPresent(3, NULL_INTEGER, 5))
568 .and(id, isLessThanOrEqualTo(10))
569 .orderBy(id)
570 .build()
571 .render(RenderingStrategies.MYBATIS3);
572 List<AnimalData> animals = mapper.selectMany(selectStatement);
573 assertAll(
574 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
575 () -> assertThat(animals).hasSize(8),
576 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
577 );
578 }
579 }
580
581 @Test
582 void testIsNotInCaseInsensitiveWhenWithValue() {
583 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
584 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
585 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
586 .from(animalData)
587 .where(animalName, isNotInCaseInsensitive("mouse", "musk shrew"))
588 .and(id, isLessThanOrEqualTo(10))
589 .orderBy(id)
590 .build()
591 .render(RenderingStrategies.MYBATIS3);
592 List<AnimalData> animals = mapper.selectMany(selectStatement);
593 assertAll(
594 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
595 () -> assertThat(animals).hasSize(8),
596 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
597 );
598 }
599 }
600
601 @Test
602 void testIsNotInCaseInsensitiveWhenWithNoValues() {
603 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
604 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
605 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
606 .from(animalData)
607 .where(animalName, isNotInCaseInsensitiveWhenPresent())
608 .and(id, isLessThanOrEqualTo(10))
609 .orderBy(id)
610 .build()
611 .render(RenderingStrategies.MYBATIS3);
612 List<AnimalData> animals = mapper.selectMany(selectStatement);
613 assertAll(
614 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
615 () -> assertThat(animals).hasSize(10),
616 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
617 );
618 }
619 }
620
621 @Test
622 void testIsBetweenWhenWithValues() {
623 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
624 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
625 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
626 .from(animalData)
627 .where(id, isBetween(3).and(6).filter(Predicates.bothPresent()))
628 .orderBy(id)
629 .build()
630 .render(RenderingStrategies.MYBATIS3);
631 List<AnimalData> animals = mapper.selectMany(selectStatement);
632 assertAll(
633 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"),
634 () -> assertThat(animals).hasSize(4),
635 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3)
636 );
637 }
638 }
639
640 @Test
641 void testIsBetweenWhenWithFirstMissing() {
642 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
643 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
644 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
645 .from(animalData)
646 .where(id, isBetweenWhenPresent(NULL_INTEGER).and(6))
647 .and(id, isLessThanOrEqualTo(10))
648 .orderBy(id)
649 .build()
650 .render(RenderingStrategies.MYBATIS3);
651 List<AnimalData> animals = mapper.selectMany(selectStatement);
652 assertAll(
653 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
654 () -> assertThat(animals).hasSize(10),
655 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
656 );
657 }
658 }
659
660 @Test
661 void testIsBetweenWhenWithSecondMissing() {
662 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
663 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
664 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
665 .from(animalData)
666 .where(id, isBetweenWhenPresent(3).and(NULL_INTEGER))
667 .and(id, isLessThanOrEqualTo(10))
668 .orderBy(id)
669 .build()
670 .render(RenderingStrategies.MYBATIS3);
671 List<AnimalData> animals = mapper.selectMany(selectStatement);
672 assertAll(
673 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
674 () -> assertThat(animals).hasSize(10),
675 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
676 );
677 }
678 }
679
680 @Test
681 void testIsBetweenWhenWithBothMissing() {
682 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
683 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
684 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
685 .from(animalData)
686 .where(id, isBetweenWhenPresent(NULL_INTEGER).and(NULL_INTEGER))
687 .and(id, isLessThanOrEqualTo(10))
688 .orderBy(id)
689 .build()
690 .render(RenderingStrategies.MYBATIS3);
691 List<AnimalData> animals = mapper.selectMany(selectStatement);
692 assertAll(
693 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
694 () -> assertThat(animals).hasSize(10),
695 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
696 );
697 }
698 }
699
700 @Test
701 void testIsNotBetweenWhenWithValues() {
702 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
703 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
704 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
705 .from(animalData)
706 .where(id, isNotBetween(3).and(6).filter(Predicates.bothPresent()))
707 .and(id, isLessThanOrEqualTo(10))
708 .orderBy(id)
709 .build()
710 .render(RenderingStrategies.MYBATIS3);
711 List<AnimalData> animals = mapper.selectMany(selectStatement);
712 assertAll(
713 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
714 () -> assertThat(animals).hasSize(6),
715 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
716 );
717 }
718 }
719
720 @Test
721 void testIsNotBetweenWhenWithFirstMissing() {
722 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
723 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
724 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
725 .from(animalData)
726 .where(id, isNotBetweenWhenPresent(NULL_INTEGER).and(6))
727 .and(id, isLessThanOrEqualTo(10))
728 .orderBy(id)
729 .build()
730 .render(RenderingStrategies.MYBATIS3);
731 List<AnimalData> animals = mapper.selectMany(selectStatement);
732 assertAll(
733 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
734 () -> assertThat(animals).hasSize(10),
735 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
736 );
737 }
738 }
739
740 @Test
741 void testIsNotBetweenWhenWithSecondMissing() {
742 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
743 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
744 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
745 .from(animalData)
746 .where(id, isNotBetweenWhenPresent(3).and(NULL_INTEGER))
747 .and(id, isLessThanOrEqualTo(10))
748 .orderBy(id)
749 .build()
750 .render(RenderingStrategies.MYBATIS3);
751 List<AnimalData> animals = mapper.selectMany(selectStatement);
752 assertAll(
753 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
754 () -> assertThat(animals).hasSize(10),
755 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
756 );
757 }
758 }
759
760 @Test
761 void testIsNotBetweenWhenWithBothMissing() {
762 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
763 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
764 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
765 .from(animalData)
766 .where(id, isNotBetweenWhenPresent(NULL_INTEGER).and(NULL_INTEGER))
767 .and(id, isLessThanOrEqualTo(10))
768 .orderBy(id)
769 .build()
770 .render(RenderingStrategies.MYBATIS3);
771 List<AnimalData> animals = mapper.selectMany(selectStatement);
772 assertAll(
773 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
774 () -> assertThat(animals).hasSize(10),
775 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
776 );
777 }
778 }
779
780 @Test
781 void testIsLikeWhenWithValue() {
782 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
783 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
784 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
785 .from(animalData)
786 .where(animalName, isLike("%mole"))
787 .and(id, isLessThanOrEqualTo(10))
788 .orderBy(id)
789 .build()
790 .render(RenderingStrategies.MYBATIS3);
791 List<AnimalData> animals = mapper.selectMany(selectStatement);
792 assertAll(
793 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
794 () -> assertThat(animals).hasSize(2),
795 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(6)
796 );
797 }
798 }
799
800 @Test
801 void testIsLikeWhenWithoutValue() {
802 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
803 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
804 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
805 .from(animalData)
806 .where(animalName, isLikeWhenPresent((String) null))
807 .and(id, isLessThanOrEqualTo(10))
808 .orderBy(id)
809 .build()
810 .render(RenderingStrategies.MYBATIS3);
811 List<AnimalData> animals = mapper.selectMany(selectStatement);
812 assertAll(
813 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
814 () -> assertThat(animals).hasSize(10),
815 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
816 );
817 }
818 }
819
820 @Test
821 void testIsLikeCaseInsensitiveWhenWithValue() {
822 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
823 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
824 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
825 .from(animalData)
826 .where(animalName, isLikeCaseInsensitive("%MoLe"))
827 .and(id, isLessThanOrEqualTo(10))
828 .orderBy(id)
829 .build()
830 .render(RenderingStrategies.MYBATIS3);
831 List<AnimalData> animals = mapper.selectMany(selectStatement);
832 assertAll(
833 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
834 () -> assertThat(animals).hasSize(2),
835 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(6)
836 );
837 }
838 }
839
840 @Test
841 void testIsLikeCaseInsensitiveWhenWithoutValue() {
842 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
843 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
844 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
845 .from(animalData)
846 .where(animalName, isLikeCaseInsensitiveWhenPresent((String) null))
847 .and(id, isLessThanOrEqualTo(10))
848 .orderBy(id)
849 .build()
850 .render(RenderingStrategies.MYBATIS3);
851 List<AnimalData> animals = mapper.selectMany(selectStatement);
852 assertAll(
853 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
854 () -> assertThat(animals).hasSize(10),
855 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
856 );
857 }
858 }
859
860 @Test
861 void testIsNotLikeWhenWithValue() {
862 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
863 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
864 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
865 .from(animalData)
866 .where(animalName, isNotLike("%mole"))
867 .and(id, isLessThanOrEqualTo(10))
868 .orderBy(id)
869 .build()
870 .render(RenderingStrategies.MYBATIS3);
871 List<AnimalData> animals = mapper.selectMany(selectStatement);
872 assertAll(
873 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
874 () -> assertThat(animals).hasSize(8),
875 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
876 );
877 }
878 }
879
880 @Test
881 void testIsNotLikeWhenWithoutValue() {
882 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
883 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
884 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
885 .from(animalData)
886 .where(animalName, isNotLikeWhenPresent((String) null))
887 .and(id, isLessThanOrEqualTo(10))
888 .orderBy(id)
889 .build()
890 .render(RenderingStrategies.MYBATIS3);
891 List<AnimalData> animals = mapper.selectMany(selectStatement);
892 assertAll(
893 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
894 () -> assertThat(animals).hasSize(10),
895 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
896 );
897 }
898 }
899
900 @Test
901 void testIsNotLikeCaseInsensitiveWhenWithValue() {
902 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
903 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
904 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
905 .from(animalData)
906 .where(animalName, isNotLikeCaseInsensitive("%MoLe"))
907 .and(id, isLessThanOrEqualTo(10))
908 .orderBy(id)
909 .build()
910 .render(RenderingStrategies.MYBATIS3);
911 List<AnimalData> animals = mapper.selectMany(selectStatement);
912 assertAll(
913 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
914 () -> assertThat(animals).hasSize(8),
915 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
916 );
917 }
918 }
919
920 @Test
921 void testIsNotLikeCaseInsensitiveWhenWithoutValue() {
922 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
923 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
924 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
925 .from(animalData)
926 .where(animalName, isNotLikeCaseInsensitiveWhenPresent((String) null))
927 .and(id, isLessThanOrEqualTo(10))
928 .orderBy(id)
929 .build()
930 .render(RenderingStrategies.MYBATIS3);
931 List<AnimalData> animals = mapper.selectMany(selectStatement);
932 assertAll(
933 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
934 () -> assertThat(animals).hasSize(10),
935 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
936 );
937 }
938 }
939 }