mirror of
https://github.com/google/nomulus.git
synced 2025-07-06 11:13:35 +02:00
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:
parent
b4676a9836
commit
5bf618e671
80 changed files with 504 additions and 346 deletions
|
@ -345,7 +345,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
|
||||||
String resourceClientId = resource.getPersistedCurrentSponsorClientId();
|
String resourceClientId = resource.getPersistedCurrentSponsorClientId();
|
||||||
if (resource instanceof HostResource && ((HostResource) resource).isSubordinate()) {
|
if (resource instanceof HostResource && ((HostResource) resource).isSubordinate()) {
|
||||||
resourceClientId =
|
resourceClientId =
|
||||||
tm().load(((HostResource) resource).getSuperordinateDomain())
|
tm().loadByKey(((HostResource) resource).getSuperordinateDomain())
|
||||||
.cloneProjectedAtTime(now)
|
.cloneProjectedAtTime(now)
|
||||||
.getCurrentSponsorClientId();
|
.getCurrentSponsorClientId();
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
|
||||||
if (host.isSubordinate()) {
|
if (host.isSubordinate()) {
|
||||||
dnsQueue.addHostRefreshTask(host.getHostName());
|
dnsQueue.addHostRefreshTask(host.getHostName());
|
||||||
tm().put(
|
tm().put(
|
||||||
tm().load(host.getSuperordinateDomain())
|
tm().loadByKey(host.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(host.getHostName())
|
.removeSubordinateHost(host.getHostName())
|
||||||
.build());
|
.build());
|
||||||
|
|
|
@ -139,7 +139,7 @@ public final class ResourceFlowUtils {
|
||||||
Class<R> clazz, String targetId, DateTime now, String clientId) throws EppException {
|
Class<R> clazz, String targetId, DateTime now, String clientId) throws EppException {
|
||||||
VKey<R> key = loadAndGetKey(clazz, targetId, now);
|
VKey<R> key = loadAndGetKey(clazz, targetId, now);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
R resource = tm().load(key);
|
R resource = tm().loadByKey(key);
|
||||||
// These are similar exceptions, but we can track them internally as log-based metrics.
|
// These are similar exceptions, but we can track them internally as log-based metrics.
|
||||||
if (Objects.equals(clientId, resource.getPersistedCurrentSponsorClientId())) {
|
if (Objects.equals(clientId, resource.getPersistedCurrentSponsorClientId())) {
|
||||||
throw new ResourceAlreadyExistsForThisClientException(targetId);
|
throw new ResourceAlreadyExistsForThisClientException(targetId);
|
||||||
|
|
|
@ -225,7 +225,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
||||||
if (gracePeriod.getOneTimeBillingEvent() != null) {
|
if (gracePeriod.getOneTimeBillingEvent() != null) {
|
||||||
// Take the amount of amount of registration time being refunded off the expiration time.
|
// Take the amount of amount of registration time being refunded off the expiration time.
|
||||||
// This can be either add grace periods or renew grace periods.
|
// This can be either add grace periods or renew grace periods.
|
||||||
BillingEvent.OneTime oneTime = tm().load(gracePeriod.getOneTimeBillingEvent());
|
BillingEvent.OneTime oneTime = tm().loadByKey(gracePeriod.getOneTimeBillingEvent());
|
||||||
newExpirationTime = newExpirationTime.minusYears(oneTime.getPeriodYears());
|
newExpirationTime = newExpirationTime.minusYears(oneTime.getPeriodYears());
|
||||||
} else if (gracePeriod.getRecurringBillingEvent() != null) {
|
} else if (gracePeriod.getRecurringBillingEvent() != null) {
|
||||||
// Take 1 year off the registration if in the autorenew grace period (no need to load the
|
// Take 1 year off the registration if in the autorenew grace period (no need to load the
|
||||||
|
@ -372,12 +372,12 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
||||||
private Money getGracePeriodCost(GracePeriod gracePeriod, DateTime now) {
|
private Money getGracePeriodCost(GracePeriod gracePeriod, DateTime now) {
|
||||||
if (gracePeriod.getType() == GracePeriodStatus.AUTO_RENEW) {
|
if (gracePeriod.getType() == GracePeriodStatus.AUTO_RENEW) {
|
||||||
DateTime autoRenewTime =
|
DateTime autoRenewTime =
|
||||||
tm().load(checkNotNull(gracePeriod.getRecurringBillingEvent()))
|
tm().loadByKey(checkNotNull(gracePeriod.getRecurringBillingEvent()))
|
||||||
.getRecurrenceTimeOfYear()
|
.getRecurrenceTimeOfYear()
|
||||||
.getLastInstanceBeforeOrAt(now);
|
.getLastInstanceBeforeOrAt(now);
|
||||||
return getDomainRenewCost(targetId, autoRenewTime, 1);
|
return getDomainRenewCost(targetId, autoRenewTime, 1);
|
||||||
}
|
}
|
||||||
return tm().load(checkNotNull(gracePeriod.getOneTimeBillingEvent())).getCost();
|
return tm().loadByKey(checkNotNull(gracePeriod.getOneTimeBillingEvent())).getCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -517,7 +517,7 @@ public class DomainFlowUtils {
|
||||||
*/
|
*/
|
||||||
public static void updateAutorenewRecurrenceEndTime(DomainBase domain, DateTime newEndTime) {
|
public static void updateAutorenewRecurrenceEndTime(DomainBase domain, DateTime newEndTime) {
|
||||||
Optional<PollMessage.Autorenew> autorenewPollMessage =
|
Optional<PollMessage.Autorenew> autorenewPollMessage =
|
||||||
tm().maybeLoad(domain.getAutorenewPollMessage());
|
tm().loadByKeyIfPresent(domain.getAutorenewPollMessage());
|
||||||
|
|
||||||
// Construct an updated autorenew poll message. If the autorenew poll message no longer exists,
|
// Construct an updated autorenew poll message. If the autorenew poll message no longer exists,
|
||||||
// create a new one at the same id. This can happen if a transfer was requested on a domain
|
// create a new one at the same id. This can happen if a transfer was requested on a domain
|
||||||
|
@ -542,7 +542,7 @@ public class DomainFlowUtils {
|
||||||
ofy().save().entity(updatedAutorenewPollMessage);
|
ofy().save().entity(updatedAutorenewPollMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Recurring recurring = tm().load(domain.getAutorenewBillingEvent());
|
Recurring recurring = tm().loadByKey(domain.getAutorenewBillingEvent());
|
||||||
ofy().save().entity(recurring.asBuilder().setRecurrenceEndTime(newEndTime).build());
|
ofy().save().entity(recurring.asBuilder().setRecurrenceEndTime(newEndTime).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ public class DomainFlowUtils {
|
||||||
for (DesignatedContact contact : contacts) {
|
for (DesignatedContact contact : contacts) {
|
||||||
builder.add(
|
builder.add(
|
||||||
ForeignKeyedDesignatedContact.create(
|
ForeignKeyedDesignatedContact.create(
|
||||||
contact.getType(), tm().load(contact.getContactKey()).getContactId()));
|
contact.getType(), tm().loadByKey(contact.getContactKey()).getContactId()));
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,8 @@ public final class DomainInfoFlow implements Flow {
|
||||||
flowCustomLogic.afterValidation(
|
flowCustomLogic.afterValidation(
|
||||||
AfterValidationParameters.newBuilder().setDomain(domain).build());
|
AfterValidationParameters.newBuilder().setDomain(domain).build());
|
||||||
// Prefetch all referenced resources. Calling values() blocks until loading is done.
|
// Prefetch all referenced resources. Calling values() blocks until loading is done.
|
||||||
tm().load(domain.getNameservers());
|
tm().loadByKeys(domain.getNameservers());
|
||||||
tm().load(domain.getReferencedContacts());
|
tm().loadByKeys(domain.getReferencedContacts());
|
||||||
// Registrars can only see a few fields on unauthorized domains.
|
// Registrars can only see a few fields on unauthorized domains.
|
||||||
// This is a policy decision that is left up to us by the rfcs.
|
// This is a policy decision that is left up to us by the rfcs.
|
||||||
DomainInfoData.Builder infoBuilder =
|
DomainInfoData.Builder infoBuilder =
|
||||||
|
@ -110,7 +110,7 @@ public final class DomainInfoFlow implements Flow {
|
||||||
.setFullyQualifiedDomainName(domain.getDomainName())
|
.setFullyQualifiedDomainName(domain.getDomainName())
|
||||||
.setRepoId(domain.getRepoId())
|
.setRepoId(domain.getRepoId())
|
||||||
.setCurrentSponsorClientId(domain.getCurrentSponsorClientId())
|
.setCurrentSponsorClientId(domain.getCurrentSponsorClientId())
|
||||||
.setRegistrant(tm().load(domain.getRegistrant()).getContactId());
|
.setRegistrant(tm().loadByKey(domain.getRegistrant()).getContactId());
|
||||||
// If authInfo is non-null, then the caller is authorized to see the full information since we
|
// If authInfo is non-null, then the caller is authorized to see the full information since we
|
||||||
// will have already verified the authInfo is valid.
|
// will have already verified the authInfo is valid.
|
||||||
if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) {
|
if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) {
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class AllocationTokenFlowUtils {
|
||||||
throw new InvalidAllocationTokenException();
|
throw new InvalidAllocationTokenException();
|
||||||
}
|
}
|
||||||
Optional<AllocationToken> maybeTokenEntity =
|
Optional<AllocationToken> maybeTokenEntity =
|
||||||
tm().maybeLoad(VKey.create(AllocationToken.class, token));
|
tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token));
|
||||||
if (maybeTokenEntity.isEmpty()) {
|
if (maybeTokenEntity.isEmpty()) {
|
||||||
throw new InvalidAllocationTokenException();
|
throw new InvalidAllocationTokenException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public final class HostDeleteFlow implements TransactionalFlow {
|
||||||
// the client id, needs to be read off of it.
|
// the client id, needs to be read off of it.
|
||||||
EppResource owningResource =
|
EppResource owningResource =
|
||||||
existingHost.isSubordinate()
|
existingHost.isSubordinate()
|
||||||
? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
|
? tm().loadByKey(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
|
||||||
: existingHost;
|
: existingHost;
|
||||||
verifyResourceOwnership(clientId, owningResource);
|
verifyResourceOwnership(clientId, owningResource);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public final class HostInfoFlow implements Flow {
|
||||||
// there is no superordinate domain, the host's own values for these fields will be correct.
|
// there is no superordinate domain, the host's own values for these fields will be correct.
|
||||||
if (host.isSubordinate()) {
|
if (host.isSubordinate()) {
|
||||||
DomainBase superordinateDomain =
|
DomainBase superordinateDomain =
|
||||||
tm().load(host.getSuperordinateDomain()).cloneProjectedAtTime(now);
|
tm().loadByKey(host.getSuperordinateDomain()).cloneProjectedAtTime(now);
|
||||||
hostInfoDataBuilder
|
hostInfoDataBuilder
|
||||||
.setCurrentSponsorClientId(superordinateDomain.getCurrentSponsorClientId())
|
.setCurrentSponsorClientId(superordinateDomain.getCurrentSponsorClientId())
|
||||||
.setLastTransferTime(host.computeLastTransferTime(superordinateDomain));
|
.setLastTransferTime(host.computeLastTransferTime(superordinateDomain));
|
||||||
|
|
|
@ -139,7 +139,7 @@ public final class HostUpdateFlow implements TransactionalFlow {
|
||||||
String newHostName = firstNonNull(suppliedNewHostName, oldHostName);
|
String newHostName = firstNonNull(suppliedNewHostName, oldHostName);
|
||||||
DomainBase oldSuperordinateDomain =
|
DomainBase oldSuperordinateDomain =
|
||||||
existingHost.isSubordinate()
|
existingHost.isSubordinate()
|
||||||
? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
|
? tm().loadByKey(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now)
|
||||||
: null;
|
: null;
|
||||||
// Note that lookupSuperordinateDomain calls cloneProjectedAtTime on the domain for us.
|
// Note that lookupSuperordinateDomain calls cloneProjectedAtTime on the domain for us.
|
||||||
Optional<DomainBase> newSuperordinateDomain =
|
Optional<DomainBase> newSuperordinateDomain =
|
||||||
|
@ -286,7 +286,7 @@ public final class HostUpdateFlow implements TransactionalFlow {
|
||||||
&& Objects.equals(
|
&& Objects.equals(
|
||||||
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
|
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
|
||||||
tm().put(
|
tm().put(
|
||||||
tm().load(existingHost.getSuperordinateDomain())
|
tm().loadByKey(existingHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(existingHost.getHostName())
|
.removeSubordinateHost(existingHost.getHostName())
|
||||||
.addSubordinateHost(newHost.getHostName())
|
.addSubordinateHost(newHost.getHostName())
|
||||||
|
@ -295,14 +295,14 @@ public final class HostUpdateFlow implements TransactionalFlow {
|
||||||
}
|
}
|
||||||
if (existingHost.isSubordinate()) {
|
if (existingHost.isSubordinate()) {
|
||||||
tm().put(
|
tm().put(
|
||||||
tm().load(existingHost.getSuperordinateDomain())
|
tm().loadByKey(existingHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(existingHost.getHostName())
|
.removeSubordinateHost(existingHost.getHostName())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (newHost.isSubordinate()) {
|
if (newHost.isSubordinate()) {
|
||||||
tm().put(
|
tm().put(
|
||||||
tm().load(newHost.getSuperordinateDomain())
|
tm().loadByKey(newHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.addSubordinateHost(newHost.getHostName())
|
.addSubordinateHost(newHost.getHostName())
|
||||||
.build());
|
.build());
|
||||||
|
|
|
@ -360,13 +360,13 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EppResource load(VKey<? extends EppResource> key) {
|
public EppResource load(VKey<? extends EppResource> key) {
|
||||||
return tm().doTransactionless(() -> tm().load(key));
|
return tm().doTransactionless(() -> tm().loadByKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<VKey<? extends EppResource>, EppResource> loadAll(
|
public Map<VKey<? extends EppResource>, EppResource> loadAll(
|
||||||
Iterable<? extends VKey<? extends EppResource>> keys) {
|
Iterable<? extends VKey<? extends EppResource>> keys) {
|
||||||
return tm().doTransactionless(() -> tm().load(keys));
|
return tm().doTransactionless(() -> tm().loadByKeys(keys));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
||||||
public static ImmutableMap<VKey<? extends EppResource>, EppResource> loadCached(
|
public static ImmutableMap<VKey<? extends EppResource>, EppResource> loadCached(
|
||||||
Iterable<VKey<? extends EppResource>> keys) {
|
Iterable<VKey<? extends EppResource>> keys) {
|
||||||
if (!RegistryConfig.isEppResourceCachingEnabled()) {
|
if (!RegistryConfig.isEppResourceCachingEnabled()) {
|
||||||
return tm().load(keys);
|
return tm().loadByKeys(keys);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return cacheEppResources.getAll(keys);
|
return cacheEppResources.getAll(keys);
|
||||||
|
@ -423,7 +423,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
||||||
*/
|
*/
|
||||||
public static <T extends EppResource> T loadCached(VKey<T> key) {
|
public static <T extends EppResource> T loadCached(VKey<T> key) {
|
||||||
if (!RegistryConfig.isEppResourceCachingEnabled()) {
|
if (!RegistryConfig.isEppResourceCachingEnabled()) {
|
||||||
return tm().load(key);
|
return tm().loadByKey(key);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Safe to cast because loading a Key<T> returns an entity of type T.
|
// Safe to cast because loading a Key<T> returns an entity of type T.
|
||||||
|
|
|
@ -144,7 +144,7 @@ public final class EppResourceUtils {
|
||||||
T resource =
|
T resource =
|
||||||
useCache
|
useCache
|
||||||
? EppResource.loadCached(fki.getResourceKey())
|
? EppResource.loadCached(fki.getResourceKey())
|
||||||
: transactIfJpaTm(() -> tm().maybeLoad(fki.getResourceKey()).orElse(null));
|
: transactIfJpaTm(() -> tm().loadByKeyIfPresent(fki.getResourceKey()).orElse(null));
|
||||||
if (resource == null || isAtOrAfter(now, resource.getDeletionTime())) {
|
if (resource == null || isAtOrAfter(now, resource.getDeletionTime())) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.model.ofy;
|
||||||
|
|
||||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
import static com.google.common.collect.ImmutableMap.toImmutableMap;
|
import static com.google.common.collect.ImmutableMap.toImmutableMap;
|
||||||
|
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ import com.google.common.base.Functions;
|
||||||
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 com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Streams;
|
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;
|
||||||
|
@ -177,26 +180,13 @@ public class DatastoreTransactionManager implements TransactionManager {
|
||||||
// VKey instead of by ofy Key. But ideally, there should be one set of TransactionManager
|
// VKey instead of by ofy Key. But ideally, there should be one set of TransactionManager
|
||||||
// interface tests that are applied to both the datastore and SQL implementations.
|
// interface tests that are applied to both the datastore and SQL implementations.
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> maybeLoad(VKey<T> key) {
|
public <T> Optional<T> loadByKeyIfPresent(VKey<T> key) {
|
||||||
return Optional.ofNullable(loadNullable(key));
|
return Optional.ofNullable(loadNullable(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T load(VKey<T> key) {
|
public <T> ImmutableMap<VKey<? extends T>, T> loadByKeysIfPresent(
|
||||||
T result = loadNullable(key);
|
Iterable<? extends VKey<? extends T>> keys) {
|
||||||
if (result == null) {
|
|
||||||
throw new NoSuchElementException(key.toString());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T load(T entity) {
|
|
||||||
return ofy().load().entity(entity).now();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> ImmutableMap<VKey<? extends T>, T> load(Iterable<? extends VKey<? extends T>> keys) {
|
|
||||||
// Keep track of the Key -> VKey mapping so we can translate them back.
|
// Keep track of the Key -> VKey mapping so we can translate them back.
|
||||||
ImmutableMap<Key<T>, VKey<? extends T>> keyMap =
|
ImmutableMap<Key<T>, VKey<? extends T>> keyMap =
|
||||||
StreamSupport.stream(keys.spliterator(), false)
|
StreamSupport.stream(keys.spliterator(), false)
|
||||||
|
@ -211,13 +201,51 @@ public class DatastoreTransactionManager implements TransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ImmutableList<T> loadAll(Class<T> clazz) {
|
public <T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> entities) {
|
||||||
return ImmutableList.copyOf(getOfy().load().type(clazz));
|
return ImmutableList.copyOf(getOfy().load().entities(entities).values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ImmutableList<T> loadAll(Iterable<T> entities) {
|
public <T> T loadByKey(VKey<T> key) {
|
||||||
return ImmutableList.copyOf(getOfy().load().entities(entities).values());
|
T result = loadNullable(key);
|
||||||
|
if (result == null) {
|
||||||
|
throw new NoSuchElementException(key.toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableMap<VKey<? extends T>, T> loadByKeys(
|
||||||
|
Iterable<? extends VKey<? extends T>> keys) {
|
||||||
|
ImmutableMap<VKey<? extends T>, T> result = loadByKeysIfPresent(keys);
|
||||||
|
ImmutableSet<? extends VKey<? extends T>> missingKeys =
|
||||||
|
Streams.stream(keys).filter(k -> !result.containsKey(k)).collect(toImmutableSet());
|
||||||
|
if (!missingKeys.isEmpty()) {
|
||||||
|
// Ofy ignores nonexistent keys but the method contract specifies to throw if nonexistent
|
||||||
|
throw new NoSuchElementException(
|
||||||
|
String.format("Failed to load nonexistent entities for keys: %s", missingKeys));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T loadByEntity(T entity) {
|
||||||
|
return ofy().load().entity(entity).now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableList<T> loadByEntities(Iterable<T> entities) {
|
||||||
|
ImmutableList<T> result = loadByEntitiesIfPresent(entities);
|
||||||
|
if (result.size() != Iterables.size(entities)) {
|
||||||
|
throw new NoSuchElementException(
|
||||||
|
String.format("Attempted to load entities, some of which are missing: %s", entities));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableList<T> loadAllOf(Class<T> clazz) {
|
||||||
|
return ImmutableList.copyOf(getOfy().load().type(clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -97,7 +97,7 @@ public final class RdeRevision extends BackupGroupRoot implements NonReplicatedE
|
||||||
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
||||||
Key<RdeRevision> ofyKey = Key.create(RdeRevision.class, id);
|
Key<RdeRevision> ofyKey = Key.create(RdeRevision.class, id);
|
||||||
Optional<RdeRevision> revisionOptional =
|
Optional<RdeRevision> revisionOptional =
|
||||||
tm().maybeLoad(VKey.create(RdeRevision.class, sqlKey, ofyKey));
|
tm().loadByKeyIfPresent(VKey.create(RdeRevision.class, sqlKey, ofyKey));
|
||||||
return revisionOptional.map(rdeRevision -> rdeRevision.revision + 1).orElse(0);
|
return revisionOptional.map(rdeRevision -> rdeRevision.revision + 1).orElse(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public final class RdeRevision extends BackupGroupRoot implements NonReplicatedE
|
||||||
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
||||||
Key<RdeRevision> ofyKey = Key.create(RdeRevision.class, triplet);
|
Key<RdeRevision> ofyKey = Key.create(RdeRevision.class, triplet);
|
||||||
Optional<RdeRevision> revisionOptional =
|
Optional<RdeRevision> revisionOptional =
|
||||||
tm().maybeLoad(VKey.create(RdeRevision.class, sqlKey, ofyKey));
|
tm().loadByKeyIfPresent(VKey.create(RdeRevision.class, sqlKey, ofyKey));
|
||||||
if (revision == 0) {
|
if (revision == 0) {
|
||||||
revisionOptional.ifPresent(
|
revisionOptional.ifPresent(
|
||||||
rdeRevision -> {
|
rdeRevision -> {
|
||||||
|
|
|
@ -815,7 +815,8 @@ public class Registrar extends ImmutableObject
|
||||||
.map(Registry::createVKey)
|
.map(Registry::createVKey)
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
Set<VKey<Registry>> missingTldKeys =
|
Set<VKey<Registry>> missingTldKeys =
|
||||||
Sets.difference(newTldKeys, transactIfJpaTm(() -> tm().load(newTldKeys)).keySet());
|
Sets.difference(
|
||||||
|
newTldKeys, transactIfJpaTm(() -> tm().loadByKeysIfPresent(newTldKeys)).keySet());
|
||||||
checkArgument(missingTldKeys.isEmpty(), "Trying to set nonexisting TLDs: %s", missingTldKeys);
|
checkArgument(missingTldKeys.isEmpty(), "Trying to set nonexisting TLDs: %s", missingTldKeys);
|
||||||
getInstance().allowedTlds = ImmutableSortedSet.copyOf(allowedTlds);
|
getInstance().allowedTlds = ImmutableSortedSet.copyOf(allowedTlds);
|
||||||
return this;
|
return this;
|
||||||
|
@ -983,7 +984,7 @@ public class Registrar extends ImmutableObject
|
||||||
public static Iterable<Registrar> loadAll() {
|
public static Iterable<Registrar> loadAll() {
|
||||||
return tm().isOfy()
|
return tm().isOfy()
|
||||||
? ImmutableList.copyOf(ofy().load().type(Registrar.class).ancestor(getCrossTldKey()))
|
? ImmutableList.copyOf(ofy().load().type(Registrar.class).ancestor(getCrossTldKey()))
|
||||||
: tm().transact(() -> tm().loadAll(Registrar.class));
|
: tm().transact(() -> tm().loadAllOf(Registrar.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loads all registrar entities using an in-memory cache. */
|
/** Loads all registrar entities using an in-memory cache. */
|
||||||
|
@ -994,7 +995,7 @@ public class Registrar extends ImmutableObject
|
||||||
/** Loads and returns a registrar entity by its client id directly from Datastore. */
|
/** Loads and returns a registrar entity by its client id directly from Datastore. */
|
||||||
public static Optional<Registrar> loadByClientId(String clientId) {
|
public static Optional<Registrar> loadByClientId(String clientId) {
|
||||||
checkArgument(!Strings.isNullOrEmpty(clientId), "clientId must be specified");
|
checkArgument(!Strings.isNullOrEmpty(clientId), "clientId must be specified");
|
||||||
return transactIfJpaTm(() -> tm().maybeLoad(createVKey(clientId)));
|
return transactIfJpaTm(() -> tm().loadByKeyIfPresent(createVKey(clientId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -69,7 +69,7 @@ public final class Registries {
|
||||||
.stream()
|
.stream()
|
||||||
.map(Key::getName)
|
.map(Key::getName)
|
||||||
.collect(toImmutableSet())
|
.collect(toImmutableSet())
|
||||||
: tm().loadAll(Registry.class).stream()
|
: tm().loadAllOf(Registry.class).stream()
|
||||||
.map(Registry::getTldStr)
|
.map(Registry::getTldStr)
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
return Registry.getAll(tlds).stream()
|
return Registry.getAll(tlds).stream()
|
||||||
|
|
|
@ -267,7 +267,7 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
|
||||||
public Optional<Registry> load(final String tld) {
|
public Optional<Registry> load(final String tld) {
|
||||||
// Enter a transaction-less context briefly; we don't want to enroll every TLD in
|
// Enter a transaction-less context briefly; we don't want to enroll every TLD in
|
||||||
// a transaction that might be wrapping this call.
|
// a transaction that might be wrapping this call.
|
||||||
return tm().doTransactionless(() -> tm().maybeLoad(createVKey(tld)));
|
return tm().doTransactionless(() -> tm().loadByKeyIfPresent(createVKey(tld)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -275,7 +275,7 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
|
||||||
ImmutableMap<String, VKey<Registry>> keysMap =
|
ImmutableMap<String, VKey<Registry>> keysMap =
|
||||||
toMap(ImmutableSet.copyOf(tlds), Registry::createVKey);
|
toMap(ImmutableSet.copyOf(tlds), Registry::createVKey);
|
||||||
Map<VKey<? extends Registry>, Registry> entities =
|
Map<VKey<? extends Registry>, Registry> entities =
|
||||||
tm().doTransactionless(() -> tm().load(keysMap.values()));
|
tm().doTransactionless(() -> tm().loadByKeys(keysMap.values()));
|
||||||
return Maps.transformEntries(
|
return Maps.transformEntries(
|
||||||
keysMap, (k, v) -> Optional.ofNullable(entities.getOrDefault(v, null)));
|
keysMap, (k, v) -> Optional.ofNullable(entities.getOrDefault(v, null)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ReservedListDualWriteDao {
|
||||||
public static Optional<ReservedList> getLatestRevision(String reservedListName) {
|
public static Optional<ReservedList> getLatestRevision(String reservedListName) {
|
||||||
Optional<ReservedList> maybeDatastoreList =
|
Optional<ReservedList> maybeDatastoreList =
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.maybeLoad(
|
.loadByKeyIfPresent(
|
||||||
VKey.createOfy(
|
VKey.createOfy(
|
||||||
ReservedList.class,
|
ReservedList.class,
|
||||||
Key.create(getCrossTldKey(), ReservedList.class, reservedListName)));
|
Key.create(getCrossTldKey(), ReservedList.class, reservedListName)));
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class ServerSecret extends CrossTldSingleton implements NonReplicatedEnti
|
||||||
// transactionally create a new ServerSecret (once per app setup) if necessary.
|
// transactionally create a new ServerSecret (once per app setup) if necessary.
|
||||||
// return the ofy() result during Datastore-primary phase
|
// return the ofy() result during Datastore-primary phase
|
||||||
ServerSecret secret =
|
ServerSecret secret =
|
||||||
ofyTm().maybeLoad(key).orElseGet(() -> create(UUID.randomUUID()));
|
ofyTm().loadByKeyIfPresent(key).orElseGet(() -> create(UUID.randomUUID()));
|
||||||
// During a dual-write period, write it to both Datastore and SQL
|
// During a dual-write period, write it to both Datastore and SQL
|
||||||
// even if we didn't have to retrieve it from the DB
|
// even if we didn't have to retrieve it from the DB
|
||||||
ofyTm().transact(() -> ofyTm().putWithoutBackup(secret));
|
ofyTm().transact(() -> ofyTm().putWithoutBackup(secret));
|
||||||
|
|
|
@ -56,7 +56,7 @@ public final class TmchCrl extends CrossTldSingleton implements NonReplicatedEnt
|
||||||
VKey.create(
|
VKey.create(
|
||||||
TmchCrl.class, SINGLETON_ID, Key.create(getCrossTldKey(), TmchCrl.class, SINGLETON_ID));
|
TmchCrl.class, SINGLETON_ID, Key.create(getCrossTldKey(), TmchCrl.class, SINGLETON_ID));
|
||||||
// return the ofy() result during Datastore-primary phase
|
// return the ofy() result during Datastore-primary phase
|
||||||
return ofyTm().transact(() -> ofyTm().maybeLoad(key));
|
return ofyTm().transact(() -> ofyTm().loadByKeyIfPresent(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ import google.registry.util.Clock;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.SystemSleeper;
|
import google.registry.util.SystemSleeper;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
@ -356,33 +356,15 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> maybeLoad(VKey<T> key) {
|
public <T> Optional<T> loadByKeyIfPresent(VKey<T> key) {
|
||||||
checkArgumentNotNull(key, "key must be specified");
|
checkArgumentNotNull(key, "key must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
return Optional.ofNullable(getEntityManager().find(key.getKind(), key.getSqlKey()));
|
return Optional.ofNullable(getEntityManager().find(key.getKind(), key.getSqlKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T load(VKey<T> key) {
|
public <T> ImmutableMap<VKey<? extends T>, T> loadByKeysIfPresent(
|
||||||
checkArgumentNotNull(key, "key must be specified");
|
Iterable<? extends VKey<? extends T>> keys) {
|
||||||
assertInTransaction();
|
|
||||||
T result = getEntityManager().find(key.getKind(), key.getSqlKey());
|
|
||||||
if (result == null) {
|
|
||||||
throw new NoSuchElementException(key.toString());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T load(T entity) {
|
|
||||||
checkArgumentNotNull(entity, "entity must be specified");
|
|
||||||
assertInTransaction();
|
|
||||||
return (T)
|
|
||||||
load(VKey.createSql(entity.getClass(), emf.getPersistenceUnitUtil().getIdentifier(entity)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> ImmutableMap<VKey<? extends T>, T> load(Iterable<? extends VKey<? extends T>> keys) {
|
|
||||||
checkArgumentNotNull(keys, "keys must be specified");
|
checkArgumentNotNull(keys, "keys must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
return StreamSupport.stream(keys.spliterator(), false)
|
return StreamSupport.stream(keys.spliterator(), false)
|
||||||
|
@ -393,11 +375,58 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
new SimpleEntry<VKey<? extends T>, T>(
|
new SimpleEntry<VKey<? extends T>, T>(
|
||||||
key, getEntityManager().find(key.getKind(), key.getSqlKey())))
|
key, getEntityManager().find(key.getKind(), key.getSqlKey())))
|
||||||
.filter(entry -> entry.getValue() != null)
|
.filter(entry -> entry.getValue() != null)
|
||||||
.collect(toImmutableMap(Entry::getKey, Entry::getValue));
|
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ImmutableList<T> loadAll(Class<T> clazz) {
|
public <T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> entities) {
|
||||||
|
return Streams.stream(entities)
|
||||||
|
.filter(this::exists)
|
||||||
|
.map(this::loadByEntity)
|
||||||
|
.collect(toImmutableList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T loadByKey(VKey<T> key) {
|
||||||
|
checkArgumentNotNull(key, "key must be specified");
|
||||||
|
assertInTransaction();
|
||||||
|
T result = getEntityManager().find(key.getKind(), key.getSqlKey());
|
||||||
|
if (result == null) {
|
||||||
|
throw new NoSuchElementException(key.toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableMap<VKey<? extends T>, T> loadByKeys(
|
||||||
|
Iterable<? extends VKey<? extends T>> keys) {
|
||||||
|
ImmutableMap<VKey<? extends T>, T> existing = loadByKeysIfPresent(keys);
|
||||||
|
ImmutableSet<? extends VKey<? extends T>> missingKeys =
|
||||||
|
Streams.stream(keys).filter(k -> !existing.containsKey(k)).collect(toImmutableSet());
|
||||||
|
if (!missingKeys.isEmpty()) {
|
||||||
|
throw new NoSuchElementException(
|
||||||
|
String.format(
|
||||||
|
"Expected to find the following VKeys but they were missing: %s.", missingKeys));
|
||||||
|
}
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T loadByEntity(T entity) {
|
||||||
|
checkArgumentNotNull(entity, "entity must be specified");
|
||||||
|
assertInTransaction();
|
||||||
|
return (T)
|
||||||
|
loadByKey(
|
||||||
|
VKey.createSql(entity.getClass(), emf.getPersistenceUnitUtil().getIdentifier(entity)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableList<T> loadByEntities(Iterable<T> entities) {
|
||||||
|
return Streams.stream(entities).map(this::loadByEntity).collect(toImmutableList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> ImmutableList<T> loadAllOf(Class<T> clazz) {
|
||||||
checkArgumentNotNull(clazz, "clazz must be specified");
|
checkArgumentNotNull(clazz, "clazz must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
return ImmutableList.copyOf(
|
return ImmutableList.copyOf(
|
||||||
|
@ -408,11 +437,6 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
.getResultList());
|
.getResultList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> ImmutableList<T> loadAll(Iterable<T> entities) {
|
|
||||||
return Streams.stream(entities).map(this::load).collect(toImmutableList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int internalDelete(VKey<?> key) {
|
private int internalDelete(VKey<?> key) {
|
||||||
checkArgumentNotNull(key, "key must be specified");
|
checkArgumentNotNull(key, "key must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
|
|
|
@ -29,17 +29,19 @@ import org.joda.time.DateTime;
|
||||||
*/
|
*/
|
||||||
public interface TransactionManager {
|
public interface TransactionManager {
|
||||||
|
|
||||||
/** Returns {@code true} if the caller is in a transaction.
|
/**
|
||||||
|
* Returns {@code true} if the caller is in a transaction.
|
||||||
*
|
*
|
||||||
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
||||||
* later when adding the cloud sql implementation.
|
* later when adding the cloud sql implementation.
|
||||||
*/
|
*/
|
||||||
boolean inTransaction();
|
boolean inTransaction();
|
||||||
|
|
||||||
/** Throws {@link IllegalStateException} if the caller is not in a transaction.
|
/**
|
||||||
|
* Throws {@link IllegalStateException} if the caller is not in a transaction.
|
||||||
*
|
*
|
||||||
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
||||||
* later when adding the cloud sql implementation.
|
* later when adding the cloud sql implementation.
|
||||||
*/
|
*/
|
||||||
void assertInTransaction();
|
void assertInTransaction();
|
||||||
|
|
||||||
|
@ -58,10 +60,11 @@ public interface TransactionManager {
|
||||||
*/
|
*/
|
||||||
<T> T transactNew(Supplier<T> work);
|
<T> T transactNew(Supplier<T> work);
|
||||||
|
|
||||||
/** Pauses the current transaction (if any) and executes the work in a new transaction.
|
/**
|
||||||
|
* Pauses the current transaction (if any) and executes the work in a new transaction.
|
||||||
*
|
*
|
||||||
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
||||||
* later when adding the cloud sql implementation.
|
* later when adding the cloud sql implementation.
|
||||||
*/
|
*/
|
||||||
void transactNew(Runnable work);
|
void transactNew(Runnable work);
|
||||||
|
|
||||||
|
@ -73,10 +76,11 @@ public interface TransactionManager {
|
||||||
*/
|
*/
|
||||||
<R> R transactNewReadOnly(Supplier<R> work);
|
<R> R transactNewReadOnly(Supplier<R> work);
|
||||||
|
|
||||||
/** Executes the work in a read-only transaction.
|
/**
|
||||||
|
* Executes the work in a read-only transaction.
|
||||||
*
|
*
|
||||||
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
* <p>Note that this function is kept for backward compatibility. We will review the use case
|
||||||
* later when adding the cloud sql implementation.
|
* later when adding the cloud sql implementation.
|
||||||
*/
|
*/
|
||||||
void transactNewReadOnly(Runnable work);
|
void transactNewReadOnly(Runnable work);
|
||||||
|
|
||||||
|
@ -182,31 +186,60 @@ public interface TransactionManager {
|
||||||
/** Returns whether the entity of given key exists. */
|
/** Returns whether the entity of given key exists. */
|
||||||
<T> boolean exists(VKey<T> key);
|
<T> boolean exists(VKey<T> key);
|
||||||
|
|
||||||
/** Loads the entity by its id, returns empty if the entity doesn't exist. */
|
/** Loads the entity by its key, returns empty if the entity doesn't exist. */
|
||||||
<T> Optional<T> maybeLoad(VKey<T> key);
|
<T> Optional<T> loadByKeyIfPresent(VKey<T> key);
|
||||||
|
|
||||||
/** Loads the entity by its id, throws NoSuchElementException if it doesn't exist. */
|
|
||||||
<T> T load(VKey<T> key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the given entity from the database, throws NoSuchElementException if it doesn't exist.
|
* Loads the set of entities by their keys.
|
||||||
*/
|
|
||||||
<T> T load(T entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the set of entities by their key id.
|
|
||||||
*
|
*
|
||||||
* @throws NoSuchElementException if any of the keys are not found.
|
* <p>Nonexistent keys / entities are absent from the resulting map, but no {@link
|
||||||
|
* NoSuchElementException} will be thrown.
|
||||||
*/
|
*/
|
||||||
<T> ImmutableMap<VKey<? extends T>, T> load(Iterable<? extends VKey<? extends T>> keys);
|
<T> ImmutableMap<VKey<? extends T>, T> loadByKeysIfPresent(
|
||||||
|
Iterable<? extends VKey<? extends T>> keys);
|
||||||
/** Loads all entities of the given type, returns empty if there is no such entity. */
|
|
||||||
<T> ImmutableList<T> loadAll(Class<T> clazz);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all given entities from the database, throws NoSuchElementException if it doesn't exist.
|
* Loads all given entities from the database if possible.
|
||||||
|
*
|
||||||
|
* <p>Nonexistent entities are absent from the resulting list, but no {@link
|
||||||
|
* NoSuchElementException} will be thrown.
|
||||||
*/
|
*/
|
||||||
<T> ImmutableList<T> loadAll(Iterable<T> entities);
|
<T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> entities);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the entity by its key.
|
||||||
|
*
|
||||||
|
* @throws NoSuchElementException if this key does not correspond to an existing entity.
|
||||||
|
*/
|
||||||
|
<T> T loadByKey(VKey<T> key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the set of entities by their keys.
|
||||||
|
*
|
||||||
|
* @throws NoSuchElementException if any of the keys do not correspond to an existing entity.
|
||||||
|
*/
|
||||||
|
<T> ImmutableMap<VKey<? extends T>, T> loadByKeys(Iterable<? extends VKey<? extends T>> keys);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given entity from the database.
|
||||||
|
*
|
||||||
|
* @throws NoSuchElementException if the entity does not exist in the database.
|
||||||
|
*/
|
||||||
|
<T> T loadByEntity(T entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all given entities from the database.
|
||||||
|
*
|
||||||
|
* @throws NoSuchElementException if any of the entities do not exist in the database.
|
||||||
|
*/
|
||||||
|
<T> ImmutableList<T> loadByEntities(Iterable<T> entities);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream of all entities of the given type that exist in the database.
|
||||||
|
*
|
||||||
|
* <p>The resulting stream is empty if there are no entities of this type.
|
||||||
|
*/
|
||||||
|
<T> ImmutableList<T> loadAllOf(Class<T> clazz);
|
||||||
|
|
||||||
/** Deletes the entity by its id. */
|
/** Deletes the entity by its id. */
|
||||||
void delete(VKey<?> key);
|
void delete(VKey<?> key);
|
||||||
|
|
|
@ -342,7 +342,7 @@ public class RdapJsonFormatter {
|
||||||
// Kick off the database loads of the nameservers that we will need, so it can load
|
// Kick off the database loads of the nameservers that we will need, so it can load
|
||||||
// asynchronously while we load and process the contacts.
|
// asynchronously while we load and process the contacts.
|
||||||
ImmutableSet<HostResource> loadedHosts =
|
ImmutableSet<HostResource> loadedHosts =
|
||||||
ImmutableSet.copyOf(tm().load(domainBase.getNameservers()).values());
|
ImmutableSet.copyOf(tm().loadByKeys(domainBase.getNameservers()).values());
|
||||||
// Load the registrant and other contacts and add them to the data.
|
// Load the registrant and other contacts and add them to the data.
|
||||||
Map<Key<ContactResource>, ContactResource> loadedContacts =
|
Map<Key<ContactResource>, ContactResource> loadedContacts =
|
||||||
ofy()
|
ofy()
|
||||||
|
@ -429,7 +429,7 @@ public class RdapJsonFormatter {
|
||||||
statuses.add(StatusValue.LINKED);
|
statuses.add(StatusValue.LINKED);
|
||||||
}
|
}
|
||||||
if (hostResource.isSubordinate()
|
if (hostResource.isSubordinate()
|
||||||
&& tm().load(hostResource.getSuperordinateDomain())
|
&& tm().loadByKey(hostResource.getSuperordinateDomain())
|
||||||
.cloneProjectedAtTime(getRequestTime())
|
.cloneProjectedAtTime(getRequestTime())
|
||||||
.getStatusValues()
|
.getStatusValues()
|
||||||
.contains(StatusValue.PENDING_TRANSFER)) {
|
.contains(StatusValue.PENDING_TRANSFER)) {
|
||||||
|
|
|
@ -172,7 +172,7 @@ final class DomainBaseToXjcConverter {
|
||||||
if (registrant == null) {
|
if (registrant == null) {
|
||||||
logger.atWarning().log("Domain %s has no registrant contact.", domainName);
|
logger.atWarning().log("Domain %s has no registrant contact.", domainName);
|
||||||
} else {
|
} else {
|
||||||
ContactResource registrantContact = tm().load(registrant);
|
ContactResource registrantContact = tm().loadByKey(registrant);
|
||||||
checkState(
|
checkState(
|
||||||
registrantContact != null,
|
registrantContact != null,
|
||||||
"Registrant contact %s on domain %s does not exist",
|
"Registrant contact %s on domain %s does not exist",
|
||||||
|
@ -305,7 +305,7 @@ final class DomainBaseToXjcConverter {
|
||||||
"Contact key for type %s is null on domain %s",
|
"Contact key for type %s is null on domain %s",
|
||||||
model.getType(),
|
model.getType(),
|
||||||
domainName);
|
domainName);
|
||||||
ContactResource contact = tm().load(model.getContactKey());
|
ContactResource contact = tm().loadByKey(model.getContactKey());
|
||||||
checkState(
|
checkState(
|
||||||
contact != null,
|
contact != null,
|
||||||
"Contact %s on domain %s does not exist",
|
"Contact %s on domain %s does not exist",
|
||||||
|
|
|
@ -203,7 +203,7 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
|
||||||
host,
|
host,
|
||||||
// Note that loadAtPointInTime() does cloneProjectedAtTime(watermark) for
|
// Note that loadAtPointInTime() does cloneProjectedAtTime(watermark) for
|
||||||
// us.
|
// us.
|
||||||
loadAtPointInTime(tm().load(host.getSuperordinateDomain()), watermark)
|
loadAtPointInTime(tm().loadByKey(host.getSuperordinateDomain()), watermark)
|
||||||
.now())
|
.now())
|
||||||
: marshaller.marshalExternalHost(host));
|
: marshaller.marshalExternalHost(host));
|
||||||
cache.put(WatermarkModePair.create(watermark, RdeMode.FULL), result);
|
cache.put(WatermarkModePair.create(watermark, RdeMode.FULL), result);
|
||||||
|
|
|
@ -75,7 +75,7 @@ final class DeleteAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
||||||
// Load the tokens in the same transaction as they are deleted to verify they weren't redeemed
|
// Load the tokens in the same transaction as they are deleted to verify they weren't redeemed
|
||||||
// since the query ran. This also filters out per-domain tokens if they're not to be deleted.
|
// since the query ran. This also filters out per-domain tokens if they're not to be deleted.
|
||||||
ImmutableSet<VKey<AllocationToken>> tokensToDelete =
|
ImmutableSet<VKey<AllocationToken>> tokensToDelete =
|
||||||
tm().load(batch).values().stream()
|
tm().loadByKeys(batch).values().stream()
|
||||||
.filter(t -> withDomains || t.getDomainName().isEmpty())
|
.filter(t -> withDomains || t.getDomainName().isEmpty())
|
||||||
.filter(t -> SINGLE_USE.equals(t.getTokenType()))
|
.filter(t -> SINGLE_USE.equals(t.getTokenType()))
|
||||||
.filter(t -> !t.isRedeemed())
|
.filter(t -> !t.isRedeemed())
|
||||||
|
|
|
@ -263,7 +263,7 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi {
|
||||||
savedTokens = tokens;
|
savedTokens = tokens;
|
||||||
} else {
|
} else {
|
||||||
transactIfJpaTm(() -> tm().transact(() -> tm().putAll(tokens)));
|
transactIfJpaTm(() -> tm().transact(() -> tm().putAll(tokens)));
|
||||||
savedTokens = tm().transact(() -> tm().loadAll(tokens));
|
savedTokens = tm().transact(() -> tm().loadByEntities(tokens));
|
||||||
}
|
}
|
||||||
savedTokens.forEach(
|
savedTokens.forEach(
|
||||||
t -> System.out.println(SKIP_NULLS.join(t.getDomainName().orElse(null), t.getToken())));
|
t -> System.out.println(SKIP_NULLS.join(t.getDomainName().orElse(null), t.getToken())));
|
||||||
|
@ -293,7 +293,7 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi {
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().load(existingTokenKeys).values().stream()
|
tm().loadByKeysIfPresent(existingTokenKeys).values().stream()
|
||||||
.map(AllocationToken::getToken)
|
.map(AllocationToken::getToken)
|
||||||
.collect(toImmutableSet()));
|
.collect(toImmutableSet()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
||||||
tokens.stream()
|
tokens.stream()
|
||||||
.map(t -> VKey.create(AllocationToken.class, t))
|
.map(t -> VKey.create(AllocationToken.class, t))
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
tm().load(tokenKeys).forEach((k, v) -> builder.put(k.getSqlKey().toString(), v));
|
tm().loadByKeysIfPresent(tokenKeys)
|
||||||
|
.forEach((k, v) -> builder.put(k.getSqlKey().toString(), v));
|
||||||
}
|
}
|
||||||
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
||||||
ImmutableMap<VKey<DomainBase>, DomainBase> domains = loadRedeemedDomains(loadedTokens.values());
|
ImmutableMap<VKey<DomainBase>, DomainBase> domains = loadRedeemedDomains(loadedTokens.values());
|
||||||
|
@ -88,14 +89,14 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
||||||
.map(AllocationToken::getRedemptionHistoryEntry)
|
.map(AllocationToken::getRedemptionHistoryEntry)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.map(key -> tm().load(key))
|
.map(key -> tm().loadByKey(key))
|
||||||
.map(he -> (Key<DomainBase>) he.getParent())
|
.map(he -> (Key<DomainBase>) he.getParent())
|
||||||
.map(key -> VKey.create(DomainBase.class, key.getName(), key))
|
.map(key -> VKey.create(DomainBase.class, key.getName(), key))
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
ImmutableMap.Builder<VKey<DomainBase>, DomainBase> domainsBuilder =
|
ImmutableMap.Builder<VKey<DomainBase>, DomainBase> domainsBuilder =
|
||||||
new ImmutableMap.Builder<>();
|
new ImmutableMap.Builder<>();
|
||||||
for (List<VKey<DomainBase>> keys : Lists.partition(domainKeys, BATCH_SIZE)) {
|
for (List<VKey<DomainBase>> keys : Lists.partition(domainKeys, BATCH_SIZE)) {
|
||||||
tm().load(ImmutableList.copyOf(keys))
|
tm().loadByKeys(ImmutableList.copyOf(keys))
|
||||||
.forEach((k, v) -> domainsBuilder.put((VKey<DomainBase>) k, v));
|
.forEach((k, v) -> domainsBuilder.put((VKey<DomainBase>) k, v));
|
||||||
}
|
}
|
||||||
return domainsBuilder.build();
|
return domainsBuilder.build();
|
||||||
|
|
|
@ -56,7 +56,7 @@ public final class ResaveEppResourceCommand extends MutatingCommand {
|
||||||
uniqueId);
|
uniqueId);
|
||||||
// Load the resource directly to bypass running cloneProjectedAtTime() automatically, which can
|
// Load the resource directly to bypass running cloneProjectedAtTime() automatically, which can
|
||||||
// cause stageEntityChange() to fail due to implicit projection changes.
|
// cause stageEntityChange() to fail due to implicit projection changes.
|
||||||
EppResource resource = tm().load(resourceKey);
|
EppResource resource = tm().loadByKey(resourceKey);
|
||||||
stageEntityChange(resource, resource);
|
stageEntityChange(resource, resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
|
||||||
|
|
||||||
private ImmutableSortedSet<String> getExistingNameservers(DomainBase domain) {
|
private ImmutableSortedSet<String> getExistingNameservers(DomainBase domain) {
|
||||||
ImmutableSortedSet.Builder<String> nameservers = ImmutableSortedSet.naturalOrder();
|
ImmutableSortedSet.Builder<String> nameservers = ImmutableSortedSet.naturalOrder();
|
||||||
for (HostResource host : tm().load(domain.getNameservers()).values()) {
|
for (HostResource host : tm().loadByKeys(domain.getNameservers()).values()) {
|
||||||
nameservers.add(host.getForeignKey());
|
nameservers.add(host.getForeignKey());
|
||||||
}
|
}
|
||||||
return nameservers.build();
|
return nameservers.build();
|
||||||
|
|
|
@ -107,7 +107,7 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
||||||
tokensToSave =
|
tokensToSave =
|
||||||
transactIfJpaTm(
|
transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().load(getTokenKeys()).values().stream()
|
tm().loadByKeys(getTokenKeys()).values().stream()
|
||||||
.collect(toImmutableMap(Function.identity(), this::updateToken))
|
.collect(toImmutableMap(Function.identity(), this::updateToken))
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
@ -329,7 +329,7 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
|
||||||
DomainBase domainBase, final DesignatedContact.Type contactType) {
|
DomainBase domainBase, final DesignatedContact.Type contactType) {
|
||||||
return domainBase.getContacts().stream()
|
return domainBase.getContacts().stream()
|
||||||
.filter(contact -> contact.getType().equals(contactType))
|
.filter(contact -> contact.getType().equals(contactType))
|
||||||
.map(contact -> tm().load(contact.getContactKey()).getContactId())
|
.map(contact -> tm().loadByKey(contact.getContactKey()).getContactId())
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand
|
||||||
checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank");
|
checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank");
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(AllocationToken.class).stream()
|
tm().loadAllOf(AllocationToken.class).stream()
|
||||||
.filter(token -> token.getToken().startsWith(prefix))
|
.filter(token -> token.getToken().startsWith(prefix))
|
||||||
.map(AllocationToken::createVKey)
|
.map(AllocationToken::createVKey)
|
||||||
.collect(toImmutableSet()));
|
.collect(toImmutableSet()));
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
||||||
private void emitForSubordinateHosts(DomainBase domain) {
|
private void emitForSubordinateHosts(DomainBase domain) {
|
||||||
ImmutableSet<String> subordinateHosts = domain.getSubordinateHosts();
|
ImmutableSet<String> subordinateHosts = domain.getSubordinateHosts();
|
||||||
if (!subordinateHosts.isEmpty()) {
|
if (!subordinateHosts.isEmpty()) {
|
||||||
for (HostResource unprojectedHost : tm().load(domain.getNameservers()).values()) {
|
for (HostResource unprojectedHost : tm().loadByKeys(domain.getNameservers()).values()) {
|
||||||
HostResource host = loadAtPointInTime(unprojectedHost, exportTime).now();
|
HostResource host = loadAtPointInTime(unprojectedHost, exportTime).now();
|
||||||
// A null means the host was deleted (or not created) at this time.
|
// A null means the host was deleted (or not created) at this time.
|
||||||
if ((host != null) && subordinateHosts.contains(host.getHostName())) {
|
if ((host != null) && subordinateHosts.contains(host.getHostName())) {
|
||||||
|
@ -283,7 +283,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
||||||
Duration dnsDefaultDsTtl) {
|
Duration dnsDefaultDsTtl) {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
String domainLabel = stripTld(domain.getDomainName(), domain.getTld());
|
String domainLabel = stripTld(domain.getDomainName(), domain.getTld());
|
||||||
for (HostResource nameserver : tm().load(domain.getNameservers()).values()) {
|
for (HostResource nameserver : tm().loadByKeys(domain.getNameservers()).values()) {
|
||||||
result.append(
|
result.append(
|
||||||
String.format(
|
String.format(
|
||||||
NS_FORMAT,
|
NS_FORMAT,
|
||||||
|
|
|
@ -49,7 +49,7 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
|
||||||
HostResource host = hosts.get(i);
|
HostResource host = hosts.get(i);
|
||||||
String clientId =
|
String clientId =
|
||||||
host.isSubordinate()
|
host.isSubordinate()
|
||||||
? tm().load(host.getSuperordinateDomain())
|
? tm().loadByKey(host.getSuperordinateDomain())
|
||||||
.cloneProjectedAtTime(getTimestamp())
|
.cloneProjectedAtTime(getTimestamp())
|
||||||
.getCurrentSponsorClientId()
|
.getCurrentSponsorClientId()
|
||||||
: host.getPersistedCurrentSponsorClientId();
|
: host.getPersistedCurrentSponsorClientId();
|
||||||
|
|
|
@ -243,7 +243,7 @@ public class ReplayCommitLogsToSqlActionTest {
|
||||||
CommitLogMutation.create(manifestKey, TestObject.create("existing", "b")));
|
CommitLogMutation.create(manifestKey, TestObject.create("existing", "b")));
|
||||||
action.run();
|
action.run();
|
||||||
TestObject fromDatabase =
|
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");
|
assertThat(fromDatabase.getField()).isEqualTo("b");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ public class ReplayCommitLogsToSqlActionTest {
|
||||||
DomainBase domain = newDomainBase("example.tld");
|
DomainBase domain = newDomainBase("example.tld");
|
||||||
CommitLogMutation domainMutation =
|
CommitLogMutation domainMutation =
|
||||||
tm().transact(() -> CommitLogMutation.create(manifestKey, domain));
|
tm().transact(() -> CommitLogMutation.create(manifestKey, domain));
|
||||||
ContactResource contact = tm().transact(() -> tm().load(domain.getRegistrant()));
|
ContactResource contact = tm().transact(() -> tm().loadByKey(domain.getRegistrant()));
|
||||||
CommitLogMutation contactMutation =
|
CommitLogMutation contactMutation =
|
||||||
tm().transact(() -> CommitLogMutation.create(manifestKey, contact));
|
tm().transact(() -> CommitLogMutation.create(manifestKey, contact));
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ public class ReplayCommitLogsToSqlActionTest {
|
||||||
inOrder.verify(spy).delete(contact.createVKey());
|
inOrder.verify(spy).delete(contact.createVKey());
|
||||||
inOrder.verify(spy).put(putCaptor.capture());
|
inOrder.verify(spy).put(putCaptor.capture());
|
||||||
assertThat(putCaptor.getValue().getClass()).isEqualTo(ContactResource.class);
|
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");
|
.isEqualTo("replay@example.tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ public class ReplayCommitLogsToSqlActionTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
jpaTm().loadAll(TestObject.class).stream()
|
jpaTm().loadAllOf(TestObject.class).stream()
|
||||||
.map(TestObject::getId)
|
.map(TestObject::getId)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
assertThat(actualIds).containsExactlyElementsIn(expectedIds);
|
assertThat(actualIds).containsExactlyElementsIn(expectedIds);
|
||||||
|
|
|
@ -241,14 +241,15 @@ class InitSqlPipelineTest {
|
||||||
initSqlPipeline.run().waitUntilFinish();
|
initSqlPipeline.run().waitUntilFinish();
|
||||||
try (AppEngineEnvironment env = new AppEngineEnvironment("test")) {
|
try (AppEngineEnvironment env = new AppEngineEnvironment("test")) {
|
||||||
assertHostResourceEquals(
|
assertHostResourceEquals(
|
||||||
jpaTm().transact(() -> jpaTm().load(hostResource.createVKey())), hostResource);
|
jpaTm().transact(() -> jpaTm().loadByKey(hostResource.createVKey())), hostResource);
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(Registrar.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(Registrar.class)))
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence("lastUpdateTime"))
|
.comparingElementsUsing(immutableObjectCorrespondence("lastUpdateTime"))
|
||||||
.containsExactly(registrar1, registrar2);
|
.containsExactly(registrar1, registrar2);
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(ContactResource.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(ContactResource.class)))
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
|
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
|
||||||
.containsExactly(contact1, contact2);
|
.containsExactly(contact1, contact2);
|
||||||
assertCleansedDomainEquals(jpaTm().transact(() -> jpaTm().load(domain.createVKey())), domain);
|
assertCleansedDomainEquals(
|
||||||
|
jpaTm().transact(() -> jpaTm().loadByKey(domain.createVKey())), domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ class WriteToSqlTest implements Serializable {
|
||||||
.localDbJpaTransactionManager()));
|
.localDbJpaTransactionManager()));
|
||||||
testPipeline.run().waitUntilFinish();
|
testPipeline.run().waitUntilFinish();
|
||||||
|
|
||||||
ImmutableList<?> sqlContacts = jpaTm().transact(() -> jpaTm().loadAll(ContactResource.class));
|
ImmutableList<?> sqlContacts = jpaTm().transact(() -> jpaTm().loadAllOf(ContactResource.class));
|
||||||
assertThat(sqlContacts)
|
assertThat(sqlContacts)
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
|
.comparingElementsUsing(immutableObjectCorrespondence("revisions", "updateTimestamp"))
|
||||||
.containsExactlyElementsIn(
|
.containsExactlyElementsIn(
|
||||||
|
|
|
@ -203,7 +203,7 @@ public abstract class FlowTestCase<F extends Flow> {
|
||||||
assertWithMessage("Billing event is present for grace period: " + gracePeriod)
|
assertWithMessage("Billing event is present for grace period: " + gracePeriod)
|
||||||
.that(gracePeriod.hasBillingEvent())
|
.that(gracePeriod.hasBillingEvent())
|
||||||
.isTrue();
|
.isTrue();
|
||||||
return tm().load(
|
return tm().loadByKey(
|
||||||
firstNonNull(
|
firstNonNull(
|
||||||
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()));
|
gracePeriod.getOneTimeBillingEvent(), gracePeriod.getRecurringBillingEvent()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,8 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
|
||||||
// Force the session to be cleared.
|
// Force the session to be cleared.
|
||||||
tm().clearSessionCache();
|
tm().clearSessionCache();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T refreshedResource = (T) transactIfJpaTm(() -> tm().load(resource)).cloneProjectedAtTime(now);
|
T refreshedResource =
|
||||||
|
(T) transactIfJpaTm(() -> tm().loadByEntity(resource)).cloneProjectedAtTime(now);
|
||||||
return refreshedResource;
|
return refreshedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,8 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
||||||
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
|
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
|
||||||
assertAboutDomains()
|
assertAboutDomains()
|
||||||
.that(domain)
|
.that(domain)
|
||||||
.hasRegistrationExpirationTime(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
|
.hasRegistrationExpirationTime(
|
||||||
|
tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
|
||||||
.and()
|
.and()
|
||||||
.hasOnlyOneHistoryEntryWhich()
|
.hasOnlyOneHistoryEntryWhich()
|
||||||
.hasType(HistoryEntry.Type.DOMAIN_CREATE)
|
.hasType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||||
|
|
|
@ -475,7 +475,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||||
assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(1);
|
assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(1);
|
||||||
assertThat(domain.getDeletePollMessage().getOfyKey())
|
assertThat(domain.getDeletePollMessage().getOfyKey())
|
||||||
.isEqualTo(getOnlyPollMessage("TheRegistrar").createVKey().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);
|
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
|
// 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.
|
// prevent it from being deleted when the domain is deleted.
|
||||||
persistResource(
|
persistResource(
|
||||||
tm().load(reloadResourceByForeignKey().getAutorenewPollMessage())
|
tm().loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setEventTime(A_MONTH_FROM_NOW.minusYears(3))
|
.setEventTime(A_MONTH_FROM_NOW.minusYears(3))
|
||||||
.build());
|
.build());
|
||||||
|
|
|
@ -197,7 +197,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
DomainBase domain = reloadResourceByForeignKey();
|
DomainBase domain = reloadResourceByForeignKey();
|
||||||
HistoryEntry historyEntryDomainRenew =
|
HistoryEntry historyEntryDomainRenew =
|
||||||
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW);
|
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW);
|
||||||
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
|
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
|
||||||
.isEqualTo(newExpiration);
|
.isEqualTo(newExpiration);
|
||||||
assertAboutDomains()
|
assertAboutDomains()
|
||||||
.that(domain)
|
.that(domain)
|
||||||
|
@ -494,7 +494,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
persistDomain();
|
persistDomain();
|
||||||
// Modify the autorenew poll message so that it has an undelivered message in the past.
|
// Modify the autorenew poll message so that it has an undelivered message in the past.
|
||||||
persistResource(
|
persistResource(
|
||||||
tm().load(reloadResourceByForeignKey().getAutorenewPollMessage())
|
tm().loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setEventTime(expirationTime.minusYears(1))
|
.setEventTime(expirationTime.minusYears(1))
|
||||||
.build());
|
.build());
|
||||||
|
|
|
@ -150,7 +150,7 @@ class DomainRestoreRequestFlowTest
|
||||||
DomainBase domain = reloadResourceByForeignKey();
|
DomainBase domain = reloadResourceByForeignKey();
|
||||||
HistoryEntry historyEntryDomainRestore =
|
HistoryEntry historyEntryDomainRestore =
|
||||||
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
|
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
|
||||||
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
|
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
|
||||||
.isEqualTo(expirationTime);
|
.isEqualTo(expirationTime);
|
||||||
assertAboutDomains()
|
assertAboutDomains()
|
||||||
.that(domain)
|
.that(domain)
|
||||||
|
@ -218,7 +218,7 @@ class DomainRestoreRequestFlowTest
|
||||||
DomainBase domain = reloadResourceByForeignKey();
|
DomainBase domain = reloadResourceByForeignKey();
|
||||||
HistoryEntry historyEntryDomainRestore =
|
HistoryEntry historyEntryDomainRestore =
|
||||||
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
|
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
|
||||||
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
|
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
|
||||||
.isEqualTo(newExpirationTime);
|
.isEqualTo(newExpirationTime);
|
||||||
assertAboutDomains()
|
assertAboutDomains()
|
||||||
.that(domain)
|
.that(domain)
|
||||||
|
|
|
@ -191,7 +191,7 @@ class DomainTransferApproveFlowTest
|
||||||
assertAboutHistoryEntries().that(historyEntryTransferApproved).hasOtherClientId("NewRegistrar");
|
assertAboutHistoryEntries().that(historyEntryTransferApproved).hasOtherClientId("NewRegistrar");
|
||||||
assertTransferApproved(domain, originalTransferData);
|
assertTransferApproved(domain, originalTransferData);
|
||||||
assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime);
|
assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime);
|
||||||
assertThat(tm().load(domain.getAutorenewBillingEvent()).getEventTime())
|
assertThat(tm().loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
|
||||||
.isEqualTo(expectedExpirationTime);
|
.isEqualTo(expectedExpirationTime);
|
||||||
// The poll message (in the future) to the losing registrar for implicit ack should be gone.
|
// 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();
|
assertThat(getPollMessages(domain, "TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
|
||||||
|
|
|
@ -291,13 +291,13 @@ class DomainTransferRequestFlowTest
|
||||||
// Assert that the domain's TransferData server-approve billing events match the above.
|
// Assert that the domain's TransferData server-approve billing events match the above.
|
||||||
if (expectTransferBillingEvent) {
|
if (expectTransferBillingEvent) {
|
||||||
assertBillingEventsEqual(
|
assertBillingEventsEqual(
|
||||||
tm().load(domain.getTransferData().getServerApproveBillingEvent()),
|
tm().loadByKey(domain.getTransferData().getServerApproveBillingEvent()),
|
||||||
optionalTransferBillingEvent.get());
|
optionalTransferBillingEvent.get());
|
||||||
} else {
|
} else {
|
||||||
assertThat(domain.getTransferData().getServerApproveBillingEvent()).isNull();
|
assertThat(domain.getTransferData().getServerApproveBillingEvent()).isNull();
|
||||||
}
|
}
|
||||||
assertBillingEventsEqual(
|
assertBillingEventsEqual(
|
||||||
tm().load(domain.getTransferData().getServerApproveAutorenewEvent()),
|
tm().loadByKey(domain.getTransferData().getServerApproveAutorenewEvent()),
|
||||||
gainingClientAutorenew);
|
gainingClientAutorenew);
|
||||||
// Assert that the full set of server-approve billing events is exactly the extra ones plus
|
// 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.
|
// the transfer billing event (if present) and the gaining client autorenew.
|
||||||
|
@ -318,7 +318,7 @@ class DomainTransferRequestFlowTest
|
||||||
BillingEvent.class),
|
BillingEvent.class),
|
||||||
Sets.union(expectedServeApproveBillingEvents, extraBillingEvents));
|
Sets.union(expectedServeApproveBillingEvents, extraBillingEvents));
|
||||||
// The domain's autorenew billing event should still point to the losing client's event.
|
// 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.getClientId()).isEqualTo("TheRegistrar");
|
||||||
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
|
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
|
||||||
// The original grace periods should remain untouched.
|
// 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.
|
// Assert that the poll messages show up in the TransferData server approve entities.
|
||||||
assertPollMessagesEqual(
|
assertPollMessagesEqual(
|
||||||
tm().load(domain.getTransferData().getServerApproveAutorenewPollMessage()),
|
tm().loadByKey(domain.getTransferData().getServerApproveAutorenewPollMessage()),
|
||||||
autorenewPollMessage);
|
autorenewPollMessage);
|
||||||
// Assert that the full set of server-approve poll messages is exactly the server approve
|
// 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.
|
// OneTime messages to gaining and losing registrars plus the gaining client autorenew.
|
||||||
|
@ -446,7 +446,8 @@ class DomainTransferRequestFlowTest
|
||||||
.hasLastEppUpdateTime(implicitTransferTime)
|
.hasLastEppUpdateTime(implicitTransferTime)
|
||||||
.and()
|
.and()
|
||||||
.hasLastEppUpdateClientId("NewRegistrar");
|
.hasLastEppUpdateClientId("NewRegistrar");
|
||||||
assertThat(tm().load(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
|
assertThat(
|
||||||
|
tm().loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
|
||||||
.isEqualTo(expectedExpirationTime);
|
.isEqualTo(expectedExpirationTime);
|
||||||
// And after the expected grace time, the grace period should be gone.
|
// And after the expected grace time, the grace period should be gone.
|
||||||
DomainBase afterGracePeriod =
|
DomainBase afterGracePeriod =
|
||||||
|
|
|
@ -330,7 +330,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
assertThat(domain.getNameservers()).hasSize(13);
|
assertThat(domain.getNameservers()).hasSize(13);
|
||||||
// getContacts does not return contacts of type REGISTRANT, so check these separately.
|
// getContacts does not return contacts of type REGISTRANT, so check these separately.
|
||||||
assertThat(domain.getContacts()).hasSize(3);
|
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();
|
assertNoBillingEvents();
|
||||||
assertDnsTasksEnqueued("example.tld");
|
assertDnsTasksEnqueued("example.tld");
|
||||||
}
|
}
|
||||||
|
@ -1238,7 +1238,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
|
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
|
||||||
.build());
|
.build());
|
||||||
runFlow();
|
runFlow();
|
||||||
assertThat(tm().load(reloadResourceByForeignKey().getRegistrant()).getContactId())
|
assertThat(tm().loadByKey(reloadResourceByForeignKey().getRegistrant()).getContactId())
|
||||||
.isEqualTo("sh8013");
|
.isEqualTo("sh8013");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,9 +1252,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
.getContacts()
|
.getContacts()
|
||||||
.forEach(
|
.forEach(
|
||||||
contact -> {
|
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");
|
.isEqualTo("mak21");
|
||||||
|
|
||||||
runFlow();
|
runFlow();
|
||||||
|
@ -1263,9 +1263,10 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
.getContacts()
|
.getContacts()
|
||||||
.forEach(
|
.forEach(
|
||||||
contact -> {
|
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");
|
.isEqualTo("sh8013");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class UpdateAutoTimestampTest {
|
||||||
private UpdateAutoTimestampTestObject reload() {
|
private UpdateAutoTimestampTestObject reload() {
|
||||||
return tm().transact(
|
return tm().transact(
|
||||||
() ->
|
() ->
|
||||||
tm().load(
|
tm().loadByKey(
|
||||||
VKey.create(
|
VKey.create(
|
||||||
UpdateAutoTimestampTestObject.class,
|
UpdateAutoTimestampTestObject.class,
|
||||||
1L,
|
1L,
|
||||||
|
|
|
@ -184,15 +184,16 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(oneTime))).isEqualTo(oneTime);
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(oneTime))).isEqualTo(oneTime);
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(oneTimeSynthetic))).isEqualTo(oneTimeSynthetic);
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(oneTimeSynthetic)))
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(recurring))).isEqualTo(recurring);
|
.isEqualTo(oneTimeSynthetic);
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(cancellationOneTime)))
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(recurring))).isEqualTo(recurring);
|
||||||
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(cancellationOneTime)))
|
||||||
.isEqualTo(cancellationOneTime);
|
.isEqualTo(cancellationOneTime);
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(cancellationRecurring)))
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(cancellationRecurring)))
|
||||||
.isEqualTo(cancellationRecurring);
|
.isEqualTo(cancellationRecurring);
|
||||||
|
|
||||||
ofyTmOrDoNothing(() -> assertThat(tm().load(modification)).isEqualTo(modification));
|
ofyTmOrDoNothing(() -> assertThat(tm().loadByEntity(modification)).isEqualTo(modification));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyOnly
|
@TestOfyOnly
|
||||||
|
@ -220,8 +221,9 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testCancellationMatching() {
|
void testCancellationMatching() {
|
||||||
VKey<?> recurringKey =
|
VKey<?> recurringKey =
|
||||||
transactIfJpaTm(() -> tm().load(oneTimeSynthetic).getCancellationMatchingBillingEvent());
|
transactIfJpaTm(
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(recurringKey))).isEqualTo(recurring);
|
() -> tm().loadByEntity(oneTimeSynthetic).getCancellationMatchingBillingEvent());
|
||||||
|
assertThat(transactIfJpaTm(() -> tm().loadByKey(recurringKey))).isEqualTo(recurring);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyOnly
|
@TestOfyOnly
|
||||||
|
|
|
@ -140,7 +140,8 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.load(VKey.createSql(ContactResource.class, originalContact.getRepoId())));
|
.loadByKey(
|
||||||
|
VKey.createSql(ContactResource.class, originalContact.getRepoId())));
|
||||||
|
|
||||||
ContactResource fixed =
|
ContactResource fixed =
|
||||||
originalContact
|
originalContact
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase result = jpaTm().load(domain.createVKey());
|
DomainBase result = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertEqualDomainExcept(result);
|
assertEqualDomainExcept(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -177,14 +177,14 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
jpaTm().put(persisted.asBuilder().build());
|
jpaTm().put(persisted.asBuilder().build());
|
||||||
});
|
});
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Load the domain in its entirety.
|
// Load the domain in its entirety.
|
||||||
DomainBase result = jpaTm().load(domain.createVKey());
|
DomainBase result = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertEqualDomainExcept(result);
|
assertEqualDomainExcept(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
||||||
jpaTm().put(modified);
|
jpaTm().put(modified);
|
||||||
|
@ -204,7 +204,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getGracePeriods()).isEmpty();
|
assertThat(persisted.getGracePeriods()).isEmpty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
|
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
|
||||||
jpaTm().put(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
@ -223,7 +223,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getGracePeriods()).isEmpty();
|
assertThat(persisted.getGracePeriods()).isEmpty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted
|
persisted
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -253,7 +253,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getGracePeriods())
|
assertThat(persisted.getGracePeriods())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
GracePeriod.create(
|
GracePeriod.create(
|
||||||
|
@ -266,7 +266,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
DomainBase.Builder builder = persisted.asBuilder();
|
DomainBase.Builder builder = persisted.asBuilder();
|
||||||
for (GracePeriod gracePeriod : persisted.getGracePeriods()) {
|
for (GracePeriod gracePeriod : persisted.getGracePeriods()) {
|
||||||
if (gracePeriod.getType() == GracePeriodStatus.RENEW) {
|
if (gracePeriod.getType() == GracePeriodStatus.RENEW) {
|
||||||
|
@ -279,7 +279,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertEqualDomainExcept(persisted);
|
assertEqualDomainExcept(persisted);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
||||||
jpaTm().put(modified);
|
jpaTm().put(modified);
|
||||||
|
@ -299,7 +299,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getGracePeriods()).isEmpty();
|
assertThat(persisted.getGracePeriods()).isEmpty();
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted
|
persisted
|
||||||
|
@ -319,7 +319,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getGracePeriods())
|
assertThat(persisted.getGracePeriods())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
GracePeriod.create(
|
GracePeriod.create(
|
||||||
|
@ -340,7 +340,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getDsData()).containsExactlyElementsIn(domain.getDsData());
|
assertThat(persisted.getDsData()).containsExactlyElementsIn(domain.getDsData());
|
||||||
DomainBase modified = persisted.asBuilder().setDsData(unionDsData).build();
|
DomainBase modified = persisted.asBuilder().setDsData(unionDsData).build();
|
||||||
jpaTm().put(modified);
|
jpaTm().put(modified);
|
||||||
|
@ -350,7 +350,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertThat(persisted.getDsData()).containsExactlyElementsIn(unionDsData);
|
assertThat(persisted.getDsData()).containsExactlyElementsIn(unionDsData);
|
||||||
assertEqualDomainExcept(persisted, "dsData");
|
assertEqualDomainExcept(persisted, "dsData");
|
||||||
});
|
});
|
||||||
|
@ -359,7 +359,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
jpaTm().put(persisted.asBuilder().setDsData(domain.getDsData()).build());
|
jpaTm().put(persisted.asBuilder().setDsData(domain.getDsData()).build());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertEqualDomainExcept(persisted);
|
assertEqualDomainExcept(persisted);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase result = jpaTm().load(domain.createVKey());
|
DomainBase result = jpaTm().loadByKey(domain.createVKey());
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(result)
|
.that(result)
|
||||||
.isEqualExceptFields(domain, "updateTimestamp", "creationTime");
|
.isEqualExceptFields(domain, "updateTimestamp", "creationTime");
|
||||||
|
@ -528,7 +528,7 @@ public class DomainBaseSqlTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store the existing BillingRecurrence VKey. This happens after the event has been persisted.
|
// 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.
|
// Verify that the domain data has been persisted.
|
||||||
// dsData still isn't persisted. gracePeriods appears to have the same values but for some
|
// 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.
|
// Verify that the DomainContent object from the history record sets the fields correctly.
|
||||||
DomainHistory persistedHistoryEntry =
|
DomainHistory persistedHistoryEntry =
|
||||||
jpaTm().transact(() -> jpaTm().load(historyEntry.createVKey()));
|
jpaTm().transact(() -> jpaTm().loadByKey(historyEntry.createVKey()));
|
||||||
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
|
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
|
||||||
.isEqualTo(domain.getAutorenewPollMessage());
|
.isEqualTo(domain.getAutorenewPollMessage());
|
||||||
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewBillingEvent())
|
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.
|
// 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.
|
// Verify that the domain data has been persisted.
|
||||||
// dsData still isn't persisted. gracePeriods appears to have the same values but for some
|
// 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.
|
// Verify that the DomainContent object from the history record sets the fields correctly.
|
||||||
DomainHistory persistedHistoryEntry =
|
DomainHistory persistedHistoryEntry =
|
||||||
jpaTm().transact(() -> jpaTm().load(historyEntry.createVKey()));
|
jpaTm().transact(() -> jpaTm().loadByKey(historyEntry.createVKey()));
|
||||||
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
|
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewPollMessage())
|
||||||
.isEqualTo(domain.getAutorenewPollMessage());
|
.isEqualTo(domain.getAutorenewPollMessage());
|
||||||
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewBillingEvent())
|
assertThat(persistedHistoryEntry.getDomainContent().get().getAutorenewBillingEvent())
|
||||||
|
|
|
@ -78,7 +78,8 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
|
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(unlimitedUseToken))).isEqualTo(unlimitedUseToken);
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(unlimitedUseToken)))
|
||||||
|
.isEqualTo(unlimitedUseToken);
|
||||||
|
|
||||||
DomainBase domain = persistActiveDomain("example.foo");
|
DomainBase domain = persistActiveDomain("example.foo");
|
||||||
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1);
|
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"))
|
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||||
.setTokenType(SINGLE_USE)
|
.setTokenType(SINGLE_USE)
|
||||||
.build());
|
.build());
|
||||||
assertThat(transactIfJpaTm(() -> tm().load(singleUseToken))).isEqualTo(singleUseToken);
|
assertThat(transactIfJpaTm(() -> tm().loadByEntity(singleUseToken))).isEqualTo(singleUseToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyOnly
|
@TestOfyOnly
|
||||||
|
|
|
@ -46,13 +46,13 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
||||||
jpaTm().transact(() -> jpaTm().insert(contact));
|
jpaTm().transact(() -> jpaTm().insert(contact));
|
||||||
VKey<ContactResource> contactVKey = contact.createVKey();
|
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());
|
ContactHistory contactHistory = createContactHistory(contactFromDb, contact.getRepoId());
|
||||||
jpaTm().transact(() -> jpaTm().insert(contactHistory));
|
jpaTm().transact(() -> jpaTm().insert(contactHistory));
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
ContactHistory fromDatabase = jpaTm().load(contactHistory.createVKey());
|
ContactHistory fromDatabase = jpaTm().loadByKey(contactHistory.createVKey());
|
||||||
assertContactHistoriesEqual(fromDatabase, contactHistory);
|
assertContactHistoriesEqual(fromDatabase, contactHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
|
||||||
});
|
});
|
||||||
|
@ -65,7 +65,7 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
||||||
jpaTm().transact(() -> jpaTm().insert(contact));
|
jpaTm().transact(() -> jpaTm().insert(contact));
|
||||||
VKey<ContactResource> contactVKey = contact.createVKey();
|
VKey<ContactResource> contactVKey = contact.createVKey();
|
||||||
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
|
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().loadByKey(contactVKey));
|
||||||
ContactHistory contactHistory =
|
ContactHistory contactHistory =
|
||||||
createContactHistory(contactFromDb, contact.getRepoId())
|
createContactHistory(contactFromDb, contact.getRepoId())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -76,7 +76,7 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
ContactHistory fromDatabase = jpaTm().load(contactHistory.createVKey());
|
ContactHistory fromDatabase = jpaTm().loadByKey(contactHistory.createVKey());
|
||||||
assertContactHistoriesEqual(fromDatabase, contactHistory);
|
assertContactHistoriesEqual(fromDatabase, contactHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(contactHistory.getParentVKey());
|
||||||
});
|
});
|
||||||
|
@ -89,7 +89,7 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
||||||
tm().transact(() -> tm().insert(contact));
|
tm().transact(() -> tm().insert(contact));
|
||||||
VKey<ContactResource> contactVKey = contact.createVKey();
|
VKey<ContactResource> contactVKey = contact.createVKey();
|
||||||
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
|
ContactResource contactFromDb = tm().transact(() -> tm().loadByKey(contactVKey));
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
ContactHistory contactHistory = createContactHistory(contactFromDb, contact.getRepoId());
|
ContactHistory contactHistory = createContactHistory(contactFromDb, contact.getRepoId());
|
||||||
tm().transact(() -> tm().insert(contactHistory));
|
tm().transact(() -> tm().insert(contactHistory));
|
||||||
|
@ -100,8 +100,8 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
VKey<ContactHistory> contactHistoryVKey = contactHistory.createVKey();
|
VKey<ContactHistory> contactHistoryVKey = contactHistory.createVKey();
|
||||||
VKey<HistoryEntry> historyEntryVKey =
|
VKey<HistoryEntry> historyEntryVKey =
|
||||||
VKey.createOfy(HistoryEntry.class, Key.create(contactHistory.asHistoryEntry()));
|
VKey.createOfy(HistoryEntry.class, Key.create(contactHistory.asHistoryEntry()));
|
||||||
ContactHistory hostHistoryFromDb = tm().transact(() -> tm().load(contactHistoryVKey));
|
ContactHistory hostHistoryFromDb = tm().transact(() -> tm().loadByKey(contactHistoryVKey));
|
||||||
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
|
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
|
||||||
|
|
||||||
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
|
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
|
DomainHistory fromDatabase = jpaTm().loadByKey(domainHistory.createVKey());
|
||||||
assertDomainHistoriesEqual(fromDatabase, domainHistory);
|
assertDomainHistoriesEqual(fromDatabase, domainHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
|
||||||
});
|
});
|
||||||
|
@ -87,7 +87,7 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
|
DomainHistory fromDatabase = jpaTm().loadByKey(domainHistory.createVKey());
|
||||||
assertDomainHistoriesEqual(fromDatabase, domainHistory);
|
assertDomainHistoriesEqual(fromDatabase, domainHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(domainHistory.getParentVKey());
|
||||||
assertThat(fromDatabase.getNsHosts())
|
assertThat(fromDatabase.getNsHosts())
|
||||||
|
@ -125,8 +125,8 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
|
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
|
||||||
VKey<HistoryEntry> historyEntryVKey =
|
VKey<HistoryEntry> historyEntryVKey =
|
||||||
VKey.createOfy(HistoryEntry.class, Key.create(domainHistory.asHistoryEntry()));
|
VKey.createOfy(HistoryEntry.class, Key.create(domainHistory.asHistoryEntry()));
|
||||||
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().load(domainHistoryVKey));
|
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
|
||||||
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
|
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
|
||||||
|
|
||||||
assertThat(domainHistoryFromDb).isEqualTo(historyEntryFromDb);
|
assertThat(domainHistoryFromDb).isEqualTo(historyEntryFromDb);
|
||||||
}
|
}
|
||||||
|
@ -183,13 +183,13 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
|
|
||||||
// Load the DomainHistory object from the datastore.
|
// Load the DomainHistory object from the datastore.
|
||||||
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
|
VKey<DomainHistory> domainHistoryVKey = domainHistory.createVKey();
|
||||||
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().load(domainHistoryVKey));
|
DomainHistory domainHistoryFromDb = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
|
||||||
|
|
||||||
// attempt to write to SQL.
|
// attempt to write to SQL.
|
||||||
jpaTm().transact(() -> jpaTm().insert(domainHistoryFromDb));
|
jpaTm().transact(() -> jpaTm().insert(domainHistoryFromDb));
|
||||||
|
|
||||||
// Reload and rewrite.
|
// Reload and rewrite.
|
||||||
DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().load(domainHistoryVKey));
|
DomainHistory domainHistoryFromDb2 = tm().transact(() -> tm().loadByKey(domainHistoryVKey));
|
||||||
jpaTm().transact(() -> jpaTm().put(domainHistoryFromDb2));
|
jpaTm().transact(() -> jpaTm().put(domainHistoryFromDb2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,13 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
jpaTm().transact(() -> jpaTm().insert(host));
|
jpaTm().transact(() -> jpaTm().insert(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().load(hostVKey));
|
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(hostVKey));
|
||||||
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
|
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
|
||||||
jpaTm().transact(() -> jpaTm().insert(hostHistory));
|
jpaTm().transact(() -> jpaTm().insert(hostHistory));
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
HostHistory fromDatabase = jpaTm().load(hostHistory.createVKey());
|
HostHistory fromDatabase = jpaTm().loadByKey(hostHistory.createVKey());
|
||||||
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
|
||||||
});
|
});
|
||||||
|
@ -65,7 +65,7 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
||||||
jpaTm().transact(() -> jpaTm().insert(host));
|
jpaTm().transact(() -> jpaTm().insert(host));
|
||||||
|
|
||||||
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(host.createVKey()));
|
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().loadByKey(host.createVKey()));
|
||||||
HostHistory hostHistory =
|
HostHistory hostHistory =
|
||||||
createHostHistory(hostFromDb, host.getRepoId()).asBuilder().setHostBase(null).build();
|
createHostHistory(hostFromDb, host.getRepoId()).asBuilder().setHostBase(null).build();
|
||||||
jpaTm().transact(() -> jpaTm().insert(hostHistory));
|
jpaTm().transact(() -> jpaTm().insert(hostHistory));
|
||||||
|
@ -73,7 +73,7 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
HostHistory fromDatabase = jpaTm().load(hostHistory.createVKey());
|
HostHistory fromDatabase = jpaTm().loadByKey(hostHistory.createVKey());
|
||||||
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
assertHostHistoriesEqual(fromDatabase, hostHistory);
|
||||||
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
|
assertThat(fromDatabase.getParentVKey()).isEqualTo(hostHistory.getParentVKey());
|
||||||
});
|
});
|
||||||
|
@ -87,7 +87,7 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
tm().transact(() -> tm().insert(host));
|
tm().transact(() -> tm().insert(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 = tm().transact(() -> tm().load(hostVKey));
|
HostResource hostFromDb = tm().transact(() -> tm().loadByKey(hostVKey));
|
||||||
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
|
HostHistory hostHistory = createHostHistory(hostFromDb, host.getRepoId());
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().insert(hostHistory));
|
tm().transact(() -> tm().insert(hostHistory));
|
||||||
|
@ -98,8 +98,8 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
VKey<HostHistory> hostHistoryVKey = hostHistory.createVKey();
|
VKey<HostHistory> hostHistoryVKey = hostHistory.createVKey();
|
||||||
VKey<HistoryEntry> historyEntryVKey =
|
VKey<HistoryEntry> historyEntryVKey =
|
||||||
VKey.createOfy(HistoryEntry.class, Key.create(hostHistory.asHistoryEntry()));
|
VKey.createOfy(HistoryEntry.class, Key.create(hostHistory.asHistoryEntry()));
|
||||||
HostHistory hostHistoryFromDb = tm().transact(() -> tm().load(hostHistoryVKey));
|
HostHistory hostHistoryFromDb = tm().transact(() -> tm().loadByKey(hostHistoryVKey));
|
||||||
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().load(historyEntryVKey));
|
HistoryEntry historyEntryFromDb = tm().transact(() -> tm().loadByKey(historyEntryVKey));
|
||||||
|
|
||||||
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
|
assertThat(hostHistoryFromDb).isEqualTo(historyEntryFromDb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.load(
|
.loadByKey(
|
||||||
VKey.create(
|
VKey.create(
|
||||||
HistoryEntry.class,
|
HistoryEntry.class,
|
||||||
historyEntryId,
|
historyEntryId,
|
||||||
|
@ -85,7 +85,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
||||||
jpaTm().insert(legacyContactHistory);
|
jpaTm().insert(legacyContactHistory);
|
||||||
});
|
});
|
||||||
ContactHistory legacyHistoryFromSql =
|
ContactHistory legacyHistoryFromSql =
|
||||||
jpaTm().transact(() -> jpaTm().load(legacyContactHistory.createVKey()));
|
jpaTm().transact(() -> jpaTm().loadByKey(legacyContactHistory.createVKey()));
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(legacyContactHistory)
|
.that(legacyContactHistory)
|
||||||
.isEqualExceptFields(legacyHistoryFromSql);
|
.isEqualExceptFields(legacyHistoryFromSql);
|
||||||
|
@ -109,7 +109,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.load(
|
.loadByKey(
|
||||||
VKey.create(
|
VKey.create(
|
||||||
HistoryEntry.class,
|
HistoryEntry.class,
|
||||||
historyEntryId,
|
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
|
// Next, save that from-Datastore object in SQL and verify we can load it back in
|
||||||
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory));
|
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory));
|
||||||
DomainHistory legacyHistoryFromSql =
|
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
|
// Don't compare nsHosts directly because one is null and the other is empty
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(legacyDomainHistory)
|
.that(legacyDomainHistory)
|
||||||
|
@ -161,7 +161,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.load(
|
.loadByKey(
|
||||||
VKey.create(
|
VKey.create(
|
||||||
HistoryEntry.class,
|
HistoryEntry.class,
|
||||||
historyEntryId,
|
historyEntryId,
|
||||||
|
@ -181,7 +181,7 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
||||||
jpaTm().insert(legacyHostHistory);
|
jpaTm().insert(legacyHostHistory);
|
||||||
});
|
});
|
||||||
HostHistory legacyHistoryFromSql =
|
HostHistory legacyHistoryFromSql =
|
||||||
jpaTm().transact(() -> jpaTm().load(legacyHostHistory.createVKey()));
|
jpaTm().transact(() -> jpaTm().loadByKey(legacyHostHistory.createVKey()));
|
||||||
assertAboutImmutableObjects().that(legacyHostHistory).isEqualExceptFields(legacyHistoryFromSql);
|
assertAboutImmutableObjects().that(legacyHostHistory).isEqualExceptFields(legacyHistoryFromSql);
|
||||||
// can't compare hostRepoId directly since it doesn't save the ofy key in SQL
|
// can't compare hostRepoId directly since it doesn't save the ofy key in SQL
|
||||||
assertThat(legacyHostHistory.getParentVKey().getSqlKey())
|
assertThat(legacyHostHistory.getParentVKey().getSqlKey())
|
||||||
|
|
|
@ -93,7 +93,7 @@ class HostResourceTest extends EntityTestCase {
|
||||||
void testPersistence() {
|
void testPersistence() {
|
||||||
HostResource newHost = host.asBuilder().setRepoId("NEWHOST").build();
|
HostResource newHost = host.asBuilder().setRepoId("NEWHOST").build();
|
||||||
tm().transact(() -> tm().insert(newHost));
|
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"))
|
.comparingElementsUsing(immutableObjectCorrespondence("revisions"))
|
||||||
.containsExactly(newHost);
|
.containsExactly(newHost);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class ForeignKeyIndexTest extends EntityTestCase {
|
||||||
HostResource host = persistActiveHost("ns1.example.com");
|
HostResource host = persistActiveHost("ns1.example.com");
|
||||||
ForeignKeyIndex<HostResource> fki =
|
ForeignKeyIndex<HostResource> fki =
|
||||||
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc());
|
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);
|
assertThat(fki.getDeletionTime()).isEqualTo(END_OF_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,13 +93,16 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
void testCloudSqlSupportForPolymorphicVKey() {
|
void testCloudSqlSupportForPolymorphicVKey() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
||||||
PollMessage persistedOneTime =
|
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).isInstanceOf(PollMessage.OneTime.class);
|
||||||
assertThat(persistedOneTime).isEqualTo(oneTime);
|
assertThat(persistedOneTime).isEqualTo(oneTime);
|
||||||
|
|
||||||
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
||||||
PollMessage persistedAutoRenew =
|
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).isInstanceOf(PollMessage.Autorenew.class);
|
||||||
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
|
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +117,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
.setMsg("Test poll message")
|
.setMsg("Test poll message")
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
.build());
|
.build());
|
||||||
assertThat(tm().transact(() -> tm().load(pollMessage))).isEqualTo(pollMessage);
|
assertThat(tm().transact(() -> tm().loadByEntity(pollMessage))).isEqualTo(pollMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
|
@ -129,7 +132,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
|
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
|
||||||
.setTargetId("foobar.foo")
|
.setTargetId("foobar.foo")
|
||||||
.build());
|
.build());
|
||||||
assertThat(tm().transact(() -> tm().load(pollMessage))).isEqualTo(pollMessage);
|
assertThat(tm().transact(() -> tm().loadByEntity(pollMessage))).isEqualTo(pollMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyOnly
|
@TestOfyOnly
|
||||||
|
|
|
@ -131,7 +131,7 @@ class RegistrarTest extends EntityTestCase {
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testPersistence() {
|
void testPersistence() {
|
||||||
assertThat(tm().transact(() -> tm().load(registrar.createVKey()))).isEqualTo(registrar);
|
assertThat(tm().transact(() -> tm().loadByKey(registrar.createVKey()))).isEqualTo(registrar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyOnly
|
@TestOfyOnly
|
||||||
|
|
|
@ -70,14 +70,15 @@ public class RegistryTest extends EntityTestCase {
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
|
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
|
||||||
tm().transact(() -> tm().put(registry));
|
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);
|
assertThat(persisted).isEqualTo(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testPersistence() {
|
void testPersistence() {
|
||||||
assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull();
|
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"));
|
.isEqualTo(Registry.get("tld"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +163,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
.containsExactlyElementsIn(
|
.containsExactlyElementsIn(
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
tm().load(
|
tm().loadByKeys(
|
||||||
ImmutableSet.of(
|
ImmutableSet.of(
|
||||||
Registry.createVKey("foo"), Registry.createVKey("tld"))))
|
Registry.createVKey("foo"), Registry.createVKey("tld"))))
|
||||||
.values());
|
.values());
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
});
|
});
|
||||||
|
|
||||||
VKey<Spec11ThreatMatch> threatVKey = VKey.createSql(Spec11ThreatMatch.class, threat.getId());
|
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 object saved for the first time doesn't have an ID; it is generated by SQL
|
||||||
threat.id = persistedThreat.id;
|
threat.id = persistedThreat.id;
|
||||||
|
|
|
@ -64,7 +64,7 @@ class BillingVKeyTest {
|
||||||
|
|
||||||
BillingVKeyTestEntity original = new BillingVKeyTestEntity(oneTimeVKey, recurringVKey);
|
BillingVKeyTestEntity original = new BillingVKeyTestEntity(oneTimeVKey, recurringVKey);
|
||||||
tm().transact(() -> tm().insert(original));
|
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).isEqualTo(original);
|
||||||
assertThat(persisted.getBillingEventVKey()).isEqualTo(oneTimeVKey);
|
assertThat(persisted.getBillingEventVKey()).isEqualTo(oneTimeVKey);
|
||||||
|
@ -75,7 +75,7 @@ class BillingVKeyTest {
|
||||||
void testHandleNullVKeyCorrectly() {
|
void testHandleNullVKeyCorrectly() {
|
||||||
BillingVKeyTestEntity original = new BillingVKeyTestEntity(null, null);
|
BillingVKeyTestEntity original = new BillingVKeyTestEntity(null, null);
|
||||||
tm().transact(() -> tm().insert(original));
|
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).isEqualTo(original);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class DomainHistoryVKeyTest {
|
||||||
DomainHistoryVKey domainHistoryVKey = DomainHistoryVKey.create(ofyKey);
|
DomainHistoryVKey domainHistoryVKey = DomainHistoryVKey.create(ofyKey);
|
||||||
TestEntity original = new TestEntity(domainHistoryVKey);
|
TestEntity original = new TestEntity(domainHistoryVKey);
|
||||||
tm().transact(() -> tm().insert(original));
|
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);
|
assertThat(persisted).isEqualTo(original);
|
||||||
// Double check that the persisted.domainHistoryVKey is a symmetric VKey
|
// Double check that the persisted.domainHistoryVKey is a symmetric VKey
|
||||||
assertThat(persisted.domainHistoryVKey.createOfyKey())
|
assertThat(persisted.domainHistoryVKey.createOfyKey())
|
||||||
|
|
|
@ -66,14 +66,14 @@ class EntityCallbacksListenerTest {
|
||||||
checkAll(updated, 0, 1, 0, 1);
|
checkAll(updated, 0, 1, 0, 1);
|
||||||
|
|
||||||
TestEntity testLoad =
|
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);
|
checkAll(testLoad, 0, 0, 0, 1);
|
||||||
|
|
||||||
TestEntity testRemove =
|
TestEntity testRemove =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
TestEntity removed = jpaTm().load(VKey.createSql(TestEntity.class, "id"));
|
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
|
||||||
jpaTm().getEntityManager().remove(removed);
|
jpaTm().getEntityManager().remove(removed);
|
||||||
return removed;
|
return removed;
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,7 +65,9 @@ public class InetAddressSetConverterTest {
|
||||||
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
|
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
|
||||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||||
InetAddressSetTestEntity persisted =
|
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);
|
assertThat(persisted.addresses).isEqualTo(inetAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,8 @@ public class LocalDateConverterTest {
|
||||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||||
LocalDateConverterTestEntity retrievedEntity =
|
LocalDateConverterTestEntity retrievedEntity =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(() -> jpaTm().load(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
.transact(
|
||||||
|
() -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
||||||
return retrievedEntity;
|
return retrievedEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ class JpaTransactionManagerImplTest {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -200,20 +200,20 @@ class JpaTransactionManagerImplTest {
|
||||||
@Test
|
@Test
|
||||||
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
|
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
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));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
JDBCConnectionException.class,
|
JDBCConnectionException.class,
|
||||||
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.loadByKey(theEntityKey)));
|
||||||
verify(spyJpaTm, times(3)).load(theEntityKey);
|
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
|
||||||
Supplier<Runnable> supplier =
|
Supplier<Runnable> supplier =
|
||||||
() -> {
|
() -> {
|
||||||
Runnable work = () -> spyJpaTm.load(theEntityKey);
|
Runnable work = () -> spyJpaTm.loadByKey(theEntityKey);
|
||||||
work.run();
|
work.run();
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
assertThrows(JDBCConnectionException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
|
assertThrows(JDBCConnectionException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
|
||||||
verify(spyJpaTm, times(6)).load(theEntityKey);
|
verify(spyJpaTm, times(6)).loadByKey(theEntityKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -223,31 +223,31 @@ class JpaTransactionManagerImplTest {
|
||||||
new RuntimeException()
|
new RuntimeException()
|
||||||
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
|
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
|
||||||
.when(spyJpaTm)
|
.when(spyJpaTm)
|
||||||
.load(any(VKey.class));
|
.loadByKey(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.loadByKey(theEntityKey)));
|
||||||
verify(spyJpaTm, times(3)).load(theEntityKey);
|
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
|
||||||
Supplier<Runnable> supplier =
|
Supplier<Runnable> supplier =
|
||||||
() -> {
|
() -> {
|
||||||
Runnable work = () -> spyJpaTm.load(theEntityKey);
|
Runnable work = () -> spyJpaTm.loadByKey(theEntityKey);
|
||||||
work.run();
|
work.run();
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
assertThrows(RuntimeException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
|
assertThrows(RuntimeException.class, () -> spyJpaTm.transactNewReadOnly(supplier));
|
||||||
verify(spyJpaTm, times(6)).load(theEntityKey);
|
verify(spyJpaTm, times(6)).loadByKey(theEntityKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doTransactionless_retriesJdbcConnectionExceptions() {
|
void doTransactionless_retriesJdbcConnectionExceptions() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
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));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.loadByKey(theEntityKey)));
|
||||||
verify(spyJpaTm, times(3)).load(theEntityKey);
|
verify(spyJpaTm, times(3)).loadByKey(theEntityKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -255,7 +255,7 @@ class JpaTransactionManagerImplTest {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
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)));
|
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ class JpaTransactionManagerImplTest {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey)))
|
||||||
.isEqualTo(compoundIdEntity);
|
.isEqualTo(compoundIdEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ class JpaTransactionManagerImplTest {
|
||||||
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
jpaTm().transact(() -> jpaTm().insertAll(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().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(moreEntities);
|
.containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,17 +296,17 @@ class JpaTransactionManagerImplTest {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().put(theEntity));
|
jpaTm().transact(() -> jpaTm().put(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
assertThat(jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void put_updatesExistingEntity() {
|
void put_updatesExistingEntity() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
TestEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
jpaTm().transact(() -> jpaTm().put(theEntity));
|
jpaTm().transact(() -> jpaTm().put(theEntity));
|
||||||
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ class JpaTransactionManagerImplTest {
|
||||||
jpaTm().transact(() -> jpaTm().putAll(moreEntities));
|
jpaTm().transact(() -> jpaTm().putAll(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().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(moreEntities);
|
.containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,22 +325,22 @@ class JpaTransactionManagerImplTest {
|
||||||
void update_succeeds() {
|
void update_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted =
|
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");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
jpaTm().transact(() -> jpaTm().update(theEntity));
|
jpaTm().transact(() -> jpaTm().update(theEntity));
|
||||||
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
persisted = jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateCompoundIdEntity_succeeds() {
|
void updateCompoundIdEntity_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
compoundIdEntity.data = "bar";
|
compoundIdEntity.data = "bar";
|
||||||
jpaTm().transact(() -> jpaTm().update(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().update(compoundIdEntity));
|
||||||
persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
persisted = jpaTm().transact(() -> jpaTm().loadByKey(compoundIdEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ class JpaTransactionManagerImplTest {
|
||||||
new TestEntity("entity2", "bar_updated"),
|
new TestEntity("entity2", "bar_updated"),
|
||||||
new TestEntity("entity3", "qux_updated"));
|
new TestEntity("entity3", "qux_updated"));
|
||||||
jpaTm().transact(() -> jpaTm().updateAll(updated));
|
jpaTm().transact(() -> jpaTm().updateAll(updated));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(updated);
|
.containsExactlyElementsIn(updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ class JpaTransactionManagerImplTest {
|
||||||
theEntity);
|
theEntity);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().updateAll(updated)));
|
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().updateAll(updated)));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAllOf(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(moreEntities);
|
.containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ class JpaTransactionManagerImplTest {
|
||||||
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));
|
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.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
@ -393,14 +393,15 @@ class JpaTransactionManagerImplTest {
|
||||||
void load_throwsOnMissingElement() {
|
void load_throwsOnMissingElement() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey)));
|
NoSuchElementException.class,
|
||||||
|
() -> jpaTm().transact(() -> jpaTm().loadByKey(theEntityKey)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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));
|
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.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
@ -408,14 +409,15 @@ class JpaTransactionManagerImplTest {
|
||||||
@Test
|
@Test
|
||||||
void maybeLoad_nonExistentObject() {
|
void maybeLoad_nonExistentObject() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().loadByKeyIfPresent(theEntityKey)).isPresent())
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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));
|
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.name).isEqualTo("compoundIdEntity");
|
||||||
assertThat(persisted.age).isEqualTo(10);
|
assertThat(persisted.age).isEqualTo(10);
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -424,7 +426,8 @@ class JpaTransactionManagerImplTest {
|
||||||
@Test
|
@Test
|
||||||
void loadAll_succeeds() {
|
void loadAll_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
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);
|
assertThat(persisted).containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class TransactionManagerTest {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().insert(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
|
TestEntity persisted = tm().transactNewReadOnly(() -> tm().loadByKey(theEntity.key()));
|
||||||
assertThat(persisted).isEqualTo(theEntity);
|
assertThat(persisted).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public class TransactionManagerTest {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().insert(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
|
@ -165,18 +165,18 @@ public class TransactionManagerTest {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().put(theEntity));
|
tm().transact(() -> tm().put(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void saveNewOrUpdate_updatesExistingEntity() {
|
void saveNewOrUpdate_updatesExistingEntity() {
|
||||||
tm().transact(() -> tm().insert(theEntity));
|
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");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().put(theEntity));
|
tm().transact(() -> tm().put(theEntity));
|
||||||
persisted = tm().transact(() -> tm().load(theEntity.key()));
|
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,13 +193,13 @@ public class TransactionManagerTest {
|
||||||
TestEntity persisted =
|
TestEntity persisted =
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
tm().load(
|
tm().loadByKey(
|
||||||
VKey.create(TestEntity.class, theEntity.name, Key.create(theEntity))));
|
VKey.create(TestEntity.class, theEntity.name, Key.create(theEntity))));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().update(theEntity));
|
tm().transact(() -> tm().update(theEntity));
|
||||||
persisted = tm().transact(() -> tm().load(theEntity.key()));
|
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ public class TransactionManagerTest {
|
||||||
void load_succeeds() {
|
void load_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().insert(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.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
@ -216,14 +216,14 @@ public class TransactionManagerTest {
|
||||||
void load_throwsOnMissingElement() {
|
void load_throwsOnMissingElement() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NoSuchElementException.class, () -> tm().transact(() -> tm().load(theEntity.key())));
|
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKey(theEntity.key())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void maybeLoad_succeeds() {
|
void maybeLoad_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().insert(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.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ public class TransactionManagerTest {
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void maybeLoad_nonExistentObject() {
|
void maybeLoad_nonExistentObject() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
assertThat(tm().transact(() -> tm().maybeLoad(theEntity.key())).isPresent()).isFalse();
|
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key())).isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
|
@ -292,7 +292,7 @@ public class TransactionManagerTest {
|
||||||
tm().transact(() -> tm().insertAll(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
List<VKey<TestEntity>> keys =
|
List<VKey<TestEntity>> keys =
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
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));
|
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ public class TransactionManagerTest {
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||||
ImmutableList<VKey<TestEntity>> doubleKeys =
|
ImmutableList<VKey<TestEntity>> doubleKeys =
|
||||||
Stream.concat(keys.stream(), keys.stream()).collect(toImmutableList());
|
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));
|
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,16 +316,66 @@ public class TransactionManagerTest {
|
||||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||||
.map(TestEntity::key)
|
.map(TestEntity::key)
|
||||||
.collect(toImmutableList());
|
.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));
|
.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
|
@TestOfyOnly
|
||||||
void loadAllForOfyTm_throwsExceptionInTransaction() {
|
void loadAllForOfyTm_throwsExceptionInTransaction() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().insertAll(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> tm().transact(() -> tm().loadAll(TestEntity.class)));
|
IllegalArgumentException.class,
|
||||||
|
() -> tm().transact(() -> tm().loadAllOf(TestEntity.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertEntityExists(TestEntity entity) {
|
private static void assertEntityExists(TestEntity entity) {
|
||||||
|
|
|
@ -60,8 +60,8 @@ class TransactionTest {
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
|
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
|
||||||
assertThat(ofyTm().load(barEntity.key())).isEqualTo(barEntity);
|
assertThat(ofyTm().loadByKey(barEntity.key())).isEqualTo(barEntity);
|
||||||
});
|
});
|
||||||
|
|
||||||
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
|
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
|
||||||
|
@ -82,7 +82,7 @@ class TransactionTest {
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
|
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
|
||||||
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
|
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -111,14 +111,14 @@ class TransactionTest {
|
||||||
jpaTm().insert(barEntity);
|
jpaTm().insert(barEntity);
|
||||||
});
|
});
|
||||||
TransactionEntity txnEnt =
|
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);
|
Transaction txn = Transaction.deserialize(txnEnt.contents);
|
||||||
txn.writeToDatastore();
|
txn.writeToDatastore();
|
||||||
ofyTm()
|
ofyTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
|
assertThat(ofyTm().loadByKey(fooEntity.key())).isEqualTo(fooEntity);
|
||||||
assertThat(ofyTm().load(barEntity.key())).isEqualTo(barEntity);
|
assertThat(ofyTm().loadByKey(barEntity.key())).isEqualTo(barEntity);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that no transaction was persisted for the load transaction.
|
// Verify that no transaction was persisted for the load transaction.
|
||||||
|
|
|
@ -67,7 +67,7 @@ class RegistrarContactTest {
|
||||||
void testPersistence_succeeds() {
|
void testPersistence_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc));
|
||||||
RegistrarContact persisted =
|
RegistrarContact persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
|
jpaTm().transact(() -> jpaTm().loadByKey(testRegistrarPoc.createVKey()));
|
||||||
assertThat(persisted).isEqualTo(testRegistrarPoc);
|
assertThat(persisted).isEqualTo(testRegistrarPoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class RegistrarDaoTest {
|
||||||
@Test
|
@Test
|
||||||
void update_worksSuccessfully() {
|
void update_worksSuccessfully() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
|
||||||
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
Registrar persisted = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
|
||||||
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -86,7 +86,7 @@ public class RegistrarDaoTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.update(
|
.update(
|
||||||
persisted.asBuilder().setRegistrarName("changedRegistrarName").build()));
|
persisted.asBuilder().setRegistrarName("changedRegistrarName").build()));
|
||||||
Registrar updated = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
Registrar updated = jpaTm().transact(() -> jpaTm().loadByKey(registrarKey));
|
||||||
assertThat(updated.getRegistrarName()).isEqualTo("changedRegistrarName");
|
assertThat(updated.getRegistrarName()).isEqualTo("changedRegistrarName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public class RegistrarDaoTest {
|
||||||
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));
|
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.getClientId()).isEqualTo("registrarId");
|
||||||
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
||||||
|
|
|
@ -413,7 +413,7 @@ public class DatabaseHelper {
|
||||||
// PremiumListUtils.savePremiumListAndEntries(). Clearing the session cache can help make sure
|
// PremiumListUtils.savePremiumListAndEntries(). Clearing the session cache can help make sure
|
||||||
// we always get the same list.
|
// we always get the same list.
|
||||||
tm().clearSessionCache();
|
tm().clearSessionCache();
|
||||||
return transactIfJpaTm(() -> tm().load(premiumList));
|
return transactIfJpaTm(() -> tm().loadByEntity(premiumList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates and persists a tld. */
|
/** Creates and persists a tld. */
|
||||||
|
@ -673,13 +673,13 @@ public class DatabaseHelper {
|
||||||
.build());
|
.build());
|
||||||
// Modify the existing autorenew event to reflect the pending transfer.
|
// Modify the existing autorenew event to reflect the pending transfer.
|
||||||
persistResource(
|
persistResource(
|
||||||
tm().load(domain.getAutorenewBillingEvent())
|
tm().loadByKey(domain.getAutorenewBillingEvent())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setRecurrenceEndTime(expirationTime)
|
.setRecurrenceEndTime(expirationTime)
|
||||||
.build());
|
.build());
|
||||||
// Update the end time of the existing autorenew poll message. We must delete it if it has no
|
// Update the end time of the existing autorenew poll message. We must delete it if it has no
|
||||||
// events left in it.
|
// events left in it.
|
||||||
PollMessage.Autorenew autorenewPollMessage = tm().load(domain.getAutorenewPollMessage());
|
PollMessage.Autorenew autorenewPollMessage = tm().loadByKey(domain.getAutorenewPollMessage());
|
||||||
if (autorenewPollMessage.getEventTime().isBefore(expirationTime)) {
|
if (autorenewPollMessage.getEventTime().isBefore(expirationTime)) {
|
||||||
persistResource(
|
persistResource(
|
||||||
autorenewPollMessage.asBuilder()
|
autorenewPollMessage.asBuilder()
|
||||||
|
@ -768,22 +768,22 @@ public class DatabaseHelper {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
Iterables.concat(
|
Iterables.concat(
|
||||||
tm().loadAll(BillingEvent.OneTime.class),
|
tm().loadAllOf(BillingEvent.OneTime.class),
|
||||||
tm().loadAll(BillingEvent.Recurring.class),
|
tm().loadAllOf(BillingEvent.Recurring.class),
|
||||||
tm().loadAll(BillingEvent.Cancellation.class)));
|
tm().loadAllOf(BillingEvent.Cancellation.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Iterable<BillingEvent> getBillingEvents(EppResource resource) {
|
private static Iterable<BillingEvent> getBillingEvents(EppResource resource) {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
Iterables.concat(
|
Iterables.concat(
|
||||||
tm().loadAll(BillingEvent.OneTime.class).stream()
|
tm().loadAllOf(BillingEvent.OneTime.class).stream()
|
||||||
.filter(oneTime -> oneTime.getDomainRepoId().equals(resource.getRepoId()))
|
.filter(oneTime -> oneTime.getDomainRepoId().equals(resource.getRepoId()))
|
||||||
.collect(toImmutableList()),
|
.collect(toImmutableList()),
|
||||||
tm().loadAll(BillingEvent.Recurring.class).stream()
|
tm().loadAllOf(BillingEvent.Recurring.class).stream()
|
||||||
.filter(recurring -> recurring.getDomainRepoId().equals(resource.getRepoId()))
|
.filter(recurring -> recurring.getDomainRepoId().equals(resource.getRepoId()))
|
||||||
.collect(toImmutableList()),
|
.collect(toImmutableList()),
|
||||||
tm().loadAll(BillingEvent.Cancellation.class).stream()
|
tm().loadAllOf(BillingEvent.Cancellation.class).stream()
|
||||||
.filter(
|
.filter(
|
||||||
cancellation -> cancellation.getDomainRepoId().equals(resource.getRepoId()))
|
cancellation -> cancellation.getDomainRepoId().equals(resource.getRepoId()))
|
||||||
.collect(toImmutableList())));
|
.collect(toImmutableList())));
|
||||||
|
@ -860,13 +860,13 @@ public class DatabaseHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableList<PollMessage> getPollMessages() {
|
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) {
|
public static ImmutableList<PollMessage> getPollMessages(String clientId) {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(PollMessage.class).stream()
|
tm().loadAllOf(PollMessage.class).stream()
|
||||||
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
|
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
}
|
}
|
||||||
|
@ -874,7 +874,7 @@ public class DatabaseHelper {
|
||||||
public static ImmutableList<PollMessage> getPollMessages(DomainContent domain) {
|
public static ImmutableList<PollMessage> getPollMessages(DomainContent domain) {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(PollMessage.class).stream()
|
tm().loadAllOf(PollMessage.class).stream()
|
||||||
.filter(
|
.filter(
|
||||||
pollMessage ->
|
pollMessage ->
|
||||||
pollMessage.getParentKey().getParent().getName().equals(domain.getRepoId()))
|
pollMessage.getParentKey().getParent().getName().equals(domain.getRepoId()))
|
||||||
|
@ -884,7 +884,7 @@ public class DatabaseHelper {
|
||||||
public static ImmutableList<PollMessage> getPollMessages(String clientId, DateTime now) {
|
public static ImmutableList<PollMessage> getPollMessages(String clientId, DateTime now) {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(PollMessage.class).stream()
|
tm().loadAllOf(PollMessage.class).stream()
|
||||||
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
|
.filter(pollMessage -> pollMessage.getClientId().equals(clientId))
|
||||||
.filter(
|
.filter(
|
||||||
pollMessage ->
|
pollMessage ->
|
||||||
|
@ -898,7 +898,7 @@ public class DatabaseHelper {
|
||||||
EppResource resource, String clientId, DateTime now) {
|
EppResource resource, String clientId, DateTime now) {
|
||||||
return transactIfJpaTm(
|
return transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(PollMessage.class).stream()
|
tm().loadAllOf(PollMessage.class).stream()
|
||||||
.filter(
|
.filter(
|
||||||
pollMessage ->
|
pollMessage ->
|
||||||
pollMessage
|
pollMessage
|
||||||
|
@ -942,7 +942,7 @@ public class DatabaseHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertAllocationTokens(AllocationToken... expectedTokens) {
|
public static void assertAllocationTokens(AllocationToken... expectedTokens) {
|
||||||
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class)))
|
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class)))
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence("updateTimestamp", "creationTime"))
|
.comparingElementsUsing(immutableObjectCorrespondence("updateTimestamp", "creationTime"))
|
||||||
.containsExactlyElementsIn(expectedTokens);
|
.containsExactlyElementsIn(expectedTokens);
|
||||||
}
|
}
|
||||||
|
@ -1018,7 +1018,7 @@ public class DatabaseHelper {
|
||||||
// (unmarshalling entity protos to POJOs, nulling out empty collections, calling @OnLoad
|
// (unmarshalling entity protos to POJOs, nulling out empty collections, calling @OnLoad
|
||||||
// methods, etc.) which is bypassed for entities loaded from the session cache.
|
// methods, etc.) which is bypassed for entities loaded from the session cache.
|
||||||
tm().clearSessionCache();
|
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. */
|
/** Persists an EPP resource with the {@link EppResourceIndex} always going into bucket one. */
|
||||||
|
@ -1037,7 +1037,7 @@ public class DatabaseHelper {
|
||||||
});
|
});
|
||||||
maybeAdvanceClock();
|
maybeAdvanceClock();
|
||||||
tm().clearSessionCache();
|
tm().clearSessionCache();
|
||||||
return transactIfJpaTm(() -> tm().load(resource));
|
return transactIfJpaTm(() -> tm().loadByEntity(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R> void persistResources(final Iterable<R> resources) {
|
public static <R> void persistResources(final Iterable<R> resources) {
|
||||||
|
@ -1059,7 +1059,7 @@ public class DatabaseHelper {
|
||||||
// and not from the transaction's session cache.
|
// and not from the transaction's session cache.
|
||||||
tm().clearSessionCache();
|
tm().clearSessionCache();
|
||||||
for (R resource : resources) {
|
for (R resource : resources) {
|
||||||
transactIfJpaTm(() -> tm().load(resource));
|
transactIfJpaTm(() -> tm().loadByEntity(resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,7 +1090,7 @@ public class DatabaseHelper {
|
||||||
});
|
});
|
||||||
maybeAdvanceClock();
|
maybeAdvanceClock();
|
||||||
tm().clearSessionCache();
|
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. */
|
/** 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;
|
ImmutableList<? extends HistoryEntry> unsorted = null;
|
||||||
if (resource instanceof ContactBase) {
|
if (resource instanceof ContactBase) {
|
||||||
unsorted = tm().loadAll(ContactHistory.class);
|
unsorted = tm().loadAllOf(ContactHistory.class);
|
||||||
} else if (resource instanceof HostBase) {
|
} else if (resource instanceof HostBase) {
|
||||||
unsorted = tm().loadAll(HostHistory.class);
|
unsorted = tm().loadAllOf(HostHistory.class);
|
||||||
} else if (resource instanceof DomainContent) {
|
} else if (resource instanceof DomainContent) {
|
||||||
unsorted = tm().loadAll(DomainHistory.class);
|
unsorted = tm().loadAllOf(DomainHistory.class);
|
||||||
} else {
|
} else {
|
||||||
fail("Expected an EppResource instance, but got " + resource.getClass());
|
fail("Expected an EppResource instance, but got " + resource.getClass());
|
||||||
}
|
}
|
||||||
|
@ -1161,7 +1161,7 @@ public class DatabaseHelper {
|
||||||
return Iterables.getOnlyElement(
|
return Iterables.getOnlyElement(
|
||||||
transactIfJpaTm(
|
transactIfJpaTm(
|
||||||
() ->
|
() ->
|
||||||
tm().loadAll(PollMessage.class).stream()
|
tm().loadAllOf(PollMessage.class).stream()
|
||||||
.filter(
|
.filter(
|
||||||
pollMessage -> pollMessage.getParentKey().equals(Key.create(historyEntry)))
|
pollMessage -> pollMessage.getParentKey().equals(Key.create(historyEntry)))
|
||||||
.collect(toImmutableList())));
|
.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
|
// 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.
|
// and not from the transaction's session cache.
|
||||||
tm().clearSessionCache();
|
tm().clearSessionCache();
|
||||||
return transactIfJpaTm(() -> tm().loadAll(resources));
|
return transactIfJpaTm(() -> tm().loadByEntities(resources));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteResource(final Object resource) {
|
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
|
// otherwise JPA would just return the input entity instead of actually creating a
|
||||||
// clone.
|
// clone.
|
||||||
tm().transact(() -> tm().put(resource));
|
tm().transact(() -> tm().put(resource));
|
||||||
result = tm().transact(() -> tm().load(resource));
|
result = tm().transact(() -> tm().loadByEntity(resource));
|
||||||
}
|
}
|
||||||
maybeAdvanceClock();
|
maybeAdvanceClock();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class SqlHelper {
|
||||||
public static Registrar saveRegistrar(String clientId) {
|
public static Registrar saveRegistrar(String clientId) {
|
||||||
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
|
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
|
||||||
jpaTm().transact(() -> jpaTm().insert(registrar));
|
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) {
|
public static void assertThrowForeignKeyViolation(Executable executable) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
|
||||||
persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
|
persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
|
||||||
VKey<OneTime> pm4 = futurePollMessage.createVKey();
|
VKey<OneTime> pm4 = futurePollMessage.createVKey();
|
||||||
runCommand("-c", "TheRegistrar");
|
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);
|
.containsExactly(futurePollMessage);
|
||||||
assertInStdout(
|
assertInStdout(
|
||||||
"1-FSDGS-TLD-2406-624-2013,2013-05-01T22:33:44.000Z,ninelives",
|
"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();
|
autorenew.asBuilder().setEventTime(DateTime.parse("2012-04-15T22:33:44Z")).build();
|
||||||
VKey<Autorenew> pm3 = autorenew.createVKey();
|
VKey<Autorenew> pm3 = autorenew.createVKey();
|
||||||
runCommand("-c", "TheRegistrar");
|
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(
|
assertInStdout(
|
||||||
"1-AAFSGS-TLD-99406-624-2011,2011-04-15T22:33:44.000Z,autorenew",
|
"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",
|
"1-FSDGS-TLD-2406-624-2013,2013-05-01T22:33:44.000Z,ninelives",
|
||||||
|
@ -117,7 +118,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
|
||||||
.build());
|
.build());
|
||||||
VKey<Autorenew> pm3 = autorenew.createVKey();
|
VKey<Autorenew> pm3 = autorenew.createVKey();
|
||||||
runCommand("-c", "TheRegistrar");
|
runCommand("-c", "TheRegistrar");
|
||||||
assertThat(tm().load(ImmutableList.of(pm1, pm2, pm3))).isEmpty();
|
assertThat(tm().loadByKeysIfPresent(ImmutableList.of(pm1, pm2, pm3))).isEmpty();
|
||||||
assertInStdout(
|
assertInStdout(
|
||||||
"1-AAFSGS-TLD-99406-624-2011,2011-04-15T22:33:44.000Z,autorenew",
|
"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",
|
"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");
|
persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "time flies");
|
||||||
VKey<OneTime> pm4 = notMatched2.createVKey();
|
VKey<OneTime> pm4 = notMatched2.createVKey();
|
||||||
runCommand("-c", "TheRegistrar", "-m", "food");
|
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);
|
.containsExactly(notMatched1, notMatched2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +164,8 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
|
||||||
.build());
|
.build());
|
||||||
VKey<OneTime> pm3 = notMatched.createVKey();
|
VKey<OneTime> pm3 = notMatched.createVKey();
|
||||||
runCommand("-c", "TheRegistrar");
|
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
|
@Test
|
||||||
|
@ -174,7 +176,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
|
||||||
OneTime pm4 = persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
|
OneTime pm4 = persistPollMessage(123L, DateTime.parse("2015-09-01T22:33:44Z"), "notme");
|
||||||
runCommand("-c", "TheRegistrar", "-d");
|
runCommand("-c", "TheRegistrar", "-d");
|
||||||
assertThat(
|
assertThat(
|
||||||
tm().load(
|
tm().loadByKeys(
|
||||||
ImmutableList.of(pm1, pm2, pm3, pm4).stream()
|
ImmutableList.of(pm1, pm2, pm3, pm4).stream()
|
||||||
.map(OneTime::createVKey)
|
.map(OneTime::createVKey)
|
||||||
.collect(toImmutableList()))
|
.collect(toImmutableList()))
|
||||||
|
|
|
@ -186,12 +186,12 @@ public abstract class CommandTestCase<C extends Command> {
|
||||||
|
|
||||||
/** Reloads the given resource from Datastore. */
|
/** Reloads the given resource from Datastore. */
|
||||||
<T> T reloadResource(T resource) {
|
<T> T reloadResource(T resource) {
|
||||||
return transactIfJpaTm(() -> tm().load(resource));
|
return transactIfJpaTm(() -> tm().loadByEntity(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns count of all poll messages in Datastore. */
|
/** Returns count of all poll messages in Datastore. */
|
||||||
int getPollMessageCount() {
|
int getPollMessageCount() {
|
||||||
return transactIfJpaTm(() -> tm().loadAll(PollMessage.class).size());
|
return transactIfJpaTm(() -> tm().loadAllOf(PollMessage.class).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -134,9 +134,9 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
persistToken(String.format("batch%2d", i), null, i % 2 == 0);
|
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");
|
runCommandForced("--prefix", "batch");
|
||||||
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size()))
|
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size()))
|
||||||
.isEqualTo(56 - 25);
|
.isEqualTo(56 - 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableList<AllocationToken> reloadTokens(AllocationToken... tokens) {
|
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) {
|
private static void assertNonexistent(AllocationToken... tokens) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
|
||||||
runCommand("--prefix", "ooo", "--number", "100", "--length", "16");
|
runCommand("--prefix", "ooo", "--number", "100", "--length", "16");
|
||||||
// The deterministic string generator makes it too much hassle to assert about each token, so
|
// The deterministic string generator makes it too much hassle to assert about each token, so
|
||||||
// just assert total number.
|
// just assert total number.
|
||||||
assertThat(transactIfJpaTm(() -> tm().loadAll(AllocationToken.class).size())).isEqualTo(100);
|
assertThat(transactIfJpaTm(() -> tm().loadAllOf(AllocationToken.class).size())).isEqualTo(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
|
@ -199,7 +199,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
|
||||||
Collection<String> sampleTokens = command.stringGenerator.createStrings(13, 100);
|
Collection<String> sampleTokens = command.stringGenerator.createStrings(13, 100);
|
||||||
runCommand("--tokens", Joiner.on(",").join(sampleTokens));
|
runCommand("--tokens", Joiner.on(",").join(sampleTokens));
|
||||||
assertInStdout(Iterables.toArray(sampleTokens, String.class));
|
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
|
@TestOfyAndSql
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
|
||||||
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC);
|
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC);
|
||||||
|
|
||||||
assertBillingEventsEqual(
|
assertBillingEventsEqual(
|
||||||
tm().load(domain.getAutorenewBillingEvent()),
|
tm().loadByKey(domain.getAutorenewBillingEvent()),
|
||||||
new BillingEvent.Recurring.Builder()
|
new BillingEvent.Recurring.Builder()
|
||||||
.setParent(synthetic)
|
.setParent(synthetic)
|
||||||
.setReason(Reason.RENEW)
|
.setReason(Reason.RENEW)
|
||||||
|
|
|
@ -68,7 +68,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
||||||
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
|
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
|
||||||
assertThat(
|
assertThat(
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(() -> jpaTm().load(VKey.createSql(Registrar.class, "NewRegistrar")))
|
.transact(() -> jpaTm().loadByKey(VKey.createSql(Registrar.class, "NewRegistrar")))
|
||||||
.verifyPassword("some_password"))
|
.verifyPassword("some_password"))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
ImmutableList<Spec11ThreatMatch> threatMatches =
|
ImmutableList<Spec11ThreatMatch> threatMatches =
|
||||||
jpaTm().loadAll(Spec11ThreatMatch.class);
|
jpaTm().loadAllOf(Spec11ThreatMatch.class);
|
||||||
assertThat(threatMatches).hasSize(6);
|
assertThat(threatMatches).hasSize(6);
|
||||||
assertThat(
|
assertThat(
|
||||||
threatMatches.stream()
|
threatMatches.stream()
|
||||||
|
@ -151,7 +151,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() ->
|
() ->
|
||||||
jpaTm().loadAll(Spec11ThreatMatch.class).stream()
|
jpaTm().loadAllOf(Spec11ThreatMatch.class).stream()
|
||||||
.filter((match) -> match.getDomainName().equals("a.com"))
|
.filter((match) -> match.getDomainName().equals("a.com"))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.get()
|
.get()
|
||||||
|
@ -177,7 +177,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
|
||||||
|
|
||||||
runCommandForced();
|
runCommandForced();
|
||||||
ImmutableList<Spec11ThreatMatch> threatMatches =
|
ImmutableList<Spec11ThreatMatch> threatMatches =
|
||||||
jpaTm().transact(() -> jpaTm().loadAll(Spec11ThreatMatch.class));
|
jpaTm().transact(() -> jpaTm().loadAllOf(Spec11ThreatMatch.class));
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(Iterables.getOnlyElement(threatMatches))
|
.that(Iterables.getOnlyElement(threatMatches))
|
||||||
.isEqualExceptFields(previous, "id");
|
.isEqualExceptFields(previous, "id");
|
||||||
|
@ -212,7 +212,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
|
||||||
assertThrows(RuntimeException.class, this::runCommandForced);
|
assertThrows(RuntimeException.class, this::runCommandForced);
|
||||||
assertThat(runtimeException.getCause().getClass()).isEqualTo(IOException.class);
|
assertThat(runtimeException.getCause().getClass()).isEqualTo(IOException.class);
|
||||||
assertThat(runtimeException).hasCauseThat().hasMessageThat().isEqualTo("hi");
|
assertThat(runtimeException).hasCauseThat().hasMessageThat().isEqualTo("hi");
|
||||||
jpaTm().transact(() -> assertThat(jpaTm().loadAll(Spec11ThreatMatch.class)).isEmpty());
|
jpaTm().transact(() -> assertThat(jpaTm().loadAllOf(Spec11ThreatMatch.class)).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -249,7 +249,7 @@ public class BackfillSpec11ThreatMatchesCommandTest
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
ImmutableList<Spec11ThreatMatch> threatMatches =
|
ImmutableList<Spec11ThreatMatch> threatMatches =
|
||||||
jpaTm().loadAll(Spec11ThreatMatch.class);
|
jpaTm().loadAllOf(Spec11ThreatMatch.class);
|
||||||
assertThat(threatMatches)
|
assertThat(threatMatches)
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence("id", "domainRepoId"))
|
.comparingElementsUsing(immutableObjectCorrespondence("id", "domainRepoId"))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue