mirror of
https://github.com/google/nomulus.git
synced 2025-05-30 01:10:14 +02:00
Add a method to set a "not in" WHERE clause in CriteriaQueryBuilder (#1225)
<!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/google/nomulus/1225) <!-- Reviewable:end -->
This commit is contained in:
parent
1e112609d9
commit
aaf3e95d08
2 changed files with 22 additions and 0 deletions
|
@ -62,6 +62,13 @@ public class CriteriaQueryBuilder<T> {
|
||||||
return where(root.get(fieldName).in(values));
|
return where(root.get(fieldName).in(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a WHERE clause to the query specifying that a value must not be in the given collection.
|
||||||
|
*/
|
||||||
|
public CriteriaQueryBuilder<T> whereFieldIsNotIn(String fieldName, Collection<?> values) {
|
||||||
|
return where(root.get(fieldName).in(values).not());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a WHERE clause to the query specifying that a collection field must contain a particular
|
* Adds a WHERE clause to the query specifying that a collection field must contain a particular
|
||||||
* value.
|
* value.
|
||||||
|
|
|
@ -152,6 +152,21 @@ class CriteriaQueryBuilderTest {
|
||||||
assertThat(result).containsExactly(entity3).inOrder();
|
assertThat(result).containsExactly(entity3).inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSuccess_where_not_in_twoResults() {
|
||||||
|
List<CriteriaQueryBuilderTestEntity> result =
|
||||||
|
jpaTm()
|
||||||
|
.transact(
|
||||||
|
() -> {
|
||||||
|
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
|
||||||
|
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
|
||||||
|
.whereFieldIsNotIn("data", ImmutableList.of("aaa", "bbb"))
|
||||||
|
.build();
|
||||||
|
return jpaTm().query(query).getResultList();
|
||||||
|
});
|
||||||
|
assertThat(result).containsExactly(entity1, entity2).inOrder();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuccess_where_in_twoResults() {
|
void testSuccess_where_in_twoResults() {
|
||||||
List<CriteriaQueryBuilderTestEntity> result =
|
List<CriteriaQueryBuilderTestEntity> result =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue