Refactor naming and behavior of bulk load methods in TransactionManager (#918)

* Refactor naming and behavior of bulk load methods in TransactionManager

The contract of loadByKeys(Iterable<VKey>) specifies that the method will
throw a NoSuchElementException if any of the specified keys don't exist.
We don't do that before this PR, but now we do.

Existing calls (when necessary) were converted to the new load*
methods, which have the same behavior as the previous methods.

Existing methods were also renamed to be more clear -- see b/176239831
for more details and discussion.
This commit is contained in:
gbrodman 2021-01-06 11:55:59 -05:00 committed by GitHub
parent b4676a9836
commit 5bf618e671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 504 additions and 346 deletions

View file

@ -243,7 +243,7 @@ public class ReplayCommitLogsToSqlActionTest {
CommitLogMutation.create(manifestKey, TestObject.create("existing", "b")));
action.run();
TestObject fromDatabase =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestObject.class, "existing")));
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestObject.class, "existing")));
assertThat(fromDatabase.getField()).isEqualTo("b");
}
@ -276,7 +276,7 @@ public class ReplayCommitLogsToSqlActionTest {
DomainBase domain = newDomainBase("example.tld");
CommitLogMutation domainMutation =
tm().transact(() -> CommitLogMutation.create(manifestKey, domain));
ContactResource contact = tm().transact(() -> tm().load(domain.getRegistrant()));
ContactResource contact = tm().transact(() -> tm().loadByKey(domain.getRegistrant()));
CommitLogMutation contactMutation =
tm().transact(() -> CommitLogMutation.create(manifestKey, contact));
@ -348,7 +348,7 @@ public class ReplayCommitLogsToSqlActionTest {
inOrder.verify(spy).delete(contact.createVKey());
inOrder.verify(spy).put(putCaptor.capture());
assertThat(putCaptor.getValue().getClass()).isEqualTo(ContactResource.class);
assertThat(jpaTm().transact(() -> jpaTm().load(contact.createVKey()).getEmailAddress()))
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(contact.createVKey()).getEmailAddress()))
.isEqualTo("replay@example.tld");
}
@ -450,7 +450,7 @@ public class ReplayCommitLogsToSqlActionTest {
jpaTm()
.transact(
() ->
jpaTm().loadAll(TestObject.class).stream()
jpaTm().loadAllOf(TestObject.class).stream()
.map(TestObject::getId)
.collect(toImmutableList()));
assertThat(actualIds).containsExactlyElementsIn(expectedIds);

View file

@ -241,14 +241,15 @@ class InitSqlPipelineTest {
initSqlPipeline.run().waitUntilFinish();
try (AppEngineEnvironment env = new AppEngineEnvironment("test")) {
assertHostResourceEquals(
jpaTm().transact(() -> jpaTm().load(hostResource.createVKey())), hostResource);
assertThat(jpaTm().transact(() -> jpaTm().loadAll(Registrar.class)))
jpaTm().transact(() -> jpaTm().loadByKey(hostResource.createVKey())), hostResource);
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(Registrar.class)))
.comparingElementsUsing(immutableObjectCorrespondence("lastUpdateTime"))
.containsExactly(registrar1, registrar2);
assertThat(jpaTm().transact(() -> jpaTm().loadAll(ContactResource.class)))
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(ContactResource.class)))
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
.containsExactly(contact1, contact2);
assertCleansedDomainEquals(jpaTm().transact(() -> jpaTm().load(domain.createVKey())), domain);
assertCleansedDomainEquals(
jpaTm().transact(() -> jpaTm().loadByKey(domain.createVKey())), domain);
}
}

View file

@ -119,7 +119,7 @@ class WriteToSqlTest implements Serializable {
.localDbJpaTransactionManager()));
testPipeline.run().waitUntilFinish();
ImmutableList<?> sqlContacts = jpaTm().transact(() -> jpaTm().loadAll(ContactResource.class));
ImmutableList<?> sqlContacts = jpaTm().transact(() -> jpaTm().loadAllOf(ContactResource.class));
assertThat(sqlContacts)
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
.containsExactlyElementsIn(

View file

@ -203,7 +203,7 @@ public abstract class FlowTestCase<F extends Flow> {
assertWithMessage("Billing event is present for grace period: " + gracePeriod)
.that(gracePeriod.hasBillingEvent())
.isTrue();
return tm().load(
return tm().loadByKey(
firstNonNull(
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()));
}

View file

@ -87,7 +87,8 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
// Force the session to be cleared.
tm().clearSessionCache();
@SuppressWarnings("unchecked")
T refreshedResource = (T) transactIfJpaTm(() -> tm().load(resource)).cloneProjectedAtTime(now);
T refreshedResource =
(T) transactIfJpaTm(() -> tm().loadByEntity(resource)).cloneProjectedAtTime(now);
return refreshedResource;
}

View file

@ -265,7 +265,8 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
assertAboutDomains()
.that(domain)
.hasRegistrationExpirationTime(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
.hasRegistrationExpirationTime(
tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.and()
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_CREATE)

View file

@ -475,7 +475,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(1);
assertThat(domain.getDeletePollMessage().getOfyKey())
.isEqualTo(getOnlyPollMessage("TheRegistrar").createVKey().getOfyKey());
PollMessage.OneTime deletePollMessage = tm().load(domain.getDeletePollMessage());
PollMessage.OneTime deletePollMessage = tm().loadByKey(domain.getDeletePollMessage());
assertThat(deletePollMessage.getMsg()).isEqualTo(expectedMessage);
}
@ -509,7 +509,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
// Modify the autorenew poll message so that it has unacked messages in the past. This should
// prevent it from being deleted when the domain is deleted.
persistResource(
tm().load(reloadResourceByForeignKey().getAutorenewPollMessage())
tm().loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage())
.asBuilder()
.setEventTime(A_MONTH_FROM_NOW.minusYears(3))
.build());

View file

@ -197,7 +197,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
DomainBase domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRenew =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW);
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(newExpiration);
assertAboutDomains()
.that(domain)
@ -494,7 +494,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
persistDomain();
// Modify the autorenew poll message so that it has an undelivered message in the past.
persistResource(
tm().load(reloadResourceByForeignKey().getAutorenewPollMessage())
tm().loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage())
.asBuilder()
.setEventTime(expirationTime.minusYears(1))
.build());

View file

@ -150,7 +150,7 @@ class DomainRestoreRequestFlowTest
DomainBase domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(expirationTime);
assertAboutDomains()
.that(domain)
@ -218,7 +218,7 @@ class DomainRestoreRequestFlowTest
DomainBase domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(newExpirationTime);
assertAboutDomains()
.that(domain)

View file

