Remove TransactionManagerFactory.jpaTm() (#1883)

Since JPA is the only TM now, there's no point distinguishing tm() from
jpaTm().
This commit is contained in:
Lai Jiang 2022-12-13 14:37:46 -05:00 committed by GitHub
parent 1242e3d50c
commit 3848771c75
123 changed files with 806 additions and 1181 deletions

View file

@ -14,7 +14,7 @@
package google.registry.batch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistEppResource;
@ -110,7 +110,7 @@ public class CheckPackagesComplianceActionTest {
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion));
tm().transact(() -> tm().put(packagePromotion));
contact = persistActiveContact("contact1234");
}
@ -199,7 +199,7 @@ public class CheckPackagesComplianceActionTest {
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion2));
tm().transact(() -> tm().put(packagePromotion2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
@ -253,7 +253,7 @@ public class CheckPackagesComplianceActionTest {
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2015-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion2));
tm().transact(() -> tm().put(packagePromotion2));
// Create limit is 1, creating 2 domains to go over the limit
persistEppResource(

View file

@ -17,7 +17,7 @@ package google.registry.batch;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.apache.http.HttpStatus.SC_OK;
@ -118,8 +118,7 @@ class WipeOutContactHistoryPiiActionTest {
void getAllHistoryEntitiesOlderThan_returnsAllPersistedEntities() {
ImmutableList<ContactHistory> expectedToBeWipedOut =
persistLotsOfContactHistoryEntities(20, MIN_MONTHS_BEFORE_WIPE_OUT + 1, 0, DEFAULT_CONTACT);
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
action.getNextContactHistoryEntitiesWithPiiBatch(
@ -135,8 +134,7 @@ class WipeOutContactHistoryPiiActionTest {
// persisted entities that should not be part of the actual result
persistLotsOfContactHistoryEntities(15, 17, MIN_MONTHS_BEFORE_WIPE_OUT - 1, DEFAULT_CONTACT);
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
action.getNextContactHistoryEntitiesWithPiiBatch(
@ -147,8 +145,7 @@ class WipeOutContactHistoryPiiActionTest {
@Test
void run_withNoEntitiesToWipeOut_success() {
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -158,8 +155,7 @@ class WipeOutContactHistoryPiiActionTest {
action.run();
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -180,8 +176,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return a stream of all persisted entities.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -197,8 +192,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return an empty stream after the wipe out action.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -217,8 +211,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return a subset of all persisted data.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -233,8 +226,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return an empty stream after the wipe out action.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -254,8 +246,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return a subset of all persisted data.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -270,8 +261,7 @@ class WipeOutContactHistoryPiiActionTest {
// The query should return an empty stream after the wipe out action.
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
action
.getNextContactHistoryEntitiesWithPiiBatch(
@ -284,8 +274,7 @@ class WipeOutContactHistoryPiiActionTest {
@Test
void wipeOutContactHistoryData_wipesOutNoEntity() {
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
action.wipeOutContactHistoryData(
@ -302,8 +291,7 @@ class WipeOutContactHistoryPiiActionTest {
assertAllEntitiesContainPii(DatabaseHelper.loadByEntitiesIfPresent(expectedToBeWipedOut));
jpaTm()
.transact(
tm().transact(
() -> {
action.wipeOutContactHistoryData(
action.getNextContactHistoryEntitiesWithPiiBatch(

View file

@ -14,7 +14,7 @@
package google.registry.beam.common;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth;
@ -81,12 +81,12 @@ public class DatabaseSnapshotTest {
jpa =
new JpaTransactionManagerImpl(
Persistence.createEntityManagerFactory("nomulus", jpaProperties), new FakeClock());
origJpa = jpaTm();
origJpa = tm();
TransactionManagerFactory.setJpaTm(() -> jpa);
Registry tld = DatabaseHelper.newRegistry("tld", "TLD");
jpaTm().transact(() -> jpaTm().put(tld));
registry = jpaTm().transact(() -> jpaTm().loadByEntity(tld));
tm().transact(() -> tm().put(tld));
registry = tm().transact(() -> tm().loadByEntity(tld));
}
@AfterAll
@ -113,11 +113,9 @@ public class DatabaseSnapshotTest {
void readSnapshot() {
try (DatabaseSnapshot databaseSnapshot = DatabaseSnapshot.createSnapshot()) {
Registry snapshotRegistry =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
tm().setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
.loadByEntity(registry));
Truth.assertThat(snapshotRegistry).isEqualTo(registry);
}
@ -131,22 +129,20 @@ public class DatabaseSnapshotTest {
.asBuilder()
.setCreateBillingCost(registry.getStandardCreateCost().plus(1))
.build();
jpaTm().transact(() -> jpaTm().put(updated));
tm().transact(() -> tm().put(updated));
Registry persistedUpdate = jpaTm().transact(() -> jpaTm().loadByEntity(registry));
Registry persistedUpdate = tm().transact(() -> tm().loadByEntity(registry));
Truth.assertThat(persistedUpdate).isNotEqualTo(registry);
Registry snapshotRegistry =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
tm().setDatabaseSnapshot(databaseSnapshot.getSnapshotId())
.loadByEntity(registry));
Truth.assertThat(snapshotRegistry).isEqualTo(registry);
} finally {
// Revert change to registry in DB, which is shared by all test methods.
jpaTm().transact(() -> jpaTm().put(registry));
tm().transact(() -> tm().put(registry));
}
}
@ -158,7 +154,7 @@ public class DatabaseSnapshotTest {
.asBuilder()
.setCreateBillingCost(registry.getStandardCreateCost().plus(1))
.build();
jpaTm().transact(() -> jpaTm().put(updated));
tm().transact(() -> tm().put(updated));
Read<Registry, Registry> read =
RegistryJpaIO.read(() -> CriteriaQueryBuilder.create(Registry.class).build(), x -> x)
@ -172,7 +168,7 @@ public class DatabaseSnapshotTest {
testPipeline.run();
} finally {
// Revert change to registry in DB, which is shared by all test methods.
jpaTm().transact(() -> jpaTm().put(registry));
tm().transact(() -> tm().put(registry));
}
}
}

View file

@ -16,7 +16,7 @@ package google.registry.beam.common;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.testing.DatabaseHelper.newContact;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -51,7 +51,7 @@ class RegistryJpaWriteTest implements Serializable {
@Test
void writeToSql_twoWriters() {
jpaTm().transact(() -> jpaTm().put(AppEngineExtension.makeRegistrar2()));
tm().transact(() -> tm().put(AppEngineExtension.makeRegistrar2()));
ImmutableList.Builder<Contact> contactsBuilder = new ImmutableList.Builder<>();
for (int i = 0; i < 3; i++) {
contactsBuilder.add(newContact("contact_" + i));
@ -72,11 +72,10 @@ class RegistryJpaWriteTest implements Serializable {
// RegistryJpaIO.Write actions should not write existing objects to the database because the
// object could have been mutated in between creation and when the Write actually occurs,
// causing a race condition
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().put(AppEngineExtension.makeRegistrar2());
jpaTm().put(newContact("contact"));
tm().put(AppEngineExtension.makeRegistrar2());
tm().put(newContact("contact"));
});
Contact contact = Iterables.getOnlyElement(loadAllOf(Contact.class));
testPipeline

View file

@ -16,7 +16,7 @@ package google.registry.beam.resave;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.testing.DatabaseHelper.loadByEntity;
@ -151,7 +151,7 @@ public class ResaveAllEppResourcesPipelineTest {
persistDomainWithDependentResources("renewed", "tld", contact, now, now, now.plusYears(1));
persistActiveDomain("nonrenewed.tld", now, now.plusYears(20));
// Spy the transaction manager so we can be sure we're only saving the renewed domain
JpaTransactionManager spy = spy(jpaTm());
JpaTransactionManager spy = spy(tm());
TransactionManagerFactory.setJpaTm(() -> spy);
ArgumentCaptor<Domain> domainPutCaptor = ArgumentCaptor.forClass(Domain.class);
runPipeline();
@ -171,7 +171,7 @@ public class ResaveAllEppResourcesPipelineTest {
persistDomainWithDependentResources(
"nonrenewed", "tld", contact, now, now, now.plusYears(20));
// Spy the transaction manager so we can be sure we're attempting to save everything
JpaTransactionManager spy = spy(jpaTm());
JpaTransactionManager spy = spy(tm());
TransactionManagerFactory.setJpaTm(() -> spy);
ArgumentCaptor<EppResource> eppResourcePutCaptor = ArgumentCaptor.forClass(EppResource.class);
runPipeline();

View file

@ -17,7 +17,7 @@ package google.registry.beam.spec11;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.AppEngineExtension.makeRegistrar1;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveContact;
@ -278,11 +278,10 @@ class Spec11PipelineTest {
}
private void verifySaveToCloudSql() {
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableList<Spec11ThreatMatch> sqlThreatMatches =
Spec11ThreatMatchDao.loadEntriesByDate(jpaTm(), new LocalDate(2020, 1, 27));
Spec11ThreatMatchDao.loadEntriesByDate(tm(), new LocalDate(2020, 1, 27));
assertThat(sqlThreatMatches)
.comparingElementsUsing(immutableObjectCorrespondence("id"))
.containsExactlyElementsIn(sqlThreatMatches);

View file

@ -22,7 +22,7 @@ import static google.registry.model.common.DatabaseMigrationStateSchedule.Migrat
import static google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState.SQL_ONLY;
import static google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState.SQL_PRIMARY;
import static google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState.SQL_PRIMARY_READ_ONLY;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.Assert.assertThrows;
@ -128,7 +128,7 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(nowInvalidMap)));
() -> tm().transact(() -> DatabaseMigrationStateSchedule.set(nowInvalidMap)));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
@ -150,7 +150,7 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
private void runValidTransition(MigrationState from, MigrationState to) {
ImmutableSortedMap<DateTime, MigrationState> transitions =
createMapEndingWithTransition(from, to);
jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(transitions));
tm().transact(() -> DatabaseMigrationStateSchedule.set(transitions));
assertThat(DatabaseMigrationStateSchedule.getUncached().toValueMap())
.containsExactlyEntriesIn(transitions);
}
@ -161,7 +161,7 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(transitions)));
() -> tm().transact(() -> DatabaseMigrationStateSchedule.set(transitions)));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(

View file

@ -15,7 +15,7 @@
package google.registry.model.console;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.truth.Truth8;
@ -62,7 +62,7 @@ public class UserDaoTest extends EntityTestCase {
// nonexistent one should never exist
Truth8.assertThat(UserDao.loadUser("nonexistent@email.com")).isEmpty();
// now try deleting the one that does exist
jpaTm().transact(() -> jpaTm().delete(fromDb));
tm().transact(() -> tm().delete(fromDb));
Truth8.assertThat(UserDao.loadUser("email@email.com")).isEmpty();
}

View file

@ -16,7 +16,7 @@ package google.registry.model.console;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.EntityTestCase;
@ -38,19 +38,15 @@ public class UserTest extends EntityTestCase {
.setUserRoles(
new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).setIsAdmin(true).build())
.build();
jpaTm().transact(() -> jpaTm().put(user));
jpaTm()
.transact(
tm().transact(() -> tm().put(user));
tm().transact(
() -> {
assertAboutImmutableObjects()
.that(
jpaTm()
.query("FROM User WHERE gaiaId = 'gaiaId'", User.class)
.getSingleResult())
tm().query("FROM User WHERE gaiaId = 'gaiaId'", User.class).getSingleResult())
.isEqualExceptFields(user, "id", "updateTimestamp");
assertThat(
jpaTm()
.query("FROM User WHERE gaiaId = 'badGaiaId'", User.class)
tm().query("FROM User WHERE gaiaId = 'badGaiaId'", User.class)
.getResultList())
.isEmpty();
});

View file

@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.loadByEntity;
@ -177,11 +177,10 @@ public class DomainSqlTest {
@Test
void testResaveDomain_succeeds() {
persistDomain();
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
jpaTm().put(persisted.asBuilder().build());
Domain persisted = tm().loadByKey(domain.createVKey());
tm().put(persisted.asBuilder().build());
});
// Load the domain in its entirety.
assertEqualDomainExcept(loadByKey(domain.createVKey()));
@ -190,18 +189,16 @@ public class DomainSqlTest {
@Test
void testModifyGracePeriod_setEmptyCollectionSuccessfully() {
persistDomain();
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
Domain modified = persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().put(modified);
tm().put(modified);
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
});
}
@ -209,18 +206,16 @@ public class DomainSqlTest {
@Test
void testModifyGracePeriod_setNullCollectionSuccessfully() {
persistDomain();
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
Domain modified = persisted.asBuilder().setGracePeriods(null).build();
jpaTm().put(modified);
tm().put(modified);
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
});
}
@ -228,10 +223,9 @@ public class DomainSqlTest {
@Test
void testModifyGracePeriod_addThenRemoveSuccessfully() {
persistDomain();
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
Domain modified =
persisted
.asBuilder()
@ -244,13 +238,12 @@ public class DomainSqlTest {
null,
200L))
.build();
jpaTm().put(modified);
tm().put(modified);
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
@ -260,23 +253,21 @@ public class DomainSqlTest {
assertEqualDomainExcept(persisted, "gracePeriods");
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
Domain.Builder builder = persisted.asBuilder();
for (GracePeriod gracePeriod : persisted.getGracePeriods()) {
if (gracePeriod.getType() == GracePeriodStatus.RENEW) {
builder.removeGracePeriod(gracePeriod);
}
}
jpaTm().put(builder.build());
tm().put(builder.build());
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertEqualDomainExcept(persisted);
});
}
@ -284,18 +275,16 @@ public class DomainSqlTest {
@Test
void testModifyGracePeriod_removeThenAddSuccessfully() {
persistDomain();
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
Domain modified = persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().put(modified);
tm().put(modified);
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
Domain modified =
persisted
@ -309,13 +298,12 @@ public class DomainSqlTest {
null,
100L))
.build();
jpaTm().put(modified);
tm().put(modified);
});
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
@ -332,37 +320,33 @@ public class DomainSqlTest {
Sets.union(domain.getDsData(), ImmutableSet.of(extraDsData)).immutableCopy();
// Add an extra DomainDsData to dsData set.
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getDsData()).containsExactlyElementsIn(domain.getDsData());
Domain modified = persisted.asBuilder().setDsData(unionDsData).build();
jpaTm().put(modified);
tm().put(modified);
});
// Verify that the persisted domain entity contains both DomainDsData records.
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertThat(persisted.getDsData()).containsExactlyElementsIn(unionDsData);
assertEqualDomainExcept(persisted, "dsData");
});
// Remove the extra DomainDsData record from dsData set.
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
jpaTm().put(persisted.asBuilder().setDsData(domain.getDsData()).build());
Domain persisted = tm().loadByKey(domain.createVKey());
tm().put(persisted.asBuilder().setDsData(domain.getDsData()).build());
});
// Verify that the persisted domain is equal to the original domain.
jpaTm()
.transact(
tm().transact(
() -> {
Domain persisted = jpaTm().loadByKey(domain.createVKey());
Domain persisted = tm().loadByKey(domain.createVKey());
assertEqualDomainExcept(persisted);
});
}
@ -371,7 +355,7 @@ public class DomainSqlTest {
void testSerializable() {
createTld("com");
insertInDb(contact, contact2, domain, host);
Domain persisted = jpaTm().transact(() -> jpaTm().loadByEntity(domain));
Domain persisted = tm().transact(() -> tm().loadByEntity(domain));
assertThat(SerializeUtils.serializeDeserialize(persisted)).isEqualTo(persisted);
}
@ -427,8 +411,7 @@ public class DomainSqlTest {
DateTime originalUpdateTime = persisted.getUpdateTimestamp().getTimestamp();
fakeClock.advanceOneMilli();
DateTime transactionTime =
jpaTm()
.transact(
tm().transact(
() -> {
Host host2 =
new Host.Builder()
@ -440,7 +423,7 @@ public class DomainSqlTest {
insertInDb(host2);
domain = persisted.asBuilder().addNameserver(host2.createVKey()).build();
updateInDb(domain);
return jpaTm().getTransactionTime();
return tm().getTransactionTime();
});
domain = loadByKey(domain.createVKey());
assertThat(domain.getUpdateTimestamp().getTimestamp()).isEqualTo(transactionTime);
@ -454,8 +437,7 @@ public class DomainSqlTest {
DateTime originalUpdateTime = persisted.getUpdateTimestamp().getTimestamp();
fakeClock.advanceOneMilli();
DateTime transactionTime =
jpaTm()
.transact(
tm().transact(
() -> {
domain =
persisted
@ -464,7 +446,7 @@ public class DomainSqlTest {
ImmutableSet.of(DomainDsData.create(1, 2, 3, new byte[] {0, 1, 2})))
.build();
updateInDb(domain);
return jpaTm().getTransactionTime();
return tm().getTransactionTime();
});
domain = loadByKey(domain.createVKey());
assertThat(domain.getUpdateTimestamp().getTimestamp()).isEqualTo(transactionTime);

View file

@ -16,7 +16,7 @@ package google.registry.model.domain.token;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -66,9 +66,9 @@ public class PackagePromotionTest extends EntityTestCase {
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion));
tm().transact(() -> tm().put(packagePromotion));
assertAboutImmutableObjects()
.that(jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get())
.that(tm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get())
.isEqualExceptFields(packagePromotion, "packagePromotionId");
}

View file

@ -15,7 +15,7 @@
package google.registry.model.eppcommon;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -83,7 +83,7 @@ class AddressTest {
/** Test the merge behavior. */
@Test
void testSuccess_putAndLoadStreetLines() {
jpaTm().transact(() -> jpaTm().put(entity));
tm().transact(() -> tm().put(entity));
assertAddress(loadByEntity(entity).address, "123 W 14th St", "8th Fl", "Rm 8");
}

View file

@ -16,7 +16,7 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.newContactWithRoid;
@ -49,10 +49,9 @@ public class ContactHistoryTest extends EntityTestCase {
Contact contactFromDb = loadByEntity(contact);
ContactHistory contactHistory = createContactHistory(contactFromDb);
insertInDb(contactHistory);
jpaTm()
.transact(
tm().transact(
() -> {
ContactHistory fromDatabase = jpaTm().loadByKey(contactHistory.createVKey());
ContactHistory fromDatabase = tm().loadByKey(contactHistory.createVKey());
assertContactHistoriesEqual(fromDatabase, contactHistory);
assertThat(fromDatabase.getRepoId()).isEqualTo(contactHistory.getRepoId());
});
@ -65,8 +64,7 @@ public class ContactHistoryTest extends EntityTestCase {
Contact contactFromDb = loadByEntity(contact);
ContactHistory contactHistory = createContactHistory(contactFromDb);
insertInDb(contactHistory);
ContactHistory fromDatabase =
jpaTm().transact(() -> jpaTm().loadByKey(contactHistory.createVKey()));
ContactHistory fromDatabase = tm().transact(() -> tm().loadByKey(contactHistory.createVKey()));
assertThat(SerializeUtils.serializeDeserialize(fromDatabase)).isEqualTo(fromDatabase);
}

View file

@ -16,7 +16,7 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newContactWithRoid;
@ -64,10 +64,9 @@ public class DomainHistoryTest extends EntityTestCase {
DomainHistory domainHistory = createDomainHistory(domain);
insertInDb(domainHistory);
jpaTm()
.transact(
tm().transact(
() -> {
DomainHistory fromDatabase = jpaTm().loadByKey(domainHistory.createVKey());
DomainHistory fromDatabase = tm().loadByKey(domainHistory.createVKey());
assertDomainHistoriesEqual(fromDatabase, domainHistory);
assertThat(fromDatabase.getRepoId()).isEqualTo(domainHistory.getRepoId());
});
@ -78,8 +77,7 @@ public class DomainHistoryTest extends EntityTestCase {
Domain domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory = createDomainHistory(domain);
insertInDb(domainHistory);
DomainHistory fromDatabase =
jpaTm().transact(() -> jpaTm().loadByKey(domainHistory.createVKey()));
DomainHistory fromDatabase = tm().transact(() -> tm().loadByKey(domainHistory.createVKey()));
assertThat(SerializeUtils.serializeDeserialize(fromDatabase)).isEqualTo(fromDatabase);
}
@ -88,11 +86,10 @@ public class DomainHistoryTest extends EntityTestCase {
Host host = newHostWithRoid("ns1.example.com", "host1");
Contact contact = newContactWithRoid("contactId", "contact1");
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().insert(host);
jpaTm().insert(contact);
tm().insert(host);
tm().insert(contact);
});
Domain domain =

View file

@ -16,7 +16,7 @@ package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.newHostWithRoid;
@ -45,10 +45,9 @@ public class HostHistoryTest extends EntityTestCase {
Host hostFromDb = loadByEntity(host);
HostHistory hostHistory = createHostHistory(hostFromDb);
insertInDb(hostHistory);
jpaTm()
.transact(
tm().transact(
() -> {
HostHistory fromDatabase = jpaTm().loadByKey(hostHistory.createVKey());
HostHistory fromDatabase = tm().loadByKey(hostHistory.createVKey());
assertHostHistoriesEqual(fromDatabase, hostHistory);
assertThat(fromDatabase.getRepoId()).isEqualTo(hostHistory.getRepoId());
});
@ -61,7 +60,7 @@ public class HostHistoryTest extends EntityTestCase {
Host hostFromDb = loadByEntity(host);
HostHistory hostHistory = createHostHistory(hostFromDb);
insertInDb(hostHistory);
HostHistory fromDatabase = jpaTm().transact(() -> jpaTm().loadByKey(hostHistory.createVKey()));
HostHistory fromDatabase = tm().transact(() -> tm().loadByKey(hostHistory.createVKey()));
assertThat(SerializeUtils.serializeDeserialize(fromDatabase)).isEqualTo(fromDatabase);
}

View file

@ -16,7 +16,7 @@ package google.registry.model.reporting;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistResource;
@ -51,32 +51,29 @@ class Spec11ThreatMatchDaoTest extends EntityTestCase {
todayOrgDomain = persistResource(DatabaseHelper.newDomain("today.org", contact));
yesterdayComDomain = persistResource(DatabaseHelper.newDomain("yesterday.com", contact));
yesterdayOrgDomain = persistResource(DatabaseHelper.newDomain("yesterday.org", contact));
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().insertAll(getThreatMatchesToday());
jpaTm().insertAll(getThreatMatchesYesterday());
tm().insertAll(getThreatMatchesToday());
tm().insertAll(getThreatMatchesYesterday());
});
}
@Test
void testDeleteEntriesByDate() {
// Verify that all entries with the date TODAY were removed
jpaTm()
.transact(
tm().transact(
() -> {
Spec11ThreatMatchDao.deleteEntriesByDate(jpaTm(), TODAY);
Spec11ThreatMatchDao.deleteEntriesByDate(tm(), TODAY);
ImmutableList<Spec11ThreatMatch> persistedToday =
Spec11ThreatMatchDao.loadEntriesByDate(jpaTm(), TODAY);
Spec11ThreatMatchDao.loadEntriesByDate(tm(), TODAY);
assertThat(persistedToday).isEmpty();
});
// Verify that all other entries were not removed
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableList<Spec11ThreatMatch> persistedYesterday =
Spec11ThreatMatchDao.loadEntriesByDate(jpaTm(), YESTERDAY);
Spec11ThreatMatchDao.loadEntriesByDate(tm(), YESTERDAY);
assertThat(persistedYesterday)
.comparingElementsUsing(immutableObjectCorrespondence("id"))
.containsExactlyElementsIn(getThreatMatchesYesterday());
@ -85,11 +82,10 @@ class Spec11ThreatMatchDaoTest extends EntityTestCase {
@Test
void testLoadEntriesByDate() {
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableList<Spec11ThreatMatch> persisted =
Spec11ThreatMatchDao.loadEntriesByDate(jpaTm(), TODAY);
Spec11ThreatMatchDao.loadEntriesByDate(tm(), TODAY);
assertThat(persisted)
.comparingElementsUsing(immutableObjectCorrespondence("id"))

View file

@ -17,7 +17,7 @@ package google.registry.model.tld;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.SqlHelper.getMostRecentRegistryLockByRepoId;
import static google.registry.testing.SqlHelper.getMostRecentUnlockedRegistryLockByRepoId;
import static google.registry.testing.SqlHelper.getMostRecentVerifiedRegistryLockByRepoId;
@ -55,16 +55,14 @@ public final class RegistryLockDaoTest extends EntityTestCase {
RegistryLock lock = createLock();
saveRegistryLock(lock);
fakeClock.advanceOneMilli();
jpaTm()
.transact(
tm().transact(
() -> {
RegistryLock updatedLock =
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
RegistryLockDao.save(
updatedLock.asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build());
});
jpaTm()
.transact(
tm().transact(
() -> {
RegistryLock fromDatabase =
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
@ -97,8 +95,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
fakeClock.advanceOneMilli();
RegistryLock updatedLock = lock.asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build();
saveRegistryLock(updatedLock);
jpaTm()
.transact(
tm().transact(
() -> {
RegistryLock fromDatabase =
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();

View file

@ -17,7 +17,7 @@ package google.registry.model.tld.label;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.newRegistry;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.JPY;
@ -28,7 +28,6 @@ import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger;
import google.registry.persistence.transaction.TransactionManagerFactory;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.FakeClock;
import google.registry.testing.TestCacheExtension;
@ -88,8 +87,7 @@ public class PremiumListDaoTest {
@Test
void saveNew_worksSuccessfully() {
PremiumListDao.save(testList);
jpaTm()
.transact(
tm().transact(
() -> {
Optional<PremiumList> persistedListOpt = PremiumListDao.getLatestRevision("testname");
assertThat(persistedListOpt).isPresent();
@ -119,8 +117,7 @@ public class PremiumListDaoTest {
BigDecimal.valueOf(30.03)))
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
tm().transact(
() -> {
Optional<PremiumList> savedListOpt = PremiumListDao.getLatestRevision("testname");
assertThat(savedListOpt).isPresent();
@ -167,8 +164,7 @@ public class PremiumListDaoTest {
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
tm().transact(
() -> {
Optional<PremiumList> persistedList = PremiumListDao.getLatestRevision("list1");
assertThat(persistedList).isPresent();
@ -188,8 +184,7 @@ public class PremiumListDaoTest {
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
tm().transact(
() -> {
PremiumList premiumList = PremiumListDao.getLatestRevision("list1").get();
assertThat(premiumList.getLabelsToPrices())
@ -260,8 +255,7 @@ public class PremiumListDaoTest {
PremiumListDao.save(testList);
PremiumList pl = PremiumListDao.getLatestRevision("testname").get();
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).hasValue(pl);
TransactionManagerFactory.tm()
.transact(() -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1")));
tm().transact(() -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1")));
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();
}

View file

@ -15,7 +15,7 @@
package google.registry.model.tld.label;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableMap;
import google.registry.model.tld.label.ReservedList.ReservedListEntry;
@ -60,12 +60,10 @@ public class ReservedListDaoTest {
@Test
void save_worksSuccessfully() {
ReservedListDao.save(testReservedList);
jpaTm()
.transact(
tm().transact(
() -> {
ReservedList persistedList =
jpaTm()
.query("FROM ReservedList WHERE name = :name", ReservedList.class)
tm().query("FROM ReservedList WHERE name = :name", ReservedList.class)
.setParameter("name", "testlist")
.getSingleResult();
assertThat(persistedList.getReservedListEntries())

View file

@ -15,7 +15,7 @@
package google.registry.model.tmch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableMap;
@ -110,7 +110,7 @@ public class ClaimsListDaoTest {
ClaimsList claimsList =
ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2"));
// Bypass the DAO to avoid the cache
jpaTm().transact(() -> jpaTm().insert(claimsList));
tm().transact(() -> tm().insert(claimsList));
ClaimsList fromDatabase = ClaimsListDao.get();
// At first, we haven't loaded any entries
assertThat(fromDatabase.claimKeyCache.getIfPresent("label1")).isNull();

View file

@ -17,7 +17,7 @@ package google.registry.persistence;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet;
@ -56,27 +56,24 @@ class EntityCallbacksListenerTest {
TestEntity testUpdate = new TestEntity();
TestEntity updated =
jpaTm()
.transact(
tm().transact(
() -> {
TestEntity merged = jpaTm().getEntityManager().merge(testUpdate);
TestEntity merged = tm().getEntityManager().merge(testUpdate);
merged.nonTransientField++;
jpaTm().getEntityManager().flush();
tm().getEntityManager().flush();
return merged;
});
// Note that when we get the merged entity, its @PostLoad callbacks are also invoked
checkAll(updated, 0, 1, 0, 1);
TestEntity testLoad =
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
TestEntity testLoad = tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, "id")));
checkAll(testLoad, 0, 0, 0, 1);
TestEntity testRemove =
jpaTm()
.transact(
tm().transact(
() -> {
TestEntity removed = jpaTm().loadByKey(VKey.create(TestEntity.class, "id"));
return jpaTm().delete(removed);
TestEntity removed = tm().loadByKey(VKey.create(TestEntity.class, "id"));
return tm().delete(removed);
});
checkAll(testRemove, 0, 0, 1, 1);
}
@ -104,11 +101,10 @@ class EntityCallbacksListenerTest {
void verifyCallbacksNotCalledOnCommit() {
insertInDb(new TestEntity());
TestEntity testLoad =
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
TestEntity testLoad = tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, "id")));
assertThat(testLoad.entityPreUpdate).isEqualTo(0);
testLoad = jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
testLoad = tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, "id")));
// Verify that post-load happened but pre-update didn't.
assertThat(testLoad.entityPostLoad).isEqualTo(1);

View file

@ -17,7 +17,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableList;
@ -52,9 +52,7 @@ public class AllocationTokenListConverterTest {
new TestAllocationTokenVKeyList(tokens);
insertInDb(testAllocationTokenVKeyList);
TestAllocationTokenVKeyList persisted =
jpaTm()
.transact(
() -> jpaTm().getEntityManager().find(TestAllocationTokenVKeyList.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestAllocationTokenVKeyList.class, "id"));
assertThat(persisted.tokenList).isEqualTo(tokens);
}

View file

@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -60,11 +60,9 @@ public class AllocationTokenStatusTransitionConverterTest {
new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty);
insertInDb(testEntity);
AllocationTokenStatusTransitionConverterTestEntity persisted =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.find(AllocationTokenStatusTransitionConverterTestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
@ -53,7 +53,7 @@ public class BillingCostTransitionConverterTest {
TestEntity testEntity = new TestEntity(timedTransitionProperty);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
}

View file

@ -16,7 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.base.Charsets.US_ASCII;
import static com.google.common.hash.Funnels.stringFunnel;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet;
@ -43,7 +43,7 @@ class BloomFilterConverterTest {
TestEntity entity = new TestEntity(bloomFilter);
insertInDb(entity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.bloomFilter).isEqualTo(bloomFilter);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableList;
@ -48,7 +48,7 @@ public class CidrAddressBlockListConverterTest {
TestEntity testEntity = new TestEntity(addresses);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.addresses).isEqualTo(addresses);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableMap;
@ -45,7 +45,7 @@ public class CurrencyToBillingConverterTest {
TestEntity testEntity = new TestEntity(currencyToBilling);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.currencyToBilling).containsExactlyEntriesIn(currencyToBilling);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -41,27 +41,23 @@ public class CurrencyUnitConverterTest {
TestEntity entity = new TestEntity(CurrencyUnit.EUR);
insertInDb(entity);
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList()))
.containsExactly("EUR");
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.currency).isEqualTo(CurrencyUnit.EUR);
}
@Test
void invalidCurrency() {
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"INSERT INTO \"TestEntity\" (name, currency) VALUES('id', 'XXXX')")
.executeUpdate());
@ -69,9 +65,7 @@ public class CurrencyUnitConverterTest {
assertThrows(
PersistenceException.class,
() ->
jpaTm()
.transact(
() -> jpaTm().getEntityManager().find(TestEntity.class, "id").currency));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id").currency));
assertThat(thrown).hasCauseThat().hasMessageThat().isEqualTo("Unknown currency 'XXXX'");
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -63,11 +63,9 @@ public class DatabaseMigrationScheduleTransitionConverterTest {
new DatabaseMigrationScheduleTransitionConverterTestEntity(timedTransitionProperty);
insertInDb(testEntity);
DatabaseMigrationScheduleTransitionConverterTestEntity persisted =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.find(DatabaseMigrationScheduleTransitionConverterTestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
@ -72,9 +72,7 @@ public class DateTimeConverterTest {
TestEntity entity = new TestEntity("normalized_utc_time", dt);
insertInDb(entity);
TestEntity retrievedEntity =
jpaTm()
.transact(
() -> jpaTm().getEntityManager().find(TestEntity.class, "normalized_utc_time"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "normalized_utc_time"));
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T01:01:01.000Z");
}
@ -85,7 +83,7 @@ public class DateTimeConverterTest {
insertInDb(entity);
TestEntity retrievedEntity =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "new_york_time"));
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z");
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
@ -82,7 +82,7 @@ public class DurationConverterTest {
DurationTestEntity entity = new DurationTestEntity(duration);
insertInDb(entity);
DurationTestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(DurationTestEntity.class, "id"));
assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis());
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet;
@ -65,8 +65,7 @@ public class InetAddressSetConverterTest {
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
insertInDb(testEntity);
InetAddressSetTestEntity persisted =
jpaTm()
.transact(() -> jpaTm().loadByKey(VKey.create(InetAddressSetTestEntity.class, "id")));
tm().transact(() -> tm().loadByKey(VKey.create(InetAddressSetTestEntity.class, "id")));
assertThat(persisted.addresses).isEqualTo(inetAddresses);
}

View file

@ -14,7 +14,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -60,11 +60,9 @@ public class JodaMoneyConverterTest {
TestEntity entity = new TestEntity(money);
insertInDb(entity);
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT amount, currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList());
@ -75,7 +73,7 @@ public class JodaMoneyConverterTest {
.containsExactly(BigDecimal.valueOf(100.12).setScale(2), "USD")
.inOrder();
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.money).isEqualTo(money);
}
@ -86,11 +84,9 @@ public class JodaMoneyConverterTest {
TestEntity entity = new TestEntity(money);
insertInDb(entity);
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT amount, currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList());
@ -102,11 +98,9 @@ public class JodaMoneyConverterTest {
.inOrder();
result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createQuery("SELECT money FROM TestEntity WHERE name" + " = 'id'")
.getResultList());
@ -114,7 +108,7 @@ public class JodaMoneyConverterTest {
assertThat(result.get(0)).isEqualTo(money);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.money).isEqualTo(money);
}
@ -130,11 +124,9 @@ public class JodaMoneyConverterTest {
ComplexTestEntity entity = new ComplexTestEntity(moneyMap, myMoney, yourMoney);
insertInDb(entity);
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT my_amount, my_currency, your_amount, your_currency FROM"
+ " \"ComplexTestEntity\" WHERE name = 'id'")
@ -145,17 +137,15 @@ public class JodaMoneyConverterTest {
BigDecimal.valueOf(100).setScale(2), "USD", BigDecimal.valueOf(80).setScale(2), "GBP")
.inOrder();
result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT map_amount, map_currency FROM \"MoneyMap\""
+ " WHERE entity_name = 'id' AND map_key = 'dos'")
.getResultList());
ComplexTestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(ComplexTestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(ComplexTestEntity.class, "id"));
assertThat(result).hasSize(1);
assertThat(Arrays.asList((Object[]) result.get(0)))
@ -173,32 +163,26 @@ public class JodaMoneyConverterTest {
*/
@Test
void testNullSafeGet_nullAmountNullCurrency_returnsNull() throws SQLException {
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"INSERT INTO \"TestEntity\" (name, amount, currency) VALUES('id', null,"
+ " null)")
.executeUpdate());
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT amount, currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList());
assertThat(result).hasSize(1);
assertThat(Arrays.asList((Object[]) result.get(0))).containsExactly(null, null).inOrder();
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createQuery("SELECT money FROM TestEntity WHERE name = 'id'")
.getResultList())
.get(0))
@ -207,21 +191,17 @@ public class JodaMoneyConverterTest {
@Test
void testNullSafeGet_nullAMountValidCurrency_throwsHibernateException() throws SQLException {
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"INSERT INTO \"TestEntity\" (name, amount, currency) VALUES('id', null,"
+ " 'USD')")
.executeUpdate());
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT amount, currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList());
@ -232,11 +212,9 @@ public class JodaMoneyConverterTest {
assertThrows(
PersistenceException.class,
() ->
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createQuery("SELECT money FROM TestEntity WHERE name = 'id'")
.getResultList()));
assertThat(thrown)
@ -249,21 +227,17 @@ public class JodaMoneyConverterTest {
@Test
void testNullSafeGet_nullAMountInValidCurrency_throwsIllegalCurrencyException()
throws SQLException {
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"INSERT INTO \"TestEntity\" (name, amount, currency) VALUES('id', 100,"
+ " 'INVALIDCURRENCY')")
.executeUpdate());
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"SELECT amount, currency FROM \"TestEntity\" WHERE name = 'id'")
.getResultList());
@ -275,11 +249,9 @@ public class JodaMoneyConverterTest {
assertThrows(
IllegalCurrencyException.class,
() ->
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createQuery("SELECT money FROM TestEntity WHERE name = 'id'")
.getResultList()));
assertThat(thrown).hasMessageThat().isEqualTo("Unknown currency 'INVALIDCURRENCY'");

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
@ -55,8 +55,8 @@ public class LocalDateConverterTest {
private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) {
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
insertInDb(entity);
return jpaTm()
.transact(() -> jpaTm().loadByKey(VKey.create(LocalDateConverterTestEntity.class, "id")));
return tm().transact(
() -> tm().loadByKey(VKey.create(LocalDateConverterTestEntity.class, "id")));
}
/** Override entity name to avoid the nested class reference. */

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet;
@ -43,7 +43,7 @@ public class StatusValueSetConverterTest {
insertInDb(obj);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "foo"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "foo"));
assertThat(persisted.data).isEqualTo(enums);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -43,7 +43,7 @@ public class StringListConverterTest {
TestEntity testEntity = new TestEntity(tlds);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
}
@ -53,11 +53,10 @@ public class StringListConverterTest {
TestEntity testEntity = new TestEntity(tlds);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
persisted.tlds = ImmutableList.of("com", "gov");
jpaTm().transact(() -> jpaTm().getEntityManager().merge(persisted));
TestEntity updated =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().merge(persisted));
TestEntity updated = tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(updated.tlds).containsExactly("com", "gov");
}
@ -66,7 +65,7 @@ public class StringListConverterTest {
TestEntity testEntity = new TestEntity(null);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isNull();
}
@ -75,7 +74,7 @@ public class StringListConverterTest {
TestEntity testEntity = new TestEntity(ImmutableList.of());
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isEmpty();
}
@ -107,13 +106,11 @@ public class StringListConverterTest {
}
private static Object getSingleResultFromNativeQuery(String sql) {
return jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).getSingleResult());
return tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).getSingleResult());
}
private static Object executeNativeQuery(String sql) {
return jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).executeUpdate());
return tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).executeUpdate());
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -51,7 +51,7 @@ public class StringMapConverterBaseTest {
TestEntity testEntity = new TestEntity(MAP);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
}
@ -60,12 +60,11 @@ public class StringMapConverterBaseTest {
TestEntity testEntity = new TestEntity(MAP);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
persisted.map = ImmutableMap.of(new Key("key4"), new Value("value4"));
jpaTm().transact(() -> jpaTm().getEntityManager().merge(persisted));
TestEntity updated =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().merge(persisted));
TestEntity updated = tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(updated.map).containsExactly(new Key("key4"), new Value("value4"));
}
@ -74,7 +73,7 @@ public class StringMapConverterBaseTest {
TestEntity testEntity = new TestEntity(null);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).isNull();
}
@ -83,7 +82,7 @@ public class StringMapConverterBaseTest {
TestEntity testEntity = new TestEntity(ImmutableMap.of());
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).isEmpty();
}
@ -117,13 +116,11 @@ public class StringMapConverterBaseTest {
}
private static Object getSingleResultFromNativeQuery(String sql) {
return jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).getSingleResult());
return tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).getSingleResult());
}
private static Object executeNativeQuery(String sql) {
return jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).executeUpdate());
return tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).executeUpdate());
}
private static class Key extends ImmutableObject {

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet;
@ -41,7 +41,7 @@ public class StringSetConverterTest {
TestEntity testEntity = new TestEntity(tlds);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
}
@ -50,7 +50,7 @@ public class StringSetConverterTest {
TestEntity testEntity = new TestEntity(null);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isNull();
}
@ -59,7 +59,7 @@ public class StringSetConverterTest {
TestEntity testEntity = new TestEntity(ImmutableSet.of());
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isEmpty();
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
@ -41,7 +41,7 @@ public class StringValueEnumeratedTest {
TestEntity testEntity = new TestEntity(State.ACTIVE);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.state).isEqualTo(State.ACTIVE);
}
@ -51,11 +51,9 @@ public class StringValueEnumeratedTest {
insertInDb(testEntity);
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery("SELECT state FROM \"TestEntity\" WHERE name = 'id'")
.getSingleResult()))
.isEqualTo("DISABLED");

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -59,7 +59,7 @@ class TimedTransitionPropertyConverterBaseTest {
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
}
@ -68,13 +68,12 @@ class TimedTransitionPropertyConverterBaseTest {
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
ImmutableSortedMap<DateTime, String> newValues = ImmutableSortedMap.of(START_OF_TIME, "val4");
persisted.property = TimedTransitionProperty.fromValueMap(newValues);
jpaTm().transact(() -> jpaTm().getEntityManager().merge(persisted));
TestEntity updated =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().merge(persisted));
TestEntity updated = tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(updated.property).isEqualTo(newValues);
}
@ -83,7 +82,7 @@ class TimedTransitionPropertyConverterBaseTest {
TestEntity testEntity = new TestEntity(null);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).isNull();
}
@ -120,12 +119,11 @@ class TimedTransitionPropertyConverterBaseTest {
}
private static Object getSingleResultFromNativeQuery(String sql) {
return jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).getSingleResult());
return tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).getSingleResult());
}
private static void executeNativeQuery(String sql) {
jpaTm().transact(() -> jpaTm().getEntityManager().createNativeQuery(sql).executeUpdate());
tm().transact(() -> tm().getEntityManager().createNativeQuery(sql).executeUpdate());
}
@Converter(autoApply = true)

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -56,7 +56,7 @@ class TldStateTransitionConverterTest {
TestEntity testEntity = new TestEntity(timedTransitionProperty);
insertInDb(testEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
@ -53,7 +53,7 @@ public class VKeyConverterTest {
insertInDb(stringEntity, longEntity, original);
TestEntity retrieved =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, 1984L));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, 1984L));
assertThat(retrieved.stringKey).isEqualTo(stringKey);
assertThat(retrieved.longKey).isEqualTo(longKey);
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.transaction;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableList;
@ -56,11 +56,9 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_noWhereClause() {
assertThat(
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.criteriaQuery(
tm().criteriaQuery(
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.build())
.getResultList()))
@ -71,17 +69,14 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_exactlyOne() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.where(
"data",
jpaTm().getEntityManager().getCriteriaBuilder()::equal,
"zztz")
"data", tm().getEntityManager().getCriteriaBuilder()::equal, "zztz")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity2);
}
@ -89,15 +84,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_like_oneResult() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.where(
"data", jpaTm().getEntityManager().getCriteriaBuilder()::like, "a%")
.where("data", tm().getEntityManager().getCriteriaBuilder()::like, "a%")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity3);
}
@ -105,15 +98,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_like_twoResults() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.where(
"data", jpaTm().getEntityManager().getCriteriaBuilder()::like, "%a%")
.where("data", tm().getEntityManager().getCriteriaBuilder()::like, "%a%")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity1, entity3).inOrder();
}
@ -121,19 +112,16 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_multipleWheres() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
// first "where" matches 1 and 3
.where(
"data", jpaTm().getEntityManager().getCriteriaBuilder()::like, "%a%")
.where("data", tm().getEntityManager().getCriteriaBuilder()::like, "%a%")
// second "where" matches 1 and 2
.where(
"data", jpaTm().getEntityManager().getCriteriaBuilder()::like, "%t%")
.where("data", tm().getEntityManager().getCriteriaBuilder()::like, "%t%")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity1);
}
@ -141,14 +129,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_in_oneResult() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.whereFieldIsIn("data", ImmutableList.of("aaa", "bbb"))
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity3).inOrder();
}
@ -156,14 +143,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_not_in_twoResults() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.whereFieldIsNotIn("data", ImmutableList.of("aaa", "bbb"))
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity1, entity2).inOrder();
}
@ -171,14 +157,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_where_in_twoResults() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.whereFieldIsIn("data", ImmutableList.of("aaa", "bbb", "data"))
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity1, entity3).inOrder();
}
@ -186,16 +171,14 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_orderByAsc() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.orderByAsc("data")
.where(
"data", jpaTm().getEntityManager().getCriteriaBuilder()::like, "%a%")
.where("data", tm().getEntityManager().getCriteriaBuilder()::like, "%a%")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity3, entity1).inOrder();
}
@ -203,14 +186,13 @@ class CriteriaQueryBuilderTest {
@Test
void testSuccess_orderByDesc() {
List<CriteriaQueryBuilderTestEntity> result =
jpaTm()
.transact(
tm().transact(
() -> {
CriteriaQuery<CriteriaQueryBuilderTestEntity> query =
CriteriaQueryBuilder.create(CriteriaQueryBuilderTestEntity.class)
.orderByDesc("data")
.build();
return jpaTm().criteriaQuery(query).getResultList();
return tm().criteriaQuery(query).getResultList();
});
assertThat(result).containsExactly(entity2, entity1, entity3).inOrder();
}

View file

@ -14,7 +14,7 @@
package google.registry.persistence.transaction;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.testing.AppEngineExtension;
@ -28,7 +28,7 @@ class DummyJpaTransactionManagerTest {
@Test
void throwsExceptionWhenAnyMethodIsInvoked() {
assertThrows(UnsupportedOperationException.class, () -> jpaTm().transact(() -> null));
assertThrows(UnsupportedOperationException.class, () -> jpaTm().getTransactionTime());
assertThrows(UnsupportedOperationException.class, () -> tm().transact(() -> null));
assertThrows(UnsupportedOperationException.class, () -> tm().getTransactionTime());
}
}

View file

@ -15,7 +15,7 @@
package google.registry.persistence.transaction;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
@ -99,11 +99,9 @@ public class JpaEntityCoverageExtension implements BeforeEachCallback, AfterEach
private static boolean isPersisted(Class<?> entityType) {
try {
List<?> result =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.query(
tm().query(
String.format("SELECT e FROM %s e", getJpaEntityName(entityType)),
entityType)
.setMaxResults(1)

View file

@ -15,7 +15,7 @@
package google.registry.persistence.transaction;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static java.nio.charset.StandardCharsets.UTF_8;
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
@ -51,8 +51,7 @@ class JpaTestExtensionsSqlLoggingTest {
@Test
void sqlLog_displayed() throws UnsupportedEncodingException {
jpaTm()
.transact(() -> jpaTm().getEntityManager().createNativeQuery("select 1").getSingleResult());
tm().transact(() -> tm().getEntityManager().createNativeQuery("select 1").getSingleResult());
assertThat(stdoutBuffer.toString(UTF_8.name())).contains("select 1");
}
}

View file

@ -213,7 +213,7 @@ abstract class JpaTransactionManagerExtension implements BeforeEachCallback, Aft
recreateSchema();
}
JpaTransactionManagerImpl txnManager = new JpaTransactionManagerImpl(emf, clock);
cachedTm = TransactionManagerFactory.jpaTm();
cachedTm = TransactionManagerFactory.tm();
TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(txnManager));
TransactionManagerFactory.setReplicaJpaTm(
Suppliers.ofInstance(new ReplicaSimulatingJpaTransactionManager(txnManager)));

View file

@ -15,8 +15,8 @@
package google.registry.persistence.transaction;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -44,19 +44,15 @@ public class JpaTransactionManagerExtensionTest {
assertThrows(
PersistenceException.class,
() ->
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery("SELECT * FROM NoneExistentTable")
.getResultList()));
jpaTm()
.transact(
tm().transact(
() -> {
List<?> results =
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery("SELECT * FROM \"TestEntity\"")
.getResultList();
assertThat(results).isEmpty();
@ -69,7 +65,7 @@ public class JpaTransactionManagerExtensionTest {
assertThat(
assertThrows(
PersistenceException.class,
() -> replicaJpaTm().transact(() -> replicaJpaTm().put(testEntity))))
() -> replicaTm().transact(() -> replicaTm().put(testEntity))))
.hasMessageThat()
.isEqualTo("Error while committing the transaction");
}
@ -81,7 +77,7 @@ public class JpaTransactionManagerExtensionTest {
TestEntity original = new TestEntity("key", "value");
insertInDb(original);
TestEntity retrieved =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "key"));
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "key"));
assertThat(retrieved).isEqualTo(original);
}

