Clean up tx manager insert() signature and add convenience helper method (#1325)

* Clean up tx manager insert() signature and add convenience helper method

This is the first of a series of PRs to clean up the type signatures on the
TransactionManager methods (which are way too generic), along with creating some
helper methods for use in tests only that don't require creating transactions
all over the place, thus reducing visual noise at callsites. This first method
is DatabaseHelper.insertInDb(), but there will be plenty of others. Note that
this is only for the Cloud SQL transaction manager -- I'm not bothering to
migrate any Datastore-only code, as that will be going away soon enough.
This commit is contained in:
Ben McIlwain 2021-09-17 14:45:07 -04:00 committed by GitHub
parent 742eff0b0a
commit b4f6280d6f
40 changed files with 173 additions and 110 deletions

View file

@ -32,6 +32,7 @@ import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Result; import com.googlecode.objectify.Result;
import com.googlecode.objectify.cmd.Query; import com.googlecode.objectify.cmd.Query;
import google.registry.model.ImmutableObject;
import google.registry.model.annotations.InCrossTld; import google.registry.model.annotations.InCrossTld;
import google.registry.model.contact.ContactHistory; import google.registry.model.contact.ContactHistory;
import google.registry.model.domain.DomainHistory; import google.registry.model.domain.DomainHistory;
@ -127,6 +128,11 @@ public class DatastoreTransactionManager implements TransactionManager {
putAll(entities); putAll(entities);
} }
@Override
public void insertAll(ImmutableObject... entities) {
putAll(entities);
}
@Override @Override
public void insertWithoutBackup(Object entity) { public void insertWithoutBackup(Object entity) {
putWithoutBackup(entity); putWithoutBackup(entity);
@ -143,7 +149,7 @@ public class DatastoreTransactionManager implements TransactionManager {
} }
@Override @Override
public void putAll(Object... entities) { public void putAll(ImmutableObject... entities) {
syncIfTransactionless( syncIfTransactionless(
getOfy().save().entities(toDatastoreEntities(ImmutableList.copyOf(entities)))); getOfy().save().entities(toDatastoreEntities(ImmutableList.copyOf(entities))));
} }

View file

@ -312,6 +312,11 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
entities.forEach(this::insert); entities.forEach(this::insert);
} }
@Override
public void insertAll(ImmutableObject... entities) {
insertAll(ImmutableSet.copyOf(entities));
}
@Override @Override
public void insertWithoutBackup(Object entity) { public void insertWithoutBackup(Object entity) {
insert(entity); insert(entity);
@ -335,7 +340,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
} }
@Override @Override
public void putAll(Object... entities) { public void putAll(ImmutableObject... entities) {
checkArgumentNotNull(entities, "entities must be specified"); checkArgumentNotNull(entities, "entities must be specified");
assertInTransaction(); assertInTransaction();
for (Object entity : entities) { for (Object entity : entities) {

View file

@ -17,6 +17,7 @@ package google.registry.persistence.transaction;
import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject;
import google.registry.model.annotations.InCrossTld; import google.registry.model.annotations.InCrossTld;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -97,6 +98,9 @@ public interface TransactionManager {
/** Persists all new entities in the database, throws exception if any entity already exists. */ /** Persists all new entities in the database, throws exception if any entity already exists. */
void insertAll(ImmutableCollection<?> entities); void insertAll(ImmutableCollection<?> entities);
/** Persists all new entities in the database, throws exception if any entity already exists. */
void insertAll(ImmutableObject... entities);
/** /**
* Persists a new entity in the database without writing any backup if the underlying database is * Persists a new entity in the database without writing any backup if the underlying database is
* Datastore. * Datastore.
@ -125,7 +129,7 @@ public interface TransactionManager {
void put(Object entity); void put(Object entity);
/** Persists all new entities or updates the existing entities in the database. */ /** Persists all new entities or updates the existing entities in the database. */
void putAll(Object... entities); void putAll(ImmutableObject... entities);
/** Persists all new entities or updates the existing entities in the database. */ /** Persists all new entities or updates the existing entities in the database. */
void putAll(ImmutableCollection<?> entities); void putAll(ImmutableCollection<?> entities);

View file

@ -16,6 +16,7 @@ package google.registry.beam.common;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.AppEngineExtension.makeRegistrar1; import static google.registry.testing.AppEngineExtension.makeRegistrar1;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newRegistry; import static google.registry.testing.DatabaseHelper.newRegistry;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -210,7 +211,6 @@ public class RegistryJpaReadTest {
null, null,
100L)) 100L))
.build(); .build();
jpaTm() insertInDb(registry, registrar, contact, domain);
.transact(() -> jpaTm().insertAll(ImmutableList.of(registry, registrar, contact, domain)));
} }
} }

View file