@ -191,7 +191,7 @@ class DomainTransferApproveFlowTest
assertAboutHistoryEntries().that(historyEntryTransferApproved).hasOtherClientId("NewRegistrar");
assertTransferApproved(domain, originalTransferData);
assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime);
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(expectedExpirationTime);
// The poll message (in the future) to the losing registrar for implicit ack should be gone.
assertThat(getPollMessages(domain, "TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();

View file

@ -291,13 +291,13 @@ class DomainTransferRequestFlowTest
// Assert that the domain's TransferData server-approve billing events match the above.
if (expectTransferBillingEvent) {
assertBillingEventsEqual(
tm().load(domain.getTransferData().getServerApproveBillingEvent()),
tm().loadByKey(domain.getTransferData().getServerApproveBillingEvent()),
optionalTransferBillingEvent.get());
} else {
assertThat(domain.getTransferData().getServerApproveBillingEvent()).isNull();
}
assertBillingEventsEqual(
tm().load(domain.getTransferData().getServerApproveAutorenewEvent()),
tm().loadByKey(domain.getTransferData().getServerApproveAutorenewEvent()),
gainingClientAutorenew);
// Assert that the full set of server-approve billing events is exactly the extra ones plus
// the transfer billing event (if present) and the gaining client autorenew.
@ -318,7 +318,7 @@ class DomainTransferRequestFlowTest
BillingEvent.class),
Sets.union(expectedServeApproveBillingEvents, extraBillingEvents));
// The domain's autorenew billing event should still point to the losing client's event.
BillingEvent.Recurring domainAutorenewEvent = tm().load(domain.getAutorenewBillingEvent());
BillingEvent.Recurring domainAutorenewEvent = tm().loadByKey(domain.getAutorenewBillingEvent());
assertThat(domainAutorenewEvent.getClientId()).isEqualTo("TheRegistrar");
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
// The original grace periods should remain untouched.
@ -414,7 +414,7 @@ class DomainTransferRequestFlowTest
// Assert that the poll messages show up in the TransferData server approve entities.
assertPollMessagesEqual(
tm().load(domain.getTransferData().getServerApproveAutorenewPollMessage()),
tm().loadByKey(domain.getTransferData().getServerApproveAutorenewPollMessage()),
autorenewPollMessage);
// Assert that the full set of server-approve poll messages is exactly the server approve
// OneTime messages to gaining and losing registrars plus the gaining client autorenew.
@ -446,7 +446,8 @@ class DomainTransferRequestFlowTest
.hasLastEppUpdateTime(implicitTransferTime)
.and()
.hasLastEppUpdateClientId("NewRegistrar");
assertThat(tm().load(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
assertThat(
tm().loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(expectedExpirationTime);
// And after the expected grace time, the grace period should be gone.
DomainBase afterGracePeriod =

View file

@ -330,7 +330,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
assertThat(domain.getNameservers()).hasSize(13);
// getContacts does not return contacts of type REGISTRANT, so check these separately.
assertThat(domain.getContacts()).hasSize(3);
assertThat(tm().load(domain.getRegistrant()).getContactId()).isEqualTo("max_test_7");
assertThat(tm().loadByKey(domain.getRegistrant()).getContactId()).isEqualTo("max_test_7");
assertNoBillingEvents();
assertDnsTasksEnqueued("example.tld");
}
@ -1238,7 +1238,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
runFlow();
assertThat(tm().load(reloadResourceByForeignKey().getRegistrant()).getContactId())
assertThat(tm().loadByKey(reloadResourceByForeignKey().getRegistrant()).getContactId())
.isEqualTo("sh8013");
}
@ -1252,9 +1252,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
.getContacts()
.forEach(
contact -> {
assertThat(tm().load(contact.getContactKey()).getContactId()).isEqualTo("mak21");
assertThat(tm().loadByKey(contact.getContactKey()).getContactId()).isEqualTo("mak21");
});
assertThat(tm().load(reloadResourceByForeignKey().getRegistrant()).getContactId())
assertThat(tm().loadByKey(reloadResourceByForeignKey().getRegistrant()).getContactId())
.isEqualTo("mak21");
runFlow();
@ -1263,9 +1263,10 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
.getContacts()
.forEach(
contact -> {
assertThat(tm().load(contact.getContactKey()).getContactId()).isEqualTo("sh8013");
assertThat(tm().loadByKey(contact.getContactKey()).getContactId())
.isEqualTo("sh8013");
});
assertThat(tm().load(reloadResourceByForeignKey().getRegistrant()).getContactId())
assertThat(tm().loadByKey(reloadResourceByForeignKey().getRegistrant()).getContactId())
.isEqualTo("sh8013");
}

View file

