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:
gbrodman
2021-05-12 15:06:19 -04:00
committed by GitHub
parent 8c9a2b5f4a
commit af67356aa0
20 changed files with 118 additions and 83 deletions
@@ -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 {