View file

@ -16,7 +16,7 @@ package google.registry.persistence.transaction;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.assertDetachedFromEntityManager;
import static google.registry.testing.DatabaseHelper.existsInDb;
import static google.registry.testing.DatabaseHelper.insertInDb;
@ -84,8 +84,7 @@ class JpaTransactionManagerImplTest {
void transact_succeeds() {
assertPersonEmpty();
assertCompanyEmpty();
jpaTm()
.transact(
tm().transact(
() -> {
insertPerson(10);
insertCompany("Foo");
@ -105,8 +104,7 @@ class JpaTransactionManagerImplTest {
assertThrows(
RuntimeException.class,
() ->
jpaTm()
.transact(
tm().transact(
() -> {
insertPerson(10);
insertCompany("Foo");
@ -120,11 +118,9 @@ class JpaTransactionManagerImplTest {
void transact_reusesExistingTransaction() {
assertPersonEmpty();
assertCompanyEmpty();
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.transact(
tm().transact(
() -> {
insertPerson(10);
insertCompany("Foo");
@ -140,14 +136,14 @@ class JpaTransactionManagerImplTest {
@Test
void insert_succeeds() {
assertThat(existsInDb(theEntity)).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
tm().transact(() -> tm().insert(theEntity));
assertThat(existsInDb(theEntity)).isTrue();
assertThat(loadByKey(theEntityKey)).isEqualTo(theEntity);
}
@Test
void transact_retriesOptimisticLockExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
JpaTransactionManager spyJpaTm = spy(tm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
@ -166,7 +162,7 @@ class JpaTransactionManagerImplTest {
@Test
void transactNoRetry_doesNotRetryOptimisticLockException() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
JpaTransactionManager spyJpaTm = spy(tm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transactNoRetry(() -> spyJpaTm.insert(theEntity));
assertThrows(
@ -185,7 +181,7 @@ class JpaTransactionManagerImplTest {
@Test
void transact_retriesNestedOptimisticLockExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
JpaTransactionManager spyJpaTm = spy(tm());
doThrow(new RuntimeException(new OptimisticLockException()))
.when(spyJpaTm)
.delete(any(VKey.class));
@ -206,18 +202,18 @@ class JpaTransactionManagerImplTest {
@Test
void insert_throwsExceptionIfEntityExists() {
assertThat(existsInDb(theEntity)).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
tm().transact(() -> tm().insert(theEntity));
assertThat(existsInDb(theEntity)).isTrue();
assertThat(loadByKey(theEntityKey)).isEqualTo(theEntity);
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity)));
assertThrows(RollbackException.class, () -> tm().transact(() -> tm().insert(theEntity)));
}
@Test
void createCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey)))
assertThat(tm().transact(() -> tm().exists(compoundIdEntity))).isFalse();
tm().transact(() -> tm().insert(compoundIdEntity));
assertThat(tm().transact(() -> tm().exists(compoundIdEntity))).isTrue();
assertThat(tm().transact(() -> tm().loadByKey(compoundIdEntityKey)))
.isEqualTo(compoundIdEntity);
}
@ -225,7 +221,7 @@ class JpaTransactionManagerImplTest {
void createNamedCompoundIdEntity_succeeds() {
// Compound IDs should also work even if the field names don't match up exactly
TestNamedCompoundIdEntity entity = new TestNamedCompoundIdEntity("foo", 1);
jpaTm().transact(() -> jpaTm().insert(entity));
tm().transact(() -> tm().insert(entity));
assertThat(existsInDb(entity)).isTrue();
assertThat(
loadByKey(VKey.create(TestNamedCompoundIdEntity.class, new NamedCompoundId("foo", 1))))
@ -234,53 +230,48 @@ class JpaTransactionManagerImplTest {
@Test
void saveAllNew_succeeds() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
moreEntities.forEach(entity -> assertThat(tm().transact(() -> tm().exists(entity))).isFalse());
insertInDb(moreEntities);
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
moreEntities.forEach(entity -> assertThat(tm().transact(() -> tm().exists(entity))).isTrue());
assertThat(tm().transact(() -> tm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@Test
void saveAllNew_rollsBackWhenFailure() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
moreEntities.forEach(entity -> assertThat(tm().transact(() -> tm().exists(entity))).isFalse());
insertInDb(moreEntities.get(0));
assertThrows(RollbackException.class, () -> insertInDb(moreEntities));
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(0)))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(1)))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(2)))).isFalse();
assertThat(tm().transact(() -> tm().exists(moreEntities.get(0)))).isTrue();
assertThat(tm().transact(() -> tm().exists(moreEntities.get(1)))).isFalse();
assertThat(tm().transact(() -> tm().exists(moreEntities.get(2)))).isFalse();
}
@Test
void put_persistsNewEntity() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().put(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
tm().transact(() -> tm().put(theEntity));
assertThat(tm().transact(() -> tm().exists(theEntity))).isTrue();
assertThat(tm().transact(() -> tm().loadByKey(theEntityKey))).isEqualTo(theEntity);
}
@Test
void put_updatesExistingEntity() {
insertInDb(theEntity);
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
jpaTm().transact(() -> jpaTm().put(theEntity));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
tm().transact(() -> tm().put(theEntity));
persisted = tm().transact(() -> tm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@Test
void putAll_succeeds() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().putAll(moreEntities));
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
moreEntities.forEach(entity -> assertThat(tm().transact(() -> tm().exists(entity))).isFalse());
tm().transact(() -> tm().putAll(moreEntities));
moreEntities.forEach(entity -> assertThat(tm().transact(() -> tm().exists(entity))).isTrue());
assertThat(tm().transact(() -> tm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@ -288,31 +279,30 @@ class JpaTransactionManagerImplTest {
void update_succeeds() {
insertInDb(theEntity);
TestEntity persisted =
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "theEntity")));
tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, "theEntity")));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
jpaTm().transact(() -> jpaTm().update(theEntity));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
tm().transact(() -> tm().update(theEntity));
persisted = tm().transact(() -> tm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@Test
void updateCompoundIdEntity_succeeds() {
insertInDb(compoundIdEntity);
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
TestCompoundIdEntity persisted = tm().transact(() -> tm().loadByKey(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("foo");
compoundIdEntity.data = "bar";
jpaTm().transact(() -> jpaTm().update(compoundIdEntity));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
tm().transact(() -> tm().update(compoundIdEntity));
persisted = tm().transact(() -> tm().loadByKey(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@Test
void update_throwsExceptionWhenEntityDoesNotExist() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThrows(
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().update(theEntity)));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
assertThrows(IllegalArgumentException.class, () -> tm().transact(() -> tm().update(theEntity)));
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
}
@Test
@ -323,8 +313,8 @@ class JpaTransactionManagerImplTest {
new TestEntity("entity1", "foo_updated"),
new TestEntity("entity2", "bar_updated"),
new TestEntity("entity3", "qux_updated"));
jpaTm().transact(() -> jpaTm().updateAll(updated));
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
tm().transact(() -> tm().updateAll(updated));
assertThat(tm().transact(() -> tm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(updated);
}
@ -338,67 +328,60 @@ class JpaTransactionManagerImplTest {
new TestEntity("entity3", "qux_updated"),
theEntity);
assertThrows(
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().updateAll(updated)));
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
IllegalArgumentException.class, () -> tm().transact(() -> tm().updateAll(updated)));
assertThat(tm().transact(() -> tm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@Test
void load_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
insertInDb(theEntity);
TestEntity persisted =
jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByKey(theEntityKey)));
tm().transact(() -> assertDetachedFromEntityManager(tm().loadByKey(theEntityKey)));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@Test
void load_throwsOnMissingElement() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
assertThrows(
NoSuchElementException.class,
() -> jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey)));
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKey(theEntityKey)));
}
@Test
void loadByEntity_succeeds() {
insertInDb(theEntity);
TestEntity persisted =
jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByEntity(theEntity)));
tm().transact(() -> assertDetachedFromEntityManager(tm().loadByEntity(theEntity)));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@Test
void maybeLoad_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
insertInDb(theEntity);
TestEntity persisted =
jpaTm()
.transact(
() ->
assertDetachedFromEntityManager(
jpaTm().loadByKeyIfPresent(theEntityKey).get()));
tm().transact(
() -> assertDetachedFromEntityManager(tm().loadByKeyIfPresent(theEntityKey).get()));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@Test
void maybeLoad_nonExistentObject() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().loadByKeyIfPresent(theEntityKey)).isPresent())
.isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntityKey)).isPresent()).isFalse();
}
@Test
void loadCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(compoundIdEntity))).isFalse();
insertInDb(compoundIdEntity);
TestCompoundIdEntity persisted =
jpaTm()
.transact(
() -> assertDetachedFromEntityManager(jpaTm().loadByKey(compoundIdEntityKey)));
tm().transact(() -> assertDetachedFromEntityManager(tm().loadByKey(compoundIdEntityKey)));
assertThat(persisted.name).isEqualTo("compoundIdEntity");
assertThat(persisted.age).isEqualTo(10);
assertThat(persisted.data).isEqualTo("foo");
@ -407,12 +390,10 @@ class JpaTransactionManagerImplTest {
@Test
void loadByKeysIfPresent() {
insertInDb(theEntity);
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableMap<VKey<? extends TestEntity>, TestEntity> results =
jpaTm()
.loadByKeysIfPresent(
tm().loadByKeysIfPresent(
ImmutableList.of(
theEntityKey, VKey.create(TestEntity.class, "does-not-exist")));
@ -424,11 +405,10 @@ class JpaTransactionManagerImplTest {
@Test
void loadByKeys_succeeds() {
insertInDb(theEntity);
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableMap<VKey<? extends TestEntity>, TestEntity> results =
jpaTm().loadByKeysIfPresent(ImmutableList.of(theEntityKey));
tm().loadByKeysIfPresent(ImmutableList.of(theEntityKey));
assertThat(results).containsExactly(theEntityKey, theEntity);
assertDetachedFromEntityManager(results.get(theEntityKey));
});
@ -437,12 +417,10 @@ class JpaTransactionManagerImplTest {
@Test
void loadByEntitiesIfPresent_succeeds() {
insertInDb(theEntity);
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableList<TestEntity> results =
jpaTm()
.loadByEntitiesIfPresent(
tm().loadByEntitiesIfPresent(
ImmutableList.of(theEntity, new TestEntity("does-not-exist", "bar")));
assertThat(results).containsExactly(theEntity);
assertDetachedFromEntityManager(results.get(0));
@ -452,11 +430,9 @@ class JpaTransactionManagerImplTest {
@Test
void loadByEntities_succeeds() {
insertInDb(theEntity);
jpaTm()
.transact(
tm().transact(
() -> {
ImmutableList<TestEntity> results =
jpaTm().loadByEntities(ImmutableList.of(theEntity));
ImmutableList<TestEntity> results = tm().loadByEntities(ImmutableList.of(theEntity));
assertThat(results).containsExactly(theEntity);
assertDetachedFromEntityManager(results.get(0));
});
@ -466,10 +442,9 @@ class JpaTransactionManagerImplTest {
void loadAll_succeeds() {
insertInDb(moreEntities);
ImmutableList<TestEntity> persisted =
jpaTm()
.transact(
tm().transact(
() ->
jpaTm().loadAllOf(TestEntity.class).stream()
tm().loadAllOf(TestEntity.class).stream()
.map(DatabaseHelper::assertDetachedFromEntityManager)
.collect(toImmutableList()));
assertThat(persisted).containsExactlyElementsIn(moreEntities);
@ -478,45 +453,41 @@ class JpaTransactionManagerImplTest {
@Test
void loadSingleton_detaches() {
insertInDb(theEntity);
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
jpaTm()
.getEntityManager()
.contains(jpaTm().loadSingleton(TestEntity.class).get())))
tm().getEntityManager().contains(tm().loadSingleton(TestEntity.class).get())))
.isFalse();
}
@Test
void delete_succeeds() {
insertInDb(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isTrue();
tm().transact(() -> tm().delete(theEntityKey));
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
}
@Test
void delete_returnsZeroWhenNoEntity() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
tm().transact(() -> tm().delete(theEntityKey));
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
}
@Test
void deleteCompoundIdEntity_succeeds() {
insertInDb(compoundIdEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(compoundIdEntity))).isTrue();
tm().transact(() -> tm().delete(compoundIdEntityKey));
assertThat(tm().transact(() -> tm().exists(compoundIdEntity))).isFalse();
}
@Test
void assertDelete_throwsExceptionWhenEntityNotDeleted() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(tm().transact(() -> tm().exists(theEntity))).isFalse();
assertThrows(
IllegalArgumentException.class,
() -> jpaTm().transact(() -> jpaTm().assertDelete(theEntityKey)));
IllegalArgumentException.class, () -> tm().transact(() -> tm().assertDelete(theEntityKey)));
}
@Test
@ -525,11 +496,10 @@ class JpaTransactionManagerImplTest {
assertThrows(
IllegalStateException.class,
() ->
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().insert(theEntity);
jpaTm().loadByKey(theEntityKey);
tm().insert(theEntity);
tm().loadByKey(theEntityKey);
})))
.hasMessageThat()
.contains("Inserted/updated object reloaded: ");
@ -542,11 +512,10 @@ class JpaTransactionManagerImplTest {
assertThrows(
IllegalStateException.class,
() ->
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().update(theEntity);
jpaTm().loadByKey(theEntityKey);
tm().update(theEntity);
tm().loadByKey(theEntityKey);
})))
.hasMessageThat()
.contains("Inserted/updated object reloaded: ");
@ -555,20 +524,16 @@ class JpaTransactionManagerImplTest {
@Test
void cqQuery_detaches() {
insertInDb(moreEntities);
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
jpaTm()
.getEntityManager()
tm().getEntityManager()
.contains(
jpaTm()
.criteriaQuery(
tm().criteriaQuery(
CriteriaQueryBuilder.create(TestEntity.class)
.where(
"name",
jpaTm().getEntityManager().getCriteriaBuilder()
::equal,
tm().getEntityManager().getCriteriaBuilder()::equal,
"entity1")
.build())
.getSingleResult()))
@ -581,11 +546,10 @@ class JpaTransactionManagerImplTest {
assertThrows(
IllegalStateException.class,
() ->
jpaTm()
.transact(
tm().transact(
() -> {
jpaTm().put(theEntity);
jpaTm().loadByKey(theEntityKey);
tm().put(theEntity);
tm().loadByKey(theEntityKey);
})))
.hasMessageThat()
.contains("Inserted/updated object reloaded: ");
@ -594,54 +558,44 @@ class JpaTransactionManagerImplTest {
@Test
void query_detachesResults() {
insertInDb(moreEntities);
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.query("FROM TestEntity", TestEntity.class)
tm().query("FROM TestEntity", TestEntity.class)
.getResultList()
.forEach(e -> assertThat(jpaTm().getEntityManager().contains(e)).isFalse()));
jpaTm()
.transact(
.forEach(e -> assertThat(tm().getEntityManager().contains(e)).isFalse()));
tm().transact(
() ->
jpaTm()
.query("FROM TestEntity", TestEntity.class)
tm().query("FROM TestEntity", TestEntity.class)
.getResultStream()
.forEach(e -> assertThat(jpaTm().getEntityManager().contains(e)).isFalse()));
.forEach(e -> assertThat(tm().getEntityManager().contains(e)).isFalse()));
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
jpaTm()
.getEntityManager()
tm().getEntityManager()
.contains(
jpaTm()
.query(
tm().query(
"FROM TestEntity WHERE name = 'entity1'", TestEntity.class)
.getSingleResult()))
.isFalse());
}
private void insertPerson(int age) {
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(String.format("INSERT INTO Person (age) VALUES (%d)", age))
.executeUpdate();
}
private void insertCompany(String name) {
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(String.format("INSERT INTO Company (name) VALUES ('%s')", name))
.executeUpdate();
}
private void assertPersonExist(int age) {
jpaTm()
.transact(
tm().transact(
() -> {
EntityManager em = jpaTm().getEntityManager();
EntityManager em = tm().getEntityManager();
Integer maybeAge =
(Integer)
em.createNativeQuery(
@ -652,13 +606,11 @@ class JpaTransactionManagerImplTest {
}
private void assertCompanyExist(String name) {
jpaTm()
.transact(
tm().transact(
() -> {
String maybeName =
(String)
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
String.format("SELECT name FROM Company WHERE name = '%s'", name))
.getSingleResult();
@ -683,13 +635,11 @@ class JpaTransactionManagerImplTest {
}
private int countTable(String tableName) {
return jpaTm()
.transact(
return tm().transact(
() -> {
BigInteger colCount =
(BigInteger)
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(String.format("SELECT COUNT(*) FROM %s", tableName))
.getSingleResult();
return colCount.intValue();

View file

@ -16,7 +16,7 @@ package google.registry.schema.registrar;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.registrar.RegistrarPoc.Type.WHOIS;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.SqlHelper.saveRegistrar;
@ -69,7 +69,7 @@ class RegistrarPocTest {
@Test
void testSerializable_succeeds() {
insertInDb(testRegistrarPoc);
RegistrarPoc persisted = jpaTm().transact(() -> jpaTm().loadByEntity(testRegistrarPoc));
RegistrarPoc persisted = tm().transact(() -> tm().loadByEntity(testRegistrarPoc));
assertThat(SerializeUtils.serializeDeserialize(persisted)).isEqualTo(persisted);
}
}

View file

@ -17,7 +17,7 @@ package google.registry.testing;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.io.Files.asCharSink;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertSimpleResources;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.ResourceUtils.readResourceUtf8;
@ -352,11 +352,9 @@ public final class AppEngineExtension implements BeforeEachCallback, AfterEachCa
}
// Reset SQL Sequence based id allocation so that ids are deterministic in tests.
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.getEntityManager()
tm().getEntityManager()
.createNativeQuery(
"alter sequence if exists project_wide_unique_id_seq start 1 minvalue 1"
+ " restart with 1")

View file

@ -16,7 +16,7 @@ package google.registry.testing;
import static com.google.common.io.Files.asCharSink;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -66,7 +66,7 @@ class AppEngineExtensionTest {
@BeforeEach
void beforeEach() throws Exception {
originalJpa = jpaTm();
originalJpa = tm();
appEngine.beforeEach(context.getContext());
}
@ -75,7 +75,7 @@ class AppEngineExtensionTest {
// Note: cannot use isSameInstanceAs() because DummyTransactionManager would throw on any
// access.
assertWithMessage("Original state not restore. Is appEngine.afterEach not called by this test?")
.that(originalJpa == jpaTm())
.that(originalJpa == tm())
.isTrue();
}

View file

@ -33,7 +33,6 @@ import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableO
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
import static google.registry.model.ResourceTransferUtils.createTransferResponse;
import static google.registry.model.tld.Registry.TldState.GENERAL_AVAILABILITY;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.util.CollectionUtils.difference;
@ -1185,21 +1184,20 @@ public final class DatabaseHelper {
* the database at all.
*/
public static List<Object> loadAllEntities() {
return jpaTm()
.transact(
() -> {
ImmutableList<? extends Class<?>> entityClasses =
jpaTm().getEntityManager().getMetamodel().getEntities().stream()
.map(javax.persistence.metamodel.Type::getJavaType)
.collect(toImmutableList());
ImmutableList.Builder<Object> result = new ImmutableList.Builder<>();
for (Class<?> entityClass : entityClasses) {
for (Object object : jpaTm().loadAllOf(entityClass)) {
result.add(object);
}
return tm().transact(
() -> {
ImmutableList<? extends Class<?>> entityClasses =
tm().getEntityManager().getMetamodel().getEntities().stream()
.map(javax.persistence.metamodel.Type::getJavaType)
.collect(toImmutableList());
ImmutableList.Builder<Object> result = new ImmutableList.Builder<>();
for (Class<?> entityClass : entityClasses) {
for (Object object : tm().loadAllOf(entityClass)) {
result.add(object);
}
return result.build();
});
}
return result.build();
});
}
/**
@ -1281,37 +1279,37 @@ public final class DatabaseHelper {
/** Returns whether or not the given entity exists in Cloud SQL. */
public static boolean existsInDb(ImmutableObject object) {
return jpaTm().transact(() -> jpaTm().exists(object));
return tm().transact(() -> tm().exists(object));
}
/** Inserts the given entity/entities into Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void insertInDb(T... entities) {
jpaTm().transact(() -> jpaTm().insertAll(entities));
tm().transact(() -> tm().insertAll(entities));
}
/** Inserts the given entities into Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void insertInDb(ImmutableCollection<T> entities) {
jpaTm().transact(() -> jpaTm().insertAll(entities));
tm().transact(() -> tm().insertAll(entities));
}
/** Puts the given entity/entities into Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void putInDb(T... entities) {
jpaTm().transact(() -> jpaTm().putAll(entities));
tm().transact(() -> tm().putAll(entities));
}
/** Puts the given entities into Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void putInDb(ImmutableCollection<T> entities) {
jpaTm().transact(() -> jpaTm().putAll(entities));
tm().transact(() -> tm().putAll(entities));
}
/** Updates the given entities in Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void updateInDb(T... entities) {
jpaTm().transact(() -> jpaTm().updateAll(entities));
tm().transact(() -> tm().updateAll(entities));
}
/** Updates the given entities in Cloud SQL in a single transaction. */
public static <T extends ImmutableObject> void updateInDb(ImmutableCollection<T> entities) {
jpaTm().transact(() -> jpaTm().updateAll(entities));
tm().transact(() -> tm().updateAll(entities));
}
/**
@ -1320,7 +1318,7 @@ public final class DatabaseHelper {
* <p>Returns the original entity object.
*/
public static <T> T assertDetachedFromEntityManager(T entity) {
assertThat(jpaTm().getEntityManager().contains(entity)).isFalse();
assertThat(tm().getEntityManager().contains(entity)).isFalse();
return entity;
}
@ -1337,8 +1335,7 @@ public final class DatabaseHelper {
*/
public static void setMigrationScheduleToDatastorePrimaryNoAsync(FakeClock fakeClock) {
DateTime now = fakeClock.nowUtc();
jpaTm()
.transact(
tm().transact(
() ->
DatabaseMigrationStateSchedule.set(
ImmutableSortedMap.of(
@ -1364,8 +1361,7 @@ public final class DatabaseHelper {
*/
public static void setMigrationScheduleToDatastorePrimaryReadOnly(FakeClock fakeClock) {
DateTime now = fakeClock.nowUtc();
jpaTm()
.transact(
tm().transact(
() ->
DatabaseMigrationStateSchedule.set(
ImmutableSortedMap.of(
@ -1392,8 +1388,7 @@ public final class DatabaseHelper {
*/
public static void setMigrationScheduleToSqlPrimary(FakeClock fakeClock) {
DateTime now = fakeClock.nowUtc();
jpaTm()
.transact(
tm().transact(
() ->
DatabaseMigrationStateSchedule.set(
ImmutableSortedMap.of(
@ -1413,11 +1408,9 @@ public final class DatabaseHelper {
/** Removes the database migration schedule, in essence transitioning to DATASTORE_ONLY. */
public static void removeDatabaseMigrationSchedule() {
// use the raw calls because going SQL_PRIMARY -> DATASTORE_ONLY is not valid
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.put(
tm().put(
new DatabaseMigrationStateSchedule(
DatabaseMigrationStateSchedule.DEFAULT_TRANSITION_MAP)));
DatabaseMigrationStateSchedule.CACHE.invalidateAll();

View file

@ -15,7 +15,7 @@
package google.registry.testing;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.AppEngineExtension.makeRegistrar1;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -33,37 +33,37 @@ import org.junit.jupiter.api.function.Executable;
public class SqlHelper {
public static RegistryLock saveRegistryLock(RegistryLock lock) {
return jpaTm().transact(() -> RegistryLockDao.save(lock));
return tm().transact(() -> RegistryLockDao.save(lock));
}
public static Optional<RegistryLock> getRegistryLockByVerificationCode(String verificationCode) {
return jpaTm().transact(() -> RegistryLockDao.getByVerificationCode(verificationCode));
return tm().transact(() -> RegistryLockDao.getByVerificationCode(verificationCode));
}
public static Optional<RegistryLock> getMostRecentRegistryLockByRepoId(String repoId) {
return jpaTm().transact(() -> RegistryLockDao.getMostRecentByRepoId(repoId));
return tm().transact(() -> RegistryLockDao.getMostRecentByRepoId(repoId));
}
public static Optional<RegistryLock> getMostRecentVerifiedRegistryLockByRepoId(String repoId) {
return jpaTm().transact(() -> RegistryLockDao.getMostRecentVerifiedLockByRepoId(repoId));
return tm().transact(() -> RegistryLockDao.getMostRecentVerifiedLockByRepoId(repoId));
}
public static Optional<RegistryLock> getMostRecentUnlockedRegistryLockByRepoId(String repoId) {
return jpaTm().transact(() -> RegistryLockDao.getMostRecentVerifiedUnlockByRepoId(repoId));
return tm().transact(() -> RegistryLockDao.getMostRecentVerifiedUnlockByRepoId(repoId));
}
public static ImmutableList<RegistryLock> getRegistryLocksByRegistrarId(String registrarId) {
return jpaTm().transact(() -> RegistryLockDao.getLocksByRegistrarId(registrarId));
return tm().transact(() -> RegistryLockDao.getLocksByRegistrarId(registrarId));
}
public static Optional<RegistryLock> getRegistryLockByRevisionId(long revisionId) {
return jpaTm().transact(() -> RegistryLockDao.getByRevisionId(revisionId));
return tm().transact(() -> RegistryLockDao.getByRevisionId(revisionId));
}
public static Registrar saveRegistrar(String registrarId) {
Registrar registrar = makeRegistrar1().asBuilder().setRegistrarId(registrarId).build();
jpaTm().transact(() -> jpaTm().insert(registrar));
return jpaTm().transact(() -> jpaTm().loadByKey(registrar.createVKey()));
tm().transact(() -> tm().insert(registrar));
return tm().transact(() -> tm().loadByKey(registrar.createVKey()));
}
public static void assertThrowForeignKeyViolation(Executable executable) {

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.tld.label.ReservationType.FULLY_BLOCKED;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.TestDataHelper.loadFile;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -111,18 +111,16 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
}
ReservedList getCloudSqlReservedList(String name) {
return jpaTm()
.transact(
return tm().transact(
() -> {
long revisionId =
jpaTm()
.query(
tm().query(
"SELECT MAX(rl.revisionId) FROM ReservedList rl WHERE name = :name",
Long.class)
.setParameter("name", name)
.getSingleResult();
return jpaTm()
.query("FROM ReservedList WHERE revisionId = :revisionId", ReservedList.class)
return tm().query(
"FROM ReservedList WHERE revisionId = :revisionId", ReservedList.class)
.setParameter("revisionId", revisionId)
.getSingleResult();
});

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -56,7 +56,7 @@ public class CreatePackagePromotionCommandTest
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
@ -130,7 +130,7 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
IllegalArgumentException thrown =
assertThrows(
@ -159,7 +159,7 @@ public class CreatePackagePromotionCommandTest
.build());
runCommandForced("--price=USD 1000.00", "--next_billing_date=2012-03-17", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(0);
@ -185,7 +185,7 @@ public class CreatePackagePromotionCommandTest
runCommandForced("--max_domains=100", "--max_creates=500", "--price=USD 1000.00", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static google.registry.model.common.DatabaseMigrationStateSchedule.DEFAULT_TRANSITION_MAP;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSortedMap;
@ -59,7 +59,7 @@ public class GetDatabaseMigrationStateCommandTest
MigrationState.SQL_PRIMARY,
now.plusHours(5),
MigrationState.SQL_ONLY);
jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(transitions));
tm().transact(() -> DatabaseMigrationStateSchedule.set(transitions));
runCommand();
assertStdoutIs(String.format("Current migration schedule: %s\n", transitions));
}

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -61,7 +61,7 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion));
tm().transact(() -> tm().put(packagePromotion));
runCommand("abc123");
}
@ -78,11 +78,9 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.put(
tm().put(
new PackagePromotion.Builder()
.setToken(token)
.setMaxDomains(100)
@ -102,11 +100,9 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
jpaTm()
.transact(
tm().transact(
() ->
jpaTm()
.put(
tm().put(
new PackagePromotion.Builder()
.setToken(token2)
.setMaxDomains(1000)

View file

@ -17,7 +17,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.common.DatabaseMigrationStateSchedule.DEFAULT_TRANSITION_MAP;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -42,15 +42,13 @@ public class SetDatabaseMigrationStateCommandTest
@Test
void testSuccess_setsBasicSchedule() throws Exception {
assertThat(DatabaseMigrationStateSchedule.get()).isEqualTo(DEFAULT_TRANSITION_MAP);
assertThat(jpaTm().transact(() -> jpaTm().loadSingleton(DatabaseMigrationStateSchedule.class)))
assertThat(tm().transact(() -> tm().loadSingleton(DatabaseMigrationStateSchedule.class)))
.isEmpty();
runCommandForced("--migration_schedule=1970-01-01T00:00:00.000Z=DATASTORE_ONLY");
jpaTm()
.transact(
tm().transact(
() ->
assertThat(
jpaTm()
.loadSingleton(DatabaseMigrationStateSchedule.class)
tm().loadSingleton(DatabaseMigrationStateSchedule.class)
.get()
.migrationTransitions)
.isEqualTo(DEFAULT_TRANSITION_MAP));

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -58,7 +58,7 @@ public class UpdatePackagePromotionCommandTest
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
jpaTm().transact(() -> jpaTm().put(packagePromotion));
tm().transact(() -> tm().put(packagePromotion));
}
@Test
@ -72,7 +72,7 @@ public class UpdatePackagePromotionCommandTest
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
@ -120,7 +120,7 @@ public class UpdatePackagePromotionCommandTest
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
@ -142,7 +142,7 @@ public class UpdatePackagePromotionCommandTest
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
@ -164,7 +164,7 @@ public class UpdatePackagePromotionCommandTest
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
@ -181,7 +181,7 @@ public class UpdatePackagePromotionCommandTest
runCommandForced("--max_domains=200", "--max_creates=1000", "--price=USD 2000.00", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);