@ -58,7 +58,7 @@ public class UpdateAutoTimestampTest {
private UpdateAutoTimestampTestObject reload() {
return tm().transact(
() ->
tm().load(
tm().loadByKey(
VKey.create(
UpdateAutoTimestampTestObject.class,
1L,

View file

@ -184,15 +184,16 @@ public class BillingEventTest extends EntityTestCase {
@TestOfyAndSql
void testPersistence() {
assertThat(transactIfJpaTm(() -> tm().load(oneTime))).isEqualTo(oneTime);
assertThat(transactIfJpaTm(() -> tm().load(oneTimeSynthetic))).isEqualTo(oneTimeSynthetic);
assertThat(transactIfJpaTm(() -> tm().load(recurring))).isEqualTo(recurring);
assertThat(transactIfJpaTm(() -> tm().load(cancellationOneTime)))
assertThat(transactIfJpaTm(() -> tm().loadByEntity(oneTime))).isEqualTo(oneTime);
assertThat(transactIfJpaTm(() -> tm().loadByEntity(oneTimeSynthetic)))
.isEqualTo(oneTimeSynthetic);
assertThat(transactIfJpaTm(() -> tm().loadByEntity(recurring))).isEqualTo(recurring);
assertThat(transactIfJpaTm(() -> tm().loadByEntity(cancellationOneTime)))
.isEqualTo(cancellationOneTime);
assertThat(transactIfJpaTm(() -> tm().load(cancellationRecurring)))
assertThat(transactIfJpaTm(() -> tm().loadByEntity(cancellationRecurring)))
.isEqualTo(cancellationRecurring);
ofyTmOrDoNothing(() -> assertThat(tm().load(modification)).isEqualTo(modification));
ofyTmOrDoNothing(() -> assertThat(tm().loadByEntity(modification)).isEqualTo(modification));
}
@TestOfyOnly
@ -220,8 +221,9 @@ public class BillingEventTest extends EntityTestCase {
@TestOfyAndSql
void testCancellationMatching() {
VKey<?> recurringKey =
transactIfJpaTm(() -> tm().load(oneTimeSynthetic).getCancellationMatchingBillingEvent());
assertThat(transactIfJpaTm(() -> tm().load(recurringKey))).isEqualTo(recurring);
transactIfJpaTm(
() -> tm().loadByEntity(oneTimeSynthetic).getCancellationMatchingBillingEvent());
assertThat(transactIfJpaTm(() -> tm().loadByKey(recurringKey))).isEqualTo(recurring);
}
@TestOfyOnly

View file

@ -140,7 +140,8 @@ public class ContactResourceTest extends EntityTestCase {
.transact(
() ->
jpaTm()
.load(VKey.createSql(ContactResource.class, originalContact.getRepoId())));
.loadByKey(
VKey.createSql(ContactResource.class, originalContact.getRepoId())));
ContactResource fixed =
originalContact

View file

@ -139,7 +139,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase result = jpaTm().load(domain.createVKey());
DomainBase result = jpaTm().loadByKey(domain.createVKey());
assertEqualDomainExcept(result);
});
}
@ -177,14 +177,14 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
jpaTm().put(persisted.asBuilder().build());
});
jpaTm()
.transact(
() -> {
// Load the domain in its entirety.
DomainBase result = jpaTm().load(domain.createVKey());
DomainBase result = jpaTm().loadByKey(domain.createVKey());
assertEqualDomainExcept(result);
});
}
@ -195,7 +195,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
DomainBase modified =
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().put(modified);
@ -204,7 +204,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
});
}
@ -215,7 +215,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
jpaTm().put(modified);
});
@ -223,7 +223,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
});
}
@ -234,7 +234,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
DomainBase modified =
persisted
.asBuilder()
@ -253,7 +253,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
@ -266,7 +266,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
DomainBase.Builder builder = persisted.asBuilder();
for (GracePeriod gracePeriod : persisted.getGracePeriods()) {
if (gracePeriod.getType() == GracePeriodStatus.RENEW) {
@ -279,7 +279,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertEqualDomainExcept(persisted);
});
}
@ -290,7 +290,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
DomainBase modified =
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().put(modified);
@ -299,7 +299,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods()).isEmpty();
DomainBase modified =
persisted
@ -319,7 +319,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
@ -340,7 +340,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getDsData()).containsExactlyElementsIn(domain.getDsData());
DomainBase modified = persisted.asBuilder().setDsData(unionDsData).build();
jpaTm().put(modified);
@ -350,7 +350,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertThat(persisted.getDsData()).containsExactlyElementsIn(unionDsData);
assertEqualDomainExcept(persisted, "dsData");
});
@ -359,7 +359,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
jpaTm().put(persisted.asBuilder().setDsData(domain.getDsData()).build());
});
@ -367,7 +367,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
assertEqualDomainExcept(persisted);
});
}
@ -388,7 +388,7 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
DomainBase result = jpaTm().load(domain.createVKey());
DomainBase result = jpaTm().loadByKey(domain.createVKey());
assertAboutImmutableObjects()
.that(result)
.isEqualExceptFields(domain, "updateTimestamp", "creationTime");
@ -528,7 +528,7 @@ public class DomainBaseSqlTest {
});
// Store the existing BillingRecurrence VKey. This happens after the event has been persisted.
DomainBase persisted = jpaTm().transact(() -> jpaTm().load(domain.createVKey()));
DomainBase persisted = jpaTm().transact(() -> jpaTm().loadByKey(domain.createVKey()));
// Verify that the domain data has been persisted.
// dsData still isn't persisted. gracePeriods appears to have the same values but for some
@ -537,7 +537,7 @@ public class DomainBaseSqlTest {
// Verify that the DomainContent object from the history record sets the fields correctly.
DomainHistory persistedHistoryEntry =
jpaTm().transact(() -> jpaTm().load(historyEntry.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(historyEntry.createVKey()));
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
.isEqualTo(domain.getAutorenewPollMessage());
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewBillingEvent())
@ -667,7 +667,7 @@ public class DomainBaseSqlTest {
});
// Store the existing BillingRecurrence VKey. This happens after the event has been persisted.
DomainBase persisted = jpaTm().transact(() -> jpaTm().load(domain.createVKey()));
DomainBase persisted = jpaTm().transact(() -> jpaTm().loadByKey(domain.createVKey()));
// Verify that the domain data has been persisted.
// dsData still isn't persisted. gracePeriods appears to have the same values but for some
@ -676,7 +676,7 @@ public class DomainBaseSqlTest {
// Verify that the DomainContent object from the history record sets the fields correctly.
DomainHistory persistedHistoryEntry =
jpaTm().transact(() -> jpaTm().load(historyEntry.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(historyEntry.createVKey()));
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
.isEqualTo(domain.getAutorenewPollMessage());
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewBillingEvent())

View file

@ -78,7 +78,8 @@ public class AllocationTokenTest extends EntityTestCase {
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
.build())
.build());
assertThat(transactIfJpaTm(() -> tm().load(unlimitedUseToken))).isEqualTo(unlimitedUseToken);
assertThat(transactIfJpaTm(() -> tm().loadByEntity(unlimitedUseToken)))
.isEqualTo(unlimitedUseToken);
DomainBase domain = persistActiveDomain("example.foo");
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1);
@ -91,7 +92,7 @@ public class AllocationTokenTest extends EntityTestCase {
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setTokenType(SINGLE_USE)
.build());
assertThat(transactIfJpaTm(() -> tm().load(singleUseToken))).isEqualTo(singleUseToken);
assertThat(transactIfJpaTm(() -> tm().loadByEntity(singleUseToken))).isEqualTo(singleUseToken);
}
@TestOfyOnly

View file

