mirror of
https://github.com/google/nomulus
synced 2026-09-06 16:17:13 +00:00
Convert more ofy() to auditedOfy() calls (#1152)
A couple of these use the QueryComposer interface to avoid branching. In addition, we enforce the Datastore restriction that there can be at most 1 field with an inequality query, see https://cloud.google.com/appengine/docs/standard/go111/datastore/query-restrictions#inequality_filters_are_limited_to_at_most_one_property
This commit is contained in:
@@ -30,6 +30,8 @@ import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import google.registry.testing.TestOfyOnly;
|
||||
import google.registry.testing.TestSqlOnly;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.NoResultException;
|
||||
@@ -263,6 +265,33 @@ public class QueryComposerTest {
|
||||
.isEqualTo(ImmutableList.of());
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
void testMultipleInequalities_failsDatastore() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
tm().createQueryComposer(TestEntity.class)
|
||||
.where("val", Comparator.GT, 1)
|
||||
.where("name", Comparator.LT, "b")
|
||||
.list()))
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Datastore cannot handle inequality queries on multiple fields, we found 2 fields.");
|
||||
}
|
||||
|
||||
@TestSqlOnly
|
||||
void testMultipleInequalities_succeedsSql() {
|
||||
assertThat(
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm().createQueryComposer(TestEntity.class)
|
||||
.where("val", Comparator.GT, 1)
|
||||
.where("name", Comparator.LT, "b")
|
||||
.list()))
|
||||
.containsExactly(alpha);
|
||||
}
|
||||
|
||||
@javax.persistence.Entity
|
||||
@Entity(name = "QueryComposerTestEntity")
|
||||
private static class TestEntity extends ImmutableObject {
|
||||
|
||||
Reference in New Issue
Block a user