Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.querydsl.core.types.ConstantImpl;
import com.querydsl.core.types.EntityPath;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.NullExpression;
import com.querydsl.core.types.Ops;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
Expand All @@ -74,6 +73,7 @@
* @author Jens Schauder
* @author Greg Turnquist
* @author Yanming Zhou
* @author Ilya Bakaev
*/
public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecutor<T>, JpaRepositoryConfigurationAware {

Expand Down Expand Up @@ -424,8 +424,9 @@ public BooleanExpression compare(Order order, Expression<?> propertyExpression,

@Override
public BooleanExpression compare(String property, Expression<?> propertyExpression, @Nullable Object value) {
return Expressions.booleanOperation(Ops.EQ, propertyExpression,
value == null ? NullExpression.DEFAULT : ConstantImpl.create(value));
return value == null
? Expressions.booleanOperation(Ops.IS_NULL, propertyExpression)
: Expressions.booleanOperation(Ops.EQ, propertyExpression, ConstantImpl.create(value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
* @author Geoffrey Deremetz
* @author Krzysztof Krason
* @author Yanming Zhou
* @author Ilya Bakaev
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:application-context.xml")
Expand Down Expand Up @@ -1522,6 +1523,130 @@ void scrollByPartTreeKeysetBackward() {
assertThat(previousWindow.hasNext()).isFalse();
}

@Test
void scrollByPredicateKeysetWithAscNullsFirst() {

User jane1 = new User("Jane", "Doe", "jane@doe1.com");
User jane2 = new User("Jane", null, "jane@doe2.com");
User jane3 = new User("Jane", null, "jane@doe3.com");
User john1 = new User("John", "Doe", "john@doe1.com");
User john2 = new User("John", null, "john@doe2.com");
User john3 = new User("John", null, "john@doe3.com");

repository.saveAllAndFlush(Arrays.asList(john1, john2, john3, jane1, jane2, jane3));

Sort sort = Sort.by(
Order.asc("firstname"),
Order.asc("lastname").nullsFirst(),
Order.asc("emailAddress")
);

Window<User> firstWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(1).sortBy(sort).scroll(ScrollPosition.keyset()));

assertThat(firstWindow).containsOnly(jane2);
assertThat(firstWindow.hasNext()).isTrue();

Window<User> nextWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(3).sortBy(sort).scroll(firstWindow.positionAt(0)));

assertThat(nextWindow).containsExactly(jane3, jane1, john2);
assertThat(nextWindow.hasNext()).isTrue();
}

@Test // GH-2878
void scrollByPredicateKeysetWithDescNullsFirst() {

User jane1 = new User("Jane", "Doe", "jane@doe1.com");
User jane2 = new User("Jane", null, "jane@doe2.com");
User jane3 = new User("Jane", null, "jane@doe3.com");
User john1 = new User("John", "Doe", "john@doe1.com");
User john2 = new User("John", null, "john@doe2.com");
User john3 = new User("John", null, "john@doe3.com");

repository.saveAllAndFlush(Arrays.asList(john1, john2, john3, jane1, jane2, jane3));

Sort sort = Sort.by(
Order.asc("firstname"),
Order.desc("lastname").nullsFirst(),
Order.asc("emailAddress")
);

Window<User> firstWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(1).sortBy(sort).scroll(ScrollPosition.keyset()));

assertThat(firstWindow).containsOnly(jane2);
assertThat(firstWindow.hasNext()).isTrue();

Window<User> nextWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(3).sortBy(sort).scroll(firstWindow.positionAt(0)));

assertThat(nextWindow).containsExactly(jane3, jane1, john2);
assertThat(nextWindow.hasNext()).isTrue();
}

@Test // GH-2878
void scrollByPredicateKeysetWithAscNullsLast() {

User jane1 = new User("Jane", "Doe", "jane@doe1.com");
User jane2 = new User("Jane", null, "jane@doe2.com");
User jane3 = new User("Jane", null, "jane@doe3.com");
User john1 = new User("John", "Doe", "john@doe1.com");
User john2 = new User("John", null, "john@doe2.com");
User john3 = new User("John", null, "john@doe3.com");

repository.saveAllAndFlush(Arrays.asList(john1, john2, john3, jane1, jane2, jane3));

Sort sort = Sort.by(
Order.asc("firstname"),
Order.asc("lastname").nullsLast(),
Order.asc("emailAddress")
);

Window<User> firstWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(1).sortBy(sort).scroll(ScrollPosition.keyset()));

assertThat(firstWindow).containsOnly(jane1);
assertThat(firstWindow.hasNext()).isTrue();

Window<User> nextWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(3).sortBy(sort).scroll(firstWindow.positionAt(0)));

assertThat(nextWindow).containsExactly(jane2, jane3, john1);
assertThat(nextWindow.hasNext()).isTrue();
}

@Test // GH-2878
void scrollByPredicateKeysetWithDescNullsLast() {

User jane1 = new User("Jane", "Doe", "jane@doe1.com");
User jane2 = new User("Jane", null, "jane@doe2.com");
User jane3 = new User("Jane", null, "jane@doe3.com");
User john1 = new User("John", "Doe", "john@doe1.com");
User john2 = new User("John", null, "john@doe2.com");
User john3 = new User("John", null, "john@doe3.com");

repository.saveAllAndFlush(Arrays.asList(john1, john2, john3, jane1, jane2, jane3));

Sort sort = Sort.by(
Order.asc("firstname"),
Order.desc("lastname").nullsLast(),
Order.asc("emailAddress")
);

Window<User> firstWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(1).sortBy(sort).scroll(ScrollPosition.keyset()));

assertThat(firstWindow).containsOnly(jane1);
assertThat(firstWindow.hasNext()).isTrue();

Window<User> nextWindow = repository.findBy(QUser.user.firstname.startsWith("J"),
q -> q.limit(3).sortBy(sort).scroll(firstWindow.positionAt(0)));

assertThat(nextWindow).containsExactly(jane2, jane3, john1);
assertThat(nextWindow.hasNext()).isTrue();
}

@Test // GH-3015, GH-3407
void shouldApplyOffsetScrollPosition() {

Expand Down