@ -46,13 +46,13 @@ public class ContactHistoryTest extends EntityTestCase {
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey));
ContactHistory contactHistory = createContactHistory(contactFromDb, contact.getRepoId());
jpaTm().transact(() -> jpaTm().insert(contactHistory));
jpaTm()
.transact(
() -> {
ContactHistory fromDatabase = jpaTm().load(contactHistory.createVKey());
ContactHistory fromDatabase = jpaTm().loadByKey(contactHistory.createVKey());
assertContactHistoriesEqual(fromDatabase, contactHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
});
@ -65,7 +65,7 @@ public class ContactHistoryTest extends EntityTestCase {
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey));
ContactHistory contactHistory =
createContactHistory(contactFromDb, contact.getRepoId())
.asBuilder()
@ -76,7 +76,7 @@ public class ContactHistoryTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
ContactHistory fromDatabase = jpaTm().load(contactHistory.createVKey());
ContactHistory fromDatabase = jpaTm().loadByKey(contactHistory.createVKey());
assertContactHistoriesEqual(fromDatabase, contactHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
});
@ -89,7 +89,7 @@ public class ContactHistoryTest extends EntityTestCase {
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
tm().transact(() -> tm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
ContactResource contactFromDb = tm().transact(() -> tm().loadByKey(contactVKey));
fakeClock.advanceOneMilli();
ContactHistory contactHistory = createContactHistory(contactFromDb, contact.getRepoId());
tm().transact(() -> tm().insert(contactHistory));
@ -100,8 +100,8 @@ public class ContactHistoryTest extends EntityTestCase {
VKey<ContactHistory> contactHistoryVKey = contactHistory.createVKey();
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(contactHistory.asHistoryEntry()));
ContactHistory hostHistoryFromDb = tm().transact(() -> tm().load(contactHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
ContactHistory hostHistoryFromDb = tm().transact(() -> tm().loadByKey(contactHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
}

View file

@ -71,7 +71,7 @@ public class DomainHistoryTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
DomainHistory fromDatabase = jpaTm().loadByKey(domainHistory.createVKey());
assertDomainHistoriesEqual(fromDatabase, domainHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
});
@ -87,7 +87,7 @@ public class DomainHistoryTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
DomainHistory fromDatabase = jpaTm().loadByKey(domainHistory.createVKey());
assertDomainHistoriesEqual(fromDatabase, domainHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
assertThat(fromDatabase.getNsHosts())
@ -125,8 +125,8 @@ public class DomainHistoryTest extends EntityTestCase {
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(domainHistory.asHistoryEntry()));
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().load(domainHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
assertThat(domainHistoryFromDb).isEqualTo(historyEntryFromDb);
}
@ -183,13 +183,13 @@ public class DomainHistoryTest extends EntityTestCase {
// Load the DomainHistory object from the datastore.
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().load(domainHistoryVKey));
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
// attempt to write to SQL.
jpaTm().transact(() -> jpaTm().insert(domainHistoryFromDb));
// Reload and rewrite.
DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().load(domainHistoryVKey));
DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
jpaTm().transact(() -> jpaTm().put(domainHistoryFromDb2));
}

View file

@ -47,13 +47,13 @@ public class HostHistoryTest extends EntityTestCase {
jpaTm().transact(() -> jpaTm().insert(host));
VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
jpaTm().transact(() -> jpaTm().insert(hostHistory));
jpaTm()
.transact(
() -> {
HostHistory fromDatabase = jpaTm().load(hostHistory.createVKey());
HostHistory fromDatabase = jpaTm().loadByKey(hostHistory.createVKey());
assertHostHistoriesEqual(fromDatabase, hostHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
});
@ -65,7 +65,7 @@ public class HostHistoryTest extends EntityTestCase {
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().insert(host));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(host.createVKey()));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(host.createVKey()));
HostHistory hostHistory =
createHostHistory(hostFromDb, host.getRepoId()).asBuilder().setHostBase(null).build();
jpaTm().transact(() -> jpaTm().insert(hostHistory));
@ -73,7 +73,7 @@ public class HostHistoryTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
HostHistory fromDatabase = jpaTm().load(hostHistory.createVKey());
HostHistory fromDatabase = jpaTm().loadByKey(hostHistory.createVKey());
assertHostHistoriesEqual(fromDatabase, hostHistory);
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
});
@ -87,7 +87,7 @@ public class HostHistoryTest extends EntityTestCase {
tm().transact(() -> tm().insert(host));
VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = tm().transact(() -> tm().load(hostVKey));
HostResource hostFromDb = tm().transact(() -> tm().loadByKey(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
fakeClock.advanceOneMilli();
tm().transact(() -> tm().insert(hostHistory));
@ -98,8 +98,8 @@ public class HostHistoryTest extends EntityTestCase {
VKey<HostHistory> hostHistoryVKey = hostHistory.createVKey();
VKey<HistoryEntry> historyEntryVKey =
VKey.createOfy(HistoryEntry.class, Key.create(hostHistory.asHistoryEntry()));
HostHistory hostHistoryFromDb = tm().transact(() -> tm().load(hostHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
HostHistory hostHistoryFromDb = tm().transact(() -> tm().loadByKey(hostHistoryVKey));
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
}

View file

@ -65,7 +65,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
.transact(
() ->
ofyTm()
.load(
.loadByKey(
VKey.create(
HistoryEntry.class,
historyEntryId,
@ -85,7 +85,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
jpaTm().insert(legacyContactHistory);
});
ContactHistory legacyHistoryFromSql =
jpaTm().transact(() -> jpaTm().load(legacyContactHistory.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(legacyContactHistory.createVKey()));
assertAboutImmutableObjects()
.that(legacyContactHistory)
.isEqualExceptFields(legacyHistoryFromSql);
@ -109,7 +109,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
.transact(
() ->
ofyTm()
.load(
.loadByKey(
VKey.create(
HistoryEntry.class,
historyEntryId,
@ -130,7 +130,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
// Next, save that from-Datastore object in SQL and verify we can load it back in
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory));
DomainHistory legacyHistoryFromSql =
jpaTm().transact(() -> jpaTm().load(legacyDomainHistory.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(legacyDomainHistory.createVKey()));
// Don't compare nsHosts directly because one is null and the other is empty
assertAboutImmutableObjects()
.that(legacyDomainHistory)
@ -161,7 +161,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
.transact(
() ->
ofyTm()
.load(
.loadByKey(
VKey.create(
HistoryEntry.class,
historyEntryId,
@ -181,7 +181,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
jpaTm().insert(legacyHostHistory);
});
HostHistory legacyHistoryFromSql =
jpaTm().transact(() -> jpaTm().load(legacyHostHistory.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(legacyHostHistory.createVKey()));
assertAboutImmutableObjects().that(legacyHostHistory).isEqualExceptFields(legacyHistoryFromSql);
// can't compare hostRepoId directly since it doesn't save the ofy key in SQL
assertThat(legacyHostHistory.getParentVKey().getSqlKey())

View file

@ -93,7 +93,7 @@ class HostResourceTest extends EntityTestCase {
void testPersistence() {
HostResource newHost = host.asBuilder().setRepoId("NEWHOST").build();
tm().transact(() -> tm().insert(newHost));
assertThat(ImmutableList.of(tm().transact(() -> tm().load(newHost.createVKey()))))
assertThat(ImmutableList.of(tm().transact(() -> tm().loadByKey(newHost.createVKey()))))
.comparingElementsUsing(immutableObjectCorrespondence("revisions"))
.containsExactly(newHost);
}

View file

@ -71,7 +71,7 @@ class ForeignKeyIndexTest extends EntityTestCase {
HostResource host = persistActiveHost("ns1.example.com");
ForeignKeyIndex<HostResource> fki =
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc());
assertThat(tm().load(fki.getResourceKey())).isEqualTo(host);
assertThat(tm().loadByKey(fki.getResourceKey())).isEqualTo(host);
assertThat(fki.getDeletionTime()).isEqualTo(END_OF_TIME);
}

View file

@ -93,13 +93,16 @@ public class PollMessageTest extends EntityTestCase {
void testCloudSqlSupportForPolymorphicVKey() {
jpaTm().transact(() -> jpaTm().insert(oneTime));
PollMessage persistedOneTime =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, oneTime.getId())));
jpaTm()
.transact(() -> jpaTm().loadByKey(VKey.createSql(PollMessage.class, oneTime.getId())));
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
assertThat(persistedOneTime).isEqualTo(oneTime);
jpaTm().transact(() -> jpaTm().insert(autoRenew));
PollMessage persistedAutoRenew =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, autoRenew.getId())));
jpaTm()
.transact(
() -> jpaTm().loadByKey(VKey.createSql(PollMessage.class, autoRenew.getId())));
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
}
@ -114,7 +117,7 @@ public class PollMessageTest extends EntityTestCase {
.setMsg("Test poll message")
.setParent(historyEntry)
.build());
assertThat(tm().transact(() -> tm().load(pollMessage))).isEqualTo(pollMessage);
assertThat(tm().transact(() -> tm().loadByEntity(pollMessage))).isEqualTo(pollMessage);
}
@TestOfyAndSql
@ -129,7 +132,7 @@ public class PollMessageTest extends EntityTestCase {
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
.setTargetId("foobar.foo")
.build());
assertThat(tm().transact(() -> tm().load(pollMessage))).isEqualTo(pollMessage);
assertThat(tm().transact(() -> tm().loadByEntity(pollMessage))).isEqualTo(pollMessage);
}
@TestOfyOnly

View file

@ -131,7 +131,7 @@ class RegistrarTest extends EntityTestCase {
@TestOfyAndSql
void testPersistence() {
assertThat(tm().transact(() -> tm().load(registrar.createVKey()))).isEqualTo(registrar);
assertThat(tm().transact(() -> tm().loadByKey(registrar.createVKey()))).isEqualTo(registrar);
}
@TestOfyOnly

View file

@ -70,14 +70,15 @@ public class RegistryTest extends EntityTestCase {
Registry registry =
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
tm().transact(() -> tm().put(registry));
Registry persisted = tm().transact(() -> tm().load(Registry.createVKey(registry.tldStrId)));
Registry persisted =
tm().transact(() -> tm().loadByKey(Registry.createVKey(registry.tldStrId)));
assertThat(persisted).isEqualTo(registry);
}
@TestOfyAndSql
void testPersistence() {
assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull();
assertThat(tm().transact(() -> tm().load(Registry.createVKey("tld"))))
assertThat(tm().transact(() -> tm().loadByKey(Registry.createVKey("tld"))))
.isEqualTo(Registry.get("tld"));
}
@ -162,7 +163,7 @@ public class RegistryTest extends EntityTestCase {
.containsExactlyElementsIn(
tm().transact(
() ->
tm().load(
tm().loadByKeys(
ImmutableSet.of(
Registry.createVKey("foo"), Registry.createVKey("tld"))))
.values());

View file

@ -118,7 +118,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
});
VKey<Spec11ThreatMatch> threatVKey = VKey.createSql(Spec11ThreatMatch.class, threat.getId());
Spec11ThreatMatch persistedThreat = jpaTm().transact(() -> jpaTm().load(threatVKey));
Spec11ThreatMatch persistedThreat = jpaTm().transact(() -> jpaTm().loadByKey(threatVKey));
// Threat object saved for the first time doesn't have an ID; it is generated by SQL
threat.id = persistedThreat.id;

View file

@ -64,7 +64,7 @@ class BillingVKeyTest {
BillingVKeyTestEntity original = new BillingVKeyTestEntity(oneTimeVKey, recurringVKey);
tm().transact(() -> tm().insert(original));
BillingVKeyTestEntity persisted = tm().transact(() -> tm().load(original.createVKey()));
BillingVKeyTestEntity persisted = tm().transact(() -> tm().loadByKey(original.createVKey()));
assertThat(persisted).isEqualTo(original);
assertThat(persisted.getBillingEventVKey()).isEqualTo(oneTimeVKey);
@ -75,7 +75,7 @@ class BillingVKeyTest {
void testHandleNullVKeyCorrectly() {
BillingVKeyTestEntity original = new BillingVKeyTestEntity(null, null);
tm().transact(() -> tm().insert(original));
BillingVKeyTestEntity persisted = tm().transact(() -> tm().load(original.createVKey()));
BillingVKeyTestEntity persisted = tm().transact(() -> tm().loadByKey(original.createVKey()));
assertThat(persisted).isEqualTo(original);
}

View file

@ -53,7 +53,7 @@ class DomainHistoryVKeyTest {
DomainHistoryVKey domainHistoryVKey = DomainHistoryVKey.create(ofyKey);
TestEntity original = new TestEntity(domainHistoryVKey);
tm().transact(() -> tm().insert(original));
TestEntity persisted = tm().transact(() -> tm().load(original.createVKey()));
TestEntity persisted = tm().transact(() -> tm().loadByKey(original.createVKey()));
assertThat(persisted).isEqualTo(original);
// Double check that the persisted.domainHistoryVKey is a symmetric VKey
assertThat(persisted.domainHistoryVKey.createOfyKey())

View file

@ -66,14 +66,14 @@ class EntityCallbacksListenerTest {
checkAll(updated, 0, 1, 0, 1);
TestEntity testLoad =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "id")));
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
checkAll(testLoad, 0, 0, 0, 1);
TestEntity testRemove =
jpaTm()
.transact(
() -> {
TestEntity removed = jpaTm().load(VKey.createSql(TestEntity.class, "id"));
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
jpaTm().getEntityManager().remove(removed);
return removed;
});

View file

@ -65,7 +65,9 @@ public class InetAddressSetConverterTest {
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
jpaTm().transact(() -> jpaTm().insert(testEntity));
InetAddressSetTestEntity persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(InetAddressSetTestEntity.class, "id")));
jpaTm()
.transact(
() -> jpaTm().loadByKey(VKey.createSql(InetAddressSetTestEntity.class, "id")));
assertThat(persisted.addresses).isEqualTo(inetAddresses);
}

View file

@ -57,7 +57,8 @@ public class LocalDateConverterTest {
jpaTm().transact(() -> jpaTm().insert(entity));
LocalDateConverterTestEntity retrievedEntity =
jpaTm()
.transact(() -> jpaTm().load(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
.transact(
() -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
return retrievedEntity;
}

View file

@ -136,7 +136,7 @@ class JpaTransactionManagerImplTest {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
}
@Test
@ -200,20 +200,20 @@ class JpaTransactionManagerImplTest {
@Test
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
doThrow(JDBCConnectionException.class).when(spyJpaTm).loadByKey(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
JDBCConnectionException.class,
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
verify(spyJpaTm, times(3)).load(theEntityKey);
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.loadByKey(theEntityKey)));
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
Supplier<Runnable> supplier =
() -> {
Runnable work = () -> spyJpaTm.load(theEntityKey);
Runnable work = () -> spyJpaTm.loadByKey(theEntityKey);
work.run();
return null;
};
assertThrows(JDBCConnectionException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
verify(spyJpaTm, times(6)).load(theEntityKey);
verify(spyJpaTm, times(6)).loadByKey(theEntityKey);
}
@Test
@ -223,31 +223,31 @@ class JpaTransactionManagerImplTest {
new RuntimeException()
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
.when(spyJpaTm)
.load(any(VKey.class));
.loadByKey(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class,
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
verify(spyJpaTm, times(3)).load(theEntityKey);
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.loadByKey(theEntityKey)));
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
Supplier<Runnable> supplier =
() -> {
Runnable work = () -> spyJpaTm.load(theEntityKey);
Runnable work = () -> spyJpaTm.loadByKey(theEntityKey);
work.run();
return null;
};
assertThrows(RuntimeException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
verify(spyJpaTm, times(6)).load(theEntityKey);
verify(spyJpaTm, times(6)).loadByKey(theEntityKey);
}
@Test
void doTransactionless_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
doThrow(JDBCConnectionException.class).when(spyJpaTm).loadByKey(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class,
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.load(theEntityKey)));
verify(spyJpaTm, times(3)).load(theEntityKey);
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.loadByKey(theEntityKey)));
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
}
@Test
@ -255,7 +255,7 @@ class JpaTransactionManagerImplTest {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity)));
}
@ -264,7 +264,7 @@ class JpaTransactionManagerImplTest {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)))
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey)))
.isEqualTo(compoundIdEntity);
}
@ -275,7 +275,7 @@ class JpaTransactionManagerImplTest {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@ -296,17 +296,17 @@ class JpaTransactionManagerImplTest {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().put(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
}
@Test
void put_updatesExistingEntity() {
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
jpaTm().transact(() -> jpaTm().put(theEntity));
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@ -317,7 +317,7 @@ class JpaTransactionManagerImplTest {
jpaTm().transact(() -> jpaTm().putAll(moreEntities));
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@ -325,22 +325,22 @@ class JpaTransactionManagerImplTest {
void update_succeeds() {
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "theEntity")));
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "theEntity")));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
jpaTm().transact(() -> jpaTm().update(theEntity));
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@Test
void updateCompoundIdEntity_succeeds() {
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("foo");
compoundIdEntity.data = "bar";
jpaTm().transact(() -> jpaTm().update(compoundIdEntity));
persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@ -361,7 +361,7 @@ class JpaTransactionManagerImplTest {
new TestEntity("entity2", "bar_updated"),
new TestEntity("entity3", "qux_updated"));
jpaTm().transact(() -> jpaTm().updateAll(updated));
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(updated);
}
@ -376,7 +376,7 @@ class JpaTransactionManagerImplTest {
theEntity);
assertThrows(
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().updateAll(updated)));
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@ -384,7 +384,7 @@ class JpaTransactionManagerImplTest {
void load_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@ -393,14 +393,15 @@ class JpaTransactionManagerImplTest {
void load_throwsOnMissingElement() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThrows(
NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey)));
NoSuchElementException.class,
() -> jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey)));
}
@Test
void maybeLoad_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey).get());
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKeyIfPresent(theEntityKey).get());
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@ -408,14 +409,15 @@ class JpaTransactionManagerImplTest {
@Test
void maybeLoad_nonExistentObject() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().loadByKeyIfPresent(theEntityKey)).isPresent())
.isFalse();
}
@Test
void loadCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
assertThat(persisted.name).isEqualTo("compoundIdEntity");
assertThat(persisted.age).isEqualTo(10);
assertThat(persisted.data).isEqualTo("foo");
@ -424,7 +426,8 @@ class JpaTransactionManagerImplTest {
@Test
void loadAll_succeeds() {
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
ImmutableList<TestEntity> persisted = jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class));
ImmutableList<TestEntity> persisted =
jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class));
assertThat(persisted).containsExactlyElementsIn(moreEntities);
}

