|
22 | 22 |
|
23 | 23 | import java.sql.Date; |
24 | 24 | import java.time.LocalDate; |
| 25 | +import java.util.LinkedHashMap; |
25 | 26 | import java.util.List; |
| 27 | +import java.util.Map; |
26 | 28 | import java.util.stream.Stream; |
27 | 29 |
|
28 | 30 | import org.hibernate.LazyInitializationException; |
|
31 | 33 | import org.junit.jupiter.api.extension.ExtendWith; |
32 | 34 |
|
33 | 35 | import org.springframework.dao.IncorrectResultSizeDataAccessException; |
| 36 | +import org.springframework.data.domain.KeysetScrollPosition; |
34 | 37 | import org.springframework.data.domain.Page; |
35 | 38 | import org.springframework.data.domain.PageRequest; |
36 | 39 | import org.springframework.data.domain.Pageable; |
| 40 | +import org.springframework.data.domain.ScrollPosition; |
37 | 41 | import org.springframework.data.domain.Slice; |
38 | 42 | import org.springframework.data.domain.Sort; |
39 | 43 | import org.springframework.data.domain.Sort.Direction; |
|
42 | 46 | import org.springframework.data.jpa.domain.sample.QUser; |
43 | 47 | import org.springframework.data.jpa.domain.sample.Role; |
44 | 48 | import org.springframework.data.jpa.domain.sample.User; |
| 49 | +import org.springframework.data.jpa.repository.query.KeysetScrollDelegate; |
45 | 50 | import org.springframework.data.querydsl.QPageRequest; |
46 | 51 | import org.springframework.data.querydsl.QSort; |
47 | 52 | import org.springframework.data.querydsl.SimpleEntityPathResolver; |
|
53 | 58 | import com.querydsl.core.types.dsl.BooleanExpression; |
54 | 59 | import com.querydsl.core.types.dsl.PathBuilder; |
55 | 60 | import com.querydsl.core.types.dsl.PathBuilderFactory; |
| 61 | +import com.querydsl.jpa.HQLTemplates; |
| 62 | +import com.querydsl.jpa.JPQLSerializer; |
56 | 63 |
|
57 | 64 | /** |
58 | 65 | * Integration test for {@link QuerydslJpaPredicateExecutor}. |
|
65 | 72 | * @author Malte Mauelshagen |
66 | 73 | * @author Greg Turnquist |
67 | 74 | * @author Krzysztof Krason |
| 75 | + * @author Ilya Bakaev |
68 | 76 | */ |
69 | 77 | @ExtendWith(SpringExtension.class) |
70 | 78 | @ContextConfiguration("classpath:hibernate-infrastructure.xml") |
@@ -562,6 +570,28 @@ void deleteShouldDeleteUsers() { |
562 | 570 | assertThat(predicateExecutor.findAll(user.dateOfBirth.isNull())).isEmpty(); |
563 | 571 | } |
564 | 572 |
|
| 573 | + @Test // GH-4275 |
| 574 | + void keysetPredicateRendersIsNullCorrectly() { |
| 575 | + |
| 576 | + Map<String, Object> keys = new LinkedHashMap<>(); |
| 577 | + keys.put("firstname", "Jane"); |
| 578 | + keys.put("lastname", null); |
| 579 | + keys.put("emailAddress", "jane@doe2.com"); |
| 580 | + |
| 581 | + KeysetScrollPosition keyset = ScrollPosition.forward(keys); |
| 582 | + Sort sort = Sort.by(Order.asc("firstname"), Order.asc("lastname"), Order.asc("emailAddress")); |
| 583 | + |
| 584 | + var strategy = predicateExecutor.new QuerydslQueryStrategy(); |
| 585 | + BooleanExpression predicate = KeysetScrollDelegate.of(keyset.getDirection()).createPredicate(keyset, sort, |
| 586 | + strategy); |
| 587 | + |
| 588 | + JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); |
| 589 | + serializer.handle(predicate); |
| 590 | + String jpql = serializer.toString(); |
| 591 | + |
| 592 | + assertThat(jpql).contains("lastname is null").contains("lastname is not null").doesNotContain("= null"); |
| 593 | + } |
| 594 | + |
565 | 595 | private interface UserProjectionInterfaceBased { |
566 | 596 |
|
567 | 597 | String getFirstname(); |
|
0 commit comments