diff --git a/core/src/main/java/google/registry/model/common/GaeUserIdConverter.java b/core/src/main/java/google/registry/model/common/GaeUserIdConverter.java index b1a6b943c..dcff7ebb7 100644 --- a/core/src/main/java/google/registry/model/common/GaeUserIdConverter.java +++ b/core/src/main/java/google/registry/model/common/GaeUserIdConverter.java @@ -16,7 +16,7 @@ package google.registry.model.common; import static com.google.common.base.Preconditions.checkState; import static google.registry.model.IdService.allocateId; -import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import com.google.appengine.api.users.User; import com.google.common.base.Splitter; @@ -55,22 +55,19 @@ public class GaeUserIdConverter extends ImmutableObject { try { // Perform these operations in a transactionless context to avoid enlisting in some outer // transaction (if any). - ofyTm() + auditedOfy() .doTransactionless( () -> { - ofyTm().putWithoutBackup(gaeUserIdConverter); + auditedOfy().saveWithoutBackup().entity(gaeUserIdConverter).now(); return null; }); - // The read must be done in its own transaction to avoid reading from the session cache. - return ofyTm().transactNew(() -> ofyTm().loadByEntity(gaeUserIdConverter).user.getUserId()); + return auditedOfy() + .transactNew(() -> auditedOfy().load().entity(gaeUserIdConverter).now().user.getUserId()); } finally { - ofyTm() + auditedOfy() .doTransactionless( - () -> { - ofyTm().deleteWithoutBackup(gaeUserIdConverter); - return null; - }); + () -> auditedOfy().deleteWithoutBackup().entity(gaeUserIdConverter).now()); } } } diff --git a/core/src/main/java/google/registry/model/ofy/Ofy.java b/core/src/main/java/google/registry/model/ofy/Ofy.java index be69d7efe..eafa8c1d6 100644 --- a/core/src/main/java/google/registry/model/ofy/Ofy.java +++ b/core/src/main/java/google/registry/model/ofy/Ofy.java @@ -242,7 +242,7 @@ public class Ofy { } /** Pause the current transaction (if any) and complete this one before returning to it. */ - R transactNew(Supplier work) { + public R transactNew(Supplier work) { // Wrap the Work in a CommitLoggedWork so that we can give transactions a frozen view of time // and maintain commit logs for them. return transactCommitLoggedWork(new CommitLoggedWork<>(work, getClock())); diff --git a/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java b/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java index 49814bb22..0fe605aef 100644 --- a/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java +++ b/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java @@ -15,8 +15,7 @@ package google.registry.model.common; import static com.google.common.truth.Truth.assertThat; -import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; -import static google.registry.persistence.transaction.TransactionManagerFactory.tm; +import static google.registry.model.ofy.ObjectifyService.auditedOfy; import google.registry.testing.AppEngineExtension; import org.junit.jupiter.api.AfterEach; @@ -32,7 +31,7 @@ public class GaeUserIdConverterTest { @AfterEach void verifyNoLingeringEntities() { - assertThat(ofyTm().loadAllOf(GaeUserIdConverter.class)).hasSize(0); + assertThat(auditedOfy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0); } @Test @@ -43,9 +42,12 @@ public class GaeUserIdConverterTest { @Test void testSuccess_inTransaction() { - tm().transactNew( - () -> - assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com")) - .matches("[0-9]+")); + auditedOfy() + .transactNew( + () -> { + assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com")) + .matches("[0-9]+"); + return null; + }); } }