View file

@ -133,7 +133,7 @@ public class TransactionManagerTest {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
TestEntity persisted = tm().transactNewReadOnly(() -> tm().loadByKey(theEntity.key()));
assertThat(persisted).isEqualTo(theEntity);
}
@ -150,7 +150,7 @@ public class TransactionManagerTest {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
}
@TestOfyAndSql
@ -165,18 +165,18 @@ public class TransactionManagerTest {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().put(theEntity));
assertEntityExists(theEntity);
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
}
@TestOfyAndSql
void saveNewOrUpdate_updatesExistingEntity() {
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
fakeClock.advanceOneMilli();
tm().transact(() -> tm().put(theEntity));
persisted = tm().transact(() -> tm().load(theEntity.key()));
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
assertThat(persisted.data).isEqualTo("bar");
}
@ -193,13 +193,13 @@ public class TransactionManagerTest {
TestEntity persisted =
tm().transact(
() ->
tm().load(
tm().loadByKey(
VKey.create(TestEntity.class, theEntity.name, Key.create(theEntity))));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
fakeClock.advanceOneMilli();
tm().transact(() -> tm().update(theEntity));
persisted = tm().transact(() -> tm().load(theEntity.key()));
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
assertThat(persisted.data).isEqualTo("bar");
}
@ -207,7 +207,7 @@ public class TransactionManagerTest {
void load_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@ -216,14 +216,14 @@ public class TransactionManagerTest {
void load_throwsOnMissingElement() {
assertEntityNotExist(theEntity);
assertThrows(
NoSuchElementException.class, () -> tm().transact(() -> tm().load(theEntity.key())));
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKey(theEntity.key())));
}
@TestOfyAndSql
void maybeLoad_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().maybeLoad(theEntity.key()).get());
TestEntity persisted = tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key()).get());
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
}
@ -231,7 +231,7 @@ public class TransactionManagerTest {
@TestOfyAndSql
void maybeLoad_nonExistentObject() {
assertEntityNotExist(theEntity);
assertThat(tm().transact(() -> tm().maybeLoad(theEntity.key())).isPresent()).isFalse();
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key())).isPresent()).isFalse();
}
@TestOfyAndSql
@ -292,7 +292,7 @@ public class TransactionManagerTest {
tm().transact(() -> tm().insertAll(moreEntities));
List<VKey<TestEntity>> keys =
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
assertThat(tm().transact(() -> tm().load(keys)))
assertThat(tm().transact(() -> tm().loadByKeys(keys)))
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
}
@ -304,7 +304,7 @@ public class TransactionManagerTest {
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
ImmutableList<VKey<TestEntity>> doubleKeys =
Stream.concat(keys.stream(), keys.stream()).collect(toImmutableList());
assertThat(tm().transact(() -> tm().load(doubleKeys)))
assertThat(tm().transact(() -> tm().loadByKeys(doubleKeys)))
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
}
@ -316,16 +316,66 @@ public class TransactionManagerTest {
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
.map(TestEntity::key)
.collect(toImmutableList());
assertThat(tm().transact(() -> tm().load(keys)))
assertThat(
assertThrows(
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKeys(keys))))
.hasMessageThat()
.contains("dark");
}
@TestOfyAndSql
void loadExisting_missingKeys() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().insertAll(moreEntities));
List<VKey<TestEntity>> keys =
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
.map(TestEntity::key)
.collect(toImmutableList());
assertThat(tm().transact(() -> tm().loadByKeysIfPresent(keys)))
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
}
@TestOfyAndSql
void loadAll_success() {
tm().transact(() -> tm().insertAll(moreEntities));
assertThat(tm().transact(() -> tm().loadByEntities(moreEntities)))
.containsExactlyElementsIn(moreEntities);
}
@TestOfyAndSql
void loadAll_missingKeys() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().insertAll(moreEntities));
ImmutableList<TestEntity> nonexistent = ImmutableList.of(new TestEntity("dark", "matter"));
assertThat(
assertThrows(
NoSuchElementException.class,
() -> tm().transact(() -> tm().loadByEntities(nonexistent))))
.hasMessageThat()
.contains("dark");
}
@TestOfyAndSql
void loadAllExisting_missingKeys() {
tm().transact(() -> tm().insertAll(moreEntities));
tm().transact(() -> tm().delete(new TestEntity("entity1", "foo")));
assertThat(
tm().transact(
() ->
tm().loadByEntitiesIfPresent(moreEntities).stream()
.map(TestEntity::key)
.map(VKey::getSqlKey)
.collect(toImmutableList())))
.containsExactly("entity2", "entity3");
}
@TestOfyOnly
void loadAllForOfyTm_throwsExceptionInTransaction() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().insertAll(moreEntities));
assertThrows(
IllegalArgumentException.class, () -> tm().transact(() -> tm().loadAll(TestEntity.class)));
IllegalArgumentException.class,
() -> tm().transact(() -> tm().loadAllOf(TestEntity.class)));
}
private static void assertEntityExists(TestEntity entity) {

View file

@ -60,8 +60,8 @@ class TransactionTest {
ofyTm()
.transact(
() -> {
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().load(barEntity.key())).isEqualTo(barEntity);
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().loadByKey(barEntity.key())).isEqualTo(barEntity);
});
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
@ -82,7 +82,7 @@ class TransactionTest {
ofyTm()
.transact(
() -> {
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
});
}
@ -111,14 +111,14 @@ class TransactionTest {
jpaTm().insert(barEntity);
});
TransactionEntity txnEnt =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TransactionEntity.class, 1L)));
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TransactionEntity.class, 1L)));
Transaction txn = Transaction.deserialize(txnEnt.contents);
txn.writeToDatastore();
ofyTm()
.transact(
() -> {
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().load(barEntity.key())).isEqualTo(barEntity);
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().loadByKey(barEntity.key())).isEqualTo(barEntity);
});
// Verify that no transaction was persisted for the load transaction.