@ -22,6 +22,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.SqlHelper.assertThrowForeignKeyViolation; import static google.registry.testing.SqlHelper.assertThrowForeignKeyViolation;
import static google.registry.testing.SqlHelper.saveRegistrar; import static google.registry.testing.SqlHelper.saveRegistrar;
@ -136,7 +137,7 @@ public class ContactResourceTest extends EntityTestCase {
@Test @Test
void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() { void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().insert(originalContact))); assertThrowForeignKeyViolation(() -> insertInDb(originalContact));
} }
@Test @Test
@ -146,7 +147,7 @@ public class ContactResourceTest extends EntityTestCase {
saveRegistrar("registrar3"); saveRegistrar("registrar3");
saveRegistrar("gaining"); saveRegistrar("gaining");
saveRegistrar("losing"); saveRegistrar("losing");
jpaTm().transact(() -> jpaTm().insert(originalContact)); insertInDb(originalContact);
ContactResource persisted = ContactResource persisted =
jpaTm() jpaTm()
.transact( .transact(

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects; import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newContactResource; import static google.registry.testing.DatabaseHelper.newContactResource;
import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid; import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar; import static google.registry.testing.SqlHelper.saveRegistrar;
@ -45,11 +46,11 @@ public class ContactHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar"); saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1"); ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().insert(contact)); insertInDb(contact);
VKey<ContactResource> contactVKey = contact.createVKey(); VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey)); ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey));
ContactHistory contactHistory = createContactHistory(contactFromDb); ContactHistory contactHistory = createContactHistory(contactFromDb);
jpaTm().transact(() -> jpaTm().insert(contactHistory)); insertInDb(contactHistory);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -64,12 +65,12 @@ public class ContactHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar"); saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1"); ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().insert(contact)); insertInDb(contact);
VKey<ContactResource> contactVKey = contact.createVKey(); VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey)); ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey));
ContactHistory contactHistory = ContactHistory contactHistory =
createContactHistory(contactFromDb).asBuilder().setContact(null).build(); createContactHistory(contactFromDb).asBuilder().setContact(null).build();
jpaTm().transact(() -> jpaTm().insert(contactHistory)); insertInDb(contactHistory);
jpaTm() jpaTm()
.transact( .transact(

View file

@ -22,6 +22,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.AppEngineExtension.makeRegistrar2; import static google.registry.testing.AppEngineExtension.makeRegistrar2;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid; import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid;
import static google.registry.testing.DatabaseHelper.newDomainBase; import static google.registry.testing.DatabaseHelper.newDomainBase;
import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid; import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid;
@ -74,7 +75,7 @@ public class DomainHistoryTest extends EntityTestCase {
void testPersistence() { void testPersistence() {
DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts()); DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory = createDomainHistory(domain); DomainHistory domainHistory = createDomainHistory(domain);
jpaTm().transact(() -> jpaTm().insert(domainHistory)); insertInDb(domainHistory);
jpaTm() jpaTm()
.transact( .transact(
@ -89,7 +90,7 @@ public class DomainHistoryTest extends EntityTestCase {
void testLegacyPersistence_nullResource() { void testLegacyPersistence_nullResource() {
DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts()); DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory = createDomainHistory(domain).asBuilder().setDomain(null).build(); DomainHistory domainHistory = createDomainHistory(domain).asBuilder().setDomain(null).build();
jpaTm().transact(() -> jpaTm().insert(domainHistory)); insertInDb(domainHistory);
jpaTm() jpaTm()
.transact( .transact(
@ -175,7 +176,7 @@ public class DomainHistoryTest extends EntityTestCase {
.setNameservers(host.createVKey()) .setNameservers(host.createVKey())
.build(); .build();
tm().transact(() -> tm().insert(domain)); tm().transact(() -> tm().insert(domain));
jpaTm().transact(() -> jpaTm().insert(domain)); insertInDb(domain);
DomainHistory domainHistory = createDomainHistory(domain); DomainHistory domainHistory = createDomainHistory(domain);
tm().transact(() -> tm().insert(domainHistory)); tm().transact(() -> tm().insert(domainHistory));
@ -185,7 +186,7 @@ public class DomainHistoryTest extends EntityTestCase {
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey)); DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
// attempt to write to SQL. // attempt to write to SQL.
jpaTm().transact(() -> jpaTm().insert(domainHistoryFromDb)); insertInDb(domainHistoryFromDb);
// Reload and rewrite. // Reload and rewrite.
DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().loadByKey(domainHistoryVKey)); DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
@ -249,7 +250,7 @@ public class DomainHistoryTest extends EntityTestCase {
.setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) .setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
.setDnsRefreshRequestTime(Optional.of(DateTime.parse("2020-03-09T16:40:00Z"))) .setDnsRefreshRequestTime(Optional.of(DateTime.parse("2020-03-09T16:40:00Z")))
.build(); .build();
jpaTm().transact(() -> jpaTm().insert(domain)); insertInDb(domain);
return domain; return domain;
} }

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects; import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newHostResource; import static google.registry.testing.DatabaseHelper.newHostResource;
import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid; import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar; import static google.registry.testing.SqlHelper.saveRegistrar;
@ -45,12 +46,12 @@ public class HostHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar"); saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1"); HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().insert(host)); insertInDb(host);
VKey<HostResource> hostVKey = VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1")); VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(hostVKey)); HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb); HostHistory hostHistory = createHostHistory(hostFromDb);
jpaTm().transact(() -> jpaTm().insert(hostHistory)); insertInDb(hostHistory);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -64,11 +65,11 @@ public class HostHistoryTest extends EntityTestCase {
void testLegacyPersistence_nullHostBase() { void testLegacyPersistence_nullHostBase() {
saveRegistrar("TheRegistrar"); saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1"); HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().insert(host)); insertInDb(host);
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(host.createVKey())); HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(host.createVKey()));
HostHistory hostHistory = createHostHistory(hostFromDb).asBuilder().setHost(null).build(); HostHistory hostHistory = createHostHistory(hostFromDb).asBuilder().setHost(null).build();
jpaTm().transact(() -> jpaTm().insert(hostHistory)); insertInDb(hostHistory);
jpaTm() jpaTm()
.transact( .transact(

View file

@ -19,6 +19,7 @@ import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableO
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid; import static google.registry.testing.DatabaseHelper.newContactResourceWithRoid;
import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid; import static google.registry.testing.DatabaseHelper.newHostResourceWithRoid;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
@ -128,7 +129,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
DomainHistory legacyDomainHistory = (DomainHistory) fromObjectify; DomainHistory legacyDomainHistory = (DomainHistory) fromObjectify;
// Next, save that from-Datastore object in SQL and verify we can load it back in // Next, save that from-Datastore object in SQL and verify we can load it back in
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory)); insertInDb(legacyDomainHistory);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.DatabaseHelper.newDomainBase; import static google.registry.testing.DatabaseHelper.newDomainBase;
import static google.registry.testing.DatabaseHelper.persistActiveContact; import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DatabaseHelper.persistResource;
@ -92,14 +93,14 @@ public class PollMessageTest extends EntityTestCase {
@TestSqlOnly @TestSqlOnly
void testCloudSqlSupportForPolymorphicVKey() { void testCloudSqlSupportForPolymorphicVKey() {
jpaTm().transact(() -> jpaTm().insert(oneTime)); insertInDb(oneTime);
PollMessage persistedOneTime = PollMessage persistedOneTime =
jpaTm() jpaTm()
.transact(() -> jpaTm().loadByKey(VKey.createSql(PollMessage.class, oneTime.getId()))); .transact(() -> jpaTm().loadByKey(VKey.createSql(PollMessage.class, oneTime.getId())));
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class); assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
assertThat(persistedOneTime).isEqualTo(oneTime); assertThat(persistedOneTime).isEqualTo(oneTime);
jpaTm().transact(() -> jpaTm().insert(autoRenew)); insertInDb(autoRenew);
PollMessage persistedAutoRenew = PollMessage persistedAutoRenew =
jpaTm() jpaTm()
.transact( .transact(

View file

@ -17,6 +17,7 @@ package google.registry.model.replay;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.LogsSubject.assertAboutLogs; import static google.registry.testing.LogsSubject.assertAboutLogs;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
@ -118,7 +119,7 @@ public class ReplicateToDatastoreActionTest {
TestObject bar = TestObject.create("bar"); TestObject bar = TestObject.create("bar");
// Write a transaction containing "foo". // Write a transaction containing "foo".
jpaTm().transact(() -> jpaTm().insert(foo)); insertInDb(foo);
task.run(); task.run();
// Verify that it propagated to datastore, then remove "foo" directly from datastore. // Verify that it propagated to datastore, then remove "foo" directly from datastore.
@ -126,7 +127,7 @@ public class ReplicateToDatastoreActionTest {
ofyTm().transact(() -> ofyTm().delete(foo.key())); ofyTm().transact(() -> ofyTm().delete(foo.key()));
// Write "bar" // Write "bar"
jpaTm().transact(() -> jpaTm().insert(bar)); insertInDb(bar);
task.run(); task.run();
// If we replayed only the most recent transaction, we should have "bar" but not "foo". // If we replayed only the most recent transaction, we should have "bar" but not "foo".
@ -140,12 +141,12 @@ public class ReplicateToDatastoreActionTest {
TestObject bar = TestObject.create("bar"); TestObject bar = TestObject.create("bar");
// Write a transaction and run just the batch fetch. // Write a transaction and run just the batch fetch.
jpaTm().transact(() -> jpaTm().insert(foo)); insertInDb(foo);
List<TransactionEntity> txns1 = task.getTransactionBatch(); List<TransactionEntity> txns1 = task.getTransactionBatch();
assertThat(txns1).hasSize(1); assertThat(txns1).hasSize(1);
// Write a second transaction and do another batch fetch. // Write a second transaction and do another batch fetch.
jpaTm().transact(() -> jpaTm().insert(bar)); insertInDb(bar);
List<TransactionEntity> txns2 = task.getTransactionBatch(); List<TransactionEntity> txns2 = task.getTransactionBatch();
assertThat(txns2).hasSize(2); assertThat(txns2).hasSize(2);
@ -173,7 +174,7 @@ public class ReplicateToDatastoreActionTest {
void testMissingTransactions() { void testMissingTransactions() {
// Write a transaction (should have a transaction id of 1). // Write a transaction (should have a transaction id of 1).
TestObject foo = TestObject.create("foo"); TestObject foo = TestObject.create("foo");
jpaTm().transact(() -> jpaTm().insert(foo)); insertInDb(foo);
// Force the last transaction id back to -1 so that we look for transaction 0. // Force the last transaction id back to -1 so that we look for transaction 0.
ofyTm().transact(() -> ofyTm().insert(new LastSqlTransaction(-1))); ofyTm().transact(() -> ofyTm().insert(new LastSqlTransaction(-1)));
@ -189,7 +190,7 @@ public class ReplicateToDatastoreActionTest {
void testMissingTransactions_fullTask() { void testMissingTransactions_fullTask() {
// Write a transaction (should have a transaction id of 1). // Write a transaction (should have a transaction id of 1).
TestObject foo = TestObject.create("foo"); TestObject foo = TestObject.create("foo");
jpaTm().transact(() -> jpaTm().insert(foo)); insertInDb(foo);
// Force the last transaction id back to -1 so that we look for transaction 0. // Force the last transaction id back to -1 so that we look for transaction 0.
ofyTm().transact(() -> ofyTm().insert(new LastSqlTransaction(-1))); ofyTm().transact(() -> ofyTm().insert(new LastSqlTransaction(-1)));
@ -229,7 +230,7 @@ public class ReplicateToDatastoreActionTest {
.build())); .build()));
fakeClock.advanceBy(Duration.standardDays(1)); fakeClock.advanceBy(Duration.standardDays(1));
jpaTm().transact(() -> jpaTm().insert(TestObject.create("foo"))); insertInDb(TestObject.create("foo"));
task.run(); task.run();
// Replication shouldn't have happened // Replication shouldn't have happened
assertThat(ofyTm().loadAllOf(TestObject.class)).isEmpty(); assertThat(ofyTm().loadAllOf(TestObject.class)).isEmpty();

View file

@ -18,8 +18,10 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules; import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -49,7 +51,7 @@ class EntityCallbacksListenerTest {
@Test @Test
void verifyAllCallbacks_executedExpectedTimes() { void verifyAllCallbacks_executedExpectedTimes() {
TestEntity testPersist = new TestEntity(); TestEntity testPersist = new TestEntity();
jpaTm().transact(() -> jpaTm().insert(testPersist)); insertInDb(testPersist);
checkAll(testPersist, 1, 0, 0, 0); checkAll(testPersist, 1, 0, 0, 0);
TestEntity testUpdate = new TestEntity(); TestEntity testUpdate = new TestEntity();
@ -100,8 +102,7 @@ class EntityCallbacksListenerTest {
@Test @Test
void verifyCallbacksNotCalledOnCommit() { void verifyCallbacksNotCalledOnCommit() {
TestEntity testEntity = new TestEntity(); insertInDb(new TestEntity());
jpaTm().transact(() -> jpaTm().insert(testEntity));
TestEntity testLoad = TestEntity testLoad =
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"))); jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
@ -263,7 +264,7 @@ class EntityCallbacksListenerTest {
} }
@MappedSuperclass @MappedSuperclass
private static class ParentEntity { private static class ParentEntity extends ImmutableObject {
@Embedded ParentEmbedded parentEmbedded = new ParentEmbedded(); @Embedded ParentEmbedded parentEmbedded = new ParentEmbedded();
@Transient int parentPostLoad = 0; @Transient int parentPostLoad = 0;
@Transient int parentPrePersist = 0; @Transient int parentPrePersist = 0;

View file

@ -19,6 +19,7 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.END
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED; 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.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
@ -58,7 +59,7 @@ public class AllocationTokenStatusTransitionConverterTest {
TimedTransitionProperty.fromValueMap(values, TokenStatusTransition.class); TimedTransitionProperty.fromValueMap(values, TokenStatusTransition.class);
AllocationTokenStatusTransitionConverterTestEntity testEntity = AllocationTokenStatusTransitionConverterTestEntity testEntity =
new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty); new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
AllocationTokenStatusTransitionConverterTestEntity persisted = AllocationTokenStatusTransitionConverterTestEntity persisted =
jpaTm() jpaTm()
.transact( .transact(

View file

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

View file

@ -17,6 +17,7 @@ import static com.google.common.base.Charsets.US_ASCII;
import static com.google.common.hash.Funnels.stringFunnel; import static com.google.common.hash.Funnels.stringFunnel;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.hash.BloomFilter; import com.google.common.hash.BloomFilter;
@ -41,7 +42,7 @@ class BloomFilterConverterTest {
BloomFilter<String> bloomFilter = BloomFilter.create(stringFunnel(US_ASCII), 3); BloomFilter<String> bloomFilter = BloomFilter.create(stringFunnel(US_ASCII), 3);
ImmutableSet.of("foo", "bar", "baz").forEach(bloomFilter::put); ImmutableSet.of("foo", "bar", "baz").forEach(bloomFilter::put);
TestEntity entity = new TestEntity(bloomFilter); TestEntity entity = new TestEntity(bloomFilter);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.bloomFilter).isEqualTo(bloomFilter); assertThat(persisted.bloomFilter).isEqualTo(bloomFilter);

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -45,7 +46,7 @@ public class CidrAddressBlockListConverterTest {
CidrAddressBlock.create("8000::/1"), CidrAddressBlock.create("8000::/1"),
CidrAddressBlock.create("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128")); CidrAddressBlock.create("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128"));
TestEntity testEntity = new TestEntity(addresses); TestEntity testEntity = new TestEntity(addresses);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.addresses).isEqualTo(addresses); assertThat(persisted.addresses).isEqualTo(addresses);

View file

@ -15,6 +15,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.CreateAutoTimestamp; import google.registry.model.CreateAutoTimestamp;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -45,7 +46,7 @@ public class CreateAutoTimestampConverterTest {
CreateAutoTimestamp ts = CreateAutoTimestamp.create(DateTime.parse("2019-09-9T11:39:00Z")); CreateAutoTimestamp ts = CreateAutoTimestamp.create(DateTime.parse("2019-09-9T11:39:00Z"));
TestEntity ent = new TestEntity("myinst", ts); TestEntity ent = new TestEntity("myinst", ts);
jpaTm().transact(() -> jpaTm().insert(ent)); insertInDb(ent);
TestEntity result = TestEntity result =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
assertThat(result).isEqualTo(new TestEntity("myinst", ts)); assertThat(result).isEqualTo(new TestEntity("myinst", ts));
@ -56,7 +57,7 @@ public class CreateAutoTimestampConverterTest {
CreateAutoTimestamp ts = CreateAutoTimestamp.create(null); CreateAutoTimestamp ts = CreateAutoTimestamp.create(null);
TestEntity ent = new TestEntity("autoinit", ts); TestEntity ent = new TestEntity("autoinit", ts);
jpaTm().transact(() -> jpaTm().insert(ent)); insertInDb(ent);
TestEntity result = TestEntity result =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "autoinit")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "autoinit"));

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -47,7 +48,7 @@ public class CurrencyToBillingConverterTest {
CurrencyUnit.of("CNY"), CurrencyUnit.of("CNY"),
new BillingAccountEntry(CurrencyUnit.of("CNY"), "accountId2")); new BillingAccountEntry(CurrencyUnit.of("CNY"), "accountId2"));
TestEntity testEntity = new TestEntity(currencyToBilling); TestEntity testEntity = new TestEntity(currencyToBilling);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.currencyToBilling).containsExactlyEntriesIn(currencyToBilling); assertThat(persisted.currencyToBilling).containsExactlyEntriesIn(currencyToBilling);

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -39,7 +40,7 @@ public class CurrencyUnitConverterTest {
@Test @Test
void roundTripConversion() { void roundTripConversion() {
TestEntity entity = new TestEntity(CurrencyUnit.EUR); TestEntity entity = new TestEntity(CurrencyUnit.EUR);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
assertThat( assertThat(
jpaTm() jpaTm()
.transact( .transact(

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
@ -59,7 +60,7 @@ public class DatabaseMigrationScheduleTransitionConverterTest {
TimedTransitionProperty.fromValueMap(values, MigrationStateTransition.class); TimedTransitionProperty.fromValueMap(values, MigrationStateTransition.class);
DatabaseMigrationScheduleTransitionConverterTestEntity testEntity = DatabaseMigrationScheduleTransitionConverterTestEntity testEntity =
new DatabaseMigrationScheduleTransitionConverterTestEntity(timedTransitionProperty); new DatabaseMigrationScheduleTransitionConverterTestEntity(timedTransitionProperty);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
DatabaseMigrationScheduleTransitionConverterTestEntity persisted = DatabaseMigrationScheduleTransitionConverterTestEntity persisted =
jpaTm() jpaTm()
.transact( .transact(

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules; import google.registry.persistence.transaction.JpaTestRules;
@ -69,7 +70,7 @@ public class DateTimeConverterTest {
void converter_generatesTimestampWithNormalizedZone() { void converter_generatesTimestampWithNormalizedZone() {
DateTime dt = parseDateTime("2019-09-01T01:01:01Z"); DateTime dt = parseDateTime("2019-09-01T01:01:01Z");
TestEntity entity = new TestEntity("normalized_utc_time", dt); TestEntity entity = new TestEntity("normalized_utc_time", dt);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity retrievedEntity = TestEntity retrievedEntity =
jpaTm() jpaTm()
.transact( .transact(
@ -82,7 +83,7 @@ public class DateTimeConverterTest {
DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00"); DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00");
TestEntity entity = new TestEntity("new_york_time", dt); TestEntity entity = new TestEntity("new_york_time", dt);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity retrievedEntity = TestEntity retrievedEntity =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z"); assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z");

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.replay.EntityTest.EntityForTesting; import google.registry.model.replay.EntityTest.EntityForTesting;
@ -78,7 +79,7 @@ public class DurationConverterTest {
private void assertPersistedEntityHasSameDuration(Duration duration) { private void assertPersistedEntityHasSameDuration(Duration duration) {
DurationTestEntity entity = new DurationTestEntity(duration); DurationTestEntity entity = new DurationTestEntity(duration);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
DurationTestEntity persisted = DurationTestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id"));
assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis()); assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis());

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@ -63,7 +64,7 @@ public class InetAddressSetConverterTest {
private void verifySaveAndLoad(@Nullable Set<InetAddress> inetAddresses) { private void verifySaveAndLoad(@Nullable Set<InetAddress> inetAddresses) {
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses); InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
InetAddressSetTestEntity persisted = InetAddressSetTestEntity persisted =
jpaTm() jpaTm()
.transact( .transact(

View file

@ -15,6 +15,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -71,7 +72,7 @@ public class JodaMoneyConverterTest {
void roundTripConversion() { void roundTripConversion() {
Money money = Money.of(CurrencyUnit.USD, 100); Money money = Money.of(CurrencyUnit.USD, 100);
TestEntity entity = new TestEntity(money); TestEntity entity = new TestEntity(money);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
List<?> result = List<?> result =
jpaTm() jpaTm()
.transact( .transact(
@ -101,7 +102,7 @@ public class JodaMoneyConverterTest {
"dos", Money.ofMajor(CurrencyUnit.JPY, 2000), "dos", Money.ofMajor(CurrencyUnit.JPY, 2000),
"tres", Money.of(CurrencyUnit.GBP, 20)); "tres", Money.of(CurrencyUnit.GBP, 20));
ComplexTestEntity entity = new ComplexTestEntity(moneyMap, myMoney, yourMoney); ComplexTestEntity entity = new ComplexTestEntity(moneyMap, myMoney, yourMoney);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
List<?> result = List<?> result =
jpaTm() jpaTm()
.transact( .transact(

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.replay.EntityTest; import google.registry.model.replay.EntityTest;
@ -54,7 +55,7 @@ public class LocalDateConverterTest {
private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) { private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) {
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date); LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
return jpaTm() return jpaTm()
.transact( .transact(
() -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id"))); () -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id")));

View file

@ -16,7 +16,9 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.persistence.WithLongVKey; import google.registry.persistence.WithLongVKey;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
@ -46,7 +48,7 @@ public class LongVKeyConverterTest {
new TestLongEntity( new TestLongEntity(
VKey.createSql(TestLongEntity.class, 10L), VKey.createSql(TestLongEntity.class, 10L),
VKey.createSql(CompositeKeyTestLongEntity.class, 20L)); VKey.createSql(CompositeKeyTestLongEntity.class, 20L));
jpaTm().transact(() -> jpaTm().insert(original)); insertInDb(original);
TestLongEntity retrieved = TestLongEntity retrieved =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestLongEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestLongEntity.class, "id"));
@ -60,7 +62,7 @@ public class LongVKeyConverterTest {
@Entity(name = "TestLongEntity") @Entity(name = "TestLongEntity")
@com.googlecode.objectify.annotation.Entity @com.googlecode.objectify.annotation.Entity
@WithLongVKey(classNameSuffix = "LongType") @WithLongVKey(classNameSuffix = "LongType")
static class TestLongEntity { static class TestLongEntity extends ImmutableObject {
@com.googlecode.objectify.annotation.Id @Id String id = "id"; @com.googlecode.objectify.annotation.Id @Id String id = "id";
VKey<TestLongEntity> number; VKey<TestLongEntity> number;

View file

@ -16,8 +16,10 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.model.ImmutableObject;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.persistence.transaction.JpaTestRules; import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension;
@ -39,14 +41,14 @@ public class StatusValueSetConverterTest {
Set<StatusValue> enums = ImmutableSet.of(StatusValue.INACTIVE, StatusValue.PENDING_DELETE); Set<StatusValue> enums = ImmutableSet.of(StatusValue.INACTIVE, StatusValue.PENDING_DELETE);
TestEntity obj = new TestEntity("foo", enums); TestEntity obj = new TestEntity("foo", enums);
jpaTm().transact(() -> jpaTm().insert(obj)); insertInDb(obj);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "foo")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "foo"));
assertThat(persisted.data).isEqualTo(enums); assertThat(persisted.data).isEqualTo(enums);
} }
@Entity(name = "TestEntity") @Entity(name = "TestEntity")
static class TestEntity { static class TestEntity extends ImmutableObject {
@Id String name; @Id String name;
Set<StatusValue> data; Set<StatusValue> data;

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -40,7 +41,7 @@ public class StringListConverterTest {
void roundTripConversion_returnsSameStringList() { void roundTripConversion_returnsSameStringList() {
List<String> tlds = ImmutableList.of("app", "dev", "how"); List<String> tlds = ImmutableList.of("app", "dev", "how");
TestEntity testEntity = new TestEntity(tlds); TestEntity testEntity = new TestEntity(tlds);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).containsExactly("app", "dev", "how"); assertThat(persisted.tlds).containsExactly("app", "dev", "how");
@ -50,7 +51,7 @@ public class StringListConverterTest {
void testMerge_succeeds() { void testMerge_succeeds() {
List<String> tlds = ImmutableList.of("app", "dev", "how"); List<String> tlds = ImmutableList.of("app", "dev", "how");
TestEntity testEntity = new TestEntity(tlds); TestEntity testEntity = new TestEntity(tlds);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
persisted.tlds = ImmutableList.of("com", "gov"); persisted.tlds = ImmutableList.of("com", "gov");
@ -63,7 +64,7 @@ public class StringListConverterTest {
@Test @Test
void testNullValue_writesAndReadsNullSuccessfully() { void testNullValue_writesAndReadsNullSuccessfully() {
TestEntity testEntity = new TestEntity(null); TestEntity testEntity = new TestEntity(null);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isNull(); assertThat(persisted.tlds).isNull();
@ -72,7 +73,7 @@ public class StringListConverterTest {
@Test @Test
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
TestEntity testEntity = new TestEntity(ImmutableList.of()); TestEntity testEntity = new TestEntity(ImmutableList.of());
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isEmpty(); assertThat(persisted.tlds).isEmpty();

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -49,7 +50,7 @@ public class StringMapConverterBaseTest {
@Test @Test
void roundTripConversion_returnsSameMap() { void roundTripConversion_returnsSameMap() {
TestEntity testEntity = new TestEntity(MAP); TestEntity testEntity = new TestEntity(MAP);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).containsExactlyEntriesIn(MAP); assertThat(persisted.map).containsExactlyEntriesIn(MAP);
@ -58,7 +59,7 @@ public class StringMapConverterBaseTest {
@Test @Test
void testUpdateColumn_succeeds() { void testUpdateColumn_succeeds() {
TestEntity testEntity = new TestEntity(MAP); TestEntity testEntity = new TestEntity(MAP);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).containsExactlyEntriesIn(MAP); assertThat(persisted.map).containsExactlyEntriesIn(MAP);
@ -72,7 +73,7 @@ public class StringMapConverterBaseTest {
@Test @Test
void testNullValue_writesAndReadsNullSuccessfully() { void testNullValue_writesAndReadsNullSuccessfully() {
TestEntity testEntity = new TestEntity(null); TestEntity testEntity = new TestEntity(null);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).isNull(); assertThat(persisted.map).isNull();
@ -81,7 +82,7 @@ public class StringMapConverterBaseTest {
@Test @Test
void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() { void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() {
TestEntity testEntity = new TestEntity(ImmutableMap.of()); TestEntity testEntity = new TestEntity(ImmutableMap.of());
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.map).isEmpty(); assertThat(persisted.map).isEmpty();

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -38,7 +39,7 @@ public class StringSetConverterTest {
void roundTripConversion_returnsSameStringList() { void roundTripConversion_returnsSameStringList() {
Set<String> tlds = ImmutableSet.of("app", "dev", "how"); Set<String> tlds = ImmutableSet.of("app", "dev", "how");
TestEntity testEntity = new TestEntity(tlds); TestEntity testEntity = new TestEntity(tlds);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).containsExactly("app", "dev", "how"); assertThat(persisted.tlds).containsExactly("app", "dev", "how");
@ -47,7 +48,7 @@ public class StringSetConverterTest {
@Test @Test
void testNullValue_writesAndReadsNullSuccessfully() { void testNullValue_writesAndReadsNullSuccessfully() {
TestEntity testEntity = new TestEntity(null); TestEntity testEntity = new TestEntity(null);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isNull(); assertThat(persisted.tlds).isNull();
@ -56,7 +57,7 @@ public class StringSetConverterTest {
@Test @Test
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
TestEntity testEntity = new TestEntity(ImmutableSet.of()); TestEntity testEntity = new TestEntity(ImmutableSet.of());
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.tlds).isEmpty(); assertThat(persisted.tlds).isEmpty();

View file

@ -16,7 +16,9 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.persistence.WithStringVKey; import google.registry.persistence.WithStringVKey;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
@ -47,7 +49,7 @@ public class StringVKeyConverterTest {
"TheRealSpartacus", "TheRealSpartacus",
VKey.createSql(TestStringEntity.class, "ImSpartacus!"), VKey.createSql(TestStringEntity.class, "ImSpartacus!"),
VKey.createSql(CompositeKeyTestStringEntity.class, "NoImSpartacus!")); VKey.createSql(CompositeKeyTestStringEntity.class, "NoImSpartacus!"));
jpaTm().transact(() -> jpaTm().insert(original)); insertInDb(original);
TestStringEntity retrieved = TestStringEntity retrieved =
jpaTm() jpaTm()
@ -63,7 +65,7 @@ public class StringVKeyConverterTest {
@Entity(name = "TestStringEntity") @Entity(name = "TestStringEntity")
@com.googlecode.objectify.annotation.Entity @com.googlecode.objectify.annotation.Entity
@WithStringVKey(classNameSuffix = "StringType") @WithStringVKey(classNameSuffix = "StringType")
static class TestStringEntity { static class TestStringEntity extends ImmutableObject {
@com.googlecode.objectify.annotation.Id @Id String id; @com.googlecode.objectify.annotation.Id @Id String id;
VKey<TestStringEntity> other; VKey<TestStringEntity> other;

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.registrar.Registrar.State; import google.registry.model.registrar.Registrar.State;
@ -38,7 +39,7 @@ public class StringValueEnumeratedTest {
@Test @Test
void roundTripConversion_returnsSameEnum() { void roundTripConversion_returnsSameEnum() {
TestEntity testEntity = new TestEntity(State.ACTIVE); TestEntity testEntity = new TestEntity(State.ACTIVE);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.state).isEqualTo(State.ACTIVE); assertThat(persisted.state).isEqualTo(State.ACTIVE);
@ -47,7 +48,7 @@ public class StringValueEnumeratedTest {
@Test @Test
void testNativeQuery_succeeds() { void testNativeQuery_succeeds() {
TestEntity testEntity = new TestEntity(State.DISABLED); TestEntity testEntity = new TestEntity(State.DISABLED);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
assertThat( assertThat(
jpaTm() jpaTm()

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
@ -59,7 +60,7 @@ class TimedTransitionPropertyConverterBaseTest {
@Test @Test
void roundTripConversion_returnsSameTimedTransitionProperty() { void roundTripConversion_returnsSameTimedTransitionProperty() {
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY); TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY); assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
@ -68,7 +69,7 @@ class TimedTransitionPropertyConverterBaseTest {
@Test @Test
void testUpdateColumn_succeeds() { void testUpdateColumn_succeeds() {
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY); TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY); assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
@ -83,7 +84,7 @@ class TimedTransitionPropertyConverterBaseTest {
@Test @Test
void testNullValue_writesAndReadsNullSuccessfully() { void testNullValue_writesAndReadsNullSuccessfully() {
TestEntity testEntity = new TestEntity(null); TestEntity testEntity = new TestEntity(null);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.property).isNull(); assertThat(persisted.property).isNull();

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
@ -56,7 +57,7 @@ class TldStateTransitionConverterTest {
TimedTransitionProperty<TldState, TldStateTransition> timedTransitionProperty = TimedTransitionProperty<TldState, TldStateTransition> timedTransitionProperty =
TimedTransitionProperty.fromValueMap(values, TldStateTransition.class); TimedTransitionProperty.fromValueMap(values, TldStateTransition.class);
TestEntity testEntity = new TestEntity(timedTransitionProperty); TestEntity testEntity = new TestEntity(timedTransitionProperty);
jpaTm().transact(() -> jpaTm().insert(testEntity)); insertInDb(testEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty); assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);

View file

@ -16,6 +16,7 @@ package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules; import google.registry.persistence.transaction.JpaTestRules;
@ -66,7 +67,7 @@ public class ZonedDateTimeConverterTest {
void converter_generatesTimestampWithNormalizedZone() { void converter_generatesTimestampWithNormalizedZone() {
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z"); ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z");
TestEntity entity = new TestEntity("normalized_utc_time", zdt); TestEntity entity = new TestEntity("normalized_utc_time", zdt);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity retrievedEntity = TestEntity retrievedEntity =
jpaTm() jpaTm()
.transact( .transact(
@ -79,7 +80,7 @@ public class ZonedDateTimeConverterTest {
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z[UTC]"); ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z[UTC]");
TestEntity entity = new TestEntity("non_normalized_utc_time", zdt); TestEntity entity = new TestEntity("non_normalized_utc_time", zdt);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity retrievedEntity = TestEntity retrievedEntity =
jpaTm() jpaTm()
.transact( .transact(
@ -92,7 +93,7 @@ public class ZonedDateTimeConverterTest {
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01+05:00"); ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01+05:00");
TestEntity entity = new TestEntity("new_york_time", zdt); TestEntity entity = new TestEntity("new_york_time", zdt);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
TestEntity retrievedEntity = TestEntity retrievedEntity =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
assertThat(retrievedEntity.zdt.toString()).isEqualTo("2019-08-31T20:01:01Z"); assertThat(retrievedEntity.zdt.toString()).isEqualTo("2019-08-31T20:01:01Z");

View file

@ -18,6 +18,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.assertDetachedFromEntityManager; import static google.registry.testing.DatabaseHelper.assertDetachedFromEntityManager;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.TestDataHelper.fileClassPath; import static google.registry.testing.TestDataHelper.fileClassPath;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -139,7 +140,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void insert_succeeds() { void insert_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity); assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
} }
@ -258,16 +259,16 @@ class JpaTransactionManagerImplTest {
@Test @Test
void insert_throwsExceptionIfEntityExists() { void insert_throwsExceptionIfEntityExists() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity); assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity))); assertThrows(RollbackException.class, () -> insertInDb(theEntity));
} }
@Test @Test
void createCompoundIdEntity_succeeds() { void createCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity)); insertInDb(compoundIdEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey))) assertThat(jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey)))
.isEqualTo(compoundIdEntity); .isEqualTo(compoundIdEntity);
@ -277,7 +278,7 @@ class JpaTransactionManagerImplTest {
void createNamedCompoundIdEntity_succeeds() { void createNamedCompoundIdEntity_succeeds() {
// Compound IDs should also work even if the field names don't match up exactly // Compound IDs should also work even if the field names don't match up exactly
TestNamedCompoundIdEntity entity = new TestNamedCompoundIdEntity("foo", 1); TestNamedCompoundIdEntity entity = new TestNamedCompoundIdEntity("foo", 1);
jpaTm().transact(() -> jpaTm().insert(entity)); insertInDb(entity);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -295,7 +296,7 @@ class JpaTransactionManagerImplTest {
void saveAllNew_succeeds() { void saveAllNew_succeeds() {
moreEntities.forEach( moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse()); entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
moreEntities.forEach( moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue()); entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class))) assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
@ -306,9 +307,8 @@ class JpaTransactionManagerImplTest {
void saveAllNew_rollsBackWhenFailure() { void saveAllNew_rollsBackWhenFailure() {
moreEntities.forEach( moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse()); entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().insert(moreEntities.get(0))); insertInDb(moreEntities.get(0));
assertThrows( assertThrows(RollbackException.class, () -> insertInDb(moreEntities));
RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insertAll(moreEntities)));
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(0)))).isTrue(); 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(1)))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(2)))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(2)))).isFalse();
@ -324,7 +324,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void put_updatesExistingEntity() { void put_updatesExistingEntity() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey)); TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("foo"); assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar"; theEntity.data = "bar";
@ -346,7 +346,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void update_succeeds() { void update_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "theEntity"))); jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "theEntity")));
assertThat(persisted.data).isEqualTo("foo"); assertThat(persisted.data).isEqualTo("foo");
@ -358,7 +358,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void updateCompoundIdEntity_succeeds() { void updateCompoundIdEntity_succeeds() {
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity)); insertInDb(compoundIdEntity);
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey)); TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("foo"); assertThat(persisted.data).isEqualTo("foo");
compoundIdEntity.data = "bar"; compoundIdEntity.data = "bar";
@ -377,7 +377,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void updateAll_succeeds() { void updateAll_succeeds() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
ImmutableList<TestEntity> updated = ImmutableList<TestEntity> updated =
ImmutableList.of( ImmutableList.of(
new TestEntity("entity1", "foo_updated"), new TestEntity("entity1", "foo_updated"),
@ -390,7 +390,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void updateAll_rollsBackWhenFailure() { void updateAll_rollsBackWhenFailure() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
ImmutableList<TestEntity> updated = ImmutableList<TestEntity> updated =
ImmutableList.of( ImmutableList.of(
new TestEntity("entity1", "foo_updated"), new TestEntity("entity1", "foo_updated"),
@ -406,7 +406,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void load_succeeds() { void load_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByKey(theEntityKey))); jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByKey(theEntityKey)));
assertThat(persisted.name).isEqualTo("theEntity"); assertThat(persisted.name).isEqualTo("theEntity");
@ -423,7 +423,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadByEntity_succeeds() { void loadByEntity_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
TestEntity persisted = TestEntity persisted =
jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByEntity(theEntity))); jpaTm().transact(() -> assertDetachedFromEntityManager(jpaTm().loadByEntity(theEntity)));
assertThat(persisted.name).isEqualTo("theEntity"); assertThat(persisted.name).isEqualTo("theEntity");
@ -433,7 +433,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void maybeLoad_succeeds() { void maybeLoad_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
TestEntity persisted = TestEntity persisted =
jpaTm() jpaTm()
.transact( .transact(
@ -454,7 +454,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadCompoundIdEntity_succeeds() { void loadCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity)); insertInDb(compoundIdEntity);
TestCompoundIdEntity persisted = TestCompoundIdEntity persisted =
jpaTm() jpaTm()
.transact( .transact(
@ -466,7 +466,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadByKeysIfPresent() { void loadByKeysIfPresent() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -483,7 +483,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadByKeys_succeeds() { void loadByKeys_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -496,7 +496,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadByEntitiesIfPresent_succeeds() { void loadByEntitiesIfPresent_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -511,7 +511,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadByEntities_succeeds() { void loadByEntities_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -524,7 +524,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadAll_succeeds() { void loadAll_succeeds() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
ImmutableList<TestEntity> persisted = ImmutableList<TestEntity> persisted =
jpaTm() jpaTm()
.transact( .transact(
@ -537,7 +537,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadSingleton_detaches() { void loadSingleton_detaches() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
jpaTm() jpaTm()
.transact( .transact(
() -> () ->
@ -550,7 +550,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void delete_succeeds() { void delete_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(theEntityKey)); jpaTm().transact(() -> jpaTm().delete(theEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
@ -565,7 +565,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void deleteCompoundIdEntity_succeeds() { void deleteCompoundIdEntity_succeeds() {
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity)); insertInDb(compoundIdEntity);
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey)); jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
@ -597,7 +597,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void loadAfterUpdate_fails() { void loadAfterUpdate_fails() {
jpaTm().transact(() -> jpaTm().insert(theEntity)); insertInDb(theEntity);
assertThat( assertThat(
assertThrows( assertThrows(
IllegalStateException.class, IllegalStateException.class,
@ -614,7 +614,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void cqQuery_detaches() { void cqQuery_detaches() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
jpaTm() jpaTm()
.transact( .transact(
() -> () ->
@ -653,7 +653,7 @@ class JpaTransactionManagerImplTest {
@Test @Test
void query_detachesResults() { void query_detachesResults() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities)); insertInDb(moreEntities);
jpaTm() jpaTm()
.transact( .transact(
() -> () ->

View file

@ -16,6 +16,7 @@ package google.registry.persistence.transaction;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -66,7 +67,7 @@ public class JpaTransactionManagerRuleTest {
// This test verifies that 1) withEntityClass() has registered TestEntity and 2) The table // This test verifies that 1) withEntityClass() has registered TestEntity and 2) The table
// has been created, implying withProperty(HBM2DDL_AUTO, "update") worked. // has been created, implying withProperty(HBM2DDL_AUTO, "update") worked.
TestEntity original = new TestEntity("key", "value"); TestEntity original = new TestEntity("key", "value");
jpaTm().transact(() -> jpaTm().insert(original)); insertInDb(original);
TestEntity retrieved = TestEntity retrieved =
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "key")); jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "key"));
assertThat(retrieved).isEqualTo(original); assertThat(retrieved).isEqualTo(original);

View file

@ -17,6 +17,7 @@ package google.registry.schema.registrar;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS; import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static google.registry.testing.SqlHelper.saveRegistrar; import static google.registry.testing.SqlHelper.saveRegistrar;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -65,7 +66,7 @@ class RegistrarContactTest {
@Test @Test
void testPersistence_succeeds() { void testPersistence_succeeds() {
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc)); insertInDb(testRegistrarPoc);
RegistrarContact persisted = RegistrarContact persisted =
jpaTm().transact(() -> jpaTm().loadByKey(testRegistrarPoc.createVKey())); jpaTm().transact(() -> jpaTm().loadByKey(testRegistrarPoc.createVKey()));
assertThat(persisted).isEqualTo(testRegistrarPoc); assertThat(persisted).isEqualTo(testRegistrarPoc);

View file

@ -16,6 +16,7 @@ package google.registry.schema.registrar;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.insertInDb;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
@ -71,13 +72,13 @@ public class RegistrarDaoTest {
@Test @Test
void saveNew_worksSuccessfully() { void saveNew_worksSuccessfully() {
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().insert(testRegistrar)); insertInDb(testRegistrar);
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isTrue(); assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isTrue();
} }
@Test @Test
void update_worksSuccessfully() { void update_worksSuccessfully() {
jpaTm().transact(() -> jpaTm().insert(testRegistrar)); insertInDb(testRegistrar);
Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey)); Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName"); assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
jpaTm() jpaTm()
@ -101,7 +102,7 @@ public class RegistrarDaoTest {
@Test @Test
void load_worksSuccessfully() { void load_worksSuccessfully() {
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().insert(testRegistrar)); insertInDb(testRegistrar);
Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey)); Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
assertThat(persisted.getRegistrarId()).isEqualTo("registrarId"); assertThat(persisted.getRegistrarId()).isEqualTo("registrarId");

View file

@ -68,6 +68,7 @@ import google.registry.model.Buildable;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.EppResource.ForeignKeyedEppResource; import google.registry.model.EppResource.ForeignKeyedEppResource;
import google.registry.model.EppResourceUtils; import google.registry.model.EppResourceUtils;
import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
@ -1375,6 +1376,16 @@ public class DatabaseHelper {
return transactIfJpaTm(() -> tm().exists(object)); return transactIfJpaTm(() -> 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));
}
/** 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));
}
/** /**
* In JPA mode, asserts that the given entity is detached from the current entity manager. * In JPA mode, asserts that the given entity is detached from the current entity manager.
* *