diff --git a/core/src/main/java/google/registry/beam/initsql/Transforms.java b/core/src/main/java/google/registry/beam/initsql/Transforms.java index df082cdbf..e18e6dc24 100644 --- a/core/src/main/java/google/registry/beam/initsql/Transforms.java +++ b/core/src/main/java/google/registry/beam/initsql/Transforms.java @@ -19,7 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static google.registry.beam.initsql.BackupPaths.getCommitLogTimestamp; import static google.registry.beam.initsql.BackupPaths.getExportFilePatterns; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static java.util.Comparator.comparing; @@ -353,7 +353,7 @@ public final class Transforms { .getEntity() .filter(Transforms::isMigratable) .map(Transforms::repairBadData) - .map(e -> ofy().toPojo(e)) + .map(e -> auditedOfy().toPojo(e)) .map(Transforms::toSqlEntity) .orElse(null); } diff --git a/core/src/main/java/google/registry/mapreduce/inputs/ChildEntityReader.java b/core/src/main/java/google/registry/mapreduce/inputs/ChildEntityReader.java index 0a84a7051..b1d5be54a 100644 --- a/core/src/main/java/google/registry/mapreduce/inputs/ChildEntityReader.java +++ b/core/src/main/java/google/registry/mapreduce/inputs/ChildEntityReader.java @@ -15,7 +15,7 @@ package google.registry.mapreduce.inputs; import static google.registry.model.EntityClasses.ALL_CLASSES; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.api.datastore.Cursor; import com.google.appengine.api.datastore.QueryResultIterator; @@ -232,7 +232,7 @@ class ChildEntityReader extend /** Query for children of the current resource and of the current child class. */ @Override public QueryResultIterator getQueryIterator(Cursor cursor) { - return startQueryAt(ofy().load().type(type).ancestor(ancestor), cursor).iterator(); + return startQueryAt(auditedOfy().load().type(type).ancestor(ancestor), cursor).iterator(); } @Override diff --git a/core/src/main/java/google/registry/mapreduce/inputs/CommitLogManifestReader.java b/core/src/main/java/google/registry/mapreduce/inputs/CommitLogManifestReader.java index 569db3c66..9fd905104 100644 --- a/core/src/main/java/google/registry/mapreduce/inputs/CommitLogManifestReader.java +++ b/core/src/main/java/google/registry/mapreduce/inputs/CommitLogManifestReader.java @@ -14,7 +14,7 @@ package google.registry.mapreduce.inputs; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.api.datastore.Cursor; import com.google.appengine.api.datastore.QueryResultIterator; @@ -68,7 +68,8 @@ class CommitLogManifestReader /** Query for children of this bucket. */ Query createBucketQuery() { - Query query = ofy().load().type(CommitLogManifest.class).ancestor(bucketKey); + Query query = + auditedOfy().load().type(CommitLogManifest.class).ancestor(bucketKey); if (olderThan != null) { query = query.filterKey( "<", diff --git a/core/src/main/java/google/registry/mapreduce/inputs/EppResourceBaseReader.java b/core/src/main/java/google/registry/mapreduce/inputs/EppResourceBaseReader.java index 768142c42..b3a42b29c 100644 --- a/core/src/main/java/google/registry/mapreduce/inputs/EppResourceBaseReader.java +++ b/core/src/main/java/google/registry/mapreduce/inputs/EppResourceBaseReader.java @@ -15,7 +15,7 @@ package google.registry.mapreduce.inputs; import static com.google.common.collect.ImmutableSet.toImmutableSet; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.api.datastore.Cursor; import com.google.appengine.api.datastore.QueryResultIterator; @@ -68,7 +68,8 @@ abstract class EppResourceBaseReader extends RetryingInputReader query() { - Query query = ofy().load().type(EppResourceIndex.class).ancestor(bucketKey); + Query query = + auditedOfy().load().type(EppResourceIndex.class).ancestor(bucketKey); return filterKinds.isEmpty() ? query : query.filter("kind in", filterKinds); } diff --git a/core/src/main/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java b/core/src/main/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java index 6e9639fad..5c44af4aa 100644 --- a/core/src/main/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java +++ b/core/src/main/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java @@ -14,7 +14,7 @@ package google.registry.mapreduce.inputs; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.tools.mapreduce.InputReader; import com.google.common.collect.ImmutableSet; @@ -62,7 +62,7 @@ class EppResourceEntityReader extends EppResourceBaseRead // Loop until we find a value, or nextQueryResult() throws a NoSuchElementException. while (true) { Key key = nextQueryResult().getKey(); - EppResource resource = ofy().load().key(key).now(); + EppResource resource = auditedOfy().load().key(key).now(); if (resource == null) { logger.atSevere().log("EppResourceIndex key %s points at a missing resource", key); continue; diff --git a/core/src/main/java/google/registry/mapreduce/inputs/RetryingInputReader.java b/core/src/main/java/google/registry/mapreduce/inputs/RetryingInputReader.java index 10a753f22..190289838 100644 --- a/core/src/main/java/google/registry/mapreduce/inputs/RetryingInputReader.java +++ b/core/src/main/java/google/registry/mapreduce/inputs/RetryingInputReader.java @@ -15,7 +15,7 @@ package google.registry.mapreduce.inputs; import static com.google.common.base.Preconditions.checkNotNull; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.api.datastore.Cursor; import com.google.appengine.api.datastore.DatastoreTimeoutException; @@ -150,7 +150,7 @@ abstract class RetryingInputReader extends InputReader { String.format("Got an unrecoverable failure while reading item %d/%d.", loaded, total), e); } finally { - ofy().clearSessionCache(); + auditedOfy().clearSessionCache(); } } diff --git a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java index b189a3fec..b86106ad4 100644 --- a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java +++ b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java @@ -66,15 +66,19 @@ public class ObjectifyService { /** A singleton instance of our Ofy wrapper. */ private static final Ofy OFY = new Ofy(null); - /** - * Returns a singleton {@link Ofy} instance. - * - *

Deprecated: This will go away once everything injects {@code Ofy}. - */ + /** Returns the singleton {@link Ofy} instance. */ public static Ofy ofy() { return OFY; } + /** + * Returns the singleton {@link Ofy} instance, signifying that the caller has been audited for the + * Registry 3.0 conversion. + */ + public static Ofy auditedOfy() { + return OFY; + } + static { initOfyOnce(); } diff --git a/core/src/main/java/google/registry/persistence/transaction/Transaction.java b/core/src/main/java/google/registry/persistence/transaction/Transaction.java index 65ba63479..b93d1638b 100644 --- a/core/src/main/java/google/registry/persistence/transaction/Transaction.java +++ b/core/src/main/java/google/registry/persistence/transaction/Transaction.java @@ -16,6 +16,7 @@ package google.registry.persistence.transaction; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; @@ -25,7 +26,6 @@ import com.google.common.collect.ImmutableList; import com.google.storage.onestore.v3.OnestoreEntity.EntityProto; import google.registry.model.Buildable; import google.registry.model.ImmutableObject; -import google.registry.model.ofy.ObjectifyService; import google.registry.persistence.VKey; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -214,7 +214,7 @@ public class Transaction extends ImmutableObject implements Buildable { @Override public void serializeTo(ObjectOutputStream out) throws IOException { out.writeObject(Type.UPDATE); - Entity realEntity = ObjectifyService.ofy().toEntity(entity); + Entity realEntity = auditedOfy().toEntity(entity); EntityProto proto = EntityTranslator.convertToPb(realEntity); out.write(VERSION_ID); proto.writeDelimitedTo(out); @@ -223,7 +223,7 @@ public class Transaction extends ImmutableObject implements Buildable { public static Update deserializeFrom(ObjectInputStream in) throws IOException { EntityProto proto = new EntityProto(); proto.parseDelimitedFrom(in); - return new Update(ObjectifyService.ofy().toPojo(EntityTranslator.createFromPb(proto))); + return new Update(auditedOfy().toPojo(EntityTranslator.createFromPb(proto))); } } diff --git a/core/src/main/java/google/registry/persistence/transaction/TransactionManager.java b/core/src/main/java/google/registry/persistence/transaction/TransactionManager.java index 06e7823cc..db00eb944 100644 --- a/core/src/main/java/google/registry/persistence/transaction/TransactionManager.java +++ b/core/src/main/java/google/registry/persistence/transaction/TransactionManager.java @@ -163,9 +163,9 @@ public interface TransactionManager { * Updates an entity in the database without writing commit logs if the underlying database is * Datastore. * - *

This method is for the sake of keeping a single code path when replacing ofy() with tm() in - * the application code. When the method is invoked with Datastore, it won't write the commit log - * backup; when invoked with Cloud SQL, it behaves the same as the method which doesn't have + *

This method is for the sake of keeping a single code path when replacing ofy calls with tm() + * in the application code. When the method is invoked with Datastore, it won't write the commit + * log backup; when invoked with Cloud SQL, it behaves the same as the method which doesn't have * "WithoutBackup" in its method name because it is not necessary to have the backup mechanism in * SQL. */ @@ -175,9 +175,9 @@ public interface TransactionManager { * Updates all entities in the database without writing any backup if the underlying database is * Datastore. * - *

This method is for the sake of keeping a single code path when replacing ofy() with tm() in - * the application code. When the method is invoked with Datastore, it won't write the commit log - * backup; when invoked with Cloud SQL, it behaves the same as the method which doesn't have + *

This method is for the sake of keeping a single code path when replacing ofy calls with tm() + * in the application code. When the method is invoked with Datastore, it won't write the commit + * log backup; when invoked with Cloud SQL, it behaves the same as the method which doesn't have * "WithoutBackup" in its method name because it is not necessary to have the backup mechanism in * SQL. */ diff --git a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java index 33a2c37e4..46013dcd2 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java @@ -17,7 +17,7 @@ package google.registry.rdap; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; @@ -206,7 +206,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { RdapResultSet resultSet; if (isDatastore()) { Query query = - ofy() + auditedOfy() .load() .type(DomainBase.class) .filter("fullyQualifiedDomainName <", partialStringQuery.getNextInitialString()) @@ -261,7 +261,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { int querySizeLimit = RESULT_SET_SIZE_SCALING_FACTOR * rdapResultSetMaxSize; RdapResultSet resultSet; if (isDatastore()) { - Query query = ofy().load().type(DomainBase.class).filter("tld", tld); + Query query = auditedOfy().load().type(DomainBase.class).filter("tld", tld); if (cursorString.isPresent()) { query = query.filter("fullyQualifiedDomainName >", cursorString.get()); } @@ -546,7 +546,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { numHostKeysSearched += chunk.size(); if (isDatastore()) { Query query = - ofy() + auditedOfy() .load() .type(DomainBase.class) .filter( diff --git a/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java b/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java index 29a72e3cc..5cf4d5225 100644 --- a/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java +++ b/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java @@ -15,7 +15,7 @@ package google.registry.rdap; import static com.google.common.base.Charsets.UTF_8; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.util.DateTimeUtils.END_OF_TIME; @@ -358,7 +358,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase { "Initial search string must be at least %d characters", RdapSearchPattern.MIN_INITIAL_STRING_LENGTH)); } - Query query = ofy().load().type(clazz); + Query query = auditedOfy().load().type(clazz); if (!partialStringQuery.getHasWildcard()) { query = query.filter(filterField, partialStringQuery.getInitialString()); } else { @@ -457,7 +457,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase { "Initial search string must be at least %d characters", RdapSearchPattern.MIN_INITIAL_STRING_LENGTH)); } - Query query = ofy().load().type(clazz).filter(filterField, queryString); + Query query = auditedOfy().load().type(clazz).filter(filterField, queryString); if (cursorString.isPresent()) { if (cursorField.isPresent()) { query = query.filter(cursorField.get() + " >", cursorString.get()); @@ -526,7 +526,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase { "Initial search string must be at least %d characters", RdapSearchPattern.MIN_INITIAL_STRING_LENGTH)); } - Query query = ofy().load().type(clazz); + Query query = auditedOfy().load().type(clazz); if (!partialStringQuery.getHasWildcard()) { query = query.filterKey("=", Key.create(clazz, partialStringQuery.getInitialString())); } else {