View file

@ -67,7 +67,7 @@ class RegistrarContactTest {
void testPersistence_succeeds() {
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc));
RegistrarContact persisted =
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
jpaTm().transact(() -> jpaTm().loadByKey(testRegistrarPoc.createVKey()));
assertThat(persisted).isEqualTo(testRegistrarPoc);
}
}

View file

@ -78,7 +78,7 @@ public class RegistrarDaoTest {
@Test
void update_worksSuccessfully() {
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
jpaTm()
.transact(
@ -86,7 +86,7 @@ public class RegistrarDaoTest {
jpaTm()
.update(
persisted.asBuilder().setRegistrarName("changedRegistrarName").build()));
Registrar updated = jpaTm().transact(() -> jpaTm().load(registrarKey));
Registrar updated = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
assertThat(updated.getRegistrarName()).isEqualTo("changedRegistrarName");
}
@ -102,7 +102,7 @@ public class RegistrarDaoTest {
void load_worksSuccessfully() {
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
assertThat(persisted.getClientId()).isEqualTo("registrarId");
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");

View file

@ -413,7 +413,7 @@ public class DatabaseHelper {
// PremiumListUtils.savePremiumListAndEntries(). Clearing the session cache can help make sure
// we always get the same list.
tm().clearSessionCache();
return transactIfJpaTm(() -> tm().load(premiumList));
return transactIfJpaTm(() -> tm().loadByEntity(premiumList));
}
/** Creates and persists a tld. */
@ -673,13 +673,13 @@ public class DatabaseHelper {
.build());
// Modify the existing autorenew event to reflect the pending transfer.
persistResource(
tm().load(domain.getAutorenewBillingEvent())
tm().loadByKey(domain.getAutorenewBillingEvent())
.asBuilder()
.setRecurrenceEndTime(expirationTime)
.build());
// Update the end time of the existing autorenew poll message. We must delete it if it has no
// events left in it.
PollMessage.Autorenew autorenewPollMessage = tm().load(domain.getAutorenewPollMessage());
PollMessage.Autorenew autorenewPollMessage = tm().loadByKey(domain.getAutorenewPollMessage());
if (autorenewPollMessage.getEventTime().isBefore(expirationTime)) {
persistResource(
autorenewPollMessage.asBuilder()
@ -768,22 +768,22 @@ public class DatabaseHelper {
return transactIfJpaTm(
() ->
Iterables.concat(
tm().loadAll(BillingEvent.OneTime.class),
tm().loadAll(BillingEvent.Recurring.class),
tm().loadAll(BillingEvent.Cancellation.class)));
tm().loadAllOf(BillingEvent.OneTime.class),
tm().loadAllOf(BillingEvent.Recurring.class),
tm().loadAllOf(BillingEvent.Cancellation.class)));
}
private static Iterable<BillingEvent> getBillingEvents(EppResource resource) {
return transactIfJpaTm(
() ->
Iterables.concat(
tm().loadAll(BillingEvent.OneTime.class).stream()
tm().loadAllOf(BillingEvent.OneTime.class).stream()
.filter(oneTime -> oneTime.getDomainRepoId().equals(resource.getRepoId()))
.collect(toImmutableList()),
tm().loadAll(BillingEvent.Recurring.class).stream()
tm().loadAllOf(BillingEvent.Recurring.class).stream()
.filter(recurring -> recurring.getDomainRepoId().equals(resource.getRepoId()))
.collect(toImmutableList()),
tm().loadAll(BillingEvent.Cancellation.class).stream()
tm().loadAllOf(BillingEvent.Cancellation.class).stream()
.filter(
cancellation -> cancellation.getDomainRepoId().equals(resource.getRepoId()))
.collect(toImmutableList())));
@ -860,13 +860,13 @@ public class DatabaseHelper {
}
public static ImmutableList<PollMessage> getPollMessages() {
return ImmutableList.copyOf(transactIfJpaTm(() -> tm().loadAll(PollMessage.class)));
return ImmutableList.copyOf(transactIfJpaTm(() -> tm().loadAllOf(PollMessage.class)));
}
public static ImmutableList<PollMessage> getPollMessages(String clientId) {
return transactIfJpaTm(
() ->
tm().loadAll(PollMessage.class).stream()
tm().loadAllOf(PollMessage.class).stream()
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
.collect(toImmutableList()));
}
@ -874,7 +874,7 @@ public class DatabaseHelper {
public static ImmutableList<PollMessage> getPollMessages(DomainContent domain) {
return transactIfJpaTm(
() ->
tm().loadAll(PollMessage.class).stream()
tm().loadAllOf(PollMessage.class).stream()
.filter(
pollMessage ->
pollMessage.getParentKey().getParent().getName().equals(domain.getRepoId()))
@ -884,7 +884,7 @@ public class DatabaseHelper {
public static ImmutableList<PollMessage> getPollMessages(String clientId, DateTime now) {
return transactIfJpaTm(
() ->
tm().loadAll(PollMessage.class).stream()
tm().loadAllOf(PollMessage.class).stream()
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
.filter(
pollMessage ->
@ -898,7 +898,7 @@ public class DatabaseHelper {
EppResource resource, String clientId, DateTime now) {
return transactIfJpaTm(
() ->
tm().loadAll(PollMessage.class).stream()
tm().loadAllOf(PollMessage.class).stream()
.filter(
pollMessage ->
pollMessage
@ -942,7 +942,7 @@ public class DatabaseHelper {
}
public static void assertAllocationTokens(AllocationToken... expectedTokens) {
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class)))
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class)))
.comparingElementsUsing(immutableObjectCorrespondence("updateTimestamp", "creationTime"))
.containsExactlyElementsIn(expectedTokens);
}
@ -1018,7 +1018,7 @@ public class DatabaseHelper {
// (unmarshalling entity protos to POJOs, nulling out empty collections, calling @OnLoad
// methods, etc.) which is bypassed for entities loaded from the session cache.
tm().clearSessionCache();
return transactIfJpaTm(() -> tm().load(resource));
return transactIfJpaTm(() -> tm().loadByEntity(resource));
}
/** Persists an EPP resource with the {@link EppResourceIndex} always going into bucket one. */
@ -1037,7 +1037,7 @@ public class DatabaseHelper {
});
maybeAdvanceClock();
tm().clearSessionCache();
return transactIfJpaTm(() -> tm().load(resource));
return transactIfJpaTm(() -> tm().loadByEntity(resource));
}
public static <R> void persistResources(final Iterable<R> resources) {
@ -1059,7 +1059,7 @@ public class DatabaseHelper {
// and not from the transaction's session cache.
tm().clearSessionCache();
for (R resource : resources) {
transactIfJpaTm(() -> tm().load(resource));
transactIfJpaTm(() -> tm().loadByEntity(resource));
}
}
@ -1090,7 +1090,7 @@ public class DatabaseHelper {
});
maybeAdvanceClock();
tm().clearSessionCache();
return transactIfJpaTm(() -> tm().load(resource));
return transactIfJpaTm(() -> tm().loadByEntity(resource));
}
/** Returns all of the history entries that are parented off the given EppResource. */
@ -1101,11 +1101,11 @@ public class DatabaseHelper {
() -> {
ImmutableList<? extends HistoryEntry> unsorted = null;
if (resource instanceof ContactBase) {
unsorted = tm().loadAll(ContactHistory.class);
unsorted = tm().loadAllOf(ContactHistory.class);
} else if (resource instanceof HostBase) {
unsorted = tm().loadAll(HostHistory.class);
unsorted = tm().loadAllOf(HostHistory.class);
} else if (resource instanceof DomainContent) {
unsorted = tm().loadAll(DomainHistory.class);
unsorted = tm().loadAllOf(DomainHistory.class);
} else {
fail("Expected an EppResource instance, but got " + resource.getClass());
}
@ -1161,7 +1161,7 @@ public class DatabaseHelper {
return Iterables.getOnlyElement(
transactIfJpaTm(
() ->
tm().loadAll(PollMessage.class).stream()
tm().loadAllOf(PollMessage.class).stream()
.filter(
pollMessage -> pollMessage.getParentKey().equals(Key.create(historyEntry)))
.collect(toImmutableList())));
@ -1194,7 +1194,7 @@ public class DatabaseHelper {
// Force the session to be cleared so that when we read it back, we read from Datastore
// and not from the transaction's session cache.
tm().clearSessionCache();
return transactIfJpaTm(() -> tm().loadAll(resources));
return transactIfJpaTm(() -> tm().loadByEntities(resources));
}
public static void deleteResource(final Object resource) {
@ -1219,7 +1219,7 @@ public class DatabaseHelper {
// otherwise JPA would just return the input entity instead of actually creating a
// clone.
tm().transact(() -> tm().put(resource));
result = tm().transact(() -> tm().load(resource));
result = tm().transact(() -> tm().loadByEntity(resource));
}
maybeAdvanceClock();
return result;

View file

@ -63,7 +63,7 @@ public class SqlHelper {
public static Registrar saveRegistrar(String clientId) {
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
jpaTm().transact(() -> jpaTm().insert(registrar));
return jpaTm().transact(() -> jpaTm().load(registrar.createVKey()));
return jpaTm().transact(() -> jpaTm().loadByKey(registrar.createVKey()));
}
public static void assertThrowForeignKeyViolation(Executable executable) {

View file

@ -60,7 +60,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
VKey<OneTime> pm4 = futurePollMessage.createVKey();
runCommand("-c", "TheRegistrar");
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3, pm4)).values())
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3, pm4)).values())
.containsExactly(futurePollMessage);
assertInStdout(
"1-FSDGS-TLD-2406-624-2013,2013-05-01T22:33:44.000Z,ninelives",
@ -90,7 +90,8 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
autorenew.asBuilder().setEventTime(DateTime.parse("2012-04-15T22:33:44Z")).build();
VKey<Autorenew> pm3 = autorenew.createVKey();
runCommand("-c", "TheRegistrar");
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3)).values()).containsExactly(resaved);
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3)).values())
.containsExactly(resaved);
assertInStdout(
"1-AAFSGS-TLD-99406-624-2011,2011-04-15T22:33:44.000Z,autorenew",
"1-FSDGS-TLD-2406-624-2013,2013-05-01T22:33:44.000Z,ninelives",
@ -117,7 +118,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
.build());
VKey<Autorenew> pm3 = autorenew.createVKey();
runCommand("-c", "TheRegistrar");
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3))).isEmpty();
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3))).isEmpty();
assertInStdout(
"1-AAFSGS-TLD-99406-624-2011,2011-04-15T22:33:44.000Z,autorenew",
"1-FSDGS-TLD-2406-624-2013,2013-05-01T22:33:44.000Z,ninelives",
@ -138,7 +139,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "time flies");
VKey<OneTime> pm4 = notMatched2.createVKey();
runCommand("-c", "TheRegistrar", "-m", "food");
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3, pm4)).values())
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3, pm4)).values())
.containsExactly(notMatched1, notMatched2);
}
@ -163,7 +164,8 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
.build());
VKey<OneTime> pm3 = notMatched.createVKey();
runCommand("-c", "TheRegistrar");
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3)).values()).containsExactly(notMatched);
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3)).values())
.containsExactly(notMatched);
}
@Test
@ -174,7 +176,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
OneTime pm4 = persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
runCommand("-c", "TheRegistrar", "-d");
assertThat(
tm().load(
tm().loadByKeys(
ImmutableList.of(pm1, pm2, pm3, pm4).stream()
.map(OneTime::createVKey)
.collect(toImmutableList()))

View file

@ -186,12 +186,12 @@ public abstract class CommandTestCase<C extends Command> {
/** Reloads the given resource from Datastore. */
<T> T reloadResource(T resource) {
return transactIfJpaTm(() -> tm().load(resource));
return transactIfJpaTm(() -> tm().loadByEntity(resource));
}
/** Returns count of all poll messages in Datastore. */
int getPollMessageCount() {
return transactIfJpaTm(() -> tm().loadAll(PollMessage.class).size());
return transactIfJpaTm(() -> tm().loadAllOf(PollMessage.class).size());
}
/**

View file

@ -134,9 +134,9 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
for (int i = 0; i < 50; i++) {
persistToken(String.format("batch%2d", i), null, i % 2 == 0);
}
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size())).isEqualTo(56);
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size())).isEqualTo(56);
runCommandForced("--prefix", "batch");
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size()))
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size()))
.isEqualTo(56 - 25);
}
@ -184,7 +184,7 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
}
private static ImmutableList<AllocationToken> reloadTokens(AllocationToken... tokens) {
return transactIfJpaTm(() -> tm().loadAll(ImmutableSet.copyOf(tokens)));
return transactIfJpaTm(() -> tm().loadByEntities(ImmutableSet.copyOf(tokens)));
}
private static void assertNonexistent(AllocationToken... tokens) {

View file

@ -134,7 +134,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
runCommand("--prefix", "ooo", "--number", "100", "--length", "16");
// The deterministic string generator makes it too much hassle to assert about each token, so
// just assert total number.
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size())).isEqualTo(100);
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size())).isEqualTo(100);
}
@TestOfyAndSql
@ -199,7 +199,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
Collection<String> sampleTokens = command.stringGenerator.createStrings(13, 100);
runCommand("--tokens", Joiner.on(",").join(sampleTokens));
assertInStdout(Iterables.toArray(sampleTokens, String.class));
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size())).isEqualTo(100);
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size())).isEqualTo(100);
}
@TestOfyAndSql

View file

@ -120,7 +120,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC);
assertBillingEventsEqual(
tm().load(domain.getAutorenewBillingEvent()),
tm().loadByKey(domain.getAutorenewBillingEvent()),
new BillingEvent.Recurring.Builder()
.setParent(synthetic)
.setReason(Reason.RENEW)

View file

@ -68,7 +68,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
assertThat(
jpaTm()
.transact(() -> jpaTm().load(VKey.createSql(Registrar.class, "NewRegistrar")))
.transact(() -> jpaTm().loadByKey(VKey.createSql(Registrar.class, "NewRegistrar")))
.verifyPassword("some_password"))
.isTrue();
}

View file

@ -91,7 +91,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
.transact(
() -> {
ImmutableList<Spec11ThreatMatch> threatMatches =
jpaTm().loadAll(Spec11ThreatMatch.class);
jpaTm().loadAllOf(Spec11ThreatMatch.class);
assertThat(threatMatches).hasSize(6);
assertThat(
threatMatches.stream()
@ -151,7 +151,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
jpaTm()
.transact(
() ->
jpaTm().loadAll(Spec11ThreatMatch.class).stream()
jpaTm().loadAllOf(Spec11ThreatMatch.class).stream()
.filter((match) -> match.getDomainName().equals("a.com"))
.findFirst()
.get()
@ -177,7 +177,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
runCommandForced();
ImmutableList<Spec11ThreatMatch> threatMatches =
jpaTm().transact(() -> jpaTm().loadAll(Spec11ThreatMatch.class));
jpaTm().transact(() -> jpaTm().loadAllOf(Spec11ThreatMatch.class));
assertAboutImmutableObjects()
.that(Iterables.getOnlyElement(threatMatches))
.isEqualExceptFields(previous, "id");
@ -212,7 +212,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
assertThrows(RuntimeException.class, this::runCommandForced);
assertThat(runtimeException.getCause().getClass()).isEqualTo(IOException.class);
assertThat(runtimeException).hasCauseThat().hasMessageThat().isEqualTo("hi");
jpaTm().transact(() -> assertThat(jpaTm().loadAll(Spec11ThreatMatch.class)).isEmpty());
jpaTm().transact(() -> assertThat(jpaTm().loadAllOf(Spec11ThreatMatch.class)).isEmpty());
}
@Test
@ -249,7 +249,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
.transact(
() -> {
ImmutableList<Spec11ThreatMatch> threatMatches =
jpaTm().loadAll(Spec11ThreatMatch.class);
jpaTm().loadAllOf(Spec11ThreatMatch.class);
assertThat(threatMatches)
.comparingElementsUsing(immutableObjectCorrespondence("id", "domainRepoId"))
.containsExactly(