From 5098b03af48c336232ad9e2e1e3534d6187970e1 Mon Sep 17 00:00:00 2001 From: cgoldfeder Date: Thu, 1 Sep 2016 10:44:23 -0700 Subject: [PATCH] DeReference the codebase This change replaces all Ref objects in the code with Key objects. These are stored in datastore as the same object (raw datastore keys), so this is not a model change. Our best practices doc says to use Keys not Refs because: * The .get() method obscures what's actually going on - Much harder to visually audit the code for datastore loads - Hard to distinguish Ref get()'s from Optional get()'s and Supplier get()'s * Implicit ofy().load() offers much less control - Antipattern for ultimate goal of making Ofy injectable - Can't control cache use or batch loading without making ofy() explicit anyway * Serialization behavior is surprising and could be quite dangerous/incorrect - Can lead to serialization errors. If it actually worked "as intended", it would lead to a Ref<> on a serialized object being replaced upon deserialization with a stale copy of the old value, which could potentially break all kinds of transactional expectations * Having both Ref and Key introduces extra boilerplate everywhere - E.g. helper methods all need to have Ref and Key overloads, or you need to call .key() to get the Key for every Ref you want to pass in - Creating a Ref is more cumbersome, since it doesn't have all the create() overloads that Key has, only create(Key) and create(Entity) - no way to create directly from kind+ID/name, raw Key, websafe key string, etc. (Note that Refs are treated specially by Objectify's @Load method and Keys are not; we don't use that feature, but it is the one advantage Refs have over Keys.) The direct impetus for this change is that I am trying to audit our use of memcache, and the implicit .get() calls to datastore were making that very hard. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131965491 --- .../flows/ResourceAsyncDeleteFlow.java | 8 +- .../async/DeleteContactResourceAction.java | 6 +- .../flows/async/DeleteEppResourceAction.java | 9 +-- .../flows/async/DeleteHostResourceAction.java | 8 +- .../async/DnsRefreshForHostRenameAction.java | 3 +- .../flows/contact/ContactDeleteFlow.java | 7 +- .../flows/domain/DomainAllocateFlow.java | 4 +- .../domain/DomainApplicationCreateFlow.java | 4 +- .../domain/DomainCreateOrAllocateFlow.java | 6 +- .../flows/domain/DomainDeleteFlow.java | 10 ++- .../flows/domain/DomainFlowUtils.java | 21 +++-- .../flows/domain/DomainRenewFlow.java | 6 +- .../domain/DomainRestoreRequestFlow.java | 6 +- .../domain/DomainTransferApproveFlow.java | 6 +- .../domain/DomainTransferRequestFlow.java | 9 +-- .../flows/domain/DomainUpdateFlow.java | 2 +- .../registry/flows/host/HostCreateFlow.java | 6 +- .../registry/flows/host/HostDeleteFlow.java | 7 +- .../registry/flows/host/HostFlowUtils.java | 12 +-- .../registry/flows/host/HostUpdateFlow.java | 22 +++--- .../inputs/EppResourceEntityReader.java | 11 +-- .../inputs/EppResourceKeyReader.java | 2 +- java/google/registry/model/EppResource.java | 6 +- .../registry/model/EppResourceUtils.java | 39 +++++----- .../registry/model/ImmutableObject.java | 13 ++-- java/google/registry/model/ModelUtils.java | 7 +- .../registry/model/billing/BillingEvent.java | 46 ++++++----- .../model/billing/RegistrarCredit.java | 10 +-- .../model/billing/RegistrarCreditBalance.java | 19 ++--- .../model/domain/DesignatedContact.java | 8 +- .../registry/model/domain/DomainAuthInfo.java | 11 +-- .../registry/model/domain/DomainBase.java | 38 ++++----- .../registry/model/domain/DomainCommand.java | 46 +++++------ .../registry/model/domain/DomainResource.java | 27 ++++--- .../registry/model/domain/GracePeriod.java | 20 ++--- .../registry/model/domain/ReferenceUnion.java | 10 +-- .../registry/model/host/HostResource.java | 12 +-- .../model/index/DomainApplicationIndex.java | 31 ++++---- .../model/index/EppResourceIndex.java | 8 +- .../registry/model/index/ForeignKeyIndex.java | 16 ++-- .../registry/label/BaseDomainLabelList.java | 4 +- .../model/registry/label/PremiumList.java | 2 +- .../model/registry/label/ReservedList.java | 2 +- .../model/reporting/HistoryEntry.java | 11 +-- .../registry/model/transfer/TransferData.java | 22 +++--- .../CommitLogRevisionsTranslatorFactory.java | 16 ++-- .../whitebox/VerifyEntityIntegrityAction.java | 39 +++------- .../registry/rdap/RdapDomainSearchAction.java | 73 +++++++---------- .../registry/rdap/RdapJsonFormatter.java | 7 +- .../rde/DomainResourceToXjcConverter.java | 10 ++- .../registry/tools/AllocateDomainCommand.java | 4 +- .../registry/tools/AuctionStatusCommand.java | 2 +- .../tools/DeleteEppResourceCommand.java | 2 +- .../GenerateApplicationsReportCommand.java | 2 +- .../tools/GenerateAuctionDataCommand.java | 3 +- .../tools/GenerateEscrowDepositCommand.java | 2 +- .../tools/UniformRapidSuspensionCommand.java | 6 +- .../tools/server/GenerateZoneFilesAction.java | 2 +- .../server/KillAllEppResourcesAction.java | 4 +- .../registry/whois/DomainWhoisResponse.java | 11 +-- .../writer/clouddns/CloudDnsWriterTest.java | 6 +- .../writer/dnsupdate/DnsUpdateWriterTest.java | 18 ++--- .../export/sheet/SyncRegistrarsSheetTest.java | 2 +- .../registry/flows/EppCommitLogsTest.java | 4 +- .../google/registry/flows/FlowTestCase.java | 9 ++- .../registry/flows/ResourceFlowTestCase.java | 3 +- .../DeleteContactResourceActionTest.java | 3 +- .../DeleteEppResourceActionTestCase.java | 3 +- .../async/DeleteHostResourceActionTest.java | 5 +- .../DnsRefreshForHostRenameActionTest.java | 21 +++-- .../flows/domain/DomainAllocateFlowTest.java | 7 +- .../DomainApplicationDeleteFlowTest.java | 6 +- .../domain/DomainApplicationInfoFlowTest.java | 16 ++-- .../DomainApplicationUpdateFlowTest.java | 38 ++++----- .../flows/domain/DomainCreateFlowTest.java | 3 +- .../flows/domain/DomainDeleteFlowTest.java | 38 ++++----- .../flows/domain/DomainInfoFlowTest.java | 19 +++-- .../flows/domain/DomainRenewFlowTest.java | 12 +-- .../domain/DomainRestoreRequestFlowTest.java | 5 +- .../domain/DomainTransferApproveFlowTest.java | 5 +- .../domain/DomainTransferFlowTestCase.java | 14 ++-- .../domain/DomainTransferRequestFlowTest.java | 13 ++-- .../flows/domain/DomainUpdateFlowTest.java | 78 ++++++++++--------- .../flows/host/HostCreateFlowTest.java | 8 +- .../flows/host/HostDeleteFlowTest.java | 5 +- .../registry/flows/host/HostInfoFlowTest.java | 7 +- .../flows/host/HostUpdateFlowTest.java | 35 ++++----- .../registry/model/EppResourceUtilsTest.java | 2 +- .../registry/model/ImmutableObjectTest.java | 38 ++++----- .../model/billing/BillingEventTest.java | 17 ++-- .../model/domain/DomainApplicationTest.java | 11 ++- .../model/domain/DomainResourceTest.java | 37 +++++---- .../model/domain/GracePeriodTest.java | 5 +- .../registry/model/host/HostResourceTest.java | 5 +- .../index/DomainApplicationIndexTest.java | 20 ++--- .../model/index/EppResourceIndexTest.java | 4 +- .../model/index/ForeignKeyIndexTest.java | 7 +- .../google/registry/model/ofy/OfyTest.java | 3 +- javatests/google/registry/model/schema.txt | 52 ++++++------- .../model/transfer/TransferDataTest.java | 18 +++-- ...mmitLogRevisionsTranslatorFactoryTest.java | 13 ++-- .../VerifyEntityIntegrityActionTest.java | 7 +- .../rdap/RdapDomainSearchActionTest.java | 6 +- .../rdap/RdapNameserverSearchActionTest.java | 6 +- .../rde/DomainResourceToXjcConverterTest.java | 23 +++--- .../google/registry/rde/RdeFixtures.java | 23 +++--- .../registry/rde/RdeImportUtilsTest.java | 2 +- javatests/google/registry/server/Fixture.java | 28 +++---- .../registry/testing/DatastoreHelper.java | 35 +++++---- .../testing/FullFieldsTestEntityHelper.java | 14 ++-- .../google/registry/tmch/LordnTaskTest.java | 4 +- .../tools/AllocateDomainCommandTest.java | 14 ++-- .../tools/CreateCreditBalanceCommandTest.java | 2 +- .../tools/CreateCreditCommandTest.java | 4 +- .../tools/GenerateDnsReportCommandTest.java | 6 +- .../UniformRapidSuspensionCommandTest.java | 6 +- .../server/GenerateZoneFilesActionTest.java | 6 +- .../whois/DomainWhoisResponseTest.java | 20 ++--- .../whois/RegistrarWhoisResponseTest.java | 2 +- 119 files changed, 772 insertions(+), 817 deletions(-) diff --git a/java/google/registry/flows/ResourceAsyncDeleteFlow.java b/java/google/registry/flows/ResourceAsyncDeleteFlow.java index ae0b78835..f145d6571 100644 --- a/java/google/registry/flows/ResourceAsyncDeleteFlow.java +++ b/java/google/registry/flows/ResourceAsyncDeleteFlow.java @@ -17,7 +17,7 @@ package google.registry.flows; import static google.registry.model.eppoutput.Result.Code.SuccessWithActionPending; import static google.registry.model.ofy.ObjectifyService.ofy; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.Work; import google.registry.flows.EppException.AssociationProhibitsOperationException; import google.registry.model.EppResource; @@ -50,7 +50,7 @@ public abstract class ResourceAsyncDeleteFlow // that would be hard to reason about, and there's no real gain in doing so. return false; } - return isLinkedForFailfast(fki.getReference()); + return isLinkedForFailfast(fki.getResourceKey()); } }); if (isLinked) { @@ -58,8 +58,8 @@ public abstract class ResourceAsyncDeleteFlow } } - /** Subclasses must override this to check if the supplied reference has incoming links. */ - protected abstract boolean isLinkedForFailfast(Ref ref); + /** Subclasses must override this to check if the supplied key has incoming links. */ + protected abstract boolean isLinkedForFailfast(Key key); @Override protected final R createOrMutateResource() { diff --git a/java/google/registry/flows/async/DeleteContactResourceAction.java b/java/google/registry/flows/async/DeleteContactResourceAction.java index 7de91fe30..f129407ea 100644 --- a/java/google/registry/flows/async/DeleteContactResourceAction.java +++ b/java/google/registry/flows/async/DeleteContactResourceAction.java @@ -16,7 +16,7 @@ package google.registry.flows.async; import static google.registry.flows.ResourceFlowUtils.handlePendingTransferOnDelete; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainBase; import google.registry.model.reporting.HistoryEntry; @@ -46,8 +46,8 @@ public class DeleteContactResourceAction extends DeleteEppResourceAction targetResourceRef) { - return domain.getReferencedContacts().contains(targetResourceRef); + DomainBase domain, Key targetResourceKey) { + return domain.getReferencedContacts().contains(targetResourceKey); } } diff --git a/java/google/registry/flows/async/DeleteEppResourceAction.java b/java/google/registry/flows/async/DeleteEppResourceAction.java index 0bb3234c1..e7624c1f1 100644 --- a/java/google/registry/flows/async/DeleteEppResourceAction.java +++ b/java/google/registry/flows/async/DeleteEppResourceAction.java @@ -30,7 +30,6 @@ import com.google.appengine.tools.mapreduce.ReducerInput; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.Work; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; @@ -142,7 +141,7 @@ public abstract class DeleteEppResourceAction implements } /** Determine whether the target resource is a linked resource on the domain. */ - protected abstract boolean isLinked(DomainBase domain, Ref targetResourceRef); + protected abstract boolean isLinked(DomainBase domain, Key targetResourceKey); @Override public void map(DomainBase domain) { @@ -154,12 +153,8 @@ public abstract class DeleteEppResourceAction implements emit(targetEppResourceKey, false); return; } - // The Ref can't be a field on the Mapper, because when a Ref is serialized (required for - // each MapShardTask), it uses the DeadRef version, which contains the Ref's value, which - // isn't serializable. Thankfully, this isn't expensive. - // See: https://github.com/objectify/objectify/blob/master/src/main/java/com/googlecode/objectify/impl/ref/DeadRef.java if (isActive(domain, targetResourceUpdateTimestamp) - && isLinked(domain, Ref.create(targetEppResourceKey))) { + && isLinked(domain, targetEppResourceKey)) { emit(targetEppResourceKey, true); } } diff --git a/java/google/registry/flows/async/DeleteHostResourceAction.java b/java/google/registry/flows/async/DeleteHostResourceAction.java index 5945c1445..494fb65b8 100644 --- a/java/google/registry/flows/async/DeleteHostResourceAction.java +++ b/java/google/registry/flows/async/DeleteHostResourceAction.java @@ -16,7 +16,7 @@ package google.registry.flows.async; import static google.registry.model.ofy.ObjectifyService.ofy; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.dns.DnsQueue; import google.registry.model.domain.DomainBase; import google.registry.model.host.HostResource; @@ -46,8 +46,8 @@ public class DeleteHostResourceAction extends DeleteEppResourceAction targetResourceRef) { - return domain.getNameservers().contains(targetResourceRef); + protected boolean isLinked(DomainBase domain, Key targetResourceKey) { + return domain.getNameservers().contains(targetResourceKey); } } @@ -72,7 +72,7 @@ public class DeleteHostResourceAction extends DeleteEppResourceAction ref) { + protected boolean isLinkedForFailfast(final Key key) { // Query for the first few linked domains, and if found, actually load them. The query is // eventually consistent and so might be very stale, but the direct load will not be stale, // just non-transactional. If we find at least one actual reference then we can reliably @@ -59,11 +58,11 @@ public class ContactDeleteFlow extends ResourceAsyncDeleteFlow() { @Override public boolean apply(DomainBase domain) { - return domain.getReferencedContacts().contains(ref); + return domain.getReferencedContacts().contains(key); }}); } diff --git a/java/google/registry/flows/domain/DomainAllocateFlow.java b/java/google/registry/flows/domain/DomainAllocateFlow.java index 1630c1472..2f9fc52c0 100644 --- a/java/google/registry/flows/domain/DomainAllocateFlow.java +++ b/java/google/registry/flows/domain/DomainAllocateFlow.java @@ -23,7 +23,7 @@ import static google.registry.util.CollectionUtils.isNullOrEmpty; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.EppException.AuthorizationErrorException; import google.registry.flows.EppException.ObjectDoesNotExistException; @@ -173,7 +173,7 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow { sunrushAddGracePeriod ? GracePeriodStatus.SUNRUSH_ADD : GracePeriodStatus.ADD, billingEvent)) .setApplicationTime(allocateCreate.getApplicationTime()) - .setApplication(Ref.create(application)) + .setApplication(Key.create(application)) .setSmdId(allocateCreate.getSmdId()) .setLaunchNotice(allocateCreate.getNotice()); // Names on the collision list will not be delegated. Set server hold. diff --git a/java/google/registry/flows/domain/DomainApplicationCreateFlow.java b/java/google/registry/flows/domain/DomainApplicationCreateFlow.java index 3eab117ee..371b6b4d4 100644 --- a/java/google/registry/flows/domain/DomainApplicationCreateFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationCreateFlow.java @@ -19,7 +19,7 @@ import static google.registry.flows.domain.DomainFlowUtils.validateFeeChallenge; import static google.registry.model.domain.fee.Fee.FEE_CREATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER; import static google.registry.model.eppoutput.Result.Code.Success; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; -import static google.registry.model.index.ForeignKeyIndex.loadAndGetReference; +import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import com.google.common.base.Function; import com.google.common.collect.FluentIterable; @@ -156,7 +156,7 @@ public class DomainApplicationCreateFlow extends BaseDomainCreateFlow contacts, - Ref registrant, - Set> nameservers) throws EppException { + Key registrant, + Set> nameservers) throws EppException { for (DesignatedContact contact : nullToEmpty(contacts)) { - verifyNotInPendingDelete(contact.getContactRef()); + verifyNotInPendingDelete(contact.getContactKey()); } if (registrant != null) { verifyNotInPendingDelete(registrant); } - for (Ref host : nullToEmpty(nameservers)) { + for (Key host : nullToEmpty(nameservers)) { verifyNotInPendingDelete(host); } } private static void verifyNotInPendingDelete( - Ref resourceRef) throws EppException { + Key resourceKey) throws EppException { - EppResource resource = resourceRef.get(); + EppResource resource = ofy().load().key(resourceKey).now(); if (resource.getStatusValues().contains(StatusValue.PENDING_DELETE)) { throw new LinkedResourceInPendingDeleteProhibitsOperationException(resource.getForeignKey()); } @@ -302,7 +301,7 @@ public class DomainFlowUtils { } static void validateRequiredContactsPresent( - Ref registrant, Set contacts) + Key registrant, Set contacts) throws RequiredParameterMissingException { if (registrant == null) { throw new MissingRegistrantException(); @@ -446,14 +445,14 @@ public class DomainFlowUtils { @SuppressWarnings("unchecked") static void updateAutorenewRecurrenceEndTime(DomainResource domain, DateTime newEndTime) { Optional autorenewPollMessage = - Optional.fromNullable(domain.getAutorenewPollMessage().get()); + Optional.fromNullable(ofy().load().key(domain.getAutorenewPollMessage()).now()); // 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 // where all autorenew poll messages had already been delivered (this would cause the poll // message to be deleted), and then subsequently the transfer was canceled, rejected, or deleted // (which would cause the poll message to be recreated here). - Key existingAutorenewKey = domain.getAutorenewPollMessage().key(); + Key existingAutorenewKey = domain.getAutorenewPollMessage(); PollMessage.Autorenew updatedAutorenewPollMessage = autorenewPollMessage.isPresent() ? autorenewPollMessage.get().asBuilder().setAutorenewEndTime(newEndTime).build() : newAutorenewPollMessage(domain) @@ -472,7 +471,7 @@ public class DomainFlowUtils { ofy().save().entity(updatedAutorenewPollMessage); } - ofy().save().entity(domain.getAutorenewBillingEvent().get().asBuilder() + ofy().save().entity(ofy().load().key(domain.getAutorenewBillingEvent()).now().asBuilder() .setRecurrenceEndTime(newEndTime) .build()); } diff --git a/java/google/registry/flows/domain/DomainRenewFlow.java b/java/google/registry/flows/domain/DomainRenewFlow.java index b1ccb9c71..f748e71e7 100644 --- a/java/google/registry/flows/domain/DomainRenewFlow.java +++ b/java/google/registry/flows/domain/DomainRenewFlow.java @@ -30,7 +30,7 @@ import static google.registry.util.DateTimeUtils.leapSafeAddYears; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.EppException.ObjectPendingTransferException; import google.registry.flows.EppException.ParameterValueRangeErrorException; @@ -145,8 +145,8 @@ public class DomainRenewFlow extends OwnedResourceMutateFlowentities(explicitRenewEvent, newAutorenewEvent, newAutorenewPollMessage); return existingResource.asBuilder() .setRegistrationExpirationTime(newExpirationTime) - .setAutorenewBillingEvent(Ref.create(newAutorenewEvent)) - .setAutorenewPollMessage(Ref.create(newAutorenewPollMessage)) + .setAutorenewBillingEvent(Key.create(newAutorenewEvent)) + .setAutorenewPollMessage(Key.create(newAutorenewPollMessage)) .addGracePeriod(GracePeriod.forBillingEvent(GracePeriodStatus.RENEW, explicitRenewEvent)) .build(); } diff --git a/java/google/registry/flows/domain/DomainRestoreRequestFlow.java b/java/google/registry/flows/domain/DomainRestoreRequestFlow.java index ccbc07527..f4e120453 100644 --- a/java/google/registry/flows/domain/DomainRestoreRequestFlow.java +++ b/java/google/registry/flows/domain/DomainRestoreRequestFlow.java @@ -28,7 +28,7 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME; import com.google.common.collect.ImmutableList; import com.google.common.net.InternetDomainName; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.dns.DnsQueue; import google.registry.flows.EppException; import google.registry.flows.EppException.CommandUseErrorException; @@ -160,8 +160,8 @@ public class DomainRestoreRequestFlow extends OwnedResourceMutateFlow> superordinateDomain; + private Optional> superordinateDomain; @Inject HostCreateFlow() {} @@ -103,7 +103,7 @@ public class HostCreateFlow extends ResourceCreateFlow ref) { + protected boolean isLinkedForFailfast(final Key key) { // Query for the first few linked domains, and if found, actually load them. The query is // eventually consistent and so might be very stale, but the direct load will not be stale, // just non-transactional. If we find at least one actual reference then we can reliably @@ -59,11 +58,11 @@ public class HostDeleteFlow extends ResourceAsyncDeleteFlow() { @Override public boolean apply(DomainBase domain) { - return domain.getNameservers().contains(ref); + return domain.getNameservers().contains(key); }}); } diff --git a/java/google/registry/flows/host/HostFlowUtils.java b/java/google/registry/flows/host/HostFlowUtils.java index b22c2259f..2ca9fc044 100644 --- a/java/google/registry/flows/host/HostFlowUtils.java +++ b/java/google/registry/flows/host/HostFlowUtils.java @@ -16,13 +16,14 @@ package google.registry.flows.host; import static google.registry.model.EppResourceUtils.isActive; import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.registry.Registries.findTldForName; import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.common.net.InternetDomainName; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.EppException.AuthorizationErrorException; import google.registry.flows.EppException.ObjectDoesNotExistException; @@ -75,7 +76,7 @@ public class HostFlowUtils { } /** Return the {@link DomainResource} this host is subordinate to, or null for external hosts. */ - static Ref lookupSuperordinateDomain( + static Key lookupSuperordinateDomain( InternetDomainName hostName, DateTime now) throws EppException { Optional tldParsed = findTldForName(hostName); if (!tldParsed.isPresent()) { @@ -91,7 +92,7 @@ public class HostFlowUtils { if (superordinateDomain == null || !isActive(superordinateDomain, now)) { throw new SuperordinateDomainDoesNotExistException(domainName); } - return Ref.create(superordinateDomain); + return Key.create(superordinateDomain); } /** Superordinate domain for this hostname does not exist. */ @@ -103,10 +104,11 @@ public class HostFlowUtils { /** Ensure that the superordinate domain is sponsored by the provided clientId. */ static void verifyDomainIsSameRegistrar( - Ref superordinateDomain, + Key superordinateDomain, String clientId) throws EppException { if (superordinateDomain != null - && !clientId.equals(superordinateDomain.get().getCurrentSponsorClientId())) { + && !clientId.equals( + ofy().load().key(superordinateDomain).now().getCurrentSponsorClientId())) { throw new HostDomainNotOwnedException(); } } diff --git a/java/google/registry/flows/host/HostUpdateFlow.java b/java/google/registry/flows/host/HostUpdateFlow.java index 69d7edd77..5d9de383d 100644 --- a/java/google/registry/flows/host/HostUpdateFlow.java +++ b/java/google/registry/flows/host/HostUpdateFlow.java @@ -18,13 +18,12 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain; import static google.registry.flows.host.HostFlowUtils.validateHostName; import static google.registry.flows.host.HostFlowUtils.verifyDomainIsSameRegistrar; -import static google.registry.model.index.ForeignKeyIndex.loadAndGetReference; +import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.CollectionUtils.isNullOrEmpty; import com.google.common.collect.ImmutableMap; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.dns.DnsQueue; import google.registry.flows.EppException; import google.registry.flows.EppException.ObjectAlreadyExistsException; @@ -63,7 +62,7 @@ import org.joda.time.Duration; */ public class HostUpdateFlow extends ResourceUpdateFlow { - private Ref superordinateDomain; + private Key superordinateDomain; private String oldHostName; private String newHostName; @@ -85,7 +84,7 @@ public class HostUpdateFlow extends ResourceUpdateFlow oldSuperordinateDomain = existingResource.getSuperordinateDomain(); + Key oldSuperordinateDomain = existingResource.getSuperordinateDomain(); if (oldSuperordinateDomain != null || superordinateDomain != null) { if (Objects.equals(oldSuperordinateDomain, superordinateDomain)) { - ofy().save().entity(oldSuperordinateDomain.get().asBuilder() - .removeSubordinateHost(oldHostName) - .addSubordinateHost(newHostName) - .build()); + ofy().save().entity( + ofy().load().key(oldSuperordinateDomain).now().asBuilder() + .removeSubordinateHost(oldHostName) + .addSubordinateHost(newHostName) + .build()); } else { if (oldSuperordinateDomain != null) { ofy().save().entity( - oldSuperordinateDomain.get() + ofy().load().key(oldSuperordinateDomain).now() .asBuilder() .removeSubordinateHost(oldHostName) .build()); } if (superordinateDomain != null) { ofy().save().entity( - superordinateDomain.get() + ofy().load().key(superordinateDomain).now() .asBuilder() .addSubordinateHost(newHostName) .build()); diff --git a/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java b/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java index 407e8cc1a..0e2c2309f 100644 --- a/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java +++ b/java/google/registry/mapreduce/inputs/EppResourceEntityReader.java @@ -14,10 +14,11 @@ package google.registry.mapreduce.inputs; +import static google.registry.model.ofy.ObjectifyService.ofy; + import com.google.appengine.tools.mapreduce.InputReader; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.EppResource; import google.registry.model.index.EppResourceIndex; import google.registry.model.index.EppResourceIndexBucket; @@ -55,12 +56,12 @@ class EppResourceEntityReader extends EppResourceBaseRead */ @Override public R next() throws NoSuchElementException { - // Loop until we find a value, or nextRef() throws a NoSuchElementException. + // Loop until we find a value, or nextEri() throws a NoSuchElementException. while (true) { - Ref reference = nextEri().getReference(); - EppResource resource = reference.get(); + Key key = nextEri().getKey(); + EppResource resource = ofy().load().key(key).now(); if (resource == null) { - logger.severefmt("Broken ERI reference: %s", reference.getKey()); + logger.severefmt("EppResourceIndex key %s points at a missing resource", key); continue; } // Postfilter to distinguish polymorphic types (e.g. DomainBase and DomainResource). diff --git a/java/google/registry/mapreduce/inputs/EppResourceKeyReader.java b/java/google/registry/mapreduce/inputs/EppResourceKeyReader.java index 48910a971..12f6f31c4 100644 --- a/java/google/registry/mapreduce/inputs/EppResourceKeyReader.java +++ b/java/google/registry/mapreduce/inputs/EppResourceKeyReader.java @@ -49,6 +49,6 @@ class EppResourceKeyReader extends EppResourceBaseReader< @SuppressWarnings("unchecked") public Key next() throws NoSuchElementException { // This is a safe cast because we filtered on kind inside the query. - return (Key) nextEri().getReference().getKey(); + return (Key) nextEri().getKey(); } } diff --git a/java/google/registry/model/EppResource.java b/java/google/registry/model/EppResource.java index 78ae0d14d..741653ae6 100644 --- a/java/google/registry/model/EppResource.java +++ b/java/google/registry/model/EppResource.java @@ -25,7 +25,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Index; import google.registry.model.eppcommon.StatusValue; @@ -129,7 +129,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable, * @see google.registry.model.translators.CommitLogRevisionsTranslatorFactory */ @XmlTransient - ImmutableSortedMap> revisions = ImmutableSortedMap.of(); + ImmutableSortedMap> revisions = ImmutableSortedMap.of(); public final String getRepoId() { return repoId; @@ -178,7 +178,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable, return deletionTime; } - public ImmutableSortedMap> getRevisions() { + public ImmutableSortedMap> getRevisions() { return nullToEmptyImmutableCopy(revisions); } diff --git a/java/google/registry/model/EppResourceUtils.java b/java/google/registry/model/EppResourceUtils.java index 9276446cc..7091f372f 100644 --- a/java/google/registry/model/EppResourceUtils.java +++ b/java/google/registry/model/EppResourceUtils.java @@ -17,7 +17,7 @@ package google.registry.model; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterables.transform; import static google.registry.model.RoidSuffixes.getRoidSuffixForTld; -import static google.registry.model.index.ForeignKeyIndex.loadAndGetReference; +import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.DateTimeUtils.isAtOrAfter; import static google.registry.util.DateTimeUtils.isBeforeOrAt; @@ -25,7 +25,6 @@ import static google.registry.util.DateTimeUtils.latestOf; import com.google.common.base.Function; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.Result; import com.googlecode.objectify.util.ResultNow; import google.registry.config.RegistryEnvironment; @@ -98,20 +97,20 @@ public final class EppResourceUtils { */ public static T loadByUniqueId( Class clazz, String foreignKey, DateTime now) { - // For regular foreign-keyed resources, get the ref by loading the FKI; for domain applications, - // we can construct the ref directly, since the provided foreignKey is just the repoId. - Ref resourceRef = ForeignKeyedEppResource.class.isAssignableFrom(clazz) - ? loadAndGetReference(clazz, foreignKey, now) - : Ref.create(Key.create(null, clazz, foreignKey)); - if (resourceRef == null) { + // For regular foreign-keyed resources, get the key by loading the FKI; for domain applications, + // we can construct the key directly, since the provided foreignKey is just the repoId. + Key resourceKey = ForeignKeyedEppResource.class.isAssignableFrom(clazz) + ? loadAndGetKey(clazz, foreignKey, now) + : Key.create(null, clazz, foreignKey); + if (resourceKey == null) { return null; } - T resource = resourceRef.get(); + T resource = ofy().load().key(resourceKey).now(); if (resource == null - // You'd think this couldn't happen, but it can. For polymorphic entities, a Ref or Key is - // of necessity a reference to the base type (since datastore doesn't have polymorphism and + // You'd think this couldn't happen, but it can. For polymorphic entities, a Key is of + // necessity a reference to the base type (since datastore doesn't have polymorphism and // Objectify is faking it). In the non-foreign-key code path above where we directly create - // a Ref, there is no way to know whether the Ref points to an instance of the desired + // a Key, there is no way to know whether the Key points to an instance of the desired // subclass without loading it. Due to type erasure, it gets stuffed into "resource" without // causing a ClassCastException even if it's the wrong type until you actually try to use it // as the wrong type, at which point it blows up somewhere else in the code. Concretely, @@ -286,13 +285,13 @@ public final class EppResourceUtils { private static Result loadMostRecentRevisionAtTime( final T resource, final DateTime timestamp) { final Key resourceKey = Key.create(resource); - final Ref revision = findMostRecentRevisionAtTime(resource, timestamp); + final Key revision = findMostRecentRevisionAtTime(resource, timestamp); if (revision == null) { logger.severefmt("No revision found for %s, falling back to resource.", resourceKey); return new ResultNow<>(resource); } final Result mutationResult = - ofy().load().key(CommitLogMutation.createKey(revision.getKey(), resourceKey)); + ofy().load().key(CommitLogMutation.createKey(revision, resourceKey)); return new Result() { @Override public T now() { @@ -310,10 +309,10 @@ public final class EppResourceUtils { } @Nullable - private static Ref + private static Key findMostRecentRevisionAtTime(final T resource, final DateTime timestamp) { final Key resourceKey = Key.create(resource); - Entry> revision = resource.getRevisions().floorEntry(timestamp); + Entry> revision = resource.getRevisions().floorEntry(timestamp); if (revision != null) { logger.infofmt("Found revision history at %s for %s: %s", timestamp, resourceKey, revision); return revision.getValue(); @@ -336,19 +335,19 @@ public final class EppResourceUtils { *

This is an eventually consistent query. * * @param clazz the referent type (contact or host) - * @param ref the referent key + * @param key the referent key * @param now the logical time of the check * @param limit max number of keys to return */ public static List> queryDomainsUsingResource( - Class clazz, Ref ref, DateTime now, int limit) { + Class clazz, Key key, DateTime now, int limit) { checkArgument(ContactResource.class.equals(clazz) || HostResource.class.equals(clazz)); return ofy().load().type(DomainBase.class) .filter( clazz.equals(ContactResource.class) ? "allContacts.contactId.linked" : "nameservers.linked", - ref) + key) .filter("deletionTime >", now) .limit(limit) .keys() @@ -358,7 +357,7 @@ public final class EppResourceUtils { /** Clone a contact or host with an eventually-consistent notion of LINKED. */ public static EppResource cloneResourceWithLinkedStatus(EppResource resource, DateTime now) { Builder builder = resource.asBuilder(); - if (queryDomainsUsingResource(resource.getClass(), Ref.create(resource), now, 1).isEmpty()) { + if (queryDomainsUsingResource(resource.getClass(), Key.create(resource), now, 1).isEmpty()) { builder.removeStatusValue(StatusValue.LINKED); } else { builder.addStatusValue(StatusValue.LINKED); diff --git a/java/google/registry/model/ImmutableObject.java b/java/google/registry/model/ImmutableObject.java index 7837d6cf6..6afaf644a 100644 --- a/java/google/registry/model/ImmutableObject.java +++ b/java/google/registry/model/ImmutableObject.java @@ -17,6 +17,7 @@ package google.registry.model; import static com.google.common.base.Functions.identity; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Maps.transformValues; +import static google.registry.model.ofy.ObjectifyService.ofy; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -24,7 +25,7 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.FluentIterable; import com.google.common.collect.Maps; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Ignore; import google.registry.model.domain.ReferenceUnion; import java.lang.annotation.Documented; @@ -109,18 +110,16 @@ public abstract class ImmutableObject implements Cloneable { /** * Similar to toString(), with a full expansion of embedded ImmutableObjects, - * collections, and references. + * collections, and referenced keys. */ public String toHydratedString() { return toStringHelper(new Function() { @Override public Object apply(Object input) { if (input instanceof ReferenceUnion) { - return apply(((ReferenceUnion) input).getLinked().get()); - } else if (input instanceof Ref) { - // Only follow references of type Ref, not of type Key (the latter deliberately used for - // references that should not be followed) - Object target = ((Ref) input).get(); + return apply(((ReferenceUnion) input).getLinked()); + } else if (input instanceof Key) { + Object target = ofy().load().key((Key) input).now(); return target != null && target.getClass().isAnnotationPresent(DoNotHydrate.class) ? input : apply(target); diff --git a/java/google/registry/model/ModelUtils.java b/java/google/registry/model/ModelUtils.java index 1694dfbc2..1388ba65d 100644 --- a/java/google/registry/model/ModelUtils.java +++ b/java/google/registry/model/ModelUtils.java @@ -39,7 +39,6 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.Parent; @@ -159,12 +158,12 @@ public class ModelUtils { // If the field's type is the same as the field's class object, then it's a non-parameterized // type, and thus we just add it directly. We also don't bother looking at the parameterized - // types of Key and Ref objects, since they are just references to other objects and don't - // actual embed themselves in the persisted object anyway. + // types of Key objects, since they are just references to other objects and don't actually + // embed themselves in the persisted object anyway. Class fieldClazz = field.getType(); Type fieldType = field.getGenericType(); builder.add(fieldClazz); - if (fieldType.equals(fieldClazz) || Ref.class.equals(clazz) || Key.class.equals(clazz)) { + if (fieldType.equals(fieldClazz) || Key.class.equals(clazz)) { continue; } diff --git a/java/google/registry/model/billing/BillingEvent.java b/java/google/registry/model/billing/BillingEvent.java index bb40af992..3a1337172 100644 --- a/java/google/registry/model/billing/BillingEvent.java +++ b/java/google/registry/model/billing/BillingEvent.java @@ -18,6 +18,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.union; import static google.registry.util.DateTimeUtils.END_OF_TIME; @@ -27,7 +28,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.IgnoreSave; @@ -410,19 +410,27 @@ public abstract class BillingEvent extends ImmutableObject @Index DateTime billingTime; - /** The one-time billing event to cancel, or null for autorenew cancellations. */ + /** + * The one-time billing event to cancel, or null for autorenew cancellations. + * + *

Although the type is {@link Key} the name "ref" is preserved for historical reasons. + */ @IgnoreSave(IfNull.class) - Ref refOneTime = null; + Key refOneTime = null; - /** The recurring billing event to cancel, or null for non-autorenew cancellations. */ + /** + * The recurring billing event to cancel, or null for non-autorenew cancellations. + * + *

Although the type is {@link Key} the name "ref" is preserved for historical reasons. + */ @IgnoreSave(IfNull.class) - Ref refRecurring = null; + Key refRecurring = null; public DateTime getBillingTime() { return billingTime; } - public Ref getEventRef() { + public Key getEventKey() { return firstNonNull(refOneTime, refRecurring); } @@ -454,9 +462,9 @@ public abstract class BillingEvent extends ImmutableObject .setParent(historyEntry); // Set the grace period's billing event using the appropriate Cancellation builder method. if (gracePeriod.getOneTimeBillingEvent() != null) { - builder.setOneTimeEventRef(gracePeriod.getOneTimeBillingEvent()); + builder.setOneTimeEventKey(gracePeriod.getOneTimeBillingEvent()); } else if (gracePeriod.getRecurringBillingEvent() != null) { - builder.setRecurringEventRef(gracePeriod.getRecurringBillingEvent()); + builder.setRecurringEventKey(gracePeriod.getRecurringBillingEvent()); } return builder.build(); } @@ -480,13 +488,13 @@ public abstract class BillingEvent extends ImmutableObject return this; } - public Builder setOneTimeEventRef(Ref eventRef) { - getInstance().refOneTime = eventRef; + public Builder setOneTimeEventKey(Key eventKey) { + getInstance().refOneTime = eventKey; return this; } - public Builder setRecurringEventRef(Ref eventRef) { - getInstance().refRecurring = eventRef; + public Builder setRecurringEventKey(Key eventKey) { + getInstance().refRecurring = eventKey; return this; } @@ -496,7 +504,7 @@ public abstract class BillingEvent extends ImmutableObject checkNotNull(instance.billingTime); checkNotNull(instance.reason); checkState((instance.refOneTime == null) != (instance.refRecurring == null), - "Cancellations must have exactly one billing event ref set"); + "Cancellations must have exactly one billing event key set"); return super.build(); } } @@ -512,7 +520,7 @@ public abstract class BillingEvent extends ImmutableObject Money cost; /** The one-time billing event to modify. */ - Ref eventRef; + Key eventRef; /** * Description of the modification (and presumably why it was issued). This text may appear as a @@ -524,7 +532,7 @@ public abstract class BillingEvent extends ImmutableObject return cost; } - public Ref getEventRef() { + public Key getEventKey() { return eventRef; } @@ -551,7 +559,7 @@ public abstract class BillingEvent extends ImmutableObject .setFlags(billingEvent.getFlags()) .setReason(billingEvent.getReason()) .setTargetId(billingEvent.getTargetId()) - .setEventRef(Ref.create(billingEvent)) + .setEventKey(Key.create(billingEvent)) .setEventTime(historyEntry.getModificationTime()) .setDescription(description) .setCost(billingEvent.getCost().negated()) @@ -573,8 +581,8 @@ public abstract class BillingEvent extends ImmutableObject return this; } - public Builder setEventRef(Ref eventRef) { - getInstance().eventRef = eventRef; + public Builder setEventKey(Key eventKey) { + getInstance().eventRef = eventKey; return this; } @@ -589,7 +597,7 @@ public abstract class BillingEvent extends ImmutableObject Modification instance = getInstance(); checkNotNull(instance.reason); checkNotNull(instance.eventRef); - BillingEvent.OneTime billingEvent = instance.eventRef.get(); + BillingEvent.OneTime billingEvent = ofy().load().key(instance.eventRef).now(); checkArgument(Objects.equals( instance.cost.getCurrencyUnit(), billingEvent.cost.getCurrencyUnit()), diff --git a/java/google/registry/model/billing/RegistrarCredit.java b/java/google/registry/model/billing/RegistrarCredit.java index dfc516fc1..144316553 100644 --- a/java/google/registry/model/billing/RegistrarCredit.java +++ b/java/google/registry/model/billing/RegistrarCredit.java @@ -25,7 +25,7 @@ import com.google.common.collect.ComparisonChain; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Parent; @@ -71,7 +71,7 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable /** The registrar to whom this credit belongs. */ @Parent - Ref parent; + Key parent; /** The type of credit. */ CreditType type; @@ -95,7 +95,7 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable */ String tld; - public Ref getParent() { + public Key getParent() { return parent; } @@ -122,7 +122,7 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable /** Returns a string representation of this credit. */ public String getSummary() { String fields = Joiner.on(' ').join(type, creationTime, tld); - return String.format("%s (%s/%d) - %s", description, parent.getKey().getName(), id, fields); + return String.format("%s (%s/%d) - %s", description, parent.getName(), id, fields); } /** Returns the default description for this {@link RegistrarCredit} instance. */ @@ -144,7 +144,7 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable } public Builder setParent(Registrar parent) { - getInstance().parent = Ref.create(parent); + getInstance().parent = Key.create(parent); return this; } diff --git a/java/google/registry/model/billing/RegistrarCreditBalance.java b/java/google/registry/model/billing/RegistrarCreditBalance.java index 8d009a4fa..444a675b3 100644 --- a/java/google/registry/model/billing/RegistrarCreditBalance.java +++ b/java/google/registry/model/billing/RegistrarCreditBalance.java @@ -27,15 +27,14 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Parent; -import com.googlecode.objectify.impl.ref.DeadRef; import google.registry.model.Buildable; import google.registry.model.ImmutableObject; import java.util.HashMap; import java.util.Map; +import org.joda.money.CurrencyUnit; import org.joda.money.Money; import org.joda.time.DateTime; @@ -58,7 +57,7 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui /** The registrar credit object for which this represents a balance. */ @Parent - Ref parent; + Key parent; /** The time at which this balance amount should become effective. */ DateTime effectiveTime; @@ -74,7 +73,7 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui /** The monetary amount of credit balance remaining as of the effective time. */ Money amount; - public Ref getParent() { + public Key getParent() { return parent; } @@ -97,6 +96,9 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui /** A Builder for an {@link RegistrarCreditBalance}. */ public static class Builder extends Buildable.Builder { + + private CurrencyUnit currency; + public Builder() {} public Builder(RegistrarCreditBalance instance) { @@ -104,8 +106,8 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui } public RegistrarCreditBalance.Builder setParent(RegistrarCredit parent) { - // Use a DeadRef so that we can retrieve the actual instance provided later on in build(). - getInstance().parent = new DeadRef<>(Key.create(parent), parent); + this.currency = parent.getCurrency(); + getInstance().parent = Key.create(parent); return this; } @@ -132,12 +134,11 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui checkNotNull(instance.effectiveTime); checkNotNull(instance.writtenTime); checkNotNull(instance.amount); - RegistrarCredit credit = instance.parent.get(); checkState( - instance.amount.getCurrencyUnit().equals(credit.getCurrency()), + instance.amount.getCurrencyUnit().equals(currency), "Currency of balance amount differs from credit currency (%s vs %s)", instance.amount.getCurrencyUnit(), - credit.getCurrency()); + currency); return super.build(); } } diff --git a/java/google/registry/model/domain/DesignatedContact.java b/java/google/registry/model/domain/DesignatedContact.java index ffb0c9f8f..a320db34d 100644 --- a/java/google/registry/model/domain/DesignatedContact.java +++ b/java/google/registry/model/domain/DesignatedContact.java @@ -15,7 +15,7 @@ package google.registry.model.domain; import com.google.common.annotations.VisibleForTesting; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.Index; import google.registry.model.ImmutableObject; @@ -48,7 +48,7 @@ public class DesignatedContact extends ImmutableObject { } @VisibleForTesting - public static DesignatedContact create(Type type, Ref contact) { + public static DesignatedContact create(Type type, Key contact) { DesignatedContact instance = new DesignatedContact(); instance.type = type; instance.contactId = ReferenceUnion.create(contact); @@ -60,14 +60,14 @@ public class DesignatedContact extends ImmutableObject { @Index @XmlValue - //TODO(b/28713909): Make this a Ref. + //TODO(b/28713909): Make this a Key. ReferenceUnion contactId; public Type getType() { return type; } - public Ref getContactRef() { + public Key getContactKey() { return contactId.getLinked(); } } diff --git a/java/google/registry/model/domain/DomainAuthInfo.java b/java/google/registry/model/domain/DomainAuthInfo.java index 7be71e4fa..0ea6e70d6 100644 --- a/java/google/registry/model/domain/DomainAuthInfo.java +++ b/java/google/registry/model/domain/DomainAuthInfo.java @@ -15,8 +15,9 @@ package google.registry.model.domain; import static com.google.common.base.Preconditions.checkNotNull; +import static google.registry.model.ofy.ObjectifyService.ofy; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Embed; import google.registry.model.EppResource; import google.registry.model.contact.ContactResource; @@ -38,9 +39,9 @@ public class DomainAuthInfo extends AuthInfo { checkNotNull(getPw()); if (getRepoId() != null) { // Make sure the repo id matches one of the contacts on the domain. - Ref foundContact = null; - for (Ref contact : domain.getReferencedContacts()) { - String contactRepoId = contact.getKey().getName(); + Key foundContact = null; + for (Key contact : domain.getReferencedContacts()) { + String contactRepoId = contact.getName(); if (getRepoId().equals(contactRepoId)) { foundContact = contact; break; @@ -50,7 +51,7 @@ public class DomainAuthInfo extends AuthInfo { throw new BadAuthInfoException(); } // Check if the password provided matches the password on the referenced contact. - if (!foundContact.get().getAuthInfo().getPw().getValue().equals( + if (!ofy().load().key(foundContact).now().getAuthInfo().getPw().getValue().equals( getPw().getValue())) { throw new BadAuthInfoException(); } diff --git a/java/google/registry/model/domain/DomainBase.java b/java/google/registry/model/domain/DomainBase.java index fd864dba7..ebe76cdb6 100644 --- a/java/google/registry/model/domain/DomainBase.java +++ b/java/google/registry/model/domain/DomainBase.java @@ -36,7 +36,7 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Ordering; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.IgnoreSave; import com.googlecode.objectify.annotation.Index; @@ -78,7 +78,7 @@ public abstract class DomainBase extends EppResource { /** References to hosts that are the nameservers for the domain. */ @XmlTransient - //TODO(b/28713909): Make this a Set>. + //TODO(b/28713909): Make this a Set>. Set> nameservers; /** @@ -149,7 +149,7 @@ public abstract class DomainBase extends EppResource { public ForeignKeyedDesignatedContact apply(DesignatedContact designated) { return ForeignKeyedDesignatedContact.create( designated.getType(), - designated.getContactRef().get().getContactId()); + ofy().load().key(designated.getContactKey()).now().getContactId()); }}) .toSet(); } @@ -158,7 +158,7 @@ public abstract class DomainBase extends EppResource { @XmlElement(name = "registrant") private String getMarshalledRegistrant() { preMarshal(); - return getRegistrant().get().getContactId(); + return ofy().load().key(getRegistrant()).now().getContactId(); } public String getFullyQualifiedDomainName() { @@ -177,8 +177,8 @@ public abstract class DomainBase extends EppResource { return idnTableName; } - public ImmutableSet> getNameservers() { - ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); + public ImmutableSet> getNameservers() { + ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); for (ReferenceUnion union : nullToEmptyImmutableCopy(nameservers)) { builder.add(union.getLinked()); } @@ -187,7 +187,7 @@ public abstract class DomainBase extends EppResource { /** Loads and returns the fully qualified host names of all linked nameservers. */ public ImmutableSortedSet loadNameserverFullyQualifiedHostNames() { - return FluentIterable.from(ofy().load().refs(getNameservers()).values()) + return FluentIterable.from(ofy().load().keys(getNameservers()).values()) .transform( new Function() { @Override @@ -198,14 +198,14 @@ public abstract class DomainBase extends EppResource { .toSortedSet(Ordering.natural()); } - /** A reference to the registrant who registered this domain. */ - public Ref getRegistrant() { + /** A key to the registrant who registered this domain. */ + public Key getRegistrant() { return FluentIterable .from(nullToEmpty(allContacts)) .filter(IS_REGISTRANT) .first() .get() - .getContactRef(); + .getContactKey(); } /** Associated contacts for the domain (other than registrant). */ @@ -221,11 +221,11 @@ public abstract class DomainBase extends EppResource { } /** Returns all referenced contacts from this domain or application. */ - public ImmutableSet> getReferencedContacts() { - ImmutableSet.Builder> contactsBuilder = + public ImmutableSet> getReferencedContacts() { + ImmutableSet.Builder> contactsBuilder = new ImmutableSet.Builder<>(); for (DesignatedContact designated : nullToEmptyImmutableCopy(allContacts)) { - contactsBuilder.add(designated.getContactRef()); + contactsBuilder.add(designated.getContactKey()); } return contactsBuilder.build(); } @@ -276,7 +276,7 @@ public abstract class DomainBase extends EppResource { return thisCastToDerived(); } - public B setRegistrant(Ref registrant) { + public B setRegistrant(Key registrant) { // Replace the registrant contact inside allContacts. getInstance().allContacts = union( getInstance().getContacts(), @@ -289,21 +289,21 @@ public abstract class DomainBase extends EppResource { return thisCastToDerived(); } - public B setNameservers(ImmutableSet> nameservers) { + public B setNameservers(ImmutableSet> nameservers) { ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); - for (Ref ref : nullToEmpty(nameservers)) { - builder.add(ReferenceUnion.create(ref)); + for (Key key : nullToEmpty(nameservers)) { + builder.add(ReferenceUnion.create(key)); } getInstance().nameservers = builder.build(); return thisCastToDerived(); } - public B addNameservers(ImmutableSet> nameservers) { + public B addNameservers(ImmutableSet> nameservers) { return setNameservers( ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers))); } - public B removeNameservers(ImmutableSet> nameservers) { + public B removeNameservers(ImmutableSet> nameservers) { return setNameservers( ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers))); } diff --git a/java/google/registry/model/domain/DomainCommand.java b/java/google/registry/model/domain/DomainCommand.java index 780aa0fb7..c7f5d04c8 100644 --- a/java/google/registry/model/domain/DomainCommand.java +++ b/java/google/registry/model/domain/DomainCommand.java @@ -32,7 +32,7 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.Work; import google.registry.model.EppResource; import google.registry.model.ImmutableObject; @@ -83,9 +83,9 @@ public class DomainCommand { @XmlElement(name = "registrant") String registrantContactId; - /** A resolved reference to the registrant who registered this domain. */ + /** A resolved key to the registrant who registered this domain. */ @XmlTransient - Ref registrant; + Key registrant; /** Authorization info (aka transfer secret) of the domain. */ DomainAuthInfo authInfo; @@ -94,7 +94,7 @@ public class DomainCommand { return registrantContactId; } - public Ref getRegistrant() { + public Key getRegistrant() { return registrant; } @@ -134,15 +134,15 @@ public class DomainCommand { @XmlElement(name = "hostObj") Set nameserverFullyQualifiedHostNames; - /** Resolved references to hosts that are the nameservers for the domain. */ + /** Resolved keys to hosts that are the nameservers for the domain. */ @XmlTransient - Set> nameservers; + Set> nameservers; /** Foreign keyed associated contacts for the domain (other than registrant). */ @XmlElement(name = "contact") Set foreignKeyedDesignatedContacts; - /** Resolved references to associated contacts for the domain (other than registrant). */ + /** Resolved keys to associated contacts for the domain (other than registrant). */ @XmlTransient Set contacts; @@ -166,7 +166,7 @@ public class DomainCommand { return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames); } - public ImmutableSet> getNameservers() { + public ImmutableSet> getNameservers() { return nullSafeImmutableCopy(nameservers); } @@ -210,7 +210,7 @@ public class DomainCommand { now); for (DesignatedContact contact : contacts) { if (DesignatedContact.Type.REGISTRANT.equals(contact.getType())) { - clone.registrant = contact.getContactRef(); + clone.registrant = contact.getContactKey(); clone.contacts = forceEmptyToNull(difference(contacts, contact)); break; } @@ -373,15 +373,15 @@ public class DomainCommand { @XmlElement(name = "hostObj") Set nameserverFullyQualifiedHostNames; - /** Resolved references to hosts that are the nameservers for the domain. */ + /** Resolved keys to hosts that are the nameservers for the domain. */ @XmlTransient - Set> nameservers; + Set> nameservers; /** Foreign keyed associated contacts for the domain (other than registrant). */ @XmlElement(name = "contact") Set foreignKeyedDesignatedContacts; - /** Resolved references to associated contacts for the domain (other than registrant). */ + /** Resolved keys to associated contacts for the domain (other than registrant). */ @XmlTransient Set contacts; @@ -389,7 +389,7 @@ public class DomainCommand { return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames); } - public ImmutableSet> getNameservers() { + public ImmutableSet> getNameservers() { return nullToEmptyImmutableCopy(nameservers); } @@ -415,7 +415,7 @@ public class DomainCommand { clone.registrant = clone.registrantContactId == null ? null : getOnlyElement( - loadReferences( + loadByForeignKey( ImmutableSet.of(clone.registrantContactId), ContactResource.class, now) .values()); return clone; @@ -456,13 +456,13 @@ public class DomainCommand { } } - private static Set> linkHosts( + private static Set> linkHosts( Set fullyQualifiedHostNames, DateTime now) throws InvalidReferencesException { if (fullyQualifiedHostNames == null) { return null; } return ImmutableSet.copyOf( - loadReferences(fullyQualifiedHostNames, HostResource.class, now).values()); + loadByForeignKey(fullyQualifiedHostNames, HostResource.class, now).values()); } private static Set linkContacts( @@ -474,8 +474,8 @@ public class DomainCommand { for (ForeignKeyedDesignatedContact contact : contacts) { foreignKeys.add(contact.contactId); } - ImmutableMap> loadedContacts = - loadReferences(foreignKeys.build(), ContactResource.class, now); + ImmutableMap> loadedContacts = + loadByForeignKey(foreignKeys.build(), ContactResource.class, now); ImmutableSet.Builder linkedContacts = new ImmutableSet.Builder<>(); for (ForeignKeyedDesignatedContact contact : contacts) { linkedContacts.add(DesignatedContact.create( @@ -484,8 +484,8 @@ public class DomainCommand { return linkedContacts.build(); } - /** Load references to resources by their foreign keys. */ - private static ImmutableMap> loadReferences( + /** Load keys to resources by their foreign keys. */ + private static ImmutableMap> loadByForeignKey( final Set foreignKeys, final Class clazz, final DateTime now) throws InvalidReferencesException { Map> fkis = ofy().doTransactionless( @@ -500,10 +500,10 @@ public class DomainCommand { } return ImmutableMap.copyOf(transformValues( fkis, - new Function, Ref>() { + new Function, Key>() { @Override - public Ref apply(ForeignKeyIndex fki) { - return fki.getReference(); + public Key apply(ForeignKeyIndex fki) { + return fki.getResourceKey(); }})); } diff --git a/java/google/registry/model/domain/DomainResource.java b/java/google/registry/model/domain/DomainResource.java index 5c3a0202f..c7b08f4af 100644 --- a/java/google/registry/model/domain/DomainResource.java +++ b/java/google/registry/model/domain/DomainResource.java @@ -28,7 +28,6 @@ import static google.registry.util.DateTimeUtils.leapSafeAddYears; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Cache; import com.googlecode.objectify.annotation.EntitySubclass; import com.googlecode.objectify.annotation.IgnoreSave; @@ -112,7 +111,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc * should be created, and this field should be updated to point to the new one. */ @XmlTransient - Ref autorenewBillingEvent; + Key autorenewBillingEvent; /** * The recurring poll message associated with this domain's autorenewals. @@ -123,7 +122,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc * should be created, and this field should be updated to point to the new one. */ @XmlTransient - Ref autorenewPollMessage; + Key autorenewPollMessage; /** The unexpired grace periods for this domain (some of which may not be active yet). */ @XmlTransient @@ -146,12 +145,12 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc DateTime applicationTime; /** - * A reference to the application used to allocate this domain. Will only be populated for domains + * A key to the application used to allocate this domain. Will only be populated for domains * allocated from an application. */ @IgnoreSave(IfNull.class) @XmlTransient - Ref application; + Key application; public ImmutableSet getSubordinateHosts() { return nullToEmptyImmutableCopy(subordinateHosts); @@ -165,11 +164,11 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc return deletePollMessage; } - public Ref getAutorenewBillingEvent() { + public Key getAutorenewBillingEvent() { return autorenewBillingEvent; } - public Ref getAutorenewPollMessage() { + public Key getAutorenewPollMessage() { return autorenewPollMessage; } @@ -185,7 +184,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc return applicationTime; } - public Ref getApplication() { + public Key getApplication() { return application; } @@ -290,13 +289,13 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc // Set the speculatively-written new autorenew events as the domain's autorenew events. .setAutorenewBillingEvent(transferData.getServerApproveAutorenewEvent()) .setAutorenewPollMessage(transferData.getServerApproveAutorenewPollMessage()) - // Set the grace period using a ref to the prescheduled transfer billing event. Not using + // Set the grace period using a key to the prescheduled transfer billing event. Not using // GracePeriod.forBillingEvent() here in order to avoid the actual datastore fetch. .setGracePeriods(ImmutableSet.of(GracePeriod.create( GracePeriodStatus.TRANSFER, transferExpirationTime.plus(Registry.get(getTld()).getTransferGracePeriodLength()), transferData.getGainingClientId(), - Ref.create(transferData.getServerApproveBillingEvent().key())))); + transferData.getServerApproveBillingEvent()))); // Set all remaining transfer properties. setAutomaticTransferSuccessProperties(builder, transferData); // Finish projecting to now. @@ -318,7 +317,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc GracePeriodStatus.AUTO_RENEW, lastAutorenewTime.plus(Registry.get(getTld()).getAutoRenewGracePeriodLength()), getCurrentSponsorClientId(), - Ref.create(autorenewBillingEvent.key()))); + autorenewBillingEvent)); } // Remove any grace periods that have expired. @@ -398,12 +397,12 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc return this; } - public Builder setAutorenewBillingEvent(Ref autorenewBillingEvent) { + public Builder setAutorenewBillingEvent(Key autorenewBillingEvent) { getInstance().autorenewBillingEvent = autorenewBillingEvent; return this; } - public Builder setAutorenewPollMessage(Ref autorenewPollMessage) { + public Builder setAutorenewPollMessage(Key autorenewPollMessage) { getInstance().autorenewPollMessage = autorenewPollMessage; return this; } @@ -418,7 +417,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc return this; } - public Builder setApplication(Ref application) { + public Builder setApplication(Key application) { getInstance().application = application; return this; } diff --git a/java/google/registry/model/domain/GracePeriod.java b/java/google/registry/model/domain/GracePeriod.java index c1928b970..dfad91f66 100644 --- a/java/google/registry/model/domain/GracePeriod.java +++ b/java/google/registry/model/domain/GracePeriod.java @@ -17,7 +17,7 @@ package google.registry.model.domain; import static com.google.common.base.Preconditions.checkArgument; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Embed; import google.registry.model.ImmutableObject; import google.registry.model.billing.BillingEvent; @@ -49,14 +49,14 @@ public class GracePeriod extends ImmutableObject { * {@code billingEventRecurring}) or for redemption grace periods (since deletes have no cost). */ // NB: Would @IgnoreSave(IfNull.class), but not allowed for @Embed collections. - Ref billingEventOneTime = null; + Key billingEventOneTime = null; /** * The recurring billing event corresponding to the action that triggered this grace period, if * applicable - i.e. if the action was an autorenew - or null in all other cases. */ // NB: Would @IgnoreSave(IfNull.class), but not allowed for @Embed collections. - Ref billingEventRecurring = null; + Key billingEventRecurring = null; public GracePeriodStatus getType() { // NB: We implicitly convert SUNRUSH_ADD to ADD, since they should be functionally equivalent. @@ -85,7 +85,7 @@ public class GracePeriod extends ImmutableObject { * period is not AUTO_RENEW. */ - public Ref getOneTimeBillingEvent() { + public Key getOneTimeBillingEvent() { return billingEventOneTime; } @@ -93,7 +93,7 @@ public class GracePeriod extends ImmutableObject { * Returns the recurring billing event. The value will only be non-null if the type of this grace * period is AUTO_RENEW. */ - public Ref getRecurringBillingEvent() { + public Key getRecurringBillingEvent() { return billingEventRecurring; } @@ -101,8 +101,8 @@ public class GracePeriod extends ImmutableObject { GracePeriodStatus type, DateTime expirationTime, String clientId, - @Nullable Ref billingEventOneTime, - @Nullable Ref billingEventRecurring) { + @Nullable Key billingEventOneTime, + @Nullable Key billingEventRecurring) { checkArgument((billingEventOneTime == null) || (billingEventRecurring == null), "A grace period can have at most one billing event"); checkArgument((billingEventRecurring != null) == (GracePeriodStatus.AUTO_RENEW.equals(type)), @@ -127,7 +127,7 @@ public class GracePeriod extends ImmutableObject { GracePeriodStatus type, DateTime expirationTime, String clientId, - @Nullable Ref billingEventOneTime) { + @Nullable Key billingEventOneTime) { return createInternal(type, expirationTime, clientId, billingEventOneTime, null); } @@ -136,7 +136,7 @@ public class GracePeriod extends ImmutableObject { GracePeriodStatus type, DateTime expirationTime, String clientId, - Ref billingEventRecurring) { + Key billingEventRecurring) { checkArgumentNotNull(billingEventRecurring); return createInternal(type, expirationTime, clientId, null, billingEventRecurring); } @@ -151,6 +151,6 @@ public class GracePeriod extends ImmutableObject { public static GracePeriod forBillingEvent( GracePeriodStatus type, BillingEvent.OneTime billingEvent) { return create( - type, billingEvent.getBillingTime(), billingEvent.getClientId(), Ref.create(billingEvent)); + type, billingEvent.getBillingTime(), billingEvent.getClientId(), Key.create(billingEvent)); } } diff --git a/java/google/registry/model/domain/ReferenceUnion.java b/java/google/registry/model/domain/ReferenceUnion.java index aa0ff5b27..2fcdbb527 100644 --- a/java/google/registry/model/domain/ReferenceUnion.java +++ b/java/google/registry/model/domain/ReferenceUnion.java @@ -14,7 +14,7 @@ package google.registry.model.domain; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.Index; import google.registry.model.EppResource; @@ -22,7 +22,7 @@ import google.registry.model.ImmutableObject; /** * Legacy shell of a "union" type to represent referenced objects as either a foreign key or as a - * link to another object in the datastore. In its current form it merely wraps a {@link Ref}. + * link to another object in the datastore. In its current form it merely wraps a {@link Key}. * * @param the type being referenced */ @@ -30,13 +30,13 @@ import google.registry.model.ImmutableObject; public class ReferenceUnion extends ImmutableObject { @Index - Ref linked; + Key linked; - public Ref getLinked() { + public Key getLinked() { return linked; } - public static ReferenceUnion create(Ref linked) { + public static ReferenceUnion create(Key linked) { ReferenceUnion instance = new ReferenceUnion<>(); instance.linked = linked; return instance; diff --git a/java/google/registry/model/host/HostResource.java b/java/google/registry/model/host/HostResource.java index 24eaeb3db..82b3b6342 100644 --- a/java/google/registry/model/host/HostResource.java +++ b/java/google/registry/model/host/HostResource.java @@ -17,13 +17,14 @@ package google.registry.model.host; import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.union; import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Cache; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.IgnoreSave; @@ -88,7 +89,7 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource @Index @IgnoreSave(IfNull.class) @XmlTransient - Ref superordinateDomain; + Key superordinateDomain; /** * The most recent time that the superordinate domain was changed, or null if this host is @@ -102,7 +103,7 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource return fullyQualifiedHostName; } - public Ref getSuperordinateDomain() { + public Key getSuperordinateDomain() { return superordinateDomain; } @@ -132,7 +133,8 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource } else { // For hosts with superordinate domains, the client id, last transfer time, and transfer data // need to be read off the domain projected to the correct time. - DomainResource domainAtTime = superordinateDomain.get().cloneProjectedAtTime(now); + DomainResource domainAtTime = ofy().load().key(superordinateDomain).now() + .cloneProjectedAtTime(now); builder.setCurrentSponsorClientId(domainAtTime.getCurrentSponsorClientId()); // If the superordinate domain's last transfer time is what is relevant, because the host's // superordinate domain was last changed less recently than the domain's last transfer, then @@ -192,7 +194,7 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource difference(getInstance().getInetAddresses(), inetAddresses))); } - public Builder setSuperordinateDomain(Ref superordinateDomain) { + public Builder setSuperordinateDomain(Key superordinateDomain) { getInstance().superordinateDomain = superordinateDomain; return this; } diff --git a/java/google/registry/model/index/DomainApplicationIndex.java b/java/google/registry/model/index/DomainApplicationIndex.java index a14ca9df7..f8222676c 100644 --- a/java/google/registry/model/index/DomainApplicationIndex.java +++ b/java/google/registry/model/index/DomainApplicationIndex.java @@ -23,7 +23,6 @@ import static google.registry.util.DateTimeUtils.latestOf; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Cache; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; @@ -48,11 +47,13 @@ public class DomainApplicationIndex extends BackupGroupRoot { /** * A set of all domain applications with this fully qualified domain name. Never null or empty. + * + *

Although this stores {@link Key}s it is named "references" for historical reasons. */ - Set> references; + Set> references; - /** Returns a cloned list of all references on this index. */ - public ImmutableSet> getReferences() { + /** Returns a cloned list of all keys on this index. */ + public ImmutableSet> getKeys() { return ImmutableSet.copyOf(references); } @@ -61,18 +62,18 @@ public class DomainApplicationIndex extends BackupGroupRoot { } /** - * Creates a DomainApplicationIndex with the specified list of references. Only use this method - * for data migrations. You probably want {@link #createUpdatedInstance}. + * Creates a DomainApplicationIndex with the specified list of keys. Only use this method for data + * migrations. You probably want {@link #createUpdatedInstance}. */ - public static DomainApplicationIndex createWithSpecifiedReferences( + public static DomainApplicationIndex createWithSpecifiedKeys( String fullyQualifiedDomainName, - ImmutableSet> references) { + ImmutableSet> keys) { checkArgument(!isNullOrEmpty(fullyQualifiedDomainName), "fullyQualifiedDomainName must not be null or empty."); - checkArgument(!isNullOrEmpty(references), "References must not be null or empty."); + checkArgument(!isNullOrEmpty(keys), "Keys must not be null or empty."); DomainApplicationIndex instance = new DomainApplicationIndex(); instance.fullyQualifiedDomainName = fullyQualifiedDomainName; - instance.references = references; + instance.references = keys; return instance; } @@ -91,7 +92,7 @@ public class DomainApplicationIndex extends BackupGroupRoot { return ImmutableSet.of(); } ImmutableSet.Builder apps = new ImmutableSet.Builder<>(); - for (DomainApplication app : ofy().load().refs(index.getReferences()).values()) { + for (DomainApplication app : ofy().load().keys(index.getKeys()).values()) { DateTime forwardedNow = latestOf(now, app.getUpdateAutoTimestamp().getTimestamp()); if (app.getDeletionTime().isAfter(forwardedNow)) { apps.add(app.cloneProjectedAtTime(forwardedNow)); @@ -121,9 +122,9 @@ public class DomainApplicationIndex extends BackupGroupRoot { */ public static DomainApplicationIndex createUpdatedInstance(DomainApplication application) { DomainApplicationIndex existing = load(application.getFullyQualifiedDomainName()); - ImmutableSet> newReferences = CollectionUtils.union( - (existing == null ? ImmutableSet.>of() : existing.getReferences()), - Ref.create(application)); - return createWithSpecifiedReferences(application.getFullyQualifiedDomainName(), newReferences); + ImmutableSet> newKeys = CollectionUtils.union( + (existing == null ? ImmutableSet.>of() : existing.getKeys()), + Key.create(application)); + return createWithSpecifiedKeys(application.getFullyQualifiedDomainName(), newKeys); } } diff --git a/java/google/registry/model/index/EppResourceIndex.java b/java/google/registry/model/index/EppResourceIndex.java index 015f2a315..0959ce236 100644 --- a/java/google/registry/model/index/EppResourceIndex.java +++ b/java/google/registry/model/index/EppResourceIndex.java @@ -18,7 +18,6 @@ import static google.registry.util.TypeUtils.instantiate; import com.google.common.annotations.VisibleForTesting; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Index; @@ -36,7 +35,8 @@ public class EppResourceIndex extends BackupGroupRoot { @Parent Key bucket; - Ref reference; + /** Although this field holds a {@link Key} it is named "reference" for historical reasons. */ + Key reference; @Index String kind; @@ -49,7 +49,7 @@ public class EppResourceIndex extends BackupGroupRoot { return kind; } - public Ref getReference() { + public Key getKey() { return reference; } @@ -62,7 +62,7 @@ public class EppResourceIndex extends BackupGroupRoot { public static EppResourceIndex create( Key bucket, Key resourceKey) { EppResourceIndex instance = instantiate(EppResourceIndex.class); - instance.reference = Ref.create(resourceKey); + instance.reference = resourceKey; instance.kind = resourceKey.getKind(); instance.id = resourceKey.getString(); // creates a web-safe key string instance.bucket = bucket; diff --git a/java/google/registry/model/index/ForeignKeyIndex.java b/java/google/registry/model/index/ForeignKeyIndex.java index 034ffd4b0..15501829b 100644 --- a/java/google/registry/model/index/ForeignKeyIndex.java +++ b/java/google/registry/model/index/ForeignKeyIndex.java @@ -23,7 +23,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Cache; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; @@ -81,9 +80,10 @@ public abstract class ForeignKeyIndex extends BackupGroup /** * The referenced resource. * - *

This field holds the only reference. It is named "topReference" for historical reasons. + *

This field holds a key to the only referenced resource. It is named "topReference" for + * historical reasons. */ - Ref topReference; + Key topReference; public String getForeignKey() { return foreignKey; @@ -93,7 +93,7 @@ public abstract class ForeignKeyIndex extends BackupGroup return deletionTime; } - public Ref getReference() { + public Key getResourceKey() { return topReference; } @@ -103,7 +103,7 @@ public abstract class ForeignKeyIndex extends BackupGroup public static ForeignKeyIndex create( E resource, DateTime deletionTime) { ForeignKeyIndex instance = instantiate(RESOURCE_CLASS_TO_FKI_CLASS.get(resource.getClass())); - instance.topReference = Ref.create(resource); + instance.topReference = Key.create(resource); instance.foreignKey = resource.getForeignKey(); instance.deletionTime = deletionTime; return instance; @@ -116,7 +116,7 @@ public abstract class ForeignKeyIndex extends BackupGroup } /** - * Loads a reference to an {@link EppResource} from the datastore by foreign key. + * Loads a {@link Key} to an {@link EppResource} from the datastore by foreign key. * *

Returns absent if no foreign key index with this foreign key was ever created, or if the * most recently created foreign key index was deleted before time "now". This method does not @@ -128,10 +128,10 @@ public abstract class ForeignKeyIndex extends BackupGroup * @param now the current logical time to use when checking for soft deletion of the foreign key * index */ - public static Ref loadAndGetReference( + public static Key loadAndGetKey( Class clazz, String foreignKey, DateTime now) { ForeignKeyIndex index = load(clazz, foreignKey, now); - return (index == null) ? null : index.getReference(); + return (index == null) ? null : index.getResourceKey(); } /** diff --git a/java/google/registry/model/registry/label/BaseDomainLabelList.java b/java/google/registry/model/registry/label/BaseDomainLabelList.java index 735a05463..aa1a596ab 100644 --- a/java/google/registry/model/registry/label/BaseDomainLabelList.java +++ b/java/google/registry/model/registry/label/BaseDomainLabelList.java @@ -130,14 +130,14 @@ public abstract class BaseDomainLabelList, R extends Dom ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); Key> key = Key.create(this); for (String tld : getTlds()) { - if (hasReference(Registry.get(tld), key)) { + if (refersToKey(Registry.get(tld), key)) { builder.add(tld); } } return builder.build(); } - protected abstract boolean hasReference( + protected abstract boolean refersToKey( Registry registry, Key> key); protected static Optional getFromCache(String listName, LoadingCache cache) { diff --git a/java/google/registry/model/registry/label/PremiumList.java b/java/google/registry/model/registry/label/PremiumList.java index 82760f6c3..af09bfabb 100644 --- a/java/google/registry/model/registry/label/PremiumList.java +++ b/java/google/registry/model/registry/label/PremiumList.java @@ -306,7 +306,7 @@ public final class PremiumList extends BaseDomainLabelList> key) { + public boolean refersToKey(Registry registry, Key> key) { return Objects.equals(registry.getPremiumList(), key); } diff --git a/java/google/registry/model/registry/label/ReservedList.java b/java/google/registry/model/registry/label/ReservedList.java index 66785267f..8c762a42a 100644 --- a/java/google/registry/model/registry/label/ReservedList.java +++ b/java/google/registry/model/registry/label/ReservedList.java @@ -118,7 +118,7 @@ public final class ReservedList } @Override - protected boolean hasReference(Registry registry, Key> key) { + protected boolean refersToKey(Registry registry, Key> key) { return registry.getReservedLists().contains(key); } diff --git a/java/google/registry/model/reporting/HistoryEntry.java b/java/google/registry/model/reporting/HistoryEntry.java index cfea2a03d..b8f24f6b1 100644 --- a/java/google/registry/model/reporting/HistoryEntry.java +++ b/java/google/registry/model/reporting/HistoryEntry.java @@ -15,7 +15,6 @@ package google.registry.model.reporting; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.IgnoreSave; @@ -25,12 +24,14 @@ import com.googlecode.objectify.condition.IfNull; import google.registry.model.Buildable; import google.registry.model.EppResource; import google.registry.model.ImmutableObject; +import google.registry.model.ImmutableObject.DoNotHydrate; import google.registry.model.domain.Period; import google.registry.model.eppcommon.Trid; import org.joda.time.DateTime; /** A record of an EPP command that mutated a resource. */ @Entity +@DoNotHydrate public class HistoryEntry extends ImmutableObject implements Buildable { /** Represents the type of history entry. */ @@ -77,7 +78,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable { /** The resource this event mutated. */ @Parent - Ref parent; + Key parent; /** The type of history entry. */ Type type; @@ -112,7 +113,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable { /** Whether this change was requested by a registrar. */ Boolean requestedByRegistrar; - public Ref getParent() { + public Key getParent() { return parent; } @@ -166,12 +167,12 @@ public class HistoryEntry extends ImmutableObject implements Buildable { } public Builder setParent(EppResource parent) { - getInstance().parent = Ref.create(parent); + getInstance().parent = Key.create(parent); return this; } public Builder setParent(Key parentKey) { - getInstance().parent = Ref.create(parentKey); + getInstance().parent = parentKey; return this; } diff --git a/java/google/registry/model/transfer/TransferData.java b/java/google/registry/model/transfer/TransferData.java index a683a726b..9cb391220 100644 --- a/java/google/registry/model/transfer/TransferData.java +++ b/java/google/registry/model/transfer/TransferData.java @@ -18,7 +18,6 @@ import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.IgnoreSave; import com.googlecode.objectify.annotation.Unindex; @@ -48,9 +47,6 @@ public class TransferData extends BaseTransferObject implements Buildable { * a number of poll messages and billing events for both the gaining and losing registrars. If the * pending transfer is explicitly approved, rejected or cancelled, the referenced entities should * be deleted. - * - *

Keys are stored here instead of references to facilitate bulk deletion (the typical use - * case, as described above), since Objectify allows bulk deletion by key but not by reference. */ @IgnoreSave(IfNull.class) Set> serverApproveEntities; @@ -62,7 +58,7 @@ public class TransferData extends BaseTransferObject implements Buildable { * being transferred is not a domain. */ @IgnoreSave(IfNull.class) - Ref serverApproveBillingEvent; + Key serverApproveBillingEvent; /** * The autorenew billing event that should be associated with this resource after the transfer. @@ -71,7 +67,7 @@ public class TransferData extends BaseTransferObject implements Buildable { * being transferred is not a domain. */ @IgnoreSave(IfNull.class) - Ref serverApproveAutorenewEvent; + Key serverApproveAutorenewEvent; /** * The autorenew poll message that should be associated with this resource after the transfer. @@ -80,7 +76,7 @@ public class TransferData extends BaseTransferObject implements Buildable { * being transferred is not a domain. */ @IgnoreSave(IfNull.class) - Ref serverApproveAutorenewPollMessage; + Key serverApproveAutorenewPollMessage; /** The transaction id of the most recent transfer request (or null if there never was one). */ Trid transferRequestTrid; @@ -95,15 +91,15 @@ public class TransferData extends BaseTransferObject implements Buildable { return nullToEmptyImmutableCopy(serverApproveEntities); } - public Ref getServerApproveBillingEvent() { + public Key getServerApproveBillingEvent() { return serverApproveBillingEvent; } - public Ref getServerApproveAutorenewEvent() { + public Key getServerApproveAutorenewEvent() { return serverApproveAutorenewEvent; } - public Ref getServerApproveAutorenewPollMessage() { + public Key getServerApproveAutorenewPollMessage() { return serverApproveAutorenewPollMessage; } @@ -138,19 +134,19 @@ public class TransferData extends BaseTransferObject implements Buildable { } public Builder setServerApproveBillingEvent( - Ref serverApproveBillingEvent) { + Key serverApproveBillingEvent) { getInstance().serverApproveBillingEvent = serverApproveBillingEvent; return this; } public Builder setServerApproveAutorenewEvent( - Ref serverApproveAutorenewEvent) { + Key serverApproveAutorenewEvent) { getInstance().serverApproveAutorenewEvent = serverApproveAutorenewEvent; return this; } public Builder setServerApproveAutorenewPollMessage( - Ref serverApproveAutorenewPollMessage) { + Key serverApproveAutorenewPollMessage) { getInstance().serverApproveAutorenewPollMessage = serverApproveAutorenewPollMessage; return this; } diff --git a/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java b/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java index f3ec7e956..b0da31241 100644 --- a/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java +++ b/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java @@ -20,19 +20,19 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.config.RegistryEnvironment; import google.registry.model.ofy.CommitLogManifest; import org.joda.time.DateTime; /** - * Objectify translator for {@code ImmutableSortedMap>} fields. + * Objectify translator for {@code ImmutableSortedMap>} fields. * *

This translator is responsible for doing three things: *

    *
  1. Translating the data into two lists of {@code Date} and {@code Key} objects, in a manner * similar to {@code @Mapify}. - *
  2. Inserting a reference to the transaction's {@link CommitLogManifest} on save. + *
  3. Inserting a key to the transaction's {@link CommitLogManifest} on save. *
  4. Truncating the map to include only the last key per day for the last 30 days. *
* @@ -45,7 +45,7 @@ import org.joda.time.DateTime; * @see google.registry.model.EppResource */ public final class CommitLogRevisionsTranslatorFactory - extends ImmutableSortedMapTranslatorFactory> { + extends ImmutableSortedMapTranslatorFactory> { private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get(); @@ -62,14 +62,14 @@ public final class CommitLogRevisionsTranslatorFactory * @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention() */ @Override - ImmutableSortedMap> transformBeforeSave( - ImmutableSortedMap> revisions) { + ImmutableSortedMap> transformBeforeSave( + ImmutableSortedMap> revisions) { DateTime now = ofy().getTransactionTime(); DateTime threshold = now.minus(ENVIRONMENT.config().getCommitLogDatastoreRetention()); DateTime preThresholdTime = firstNonNull(revisions.floorKey(threshold), START_OF_TIME); - return new ImmutableSortedMap.Builder>(Ordering.natural()) + return new ImmutableSortedMap.Builder>(Ordering.natural()) .putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false)) - .put(now, Ref.create(ofy().getCommitLogManifestKey())) + .put(now, ofy().getCommitLogManifestKey()) .build(); } } diff --git a/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java b/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java index 79d040d9a..b46b9cce9 100644 --- a/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java +++ b/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java @@ -39,7 +39,6 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; import google.registry.model.EppResource; @@ -77,8 +76,7 @@ import org.joda.time.DateTime; *

Specifically this validates all of the following system invariants that are expected to hold * true for all {@link EppResource} entities and their related indexes: *

    - *
  • All {@link Key} and {@link Ref} fields (including nested ones) point to entities that - * exist. + *
  • All {@link Key} fields (including nested ones) point to entities that exist. *
  • There is exactly one {@link EppResourceIndex} pointing to each {@link EppResource}. *
  • All contacts, hosts, and domains, when grouped by foreign key, have at most one active * resource, and exactly one {@link ForeignKeyIndex} of the appropriate type, which points to @@ -241,8 +239,8 @@ public class VerifyEntityIntegrityAction implements Runnable { if (resource instanceof DomainBase) { DomainBase domainBase = (DomainBase) resource; Key key = Key.create(domainBase); - verifyExistence(key, refsToKeys(domainBase.getReferencedContacts())); - verifyExistence(key, refsToKeys(domainBase.getNameservers())); + verifyExistence(key, domainBase.getReferencedContacts()); + verifyExistence(key, domainBase.getNameservers()); verifyExistence(key, domainBase.getTransferData().getServerApproveAutorenewEvent()); verifyExistence(key, domainBase.getTransferData().getServerApproveAutorenewPollMessage()); verifyExistence(key, domainBase.getTransferData().getServerApproveBillingEvent()); @@ -299,7 +297,7 @@ public class VerifyEntityIntegrityAction implements Runnable { private void mapForeignKeyIndex(ForeignKeyIndex fki) { Key> fkiKey = Key.>create(fki); @SuppressWarnings("cast") - EppResource resource = verifyExistence(fkiKey, fki.getReference()); + EppResource resource = verifyExistence(fkiKey, fki.getResourceKey()); if (resource != null) { // TODO(user): Traverse the chain of pointers to old FKIs instead once they are written. if (isAtOrAfter(fki.getDeletionTime(), resource.getDeletionTime())) { @@ -328,8 +326,8 @@ public class VerifyEntityIntegrityAction implements Runnable { private void mapDomainApplicationIndex(DomainApplicationIndex dai) { getContext().incrementCounter("domain application indexes"); Key daiKey = Key.create(dai); - for (Ref ref : dai.getReferences()) { - DomainApplication application = verifyExistence(daiKey, ref); + for (Key key : dai.getKeys()) { + DomainApplication application = verifyExistence(daiKey, key); if (application != null) { integrity().check( dai.getFullyQualifiedDomainName().equals(application.getFullyQualifiedDomainName()), @@ -347,11 +345,11 @@ public class VerifyEntityIntegrityAction implements Runnable { Key eriKey = Key.create(eri); String eriRepoId = Key.create(eri.getId()).getName(); integrity().check( - eriRepoId.equals(eri.getReference().getKey().getName()), + eriRepoId.equals(eri.getKey().getName()), eriKey, - eri.getReference().getKey(), + eri.getKey(), "EPP resource index id does not match repoId of reference"); - verifyExistence(eriKey, eri.getReference()); + verifyExistence(eriKey, eri.getKey()); emit(MapperKey.create(EntityKind.EPP_RESOURCE, eriRepoId), eriKey); getContext().incrementCounter("EPP resource indexes to " + eri.getKind()); } @@ -366,14 +364,6 @@ public class VerifyEntityIntegrityAction implements Runnable { "Target entity does not exist"); } - @Nullable - private E verifyExistence(Key source, @Nullable Ref target) { - if (target == null) { - return null; - } - return verifyExistence(source, target.getKey()); - } - @Nullable private E verifyExistence(Key source, @Nullable Key target) { if (target == null) { @@ -383,17 +373,6 @@ public class VerifyEntityIntegrityAction implements Runnable { integrity().check(entity != null, source, target, "Target entity does not exist"); return entity; } - - private static ImmutableSet> refsToKeys(Iterable> refs) { - return FluentIterable - .from(refs) - .transform(new Function, Key>() { - @Override - public Key apply(Ref ref) { - return ref.getKey(); - }}) - .toSet(); - } } /** Reducer that checks integrity of foreign key entities. */ diff --git a/java/google/registry/rdap/RdapDomainSearchAction.java b/java/google/registry/rdap/RdapDomainSearchAction.java index b860629bb..c8246ddaf 100644 --- a/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/java/google/registry/rdap/RdapDomainSearchAction.java @@ -15,7 +15,7 @@ package google.registry.rdap; import static google.registry.model.EppResourceUtils.loadByUniqueId; -import static google.registry.model.index.ForeignKeyIndex.loadAndGetReference; +import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; @@ -28,9 +28,7 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.primitives.Booleans; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.cmd.Query; -import com.googlecode.objectify.cmd.QueryKeys; import google.registry.model.domain.DomainResource; import google.registry.model.host.HostResource; import google.registry.rdap.RdapJsonFormatter.BoilerplateType; @@ -164,31 +162,25 @@ public class RdapDomainSearchAction extends RdapActionBase { private ImmutableList> searchByNameserverLdhName(final RdapSearchPattern partialStringQuery, final DateTime now) throws HttpException { - ImmutableList> hostRefs; + Iterable> hostKeys; // Handle queries without a wildcard; just load the host by foreign key in the usual way. if (!partialStringQuery.getHasWildcard()) { - Ref hostRef = loadAndGetReference( + Key hostKey = loadAndGetKey( HostResource.class, partialStringQuery.getInitialString(), now); - if (hostRef == null) { + if (hostKey == null) { return ImmutableList.of(); } - hostRefs = ImmutableList.of(hostRef); + hostKeys = ImmutableList.of(hostKey); // Handle queries with a wildcard, but no suffix. Query the host resources themselves, rather // than the foreign key index, because then we have an index on fully qualified host name and // deletion time, so we can check the deletion status in the query itself. There are no pending // deletes for hosts, so we can call queryUndeleted. } else if (partialStringQuery.getSuffix() == null) { // TODO (b/24463238): figure out how to limit the size of these queries effectively - Query query = queryUndeleted( - HostResource.class, - "fullyQualifiedHostName", - partialStringQuery, 1000); - ImmutableList.Builder> builder = new ImmutableList.Builder<>(); - for (Key hostResourceKey : query.keys()) { - builder.add(Ref.create(hostResourceKey)); - } - hostRefs = builder.build(); - if (hostRefs.isEmpty()) { + hostKeys = + queryUndeleted(HostResource.class, "fullyQualifiedHostName", partialStringQuery, 1000) + .keys(); + if (Iterables.isEmpty(hostKeys)) { throw new NotFoundException("No matching nameservers found"); } // Handle queries with a wildcard and a suffix. In this case, it is more efficient to do things @@ -200,24 +192,24 @@ public class RdapDomainSearchAction extends RdapActionBase { if (domainResource == null) { throw new NotFoundException("No domain found for specified nameserver suffix"); } - ImmutableList.Builder> builder = new ImmutableList.Builder<>(); + ImmutableList.Builder> builder = new ImmutableList.Builder<>(); for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) { // We can't just check that the host name starts with the initial query string, because then // the query ns.exam*.example.com would match against nameserver ns.example.com. if (partialStringQuery.matches(fqhn)) { - Ref hostRef = loadAndGetReference(HostResource.class, fqhn, now); - if (hostRef != null) { - builder.add(hostRef); + Key hostKey = loadAndGetKey(HostResource.class, fqhn, now); + if (hostKey != null) { + builder.add(hostKey); } } } - hostRefs = builder.build(); - if (hostRefs.isEmpty()) { + hostKeys = builder.build(); + if (Iterables.isEmpty(hostKeys)) { throw new NotFoundException("No matching nameservers found"); } } // Find all domains that link to any of these hosts, and return information about them. - return searchByNameserverRefs(hostRefs, now); + return searchByNameserverRefs(hostKeys, now); } /** Searches for domains by nameserver address, returning a JSON array of domain info maps. */ @@ -226,35 +218,28 @@ public class RdapDomainSearchAction extends RdapActionBase { // In theory, we could filter on the deletion time being in the future. But we can't do that in // the query on nameserver name (because we're already using an inequality query), and it seems // dangerous and confusing to filter on deletion time differently between the two queries. - QueryKeys query = ofy() - .load() - .type(HostResource.class) - .filter("inetAddresses", inetAddress.getHostAddress()) - .filter("deletionTime", END_OF_TIME) - .limit(1000) - .keys(); - ImmutableList.Builder> builder = new ImmutableList.Builder<>(); - for (Key key : query) { - builder.add(Ref.create(key)); - } - ImmutableList> hostRefs = builder.build(); - if (hostRefs.isEmpty()) { - return ImmutableList.of(); - } // Find all domains that link to any of these hosts, and return information about them. - return searchByNameserverRefs(hostRefs, now); + return searchByNameserverRefs( + ofy() + .load() + .type(HostResource.class) + .filter("inetAddresses", inetAddress.getHostAddress()) + .filter("deletionTime", END_OF_TIME) + .limit(1000) + .keys(), + now); } /** - * Locates all domains which are linked to a set of host refs. This method is called by + * Locates all domains which are linked to a set of host keys. This method is called by * {@link #searchByNameserverLdhName} and {@link #searchByNameserverIp} after they assemble the - * relevant host refs. + * relevant host keys. */ private ImmutableList> - searchByNameserverRefs(final Iterable> hostRefs, final DateTime now) { + searchByNameserverRefs(final Iterable> hostKeys, final DateTime now) { // We must break the query up into chunks, because the in operator is limited to 30 subqueries. ImmutableList.Builder> builder = new ImmutableList.Builder<>(); - for (List> chunk : Iterables.partition(hostRefs, 30)) { + for (List> chunk : Iterables.partition(hostKeys, 30)) { Query query = ofy().load() .type(DomainResource.class) .filter("nameservers.linked in", chunk) diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index 91a38a348..c81afe1da 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -417,10 +417,10 @@ public class RdapJsonFormatter { DateTime now) { // Kick off the database loads of the nameservers that we will need. Map, HostResource> loadedHosts = - ofy().load().refs(domainResource.getNameservers()); + ofy().load().keys(domainResource.getNameservers()); // And the registrant and other contacts. Map, ContactResource> loadedContacts = - ofy().load().refs(domainResource.getReferencedContacts()); + ofy().load().keys(domainResource.getReferencedContacts()); // Now, assemble the results, using the loaded objects as needed. ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); @@ -453,8 +453,7 @@ public class RdapJsonFormatter { for (DesignatedContact designatedContact : FluentIterable.from(domainResource.getContacts()) .append(DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant())) .toSortedList(DESIGNATED_CONTACT_ORDERING)) { - ContactResource loadedContact = - loadedContacts.get(designatedContact.getContactRef().key()); + ContactResource loadedContact = loadedContacts.get(designatedContact.getContactKey()); entitiesBuilder.add(makeRdapJsonForContact( loadedContact, false, Optional.of(designatedContact.getType()), linkBase, null, now)); } diff --git a/java/google/registry/rde/DomainResourceToXjcConverter.java b/java/google/registry/rde/DomainResourceToXjcConverter.java index 66f0bcc27..d23c3305c 100644 --- a/java/google/registry/rde/DomainResourceToXjcConverter.java +++ b/java/google/registry/rde/DomainResourceToXjcConverter.java @@ -14,10 +14,12 @@ package google.registry.rde; +import static google.registry.model.ofy.ObjectifyService.ofy; + import com.google.common.base.Ascii; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainResource; @@ -161,9 +163,9 @@ final class DomainResourceToXjcConverter { // o An OPTIONAL element that contain the identifier for // the human or organizational social information object associated // as the holder of the domain name object. - Ref registrant = model.getRegistrant(); + Key registrant = model.getRegistrant(); if (registrant != null) { - bean.setRegistrant(registrant.get().getContactId()); + bean.setRegistrant(ofy().load().key(registrant).now().getContactId()); } // o Zero or more OPTIONAL elements that contain identifiers @@ -280,7 +282,7 @@ final class DomainResourceToXjcConverter { /** Converts {@link DesignatedContact} to {@link XjcDomainContactType}. */ private static XjcDomainContactType convertDesignatedContact(DesignatedContact model) { XjcDomainContactType bean = new XjcDomainContactType(); - ContactResource contact = model.getContactRef().get(); + ContactResource contact = ofy().load().key(model.getContactKey()).now(); bean.setType(XjcDomainContactAttrType.fromValue(Ascii.toLowerCase(model.getType().toString()))); bean.setValue(contact.getContactId()); return bean; diff --git a/java/google/registry/tools/AllocateDomainCommand.java b/java/google/registry/tools/AllocateDomainCommand.java index 40dc3f34a..49400cea5 100644 --- a/java/google/registry/tools/AllocateDomainCommand.java +++ b/java/google/registry/tools/AllocateDomainCommand.java @@ -136,14 +136,14 @@ final class AllocateDomainCommand extends MutatingEppToolCommand { for (DesignatedContact contact : application.getContacts()) { contactsMapBuilder.put( Ascii.toLowerCase(contact.getType().toString()), - contact.getContactRef().get().getForeignKey()); + ofy().load().key(contact.getContactKey()).now().getForeignKey()); } LaunchNotice launchNotice = application.getLaunchNotice(); addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData( "name", application.getFullyQualifiedDomainName(), "period", period.getValue(), "nameservers", application.loadNameserverFullyQualifiedHostNames(), - "registrant", application.getRegistrant().get().getForeignKey(), + "registrant", ofy().load().key(application.getRegistrant()).now().getForeignKey(), "contacts", contactsMapBuilder.build(), "authInfo", application.getAuthInfo().getPw().getValue(), "smdId", application.getEncodedSignedMarks().isEmpty() diff --git a/java/google/registry/tools/AuctionStatusCommand.java b/java/google/registry/tools/AuctionStatusCommand.java index 566e01384..73db44d52 100644 --- a/java/google/registry/tools/AuctionStatusCommand.java +++ b/java/google/registry/tools/AuctionStatusCommand.java @@ -101,7 +101,7 @@ final class AuctionStatusCommand implements RemoteApiCommand, GtechCommand { new Function() { @Override public String apply(DomainApplication app) { - ContactResource registrant = checkNotNull(app.getRegistrant().get()); + ContactResource registrant = checkNotNull(ofy().load().key(app.getRegistrant()).now()); Object[] keysAndValues = new Object[] { "Domain", app.getFullyQualifiedDomainName(), "Type", app.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise", diff --git a/java/google/registry/tools/DeleteEppResourceCommand.java b/java/google/registry/tools/DeleteEppResourceCommand.java index c7d67aa9b..f566ce81f 100644 --- a/java/google/registry/tools/DeleteEppResourceCommand.java +++ b/java/google/registry/tools/DeleteEppResourceCommand.java @@ -93,7 +93,7 @@ final class DeleteEppResourceCommand extends MutatingCommand { System.out.printf("Creating non-existent ForeignKeyIndex for: %s\n", key); stageEntityChange(null, ForeignKeyIndex.create(resource, now)); } else { - if (fki.getReference().key().equals(key)) { + if (fki.getResourceKey().equals(key)) { if (isBeforeOrAt(fki.getDeletionTime(), now)) { System.out.printf("ForeignKeyIndex already deleted for: %s\n", key); } else { diff --git a/java/google/registry/tools/GenerateApplicationsReportCommand.java b/java/google/registry/tools/GenerateApplicationsReportCommand.java index 4ffd44713..7ff1b6073 100644 --- a/java/google/registry/tools/GenerateApplicationsReportCommand.java +++ b/java/google/registry/tools/GenerateApplicationsReportCommand.java @@ -172,7 +172,7 @@ final class GenerateApplicationsReportCommand implements RemoteApiCommand, Gtech domainApplication.getEncodedSignedMarks().isEmpty() ? "landrush" : "sunrise", domainApplication.getApplicationStatus(), domainApplication.getCurrentSponsorClientId(), - domainApplication.getRegistrant().get().getEmailAddress(), + ofy().load().key(domainApplication.getRegistrant()).now().getEmailAddress(), validityMessage); } } diff --git a/java/google/registry/tools/GenerateAuctionDataCommand.java b/java/google/registry/tools/GenerateAuctionDataCommand.java index fc23bda8b..eca248d18 100644 --- a/java/google/registry/tools/GenerateAuctionDataCommand.java +++ b/java/google/registry/tools/GenerateAuctionDataCommand.java @@ -114,7 +114,8 @@ final class GenerateAuctionDataCommand implements RemoteApiCommand, GtechCommand + "Can't process contending applications for %s because some applications " + "are not yet validated.", domainName); - ContactResource registrant = checkNotNull(domainApplication.getRegistrant().get()); + ContactResource registrant = + ofy().load().key(checkNotNull(domainApplication.getRegistrant())).now(); result.add(emitApplication(domainApplication, registrant)); // Ensure the registrant's email address is unique across the contending applications. diff --git a/java/google/registry/tools/GenerateEscrowDepositCommand.java b/java/google/registry/tools/GenerateEscrowDepositCommand.java index 27a1057ad..feadf162b 100644 --- a/java/google/registry/tools/GenerateEscrowDepositCommand.java +++ b/java/google/registry/tools/GenerateEscrowDepositCommand.java @@ -201,7 +201,7 @@ final class GenerateEscrowDepositCommand implements RemoteApiCommand { @Override @SuppressWarnings("unchecked") public Key apply(EppResourceIndex index) { - return (Key) index.getReference().getKey(); + return (Key) index.getKey(); }})) .values(); } diff --git a/java/google/registry/tools/UniformRapidSuspensionCommand.java b/java/google/registry/tools/UniformRapidSuspensionCommand.java index fde83b821..c240fbafa 100644 --- a/java/google/registry/tools/UniformRapidSuspensionCommand.java +++ b/java/google/registry/tools/UniformRapidSuspensionCommand.java @@ -19,6 +19,7 @@ import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.collect.Sets.difference; import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.ofy.ObjectifyService.ofy; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.Parameter; @@ -28,7 +29,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.template.soy.data.SoyMapData; -import com.googlecode.objectify.Ref; import google.registry.model.domain.DomainResource; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; @@ -147,8 +147,8 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand impleme private ImmutableSortedSet getExistingNameservers(DomainResource domain) { ImmutableSortedSet.Builder nameservers = ImmutableSortedSet.naturalOrder(); - for (Ref nameserverRef : domain.getNameservers()) { - nameservers.add(nameserverRef.get().getForeignKey()); + for (HostResource host : ofy().load().keys(domain.getNameservers()).values()) { + nameservers.add(host.getForeignKey()); } return nameservers.build(); } diff --git a/java/google/registry/tools/server/GenerateZoneFilesAction.java b/java/google/registry/tools/server/GenerateZoneFilesAction.java index 6db987d76..50f3e1c45 100644 --- a/java/google/registry/tools/server/GenerateZoneFilesAction.java +++ b/java/google/registry/tools/server/GenerateZoneFilesAction.java @@ -272,7 +272,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA */ private static String domainStanza(DomainResource domain, DateTime exportTime) { StringBuilder result = new StringBuilder(); - for (HostResource nameserver : ofy().load().refs(domain.getNameservers()).values()) { + for (HostResource nameserver : ofy().load().keys(domain.getNameservers()).values()) { result.append(String.format( NS_FORMAT, domain.getFullyQualifiedDomainName(), diff --git a/java/google/registry/tools/server/KillAllEppResourcesAction.java b/java/google/registry/tools/server/KillAllEppResourcesAction.java index 344eee6b2..97f9ef541 100644 --- a/java/google/registry/tools/server/KillAllEppResourcesAction.java +++ b/java/google/registry/tools/server/KillAllEppResourcesAction.java @@ -81,7 +81,7 @@ public class KillAllEppResourcesAction implements Runnable { public void map(final EppResourceIndex eri) { Key eriKey = Key.create(eri); emitAndIncrementCounter(eriKey, eriKey); - Key resourceKey = eri.getReference().getKey(); + Key resourceKey = eri.getKey(); for (Key key : ofy().load().ancestor(resourceKey).keys()) { emitAndIncrementCounter(resourceKey, key); } @@ -91,7 +91,7 @@ public class KillAllEppResourcesAction implements Runnable { new Work() { @Override public EppResource run() { - return eri.getReference().get(); + return ofy().load().key(eri.getKey()).now(); }}); // TODO(b/28247733): What about FKI's for renamed hosts? Key indexKey = resource instanceof DomainApplication diff --git a/java/google/registry/whois/DomainWhoisResponse.java b/java/google/registry/whois/DomainWhoisResponse.java index 7b2c9434b..2bdd546dd 100644 --- a/java/google/registry/whois/DomainWhoisResponse.java +++ b/java/google/registry/whois/DomainWhoisResponse.java @@ -16,6 +16,7 @@ package google.registry.whois; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.tryFind; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.xml.UtcDateTimeAdapter.getFormattedString; @@ -23,7 +24,7 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactResource; import google.registry.model.contact.PostalInfo; @@ -100,14 +101,14 @@ final class DomainWhoisResponse extends WhoisResponseImpl { /** Returns the contact of the given type, or null if it does not exist. */ @Nullable - private Ref getContactReference(final Type type) { + private Key getContactReference(final Type type) { Optional contactOfType = tryFind(domain.getContacts(), new Predicate() { @Override public boolean apply(DesignatedContact d) { return d.getType() == type; }}); - return contactOfType.isPresent() ? contactOfType.get().getContactRef() : null; + return contactOfType.isPresent() ? contactOfType.get().getContactKey() : null; } /** Output emitter with logic for domains. */ @@ -123,7 +124,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl { /** Emit the contact entry of the given type. */ DomainEmitter emitContact( String contactType, - @Nullable Ref contact, + @Nullable Key contact, boolean preferUnicode) { if (contact == null) { return this; @@ -131,7 +132,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl { // If we refer to a contact that doesn't exist, that's a bug. It means referential integrity // has somehow been broken. We skip the rest of this contact, but log it to hopefully bring it // someone's attention. - ContactResource contactResource = contact.get(); + ContactResource contactResource = ofy().load().key(contact).now(); if (contactResource == null) { logger.severefmt("(BUG) Broken reference found from domain %s to contact %s", domain.getFullyQualifiedDomainName(), contact); diff --git a/javatests/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java b/javatests/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java index 419da91da..f3849a456 100644 --- a/javatests/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java +++ b/javatests/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java @@ -37,7 +37,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.dns.writer.clouddns.CloudDnsWriter.ZoneStateException; import google.registry.model.domain.DomainResource; import google.registry.model.domain.secdns.DelegationSignerData; @@ -285,9 +285,9 @@ public class CloudDnsWriterTest { i, DS_DATA.getAlgorithm(), DS_DATA.getDigestType(), DS_DATA.getDigest())); } - ImmutableSet.Builder> hostResourceRefBuilder = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> hostResourceRefBuilder = new ImmutableSet.Builder<>(); for (HostResource nameserver : nameservers) { - hostResourceRefBuilder.add(Ref.create(nameserver)); + hostResourceRefBuilder.add(Key.create(nameserver)); } return newDomainResource(domainName) diff --git a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java index d0b0c3015..2aec17ec2 100644 --- a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java +++ b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java @@ -34,7 +34,7 @@ import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.domain.DomainResource; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; @@ -107,7 +107,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers(ImmutableSet.of(Ref.create(host1), Ref.create(host2))) + .setNameservers(ImmutableSet.of(Key.create(host1), Key.create(host2))) .build(); persistResource(domain); @@ -126,7 +126,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld")))) .setDsData( ImmutableSet.of( DelegationSignerData.create(1, 3, 1, base16().decode("0123456789ABCDEF")))) @@ -150,7 +150,7 @@ public class DnsUpdateWriterTest { persistActiveDomain("example.tld") .asBuilder() .addStatusValue(StatusValue.SERVER_HOLD) - .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld")))) .build(); persistResource(domain); @@ -192,7 +192,7 @@ public class DnsUpdateWriterTest { newDomainResource("example.tld") .asBuilder() .addSubordinateHost("ns1.example.tld") - .addNameservers(ImmutableSet.of(Ref.create(host))) + .addNameservers(ImmutableSet.of(Key.create(host))) .build()); writer.publishHost("ns1.example.tld"); @@ -229,7 +229,7 @@ public class DnsUpdateWriterTest { persistResource( persistActiveDomain("example.tld") .asBuilder() - .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.com")))) + .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.com")))) .build()); writer.publishHost("ns1.example.tld"); @@ -262,7 +262,7 @@ public class DnsUpdateWriterTest { .asBuilder() .addSubordinateHost("ns1.example.tld") .addNameservers( - ImmutableSet.of(Ref.create(externalNameserver), Ref.create(inBailiwickNameserver))) + ImmutableSet.of(Key.create(externalNameserver), Key.create(inBailiwickNameserver))) .build()); writer.publishDomain("example.tld"); @@ -296,7 +296,7 @@ public class DnsUpdateWriterTest { .asBuilder() .addSubordinateHost("ns1.example.tld") .addSubordinateHost("foo.example.tld") - .addNameservers(ImmutableSet.of(Ref.create(inBailiwickNameserver))) + .addNameservers(ImmutableSet.of(Key.create(inBailiwickNameserver))) .build()); writer.publishDomain("example.tld"); @@ -318,7 +318,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld")))) .build(); persistResource(domain); when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL)); diff --git a/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java b/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java index 53bfcb90f..5d12e7c6d 100644 --- a/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java +++ b/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java @@ -186,7 +186,7 @@ public class SyncRegistrarsSheetTest { .setEmailAddress("pride@example.net") .setTypes(ImmutableSet.of(RegistrarContact.Type.TECH)) .build()); - // Use registrar ref for contacts' parent. + // Use registrar key for contacts' parent. persistSimpleResources(contacts); persistResource(registrar); diff --git a/javatests/google/registry/flows/EppCommitLogsTest.java b/javatests/google/registry/flows/EppCommitLogsTest.java index 31a1f1c67..9da9cbfc7 100644 --- a/javatests/google/registry/flows/EppCommitLogsTest.java +++ b/javatests/google/registry/flows/EppCommitLogsTest.java @@ -146,8 +146,8 @@ public class EppCommitLogsTest extends ShardableTestCase { .isEqualTo(domainAfterCreate); // Both updates happened on the same day. Since the revisions field has day granularity, the - // reference to the first update should have been overwritten by the second, and its timestamp - // rolled forward. So we have to fall back to the last revision before midnight. + // key to the first update should have been overwritten by the second, and its timestamp rolled + // forward. So we have to fall back to the last revision before midnight. ofy().clearSessionCache(); assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now()) .isEqualTo(domainAfterCreate); diff --git a/javatests/google/registry/flows/FlowTestCase.java b/javatests/google/registry/flows/FlowTestCase.java index 8489ff7c5..dd932d9f7 100644 --- a/javatests/google/registry/flows/FlowTestCase.java +++ b/javatests/google/registry/flows/FlowTestCase.java @@ -224,10 +224,11 @@ public abstract class FlowTestCase extends ShardableTestCase { assertThat(gracePeriod.hasBillingEvent()) .named("Billing event is present for grace period: " + gracePeriod) .isTrue(); - return firstNonNull( - gracePeriod.getOneTimeBillingEvent(), - gracePeriod.getRecurringBillingEvent()) - .get(); + return ofy().load() + .key(firstNonNull( + gracePeriod.getOneTimeBillingEvent(), + gracePeriod.getRecurringBillingEvent())) + .now(); }}; assertThat(canonicalizeGracePeriods(Maps.toMap(actual, gracePeriodExpander))) .isEqualTo(canonicalizeGracePeriods(expected)); diff --git a/javatests/google/registry/flows/ResourceFlowTestCase.java b/javatests/google/registry/flows/ResourceFlowTestCase.java index d999e16fe..6f7d1101f 100644 --- a/javatests/google/registry/flows/ResourceFlowTestCase.java +++ b/javatests/google/registry/flows/ResourceFlowTestCase.java @@ -128,7 +128,8 @@ public abstract class ResourceFlowTestCase() { @Override public boolean apply(EppResourceIndex index) { - return index.getReference().get().equals(resource); + return Key.create(resource).equals(index.getKey()) + && ofy().load().key(index.getKey()).now().equals(resource); }}) .toList(); assertThat(indices).hasSize(1); diff --git a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java index d1f5ac478..170167a75 100644 --- a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java +++ b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java @@ -32,7 +32,6 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactResource; @@ -75,7 +74,7 @@ public class DeleteContactResourceActionTest assertAboutContacts().that(contactUsed).doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and().hasDeletionTime(END_OF_TIME); domain = loadByUniqueId(DomainResource.class, "example.tld", now); - assertThat(domain.getReferencedContacts()).contains(Ref.create(contactUsed)); + assertThat(domain.getReferencedContacts()).contains(Key.create(contactUsed)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(contactUsed, HistoryEntry.Type.CONTACT_DELETE_FAILURE); assertPollMessageFor( diff --git a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java index b0d956348..b62c45a46 100644 --- a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java +++ b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java @@ -28,7 +28,6 @@ import static google.registry.testing.DatastoreHelper.persistResource; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.mapreduce.MapreduceRunner; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainResource; @@ -81,7 +80,7 @@ public abstract class DeleteEppResourceActionTestCase renamedHostRef = Ref.create(persistActiveHost("ns1.example.tld")); - Ref otherHostRef = Ref.create(persistActiveHost("ns2.example.tld")); + Key renamedHostKey = Key.create(persistActiveHost("ns1.example.tld")); + Key otherHostKey = Key.create(persistActiveHost("ns2.example.tld")); persistResource(newDomainApplication("notadomain.tld").asBuilder() - .setNameservers(ImmutableSet.of(renamedHostRef)) + .setNameservers(ImmutableSet.of(renamedHostKey)) .build()); persistResource(newDomainResource("example.tld").asBuilder() - .setNameservers(ImmutableSet.of(renamedHostRef)) + .setNameservers(ImmutableSet.of(renamedHostKey)) .build()); persistResource(newDomainResource("otherexample.tld").asBuilder() - .setNameservers(ImmutableSet.of(renamedHostRef)) + .setNameservers(ImmutableSet.of(renamedHostKey)) .build()); persistResource(newDomainResource("untouched.tld").asBuilder() - .setNameservers(ImmutableSet.of(otherHostRef)) + .setNameservers(ImmutableSet.of(otherHostKey)) .build()); - runMapreduce(renamedHostRef.getKey().getString()); + runMapreduce(renamedHostKey.getString()); verify(dnsQueue).addDomainRefreshTask("example.tld"); verify(dnsQueue).addDomainRefreshTask("otherexample.tld"); verifyNoMoreInteractions(dnsQueue); @@ -97,12 +96,12 @@ public class DnsRefreshForHostRenameActionTest @Test public void testSuccess_noDnsTasksForDeletedDomain() throws Exception { createTld("tld"); - Ref renamedHostRef = Ref.create(persistActiveHost("ns1.example.tld")); + Key renamedHostKey = Key.create(persistActiveHost("ns1.example.tld")); persistResource(newDomainResource("example.tld").asBuilder() - .setNameservers(ImmutableSet.of(renamedHostRef)) + .setNameservers(ImmutableSet.of(renamedHostKey)) .setDeletionTime(START_OF_TIME) .build()); - runMapreduce(renamedHostRef.getKey().getString()); + runMapreduce(renamedHostKey.getString()); verifyZeroInteractions(dnsQueue); } diff --git a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java index 9e641d547..9fc0505af 100644 --- a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java @@ -17,6 +17,7 @@ package google.registry.flows.domain; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType; @@ -39,7 +40,7 @@ import static org.joda.money.CurrencyUnit.USD; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.ResourceCreateFlow.ResourceAlreadyExistsException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.domain.DomainAllocateFlow.HasFinalStatusException; @@ -208,11 +209,11 @@ public class DomainAllocateFlowTest CLIENT_ID, null), createBillingEvent)); - assertThat(domain.getAutorenewBillingEvent().get().getEventTime()) + assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime()) .isEqualTo(domain.getRegistrationExpirationTime()); assertThat(domain.getApplicationTime()).isEqualTo(APPLICATION_TIME); - assertThat(domain.getApplication()).isEqualTo(Ref.create(application)); + assertThat(domain.getApplication()).isEqualTo(Key.create(application)); if (nameservers == 0) { assertNoDnsTasksEnqueued(); } else { diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index c04f064f1..5d7d58ca1 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -26,7 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ResourceFlow.BadCommandForRegistryPhaseException; import google.registry.flows.ResourceFlowTestCase; @@ -85,10 +85,10 @@ public class DomainApplicationDeleteFlowTest persistResource(newDomainApplication("example.tld").asBuilder() .setRepoId("1-TLD") .setRegistrant( - Ref.create( + Key.create( loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()))) .setNameservers(ImmutableSet.of( - Ref.create( + Key.create( loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc())))) .build()); doSuccessfulTest(); diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index 134c5cd10..6d38022f5 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -25,7 +25,7 @@ import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceQueryFlow.ResourceToQueryDoesNotExistException; @@ -87,12 +87,12 @@ public class DomainApplicationInfoFlowTest .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) .setLastTransferTime(DateTime.parse("2000-04-08T09:00:00.0Z")) - .setRegistrant(Ref.create(registrant)) + .setRegistrant(Key.create(registrant)) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Ref.create(contact)), - DesignatedContact.create(Type.TECH, Ref.create(contact)))) + DesignatedContact.create(Type.ADMIN, Key.create(contact)), + DesignatedContact.create(Type.TECH, Key.create(contact)))) .setNameservers(hostsState.equals(HostsState.HOSTS_EXIST) ? ImmutableSet.of( - Ref.create(host1), Ref.create(host2)) : null) + Key.create(host1), Key.create(host2)) : null) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) .addStatusValue(StatusValue.PENDING_CREATE) .setApplicationStatus(ApplicationStatus.PENDING_VALIDATION) @@ -242,7 +242,7 @@ public class DomainApplicationInfoFlowTest .setDsData(ImmutableSet.of(DelegationSignerData.create( 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")))) .setNameservers(ImmutableSet.of( - Ref.create(host1), Ref.create(host2))) + Key.create(host1), Key.create(host2))) .build()); doSuccessfulTest("domain_info_sunrise_response_dsdata.xml", HostsState.NO_HOSTS_EXIST); } @@ -275,7 +275,7 @@ public class DomainApplicationInfoFlowTest .setRepoId("123-COM") .setFullyQualifiedDomainName("timber.com") .setDeletionTime(DateTime.now().minusDays(1)) - .setRegistrant(Ref.create(persistActiveContact("jd1234"))) + .setRegistrant(Key.create(persistActiveContact("jd1234"))) .build()); runFlow(); } @@ -296,7 +296,7 @@ public class DomainApplicationInfoFlowTest persistResource(new DomainApplication.Builder() .setRepoId("123-TLD") .setFullyQualifiedDomainName("invalid.tld") - .setRegistrant(Ref.create(persistActiveContact("jd1234"))) + .setRegistrant(Key.create(persistActiveContact("jd1234"))) .setPhase(LaunchPhase.SUNRUSH) .build()); runFlow(); diff --git a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java index dd26a9544..e268f79dd 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java @@ -29,7 +29,7 @@ import static google.registry.testing.DomainApplicationSubject.assertAboutApplic import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; @@ -104,9 +104,9 @@ public class DomainApplicationUpdateFlowTest private DomainApplication persistApplication() throws Exception { return persistResource(newApplicationBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact)), - DesignatedContact.create(Type.ADMIN, Ref.create(unusedContact)))) - .setNameservers(ImmutableSet.of(Ref.create( + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), + DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) + .setNameservers(ImmutableSet.of(Key.create( loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .build()); } @@ -170,7 +170,7 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()); persistResource( - newApplicationBuilder().setRegistrant(Ref.create(sh8013)).build()); + newApplicationBuilder().setRegistrant(Key.create(sh8013)).build()); clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_update_response.xml")); } @@ -180,13 +180,13 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_remove_multiple_contacts.xml"); persistReferencedEntities(); ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()); - Ref sh8013Ref = Ref.create(sh8013); + Key sh8013Key = Key.create(sh8013); persistResource(newApplicationBuilder() - .setRegistrant(sh8013Ref) + .setRegistrant(sh8013Key) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, sh8013Ref), - DesignatedContact.create(Type.BILLING, sh8013Ref), - DesignatedContact.create(Type.TECH, sh8013Ref))) + DesignatedContact.create(Type.ADMIN, sh8013Key), + DesignatedContact.create(Type.BILLING, sh8013Key), + DesignatedContact.create(Type.TECH, sh8013Key))) .build()); clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_update_response.xml")); @@ -369,10 +369,10 @@ public class DomainApplicationUpdateFlowTest } private void modifyApplicationToHave13Nameservers() throws Exception { - ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); for (int i = 1; i < 15; i++) { if (i != 2) { // Skip 2 since that's the one that the tests will add. - nameservers.add(Ref.create(loadByUniqueId( + nameservers.add(Key.create(loadByUniqueId( HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); } } @@ -492,7 +492,7 @@ public class DomainApplicationUpdateFlowTest // Add a tech contact to the persisted entity, which should cause the flow to fail when it tries // to add "mak21" as a second tech contact. persistResource(reloadResourceByUniqueId().asBuilder().setContacts(ImmutableSet.of( - DesignatedContact.create(Type.TECH, Ref.create( + DesignatedContact.create(Type.TECH, Key.create( loadByUniqueId(ContactResource.class, "foo", clock.nowUtc()))))).build()); runFlow(); } @@ -576,7 +576,7 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_add_remove_same_host.xml"); persistReferencedEntities(); persistResource(newApplicationBuilder() - .setNameservers(ImmutableSet.of(Ref.create( + .setNameservers(ImmutableSet.of(Key.create( loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .build()); runFlow(); @@ -590,7 +590,7 @@ public class DomainApplicationUpdateFlowTest persistResource(newApplicationBuilder() .setContacts(ImmutableSet.of(DesignatedContact.create( Type.TECH, - Ref.create( + Key.create( loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()))))) .build()); runFlow(); @@ -603,8 +603,8 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistResource(newApplicationBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Ref.create(sh8013Contact)), - DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact)))) + DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) .build()); runFlow(); } @@ -616,8 +616,8 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistResource(newApplicationBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Ref.create(sh8013Contact)), - DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact)))) + DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) .build()); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index 9111e46d5..14580ad1b 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -181,7 +181,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCaseof()); } - + private void doImmediateDeleteTest( GracePeriodStatus gracePeriodStatus, String responseFilename, @@ -296,7 +295,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCaseof()); } - + private void doSuccessfulTest_noAddGracePeriod( String responseFilename, Map substitutions) throws Exception { // Persist the billing event so it can be retrieved for cancellation generation and checking. @@ -373,7 +372,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase[]{}))) @@ -554,12 +554,12 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase .setCreationClientId("TheRegistrar") .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setRegistrationExpirationTime(REGISTRATION_EXPIRATION_TIME) - .setRegistrant(Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))) + .setRegistrant(Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))) .setContacts(ImmutableSet.of( DesignatedContact.create( Type.ADMIN, - Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))), + Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))), DesignatedContact.create( Type.TECH, - Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))))) + Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("fooBAR"))) .addGracePeriod(GracePeriod.create( GracePeriodStatus.ADD, clock.nowUtc().plusDays(10), "foo", null)) @@ -163,11 +163,11 @@ public class DomainTransferFlowTestCase .setCurrentSponsorClientId("TheRegistrar") .setCreationClientId("TheRegistrar") .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) - .setSuperordinateDomain(Ref.create(domain)) + .setSuperordinateDomain(Key.create(domain)) .build()); domain = persistResource(domain.asBuilder() - .setAutorenewBillingEvent(Ref.create(autorenewEvent)) - .setAutorenewPollMessage(Ref.create(autorenewPollMessage)) + .setAutorenewBillingEvent(Key.create(autorenewEvent)) + .setAutorenewPollMessage(Key.create(autorenewPollMessage)) .addSubordinateHost(subordinateHost.getFullyQualifiedHostName()) .build()); } diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index e0ebfe21e..fbec36baa 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -15,6 +15,7 @@ package google.registry.flows.domain; import static com.google.common.truth.Truth.assertThat; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType; @@ -192,7 +193,8 @@ public class DomainTransferRequestFlowTest .build()) .toArray(BillingEvent.class)); // The domain's autorenew billing event should still point to the losing client's event. - BillingEvent.Recurring domainAutorenewEvent = domain.getAutorenewBillingEvent().get(); + BillingEvent.Recurring domainAutorenewEvent = + ofy().load().key(domain.getAutorenewBillingEvent()).now(); assertThat(domainAutorenewEvent.getClientId()).isEqualTo("TheRegistrar"); assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime); // The original grace periods should remain untouched. @@ -263,8 +265,9 @@ public class DomainTransferRequestFlowTest assertAboutDomains().that(domainAfterAutomaticTransfer) .hasRegistrationExpirationTime(expectedExpirationTime); - assertThat(domainAfterAutomaticTransfer.getAutorenewBillingEvent().get().getEventTime()) - .isEqualTo(expectedExpirationTime); + assertThat(ofy().load().key(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).now() + .getEventTime()) + .isEqualTo(expectedExpirationTime); // And after the expected grace time, the grace period should be gone. DomainResource afterGracePeriod = domain.cloneProjectedAtTime( clock.nowUtc().plus(Registry.get("tld").getAutomaticTransferLength()).plus( @@ -315,7 +318,7 @@ public class DomainTransferRequestFlowTest assertTransactionalFlow(true); runFlow(CommitMode.LIVE, userPrivileges); } - + private void runTest(String commandFilename, UserPrivileges userPrivileges) throws Exception { runTest(commandFilename, userPrivileges, ImmutableMap.of()); } @@ -516,7 +519,7 @@ public class DomainTransferRequestFlowTest .setBillingTime(oldResource.getRegistrationExpirationTime().plus( Registry.get("tld").getAutoRenewGracePeriodLength())) // The cancellation should refer to the old autorenew billing event. - .setRecurringEventRef(oldResource.getAutorenewBillingEvent())); + .setRecurringEventKey(oldResource.getAutorenewBillingEvent())); } @Test diff --git a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java index ffe22e4d5..027f63742 100644 --- a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -18,6 +18,7 @@ import static com.google.common.collect.Sets.union; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; @@ -39,7 +40,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.EppRequestSource; import google.registry.flows.ResourceCreateOrMutateFlow.OnlyToolCanPassMetadataException; @@ -123,9 +123,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); for (int i = 1; i < 15; i++) { if (i != 2) { // Skip 2 since that's the one that the tests will add. - nameservers.add(Ref.create(loadByUniqueId( + nameservers.add(Key.create(loadByUniqueId( HostResource.class, String.format("ns%d.example.foo", i), clock.nowUtc()))); } } @@ -374,11 +374,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); for (int i = 0; i < 26; i++) { HostResource host = persistActiveHost(String.format("max_test_%d.example.tld", i)); if (i < 13) { - nameservers.add(Ref.create(host)); + nameservers.add(Key.create(host)); } } ImmutableList.Builder contactsBuilder = new ImmutableList.Builder<>(); @@ -386,14 +386,14 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase contacts = contactsBuilder.build(); persistResource( reloadResourceByUniqueId().asBuilder() .setNameservers(nameservers.build()) .setContacts(ImmutableSet.copyOf(contacts.subList(0, 3))) - .setRegistrant(contacts.get(3).getContactRef()) + .setRegistrant(contacts.get(3).getContactKey()) .build()); clock.advanceOneMilli(); assertTransactionalFlow(true); @@ -406,7 +406,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase sh8013Ref = Ref.create(sh8013); + Key sh8013Key = Key.create(sh8013); persistResource( newDomainResource(getUniqueIdFromCommand()).asBuilder() - .setRegistrant(sh8013Ref) + .setRegistrant(sh8013Key) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, sh8013Ref), - DesignatedContact.create(Type.BILLING, sh8013Ref), - DesignatedContact.create(Type.TECH, sh8013Ref))) + DesignatedContact.create(Type.ADMIN, sh8013Key), + DesignatedContact.create(Type.BILLING, sh8013Key), + DesignatedContact.create(Type.TECH, sh8013Key))) .build()); clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_update_response.xml")); @@ -890,7 +891,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCasecreate(persistHostResource(true)))) + .addNameservers(ImmutableSet.of(Key.create(persistHostResource(true)))) .build()); assertTransactionalFlow(false); // Check that the persisted host info was returned. @@ -112,7 +111,7 @@ public class HostInfoFlowTest extends ResourceFlowTestCase oldFkiBeforeRename = ForeignKeyIndex.load( HostResource.class, oldHostName(), clock.nowUtc().minusMillis(1)); - assertThat(oldFkiBeforeRename.getReference()).isEqualTo(Ref.create(renamedHost)); + assertThat(oldFkiBeforeRename.getResourceKey()).isEqualTo(Key.create(renamedHost)); assertThat(oldFkiBeforeRename.getDeletionTime()).isEqualTo(clock.nowUtc()); ForeignKeyIndex oldFkiAfterRename = ForeignKeyIndex.load( @@ -157,7 +156,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase1080:0:0:0:8:800:200C:417A"); createTld("tld"); persistResource(newHostResource(oldHostName()).asBuilder() - .setSuperordinateDomain(Ref.create(persistActiveDomain("example.tld"))) + .setSuperordinateDomain(Key.create(persistActiveDomain("example.tld"))) .build()); thrown.expect(CannotRemoveSubordinateHostLastIpException.class); runFlow(); @@ -759,7 +758,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase hydratable; + Key hydratable; - Ref unhydratable; + Key unhydratable; - Key key; + Map> map; - Map> map; - - Set> set; + Set> set; ReferenceUnion referenceUnion; } @@ -297,21 +294,12 @@ public class ImmutableObjectTest { UnhydratableObject unhydratable = new UnhydratableObject(); unhydratable.value = "unexpected"; RootObject root = new RootObject(); - root.hydratable = Ref.create(persistResource(hydratable)); - root.unhydratable = Ref.create(persistResource(unhydratable)); + root.hydratable = Key.create(persistResource(hydratable)); + root.unhydratable = Key.create(persistResource(unhydratable)); assertThat(root.toHydratedString()).contains("expected"); assertThat(root.toHydratedString()).doesNotContain("unexpected"); } - @Test - public void testToHydratedString_skipsKeys() { - HydratableObject hydratable = new HydratableObject(); - hydratable.value = "unexpected"; - RootObject root = new RootObject(); - root.key = Key.create(persistResource(hydratable)); - assertThat(root.toHydratedString()).doesNotContain("unexpected"); - } - @Test public void testToHydratedString_expandsMaps() { HydratableObject hydratable = new HydratableObject(); @@ -319,9 +307,9 @@ public class ImmutableObjectTest { UnhydratableObject unhydratable = new UnhydratableObject(); unhydratable.value = "unexpected"; RootObject root = new RootObject(); - root.map = ImmutableMap.>of( - "hydratable", Ref.create(persistResource(hydratable)), - "unhydratable", Ref.create(persistResource(unhydratable))); + root.map = ImmutableMap.>of( + "hydratable", Key.create(persistResource(hydratable)), + "unhydratable", Key.create(persistResource(unhydratable))); assertThat(root.toHydratedString()).contains("expected"); assertThat(root.toHydratedString()).doesNotContain("unexpected"); } @@ -333,9 +321,9 @@ public class ImmutableObjectTest { UnhydratableObject unhydratable = new UnhydratableObject(); unhydratable.value = "unexpected"; RootObject root = new RootObject(); - root.set = ImmutableSet.>of( - Ref.create(persistResource(hydratable)), - Ref.create(persistResource(unhydratable))); + root.set = ImmutableSet.>of( + Key.create(persistResource(hydratable)), + Key.create(persistResource(unhydratable))); assertThat(root.toHydratedString()).contains("expected"); assertThat(root.toHydratedString()).doesNotContain("unexpected"); } @@ -343,7 +331,7 @@ public class ImmutableObjectTest { @Test public void testToHydratedString_expandsReferenceUnions() { RootObject root = new RootObject(); - root.referenceUnion = ReferenceUnion.create(Ref.create(persistActiveContact("expected"))); + root.referenceUnion = ReferenceUnion.create(Key.create(persistActiveContact("expected"))); assertThat(root.toHydratedString()).contains("expected"); } } diff --git a/javatests/google/registry/model/billing/BillingEventTest.java b/javatests/google/registry/model/billing/BillingEventTest.java index b7ab8d244..3b9ed8c47 100644 --- a/javatests/google/registry/model/billing/BillingEventTest.java +++ b/javatests/google/registry/model/billing/BillingEventTest.java @@ -25,7 +25,6 @@ import static org.joda.time.DateTimeZone.UTC; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.EntityTestCase; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; @@ -106,14 +105,14 @@ public class BillingEventTest extends EntityTestCase { .setReason(Reason.CREATE) .setEventTime(now.plusDays(1)) .setBillingTime(now.plusDays(5)) - .setOneTimeEventRef(Ref.create(oneTime)))); + .setOneTimeEventKey(Key.create(oneTime)))); cancellationRecurring = persistResource(commonInit( new BillingEvent.Cancellation.Builder() .setParent(historyEntry2) .setReason(Reason.RENEW) .setEventTime(now.plusDays(1)) .setBillingTime(now.plusYears(1).plusDays(45)) - .setRecurringEventRef(Ref.create(recurring)))); + .setRecurringEventKey(Key.create(recurring)))); modification = persistResource(commonInit( new BillingEvent.Modification.Builder() .setParent(historyEntry2) @@ -121,7 +120,7 @@ public class BillingEventTest extends EntityTestCase { .setCost(Money.of(USD, 1)) .setDescription("Something happened") .setEventTime(now.plusDays(1)) - .setEventRef(Ref.create(oneTime)))); + .setEventKey(Key.create(oneTime)))); } private > E commonInit(B builder) { @@ -169,7 +168,7 @@ public class BillingEventTest extends EntityTestCase { .getCancellationMatchingBillingEvent(); assertThat(ofy().load().key(recurringKey).now()).isEqualTo(recurring); } - + @Test public void testIndexing() throws Exception { verifyIndexing(oneTime, "clientId", "eventTime", "billingTime", "syntheticCreationTime"); @@ -241,7 +240,7 @@ public class BillingEventTest extends EntityTestCase { GracePeriodStatus.AUTO_RENEW, now.plusYears(1).plusDays(45), "a registrar", - Ref.create(recurring)), + Key.create(recurring)), historyEntry2, "foo.tld"); // Set ID to be the same to ignore for the purposes of comparison. @@ -264,15 +263,15 @@ public class BillingEventTest extends EntityTestCase { @Test public void testFailure_cancellationWithNoBillingEvent() { thrown.expect(IllegalStateException.class, "exactly one billing event"); - cancellationOneTime.asBuilder().setOneTimeEventRef(null).setRecurringEventRef(null).build(); + cancellationOneTime.asBuilder().setOneTimeEventKey(null).setRecurringEventKey(null).build(); } @Test public void testFailure_cancellationWithBothBillingEvents() { thrown.expect(IllegalStateException.class, "exactly one billing event"); cancellationOneTime.asBuilder() - .setOneTimeEventRef(Ref.create(oneTime)) - .setRecurringEventRef(Ref.create(recurring)) + .setOneTimeEventKey(Key.create(oneTime)) + .setRecurringEventKey(Key.create(recurring)) .build(); } diff --git a/javatests/google/registry/model/domain/DomainApplicationTest.java b/javatests/google/registry/model/domain/DomainApplicationTest.java index 47b7a4060..fd3ff6ae5 100644 --- a/javatests/google/registry/model/domain/DomainApplicationTest.java +++ b/javatests/google/registry/model/domain/DomainApplicationTest.java @@ -29,7 +29,6 @@ import static org.joda.money.CurrencyUnit.USD; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.EntityTestCase; import google.registry.model.billing.BillingEvent; import google.registry.model.domain.launch.ApplicationStatus; @@ -77,12 +76,12 @@ public class DomainApplicationTest extends EntityTestCase { StatusValue.SERVER_UPDATE_PROHIBITED, StatusValue.SERVER_RENEW_PROHIBITED, StatusValue.SERVER_HOLD)) - .setRegistrant(Ref.create(persistActiveContact("contact_id1"))) + .setRegistrant(Key.create(persistActiveContact("contact_id1"))) .setContacts(ImmutableSet.of(DesignatedContact.create( DesignatedContact.Type.ADMIN, - Ref.create(persistActiveContact("contact_id2"))))) + Key.create(persistActiveContact("contact_id2"))))) .setNameservers( - ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.com")))) + ImmutableSet.of(Key.create(persistActiveHost("ns1.example.com")))) .setCurrentSponsorClientId("a third registrar") .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("password"))) .setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) @@ -148,12 +147,12 @@ public class DomainApplicationTest extends EntityTestCase { public void testEmptySetsAndArraysBecomeNull() { assertThat(emptyBuilder().setNameservers(null).build().nameservers).isNull(); assertThat(emptyBuilder() - .setNameservers(ImmutableSet.>of()) + .setNameservers(ImmutableSet.>of()) .build() .nameservers) .isNull(); assertThat(emptyBuilder() - .setNameservers(ImmutableSet.of(Ref.create(newHostResource("foo.example.tld")))) + .setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld")))) .build() .nameservers) .isNotNull(); diff --git a/javatests/google/registry/model/domain/DomainResourceTest.java b/javatests/google/registry/model/domain/DomainResourceTest.java index ca6f4c92f..07191438d 100644 --- a/javatests/google/registry/model/domain/DomainResourceTest.java +++ b/javatests/google/registry/model/domain/DomainResourceTest.java @@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.flows.EppXmlTransformer; import google.registry.model.EntityTestCase; import google.registry.model.billing.BillingEvent; @@ -111,11 +110,11 @@ public class DomainResourceTest extends EntityTestCase { StatusValue.SERVER_UPDATE_PROHIBITED, StatusValue.SERVER_RENEW_PROHIBITED, StatusValue.SERVER_HOLD)) - .setRegistrant(Ref.create(contactResource1)) + .setRegistrant(Key.create(contactResource1)) .setContacts(ImmutableSet.of(DesignatedContact.create( DesignatedContact.Type.ADMIN, - Ref.create(contactResource2)))) - .setNameservers(ImmutableSet.of(Ref.create(hostResource))) + Key.create(contactResource2)))) + .setNameservers(ImmutableSet.of(Key.create(hostResource))) .setSubordinateHosts(ImmutableSet.of("ns1.example.com")) .setCurrentSponsorClientId("ThirdRegistrar") .setRegistrationExpirationTime(clock.nowUtc().plusYears(1)) @@ -135,21 +134,21 @@ public class DomainResourceTest extends EntityTestCase { Key.create(BillingEvent.Recurring.class, 2), Key.create(PollMessage.Autorenew.class, 3))) .setServerApproveBillingEvent( - Ref.create(Key.create(BillingEvent.OneTime.class, 1))) + Key.create(BillingEvent.OneTime.class, 1)) .setServerApproveAutorenewEvent( - Ref.create(Key.create(BillingEvent.Recurring.class, 2))) + Key.create(BillingEvent.Recurring.class, 2)) .setServerApproveAutorenewPollMessage( - Ref.create(Key.create(PollMessage.Autorenew.class, 3))) + Key.create(PollMessage.Autorenew.class, 3)) .setTransferRequestTime(clock.nowUtc().plusDays(1)) .setTransferStatus(TransferStatus.SERVER_APPROVED) .setTransferRequestTrid(Trid.create("client trid")) .build()) .setDeletePollMessage(Key.create(PollMessage.OneTime.class, 1)) - .setAutorenewBillingEvent(Ref.create(Key.create(BillingEvent.Recurring.class, 1))) - .setAutorenewPollMessage(Ref.create(Key.create(PollMessage.Autorenew.class, 2))) + .setAutorenewBillingEvent(Key.create(BillingEvent.Recurring.class, 1)) + .setAutorenewPollMessage(Key.create(PollMessage.Autorenew.class, 2)) .setSmdId("smdid") .setApplicationTime(START_OF_TIME) - .setApplication(Ref.create(Key.create(DomainApplication.class, 1))) + .setApplication(Key.create(DomainApplication.class, 1)) .addGracePeriod(GracePeriod.create( GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "registrar", null)) .build()); @@ -198,10 +197,10 @@ public class DomainResourceTest extends EntityTestCase { assertThat(newDomainResource("example.com").asBuilder() .setNameservers(null).build().nameservers).isNull(); assertThat(newDomainResource("example.com").asBuilder() - .setNameservers(ImmutableSet.>of()).build().nameservers) + .setNameservers(ImmutableSet.>of()).build().nameservers) .isNull(); assertThat(newDomainResource("example.com").asBuilder() - .setNameservers(ImmutableSet.of(Ref.create(newHostResource("foo.example.tld")))) + .setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld")))) .build().nameservers) .isNotNull(); // This behavior should also hold true for ImmutableObjects nested in collections. @@ -230,8 +229,8 @@ public class DomainResourceTest extends EntityTestCase { @Test public void testImplicitStatusValues() { - ImmutableSet> nameservers = - ImmutableSet.of(Ref.create(newHostResource("foo.example.tld"))); + ImmutableSet> nameservers = + ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))); StatusValue[] statuses = {StatusValue.OK}; // OK is implicit if there's no other statuses but there are nameservers. assertAboutDomains() @@ -284,7 +283,7 @@ public class DomainResourceTest extends EntityTestCase { assertThat(domain.getCurrentSponsorClientId()).isEqualTo("winner"); assertThat(domain.getLastTransferTime()).isEqualTo(clock.nowUtc().plusDays(1)); assertThat(domain.getRegistrationExpirationTime()).isEqualTo(newExpirationTime); - assertThat(domain.getAutorenewBillingEvent().getKey()).isEqualTo(newAutorenewEvent); + assertThat(domain.getAutorenewBillingEvent()).isEqualTo(newAutorenewEvent); } private void doExpiredTransferTest(DateTime oldExpirationTime) { @@ -308,7 +307,7 @@ public class DomainResourceTest extends EntityTestCase { .setTransferRequestTime(clock.nowUtc().minusDays(4)) .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .setGainingClientId("winner") - .setServerApproveBillingEvent(Ref.create(Key.create(transferBillingEvent))) + .setServerApproveBillingEvent(Key.create(transferBillingEvent)) .setServerApproveEntities(ImmutableSet.>of( Key.create(transferBillingEvent))) .setExtendedRegistrationYears(1) @@ -321,14 +320,14 @@ public class DomainResourceTest extends EntityTestCase { DomainResource afterTransfer = domain.cloneProjectedAtTime(clock.nowUtc().plusDays(1)); DateTime newExpirationTime = oldExpirationTime.plusYears(1); Key serverApproveAutorenewEvent = - domain.getTransferData().getServerApproveAutorenewEvent().getKey(); + domain.getTransferData().getServerApproveAutorenewEvent(); assertTransferred(afterTransfer, newExpirationTime, serverApproveAutorenewEvent); assertThat(afterTransfer.getGracePeriods()) .containsExactly(GracePeriod.create( GracePeriodStatus.TRANSFER, clock.nowUtc().plusDays(1).plus(Registry.get("com").getTransferGracePeriodLength()), "winner", - Ref.create(transferBillingEvent))); + Key.create(transferBillingEvent))); // If we project after the grace period expires all should be the same except the grace period. DomainResource afterGracePeriod = domain.cloneProjectedAtTime( clock.nowUtc().plusDays(2).plus(Registry.get("com").getTransferGracePeriodLength())); @@ -420,7 +419,7 @@ public class DomainResourceTest extends EntityTestCase { oldExpirationTime.plusYears(2).plus( Registry.get("com").getAutoRenewGracePeriodLength()), renewedThreeTimes.getCurrentSponsorClientId(), - Ref.create(renewedThreeTimes.autorenewBillingEvent.key()))); + renewedThreeTimes.autorenewBillingEvent)); } @Test diff --git a/javatests/google/registry/model/domain/GracePeriodTest.java b/javatests/google/registry/model/domain/GracePeriodTest.java index 00575c881..aa65b2b16 100644 --- a/javatests/google/registry/model/domain/GracePeriodTest.java +++ b/javatests/google/registry/model/domain/GracePeriodTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.joda.time.DateTimeZone.UTC; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Recurring; @@ -68,7 +67,7 @@ public class GracePeriodTest { public void testSuccess_forBillingEvent() { GracePeriod gracePeriod = GracePeriod.forBillingEvent(GracePeriodStatus.ADD, onetime); assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.ADD); - assertThat(gracePeriod.getOneTimeBillingEvent()).isEqualTo(Ref.create(onetime)); + assertThat(gracePeriod.getOneTimeBillingEvent()).isEqualTo(Key.create(onetime)); assertThat(gracePeriod.getRecurringBillingEvent()).isNull(); assertThat(gracePeriod.getClientId()).isEqualTo("TheRegistrar"); assertThat(gracePeriod.getExpirationTime()).isEqualTo(now.plusDays(1)); @@ -108,6 +107,6 @@ public class GracePeriodTest { GracePeriodStatus.RENEW, now.plusDays(1), "TheRegistrar", - Ref.create(Key.create(Recurring.class, 12345))); + Key.create(Recurring.class, 12345)); } } diff --git a/javatests/google/registry/model/host/HostResourceTest.java b/javatests/google/registry/model/host/HostResourceTest.java index 843c7c1a5..fb770133b 100644 --- a/javatests/google/registry/model/host/HostResourceTest.java +++ b/javatests/google/registry/model/host/HostResourceTest.java @@ -25,7 +25,6 @@ import static google.registry.testing.HostResourceSubject.assertAboutHosts; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.EntityTestCase; import google.registry.model.billing.BillingEvent; import google.registry.model.domain.DomainResource; @@ -84,7 +83,7 @@ public class HostResourceTest extends EntityTestCase { .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) .setStatusValues(ImmutableSet.of(StatusValue.OK)) .setSuperordinateDomain( - Ref.create(loadByUniqueId(DomainResource.class, "example.com", clock.nowUtc()))) + Key.create(loadByUniqueId(DomainResource.class, "example.com", clock.nowUtc()))) .build()); persistResource(hostResource); } @@ -265,7 +264,7 @@ public class HostResourceTest extends EntityTestCase { .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .setGainingClientId("winner") .setExtendedRegistrationYears(2) - .setServerApproveBillingEvent(Ref.create( + .setServerApproveBillingEvent(Key.create( new BillingEvent.OneTime.Builder() .setParent(new HistoryEntry.Builder().setParent(domain).build()) .setCost(Money.parse("USD 100")) diff --git a/javatests/google/registry/model/index/DomainApplicationIndexTest.java b/javatests/google/registry/model/index/DomainApplicationIndexTest.java index 1536123e9..1c300b982 100644 --- a/javatests/google/registry/model/index/DomainApplicationIndexTest.java +++ b/javatests/google/registry/model/index/DomainApplicationIndexTest.java @@ -16,7 +16,7 @@ package google.registry.model.index; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.index.DomainApplicationIndex.createUpdatedInstance; -import static google.registry.model.index.DomainApplicationIndex.createWithSpecifiedReferences; +import static google.registry.model.index.DomainApplicationIndex.createWithSpecifiedKeys; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainApplication; @@ -24,7 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistSimpleResource; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.EntityTestCase; import google.registry.model.domain.DomainApplication; import google.registry.testing.ExceptionRule; @@ -46,14 +46,14 @@ public class DomainApplicationIndexTest extends EntityTestCase { @Test public void testFailure_create_nullReferences() { - thrown.expect(IllegalArgumentException.class, "References must not be null or empty."); - DomainApplicationIndex.createWithSpecifiedReferences("blah.com", null); + thrown.expect(IllegalArgumentException.class, "Keys must not be null or empty."); + DomainApplicationIndex.createWithSpecifiedKeys("blah.com", null); } @Test public void testFailure_create_emptyReferences() { - thrown.expect(IllegalArgumentException.class, "References must not be null or empty."); - createWithSpecifiedReferences("blah.com", ImmutableSet.>of()); + thrown.expect(IllegalArgumentException.class, "Keys must not be null or empty."); + createWithSpecifiedKeys("blah.com", ImmutableSet.>of()); } @Test @@ -62,7 +62,7 @@ public class DomainApplicationIndexTest extends EntityTestCase { persistResource(createUpdatedInstance(application)); DomainApplicationIndex savedIndex = DomainApplicationIndex.load("example.com"); assertThat(savedIndex).isNotNull(); - assertThat(savedIndex.getReferences()).containsExactly(Ref.create(application)); + assertThat(savedIndex.getKeys()).containsExactly(Key.create(application)); assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now())) .containsExactly(application); } @@ -83,8 +83,8 @@ public class DomainApplicationIndexTest extends EntityTestCase { persistResource(createUpdatedInstance(application3)); DomainApplicationIndex savedIndex = DomainApplicationIndex.load("example.com"); assertThat(savedIndex).isNotNull(); - assertThat(savedIndex.getReferences()).containsExactly( - Ref.create(application1), Ref.create(application2), Ref.create(application3)); + assertThat(savedIndex.getKeys()).containsExactly( + Key.create(application1), Key.create(application2), Key.create(application3)); assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now())) .containsExactly(application1, application2, application3); } @@ -113,7 +113,7 @@ public class DomainApplicationIndexTest extends EntityTestCase { persistResource(createUpdatedInstance(application2)); DomainApplicationIndex savedIndex = DomainApplicationIndex.load(application1.getFullyQualifiedDomainName()); - assertThat(savedIndex.getReferences()).hasSize(2); + assertThat(savedIndex.getKeys()).hasSize(2); assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now())) .containsExactly(application1); } diff --git a/javatests/google/registry/model/index/EppResourceIndexTest.java b/javatests/google/registry/model/index/EppResourceIndexTest.java index 6f34d6d96..12c379063 100644 --- a/javatests/google/registry/model/index/EppResourceIndexTest.java +++ b/javatests/google/registry/model/index/EppResourceIndexTest.java @@ -44,7 +44,7 @@ public class EppResourceIndexTest extends EntityTestCase { @Test public void testPersistence() throws Exception { EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); - assertThat(loadedIndex.reference.get()).isEqualTo(contact); + assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); } @Test @@ -56,7 +56,7 @@ public class EppResourceIndexTest extends EntityTestCase { public void testIdempotentOnUpdate() throws Exception { contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build()); EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); - assertThat(loadedIndex.reference.get()).isEqualTo(contact); + assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); } /** diff --git a/javatests/google/registry/model/index/ForeignKeyIndexTest.java b/javatests/google/registry/model/index/ForeignKeyIndexTest.java index 8a81e09b0..0c5c0cfdf 100644 --- a/javatests/google/registry/model/index/ForeignKeyIndexTest.java +++ b/javatests/google/registry/model/index/ForeignKeyIndexTest.java @@ -15,13 +15,14 @@ package google.registry.model.index; import static com.google.common.truth.Truth.assertThat; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.util.DateTimeUtils.END_OF_TIME; import com.google.common.collect.ImmutableList; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.EntityTestCase; import google.registry.model.host.HostResource; import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex; @@ -47,7 +48,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { HostResource host = persistActiveHost("ns1.example.com"); ForeignKeyIndex fki = ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc()); - assertThat(fki.getReference().get()).isEqualTo(host); + assertThat(ofy().load().key(fki.getResourceKey()).now()).isEqualTo(host); assertThat(fki.getDeletionTime()).isEqualTo(END_OF_TIME); } @@ -80,7 +81,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { clock.advanceOneMilli(); ForeignKeyHostIndex fki = new ForeignKeyHostIndex(); fki.foreignKey = "ns1.example.com"; - fki.topReference = Ref.create(host1); + fki.topReference = Key.create(host1); fki.deletionTime = clock.nowUtc(); persistResource(fki); assertThat(ForeignKeyIndex.load( diff --git a/javatests/google/registry/model/ofy/OfyTest.java b/javatests/google/registry/model/ofy/OfyTest.java index 83cfeb31b..b15ff42d2 100644 --- a/javatests/google/registry/model/ofy/OfyTest.java +++ b/javatests/google/registry/model/ofy/OfyTest.java @@ -88,7 +88,8 @@ public class OfyTest { } private void doBackupGroupRootTimestampInversionTest(VoidWork work) { - DateTime groupTimestamp = someObject.getParent().get().getUpdateAutoTimestamp().getTimestamp(); + DateTime groupTimestamp = ofy().load().key(someObject.getParent()).now() + .getUpdateAutoTimestamp().getTimestamp(); // Set the clock in Ofy to the same time as the backup group root's save time. Ofy ofy = new Ofy(new FakeClock(groupTimestamp)); thrown.expect( diff --git a/javatests/google/registry/model/schema.txt b/javatests/google/registry/model/schema.txt index 6ef63ec90..afd4f07bb 100644 --- a/javatests/google/registry/model/schema.txt +++ b/javatests/google/registry/model/schema.txt @@ -11,8 +11,8 @@ class google.registry.model.UpdateAutoTimestamp { class google.registry.model.billing.BillingEvent$Cancellation { @Id long id; @Parent com.googlecode.objectify.Key parent; - com.googlecode.objectify.Ref refOneTime; - com.googlecode.objectify.Ref refRecurring; + com.googlecode.objectify.Key refOneTime; + com.googlecode.objectify.Key refRecurring; google.registry.model.billing.BillingEvent$Reason reason; java.lang.String clientId; java.lang.String targetId; @@ -31,7 +31,7 @@ enum google.registry.model.billing.BillingEvent$Flag { class google.registry.model.billing.BillingEvent$Modification { @Id long id; @Parent com.googlecode.objectify.Key parent; - com.googlecode.objectify.Ref eventRef; + com.googlecode.objectify.Key eventRef; google.registry.model.billing.BillingEvent$Reason reason; java.lang.String clientId; java.lang.String description; @@ -86,7 +86,7 @@ class google.registry.model.billing.RegistrarBillingEntry { } class google.registry.model.billing.RegistrarCredit { @Id long id; - @Parent com.googlecode.objectify.Ref parent; + @Parent com.googlecode.objectify.Key parent; google.registry.model.billing.RegistrarCredit$CreditType type; java.lang.String description; java.lang.String tld; @@ -99,7 +99,7 @@ enum google.registry.model.billing.RegistrarCredit$CreditType { } class google.registry.model.billing.RegistrarCreditBalance { @Id long id; - @Parent com.googlecode.objectify.Ref parent; + @Parent com.googlecode.objectify.Key parent; org.joda.money.Money amount; org.joda.time.DateTime effectiveTime; org.joda.time.DateTime writtenTime; @@ -142,7 +142,7 @@ class google.registry.model.contact.ContactPhoneNumber { } class google.registry.model.contact.ContactResource { @Id java.lang.String repoId; - com.google.common.collect.ImmutableSortedMap> revisions; + com.google.common.collect.ImmutableSortedMap> revisions; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; google.registry.model.contact.ContactAuthInfo authInfo; @@ -197,7 +197,7 @@ enum google.registry.model.domain.DesignatedContact$Type { } class google.registry.model.domain.DomainApplication { @Id java.lang.String repoId; - com.google.common.collect.ImmutableSortedMap> revisions; + com.google.common.collect.ImmutableSortedMap> revisions; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; google.registry.model.domain.DomainAuthInfo authInfo; @@ -227,7 +227,7 @@ class google.registry.model.domain.DomainAuthInfo { } class google.registry.model.domain.DomainBase { @Id java.lang.String repoId; - com.google.common.collect.ImmutableSortedMap> revisions; + com.google.common.collect.ImmutableSortedMap> revisions; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; google.registry.model.domain.DomainAuthInfo authInfo; @@ -249,11 +249,11 @@ class google.registry.model.domain.DomainBase { } class google.registry.model.domain.DomainResource { @Id java.lang.String repoId; - com.google.common.collect.ImmutableSortedMap> revisions; + com.google.common.collect.ImmutableSortedMap> revisions; com.googlecode.objectify.Key deletePollMessage; - com.googlecode.objectify.Ref autorenewBillingEvent; - com.googlecode.objectify.Ref application; - com.googlecode.objectify.Ref autorenewPollMessage; + com.googlecode.objectify.Key autorenewBillingEvent; + com.googlecode.objectify.Key application; + com.googlecode.objectify.Key autorenewPollMessage; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; google.registry.model.domain.DomainAuthInfo authInfo; @@ -279,8 +279,8 @@ class google.registry.model.domain.DomainResource { org.joda.time.DateTime registrationExpirationTime; } class google.registry.model.domain.GracePeriod { - com.googlecode.objectify.Ref billingEventOneTime; - com.googlecode.objectify.Ref billingEventRecurring; + com.googlecode.objectify.Key billingEventOneTime; + com.googlecode.objectify.Key billingEventRecurring; google.registry.model.domain.rgp.GracePeriodStatus type; java.lang.String clientId; org.joda.time.DateTime expirationTime; @@ -301,7 +301,7 @@ enum google.registry.model.domain.Period$Unit { YEARS; } class google.registry.model.domain.ReferenceUnion { - com.googlecode.objectify.Ref linked; + com.googlecode.objectify.Key linked; } enum google.registry.model.domain.launch.ApplicationStatus { ALLOCATED; @@ -384,8 +384,8 @@ class google.registry.model.export.LogsExportCursor { } class google.registry.model.host.HostResource { @Id java.lang.String repoId; - com.google.common.collect.ImmutableSortedMap> revisions; - com.googlecode.objectify.Ref superordinateDomain; + com.google.common.collect.ImmutableSortedMap> revisions; + com.googlecode.objectify.Key superordinateDomain; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; google.registry.model.transfer.TransferData transferData; @@ -403,12 +403,12 @@ class google.registry.model.host.HostResource { class google.registry.model.index.DomainApplicationIndex { @Id java.lang.String fullyQualifiedDomainName; google.registry.model.UpdateAutoTimestamp updateTimestamp; - java.util.Set> references; + java.util.Set> references; } class google.registry.model.index.EppResourceIndex { @Id java.lang.String id; @Parent com.googlecode.objectify.Key bucket; - com.googlecode.objectify.Ref reference; + com.googlecode.objectify.Key reference; google.registry.model.UpdateAutoTimestamp updateTimestamp; java.lang.String kind; } @@ -417,19 +417,19 @@ class google.registry.model.index.EppResourceIndexBucket { } class google.registry.model.index.ForeignKeyIndex$ForeignKeyContactIndex { @Id java.lang.String foreignKey; - com.googlecode.objectify.Ref topReference; + com.googlecode.objectify.Key topReference; google.registry.model.UpdateAutoTimestamp updateTimestamp; org.joda.time.DateTime deletionTime; } class google.registry.model.index.ForeignKeyIndex$ForeignKeyDomainIndex { @Id java.lang.String foreignKey; - com.googlecode.objectify.Ref topReference; + com.googlecode.objectify.Key topReference; google.registry.model.UpdateAutoTimestamp updateTimestamp; org.joda.time.DateTime deletionTime; } class google.registry.model.index.ForeignKeyIndex$ForeignKeyHostIndex { @Id java.lang.String foreignKey; - com.googlecode.objectify.Ref topReference; + com.googlecode.objectify.Key topReference; google.registry.model.UpdateAutoTimestamp updateTimestamp; org.joda.time.DateTime deletionTime; } @@ -773,7 +773,7 @@ class google.registry.model.registry.label.ReservedList$ReservedListEntry { } class google.registry.model.reporting.HistoryEntry { @Id long id; - @Parent com.googlecode.objectify.Ref parent; + @Parent com.googlecode.objectify.Key parent; boolean bySuperuser; byte[] xmlBytes; google.registry.model.domain.Period period; @@ -858,9 +858,9 @@ class google.registry.model.tmch.TmchCrl { org.joda.time.DateTime updated; } class google.registry.model.transfer.TransferData { - com.googlecode.objectify.Ref serverApproveBillingEvent; - com.googlecode.objectify.Ref serverApproveAutorenewEvent; - com.googlecode.objectify.Ref serverApproveAutorenewPollMessage; + com.googlecode.objectify.Key serverApproveBillingEvent; + com.googlecode.objectify.Key serverApproveAutorenewEvent; + com.googlecode.objectify.Key serverApproveAutorenewPollMessage; google.registry.model.eppcommon.Trid transferRequestTrid; google.registry.model.transfer.TransferStatus transferStatus; java.lang.Integer extendedRegistrationYears; diff --git a/javatests/google/registry/model/transfer/TransferDataTest.java b/javatests/google/registry/model/transfer/TransferDataTest.java index ae295bd51..ee898e2b6 100644 --- a/javatests/google/registry/model/transfer/TransferDataTest.java +++ b/javatests/google/registry/model/transfer/TransferDataTest.java @@ -15,6 +15,7 @@ package google.registry.model.transfer; import static com.google.common.truth.Truth.assertThat; +import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.util.DateTimeUtils.END_OF_TIME; @@ -23,7 +24,6 @@ import static org.joda.time.DateTimeZone.UTC; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; @@ -125,10 +125,12 @@ public class TransferDataTest { @Test public void testSuccess_GetStoredBillingEventNoEntities() throws Exception { transferData = new TransferData.Builder() - .setServerApproveBillingEvent(Ref.create(Key.create(transferBillingEvent))) + .setServerApproveBillingEvent(Key.create(transferBillingEvent)) .build(); - assertThat(transferData.serverApproveBillingEvent.get()).isEqualTo(transferBillingEvent); - assertThat(transferData.getServerApproveBillingEvent().get()).isEqualTo(transferBillingEvent); + assertThat(ofy().load().key(transferData.serverApproveBillingEvent).now()) + .isEqualTo(transferBillingEvent); + assertThat(ofy().load().key(transferData.getServerApproveBillingEvent()).now()) + .isEqualTo(transferBillingEvent); } @Test @@ -139,9 +141,11 @@ public class TransferDataTest { Key.create(recurringBillingEvent), Key.create(PollMessage.OneTime.class, 1)); transferData = transferData.asBuilder() - .setServerApproveBillingEvent(Ref.create(Key.create(transferBillingEvent))) + .setServerApproveBillingEvent(Key.create(transferBillingEvent)) .build(); - assertThat(transferData.serverApproveBillingEvent.get()).isEqualTo(transferBillingEvent); - assertThat(transferData.getServerApproveBillingEvent().get()).isEqualTo(transferBillingEvent); + assertThat(ofy().load().key(transferData.serverApproveBillingEvent).now()) + .isEqualTo(transferBillingEvent); + assertThat(ofy().load().key(transferData.getServerApproveBillingEvent()).now()) + .isEqualTo(transferBillingEvent); } } diff --git a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java index 75748fdff..1bb06f1d0 100644 --- a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java +++ b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java @@ -21,8 +21,8 @@ import static org.joda.time.Duration.standardHours; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; +import com.googlecode.objectify.Key; import com.googlecode.objectify.ObjectifyService; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.Entity; @@ -52,7 +52,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { @Entity public static class TestObject extends CrossTldSingleton { - ImmutableSortedMap> revisions = ImmutableSortedMap.of(); + ImmutableSortedMap> revisions = ImmutableSortedMap.of(); } @Rule @@ -105,18 +105,17 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_translatorAddsReferenceToCommitLogToField() throws Exception { + public void testSave_translatorAddsKeyToCommitLogToField() throws Exception { save(new TestObject()); TestObject object = reload(); assertThat(object.revisions).hasSize(1); assertThat(object.revisions).containsKey(START_TIME); - Ref ref = object.revisions.get(START_TIME); - CommitLogManifest commitLogManifest = ref.get(); + CommitLogManifest commitLogManifest = ofy().load().key(object.revisions.get(START_TIME)).now(); assertThat(commitLogManifest.getCommitTime()).isEqualTo(START_TIME); } @Test - public void testSave_twoVersionsOnOneDay_referenceToLastCommitLogsGetsStored() throws Exception { + public void testSave_twoVersionsOnOneDay_keyToLastCommitLogsGetsStored() throws Exception { save(new TestObject()); clock.advanceBy(standardHours(1)); save(reload()); @@ -126,7 +125,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_twoVersionsOnTwoDays_referenceToBothCommitLogsGetsStored() throws Exception { + public void testSave_twoVersionsOnTwoDays_keyToBothCommitLogsGetsStored() throws Exception { save(new TestObject()); clock.advanceBy(standardDays(1)); save(reload()); diff --git a/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java b/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java index a4ac9e0f8..ae61bded9 100644 --- a/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java +++ b/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java @@ -42,7 +42,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.bigquery.BigqueryFactory; import google.registry.config.RegistryEnvironment; import google.registry.mapreduce.MapreduceRunner; @@ -187,11 +186,7 @@ public class VerifyEntityIntegrityActionTest persistResource( newDomainResource("blah.tld") .asBuilder() - .setNameservers( - ImmutableSet.of( - Ref.create(missingHost1), - Ref.create(missingHost2), - Ref.create(missingHost3))) + .setNameservers(ImmutableSet.of(missingHost1, missingHost2, missingHost3)) .build()); Key domainKey = Key.create(domain); runMapreduce(); diff --git a/javatests/google/registry/rdap/RdapDomainSearchActionTest.java b/javatests/google/registry/rdap/RdapDomainSearchActionTest.java index 9b1d41ee5..37f0c78b8 100644 --- a/javatests/google/registry/rdap/RdapDomainSearchActionTest.java +++ b/javatests/google/registry/rdap/RdapDomainSearchActionTest.java @@ -33,7 +33,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.domain.DomainResource; import google.registry.model.domain.Period; import google.registry.model.host.HostResource; @@ -144,9 +144,9 @@ public class RdapDomainSearchActionTest { registrar) .asBuilder().setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol")).build()); persistResource( - hostNs1CatLol.asBuilder().setSuperordinateDomain(Ref.create(domainCatLol)).build()); + hostNs1CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); persistResource( - hostNs2CatLol.asBuilder().setSuperordinateDomain(Ref.create(domainCatLol)).build()); + hostNs2CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); domainCatLol2 = persistResource(makeDomainResource( "cat2.lol", makeAndPersistContactResource( diff --git a/javatests/google/registry/rdap/RdapNameserverSearchActionTest.java b/javatests/google/registry/rdap/RdapNameserverSearchActionTest.java index e9e3fec26..895468d62 100644 --- a/javatests/google/registry/rdap/RdapNameserverSearchActionTest.java +++ b/javatests/google/registry/rdap/RdapNameserverSearchActionTest.java @@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.domain.DomainResource; import google.registry.model.host.HostResource; import google.registry.model.ofy.Ofy; @@ -121,9 +121,9 @@ public class RdapNameserverSearchActionTest { .setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol")) .build()); persistResource( - hostNs1CatLol.asBuilder().setSuperordinateDomain(Ref.create(domainCatLol)).build()); + hostNs1CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); persistResource( - hostNs2CatLol.asBuilder().setSuperordinateDomain(Ref.create(domainCatLol)).build()); + hostNs2CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); inject.setStaticField(Ofy.class, "clock", clock); action.clock = clock; diff --git a/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java b/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java index c76ad8600..8ce331962 100644 --- a/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java +++ b/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java @@ -32,7 +32,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; @@ -259,10 +258,10 @@ public class DomainResourceToXjcConverterTest { domain = domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret"))) .setContacts(ImmutableSet.of( - DesignatedContact.create(DesignatedContact.Type.ADMIN, Ref.create( + DesignatedContact.create(DesignatedContact.Type.ADMIN, Key.create( makeContactResource(clock, "10-Q9JYB4C", "5372808-IRL", "be that word our sign in parting", "BOFH@cat.みんな"))), - DesignatedContact.create(DesignatedContact.Type.TECH, Ref.create( + DesignatedContact.create(DesignatedContact.Type.TECH, Key.create( makeContactResource(clock, "11-Q9JYB4C", "5372808-TRL", "bird or fiend!? i shrieked upstarting", "bog@cat.みんな"))))) .setCreationClientId("LawyerCat") @@ -275,11 +274,11 @@ public class DomainResourceToXjcConverterTest { .setLastEppUpdateClientId("IntoTheTempest") .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) .setNameservers(ImmutableSet.of( - Ref.create( + Key.create( makeHostResource(clock, "3-Q9JYB4C", "bird.or.devil.みんな", "1.2.3.4")), - Ref.create( + Key.create( makeHostResource(clock, "4-Q9JYB4C", "ns2.cat.みんな", "bad:f00d:cafe::15:beef")))) - .setRegistrant(Ref.create(makeContactResource( + .setRegistrant(Key.create(makeContactResource( clock, "12-Q9JYB4C", "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな"))) .setRegistrationExpirationTime(DateTime.parse("1930-01-01T00:00:00Z")) .setGracePeriods(ImmutableSet.of( @@ -304,7 +303,7 @@ public class DomainResourceToXjcConverterTest { StatusValue.CLIENT_TRANSFER_PROHIBITED, StatusValue.SERVER_UPDATE_PROHIBITED)) .setAutorenewBillingEvent( - Ref.create(persistResource( + Key.create(persistResource( new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) @@ -315,7 +314,7 @@ public class DomainResourceToXjcConverterTest { .setParent(historyEntry) .build()))) .setAutorenewPollMessage( - Ref.create(persistResource( + Key.create(persistResource( new PollMessage.Autorenew.Builder() .setTargetId("lol") .setClientId("TheRegistrar") @@ -329,9 +328,9 @@ public class DomainResourceToXjcConverterTest { .setGainingClientId("gaining") .setLosingClientId("losing") .setPendingTransferExpirationTime(DateTime.parse("1925-04-20T00:00:00Z")) - .setServerApproveBillingEvent(Ref.create(billingEvent)) + .setServerApproveBillingEvent(Key.create(billingEvent)) .setServerApproveAutorenewEvent( - Ref.create(persistResource( + Key.create(persistResource( new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) @@ -341,7 +340,7 @@ public class DomainResourceToXjcConverterTest { .setRecurrenceEndTime(END_OF_TIME) .setParent(historyEntry) .build()))) - .setServerApproveAutorenewPollMessage(Ref.create(persistResource( + .setServerApproveAutorenewPollMessage(Key.create(persistResource( new Autorenew.Builder() .setTargetId("example.xn--q9jyb4c") .setClientId("TheRegistrar") @@ -351,7 +350,7 @@ public class DomainResourceToXjcConverterTest { .setParent(historyEntry) .build()))) .setServerApproveEntities(ImmutableSet.>of( - Ref.create(billingEvent).getKey())) + Key.create(billingEvent))) .setTransferRequestTime(DateTime.parse("1919-01-01T00:00:00Z")) .setTransferStatus(TransferStatus.PENDING) .setTransferRequestTrid(Trid.create("client trid")) diff --git a/javatests/google/registry/rde/RdeFixtures.java b/javatests/google/registry/rde/RdeFixtures.java index 76eeabc0c..73b970c23 100644 --- a/javatests/google/registry/rde/RdeFixtures.java +++ b/javatests/google/registry/rde/RdeFixtures.java @@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; @@ -63,7 +62,7 @@ final class RdeFixtures { DomainResource domain = new DomainResource.Builder() .setFullyQualifiedDomainName("example." + tld) .setRepoId(generateNewDomainRoid(tld)) - .setRegistrant(Ref.create( + .setRegistrant(Key.create( makeContactResource(clock, "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな"))) .build(); @@ -84,10 +83,10 @@ final class RdeFixtures { domain = domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret"))) .setContacts(ImmutableSet.of( - DesignatedContact.create(DesignatedContact.Type.ADMIN, Ref.create( + DesignatedContact.create(DesignatedContact.Type.ADMIN, Key.create( makeContactResource(clock, "5372808-IRL", "be that word our sign in parting", "BOFH@cat.みんな"))), - DesignatedContact.create(DesignatedContact.Type.TECH, Ref.create( + DesignatedContact.create(DesignatedContact.Type.TECH, Key.create( makeContactResource(clock, "5372808-TRL", "bird or fiend!? i shrieked upstarting", "bog@cat.みんな"))))) .setCreationClientId("TheRegistrar") @@ -101,9 +100,9 @@ final class RdeFixtures { .setLastEppUpdateTime(clock.nowUtc()) .setIdnTableName("extended_latin") .setNameservers(ImmutableSet.of( - Ref.create( + Key.create( makeHostResource(clock, "bird.or.devil.みんな", "1.2.3.4")), - Ref.create( + Key.create( makeHostResource( clock, "ns2.cat.みんな", "bad:f00d:cafe::15:beef")))) .setRegistrationExpirationTime(DateTime.parse("1930-01-01T00:00:00Z")) @@ -129,7 +128,7 @@ final class RdeFixtures { StatusValue.CLIENT_TRANSFER_PROHIBITED, StatusValue.SERVER_UPDATE_PROHIBITED)) .setAutorenewBillingEvent( - Ref.create(persistResource( + Key.create(persistResource( new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) @@ -140,7 +139,7 @@ final class RdeFixtures { .setParent(historyEntry) .build()))) .setAutorenewPollMessage( - Ref.create(persistSimpleResource( + Key.create(persistSimpleResource( new PollMessage.Autorenew.Builder() .setTargetId(tld) .setClientId("TheRegistrar") @@ -154,9 +153,9 @@ final class RdeFixtures { .setGainingClientId("gaining") .setLosingClientId("losing") .setPendingTransferExpirationTime(DateTime.parse("1925-04-20T00:00:00Z")) - .setServerApproveBillingEvent(Ref.create(billingEvent)) + .setServerApproveBillingEvent(Key.create(billingEvent)) .setServerApproveAutorenewEvent( - Ref.create(persistResource( + Key.create(persistResource( new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) @@ -166,7 +165,7 @@ final class RdeFixtures { .setRecurrenceEndTime(END_OF_TIME) .setParent(historyEntry) .build()))) - .setServerApproveAutorenewPollMessage(Ref.create(persistResource( + .setServerApproveAutorenewPollMessage(Key.create(persistResource( new Autorenew.Builder() .setTargetId("example." + tld) .setClientId("TheRegistrar") @@ -176,7 +175,7 @@ final class RdeFixtures { .setParent(historyEntry) .build()))) .setServerApproveEntities(ImmutableSet.>of( - Ref.create(billingEvent).getKey())) + Key.create(billingEvent))) .setTransferRequestTime(DateTime.parse("1919-01-01T00:00:00Z")) .setTransferStatus(TransferStatus.PENDING) .setTransferRequestTrid(Trid.create("client trid")) diff --git a/javatests/google/registry/rde/RdeImportUtilsTest.java b/javatests/google/registry/rde/RdeImportUtilsTest.java index c5906f53b..a20f8d936 100644 --- a/javatests/google/registry/rde/RdeImportUtilsTest.java +++ b/javatests/google/registry/rde/RdeImportUtilsTest.java @@ -202,7 +202,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { .filter(new Predicate() { @Override public boolean apply(EppResourceIndex index) { - return index.getReference().get().equals(resource); + return ofy().load().key(index.getKey()).now().equals(resource); }}) .toList(); assertThat(indices).hasSize(1); diff --git a/javatests/google/registry/server/Fixture.java b/javatests/google/registry/server/Fixture.java index 6b4c84cec..2fc310ae9 100644 --- a/javatests/google/registry/server/Fixture.java +++ b/javatests/google/registry/server/Fixture.java @@ -25,7 +25,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactResource; import google.registry.model.contact.PostalInfo; @@ -112,26 +112,26 @@ public enum Fixture { persistResource( newDomainResource("love.xn--q9jyb4c", justine).asBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(ADMIN, Ref.create(robert)), - DesignatedContact.create(BILLING, Ref.create(google)), - DesignatedContact.create(TECH, Ref.create(justine)))) + DesignatedContact.create(ADMIN, Key.create(robert)), + DesignatedContact.create(BILLING, Key.create(google)), + DesignatedContact.create(TECH, Key.create(justine)))) .setNameservers(ImmutableSet.of( - Ref.create(persistActiveHost("ns1.love.xn--q9jyb4c")), - Ref.create(persistActiveHost("ns2.love.xn--q9jyb4c")))) + Key.create(persistActiveHost("ns1.love.xn--q9jyb4c")), + Key.create(persistActiveHost("ns2.love.xn--q9jyb4c")))) .build()); persistResource( newDomainResource("moogle.example", justine).asBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(ADMIN, Ref.create(robert)), - DesignatedContact.create(BILLING, Ref.create(google)), - DesignatedContact.create(TECH, Ref.create(justine)))) + DesignatedContact.create(ADMIN, Key.create(robert)), + DesignatedContact.create(BILLING, Key.create(google)), + DesignatedContact.create(TECH, Key.create(justine)))) .setNameservers(ImmutableSet.of( - Ref.create(persistActiveHost("ns1.linode.com")), - Ref.create(persistActiveHost("ns2.linode.com")), - Ref.create(persistActiveHost("ns3.linode.com")), - Ref.create(persistActiveHost("ns4.linode.com")), - Ref.create(persistActiveHost("ns5.linode.com")))) + Key.create(persistActiveHost("ns1.linode.com")), + Key.create(persistActiveHost("ns2.linode.com")), + Key.create(persistActiveHost("ns3.linode.com")), + Key.create(persistActiveHost("ns4.linode.com")), + Key.create(persistActiveHost("ns5.linode.com")))) .build()); persistResource( diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index fa9e6ea7f..f966d100c 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -48,7 +48,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.cmd.Saver; @@ -129,7 +128,7 @@ public class DatastoreHelper { public static DomainResource newDomainResource( String domainName, String repoId, ContactResource contact) { - Ref contactRef = Ref.create(contact); + Key contactKey = Key.create(contact); return new DomainResource.Builder() .setRepoId(repoId) .setFullyQualifiedDomainName(domainName) @@ -137,10 +136,10 @@ public class DatastoreHelper { .setCurrentSponsorClientId("TheRegistrar") .setCreationTimeForTest(START_OF_TIME) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) - .setRegistrant(contactRef) + .setRegistrant(contactKey) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, contactRef), - DesignatedContact.create(Type.TECH, contactRef))) + DesignatedContact.create(Type.ADMIN, contactKey), + DesignatedContact.create(Type.TECH, contactKey))) .setRegistrationExpirationTime(END_OF_TIME) .build(); } @@ -170,16 +169,16 @@ public class DatastoreHelper { public static DomainApplication newDomainApplication( String domainName, String repoId, ContactResource contact, LaunchPhase phase) { - Ref contactRef = Ref.create(contact); + Key contactKey = Key.create(contact); return new DomainApplication.Builder() .setRepoId(repoId) .setFullyQualifiedDomainName(domainName) .setCurrentSponsorClientId("TheRegistrar") .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) - .setRegistrant(contactRef) + .setRegistrant(contactKey) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, contactRef), - DesignatedContact.create(Type.TECH, contactRef))) + DesignatedContact.create(Type.ADMIN, contactKey), + DesignatedContact.create(Type.TECH, contactKey))) .setPhase(phase) .setApplicationStatus(VALIDATED) .addStatusValue(StatusValue.PENDING_CREATE) @@ -261,7 +260,7 @@ public class DatastoreHelper { return persistResource( newHostResource(hostName) .asBuilder() - .setSuperordinateDomain(Ref.create(superordinateDomain)) + .setSuperordinateDomain(Key.create(superordinateDomain)) .build()); } @@ -526,18 +525,20 @@ public class DatastoreHelper { .build()); // Modify the existing autorenew event to reflect the pending transfer. persistResource( - domain.getAutorenewBillingEvent().get().asBuilder() + ofy().load().key(domain.getAutorenewBillingEvent()).now().asBuilder() .setRecurrenceEndTime(expirationTime) .build()); // Update the end time of the existing autorenew poll message. We must delete it if it has no // events left in it. - if (domain.getAutorenewPollMessage().get().getEventTime().isBefore(expirationTime)) { + PollMessage.Autorenew autorenewPollMessage = + ofy().load().key(domain.getAutorenewPollMessage()).now(); + if (autorenewPollMessage.getEventTime().isBefore(expirationTime)) { persistResource( - domain.getAutorenewPollMessage().get().asBuilder() + autorenewPollMessage.asBuilder() .setAutorenewEndTime(expirationTime) .build()); } else { - deleteResource(domain.getAutorenewPollMessage().get()); + deleteResource(autorenewPollMessage); } Builder transferDataBuilder = createTransferDataBuilder( requestTime, expirationTime, extendedRegistrationYears); @@ -546,9 +547,9 @@ public class DatastoreHelper { .addStatusValue(StatusValue.PENDING_TRANSFER) .setTransferData(transferDataBuilder .setPendingTransferExpirationTime(expirationTime) - .setServerApproveBillingEvent(Ref.create(transferBillingEvent)) - .setServerApproveAutorenewEvent(Ref.create(gainingClientAutorenewEvent)) - .setServerApproveAutorenewPollMessage(Ref.create(gainingClientAutorenewPollMessage)) + .setServerApproveBillingEvent(Key.create(transferBillingEvent)) + .setServerApproveAutorenewEvent(Key.create(gainingClientAutorenewEvent)) + .setServerApproveAutorenewPollMessage(Key.create(gainingClientAutorenewPollMessage)) .setServerApproveEntities(ImmutableSet.>of( Key.create(transferBillingEvent), Key.create(gainingClientAutorenewEvent), diff --git a/javatests/google/registry/testing/FullFieldsTestEntityHelper.java b/javatests/google/registry/testing/FullFieldsTestEntityHelper.java index ac6f1a128..418a4f6d5 100644 --- a/javatests/google/registry/testing/FullFieldsTestEntityHelper.java +++ b/javatests/google/registry/testing/FullFieldsTestEntityHelper.java @@ -23,7 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.EppResource; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactPhoneNumber; @@ -233,27 +233,27 @@ public final class FullFieldsTestEntityHelper { StatusValue.SERVER_UPDATE_PROHIBITED)) .setDsData(ImmutableSet.of(new DelegationSignerData())); if (registrant != null) { - builder.setRegistrant(Ref.create(registrant)); + builder.setRegistrant(Key.create(registrant)); } if ((admin != null) || (tech != null)) { ImmutableSet.Builder contactsBuilder = new ImmutableSet.Builder<>(); if (admin != null) { contactsBuilder.add(DesignatedContact.create( - DesignatedContact.Type.ADMIN, Ref.create(admin))); + DesignatedContact.Type.ADMIN, Key.create(admin))); } if (tech != null) { contactsBuilder.add(DesignatedContact.create( - DesignatedContact.Type.TECH, Ref.create(tech))); + DesignatedContact.Type.TECH, Key.create(tech))); } builder.setContacts(contactsBuilder.build()); } if ((ns1 != null) || (ns2 != null)) { - ImmutableSet.Builder> nsBuilder = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nsBuilder = new ImmutableSet.Builder<>(); if (ns1 != null) { - nsBuilder.add(Ref.create(ns1)); + nsBuilder.add(Key.create(ns1)); } if (ns2 != null) { - nsBuilder.add(Ref.create(ns2)); + nsBuilder.add(Key.create(ns2)); } builder.setNameservers(nsBuilder.build()); } diff --git a/javatests/google/registry/tmch/LordnTaskTest.java b/javatests/google/registry/tmch/LordnTaskTest.java index 25ac7a485..4b9b62159 100644 --- a/javatests/google/registry/tmch/LordnTaskTest.java +++ b/javatests/google/registry/tmch/LordnTaskTest.java @@ -32,7 +32,7 @@ import com.google.appengine.api.taskqueue.TaskOptions.Method; import com.google.appengine.api.taskqueue.TransientFailureException; import com.google.apphosting.api.DeadlineExceededException; import com.google.common.collect.ImmutableList; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import com.googlecode.objectify.VoidWork; import google.registry.model.domain.DomainResource; import google.registry.model.domain.launch.LaunchNotice; @@ -104,7 +104,7 @@ public class LordnTaskTest { private DomainResource.Builder newDomainBuilder(DateTime applicationTime) { return new DomainResource.Builder() .setFullyQualifiedDomainName("fleece.example") - .setRegistrant(Ref.create(persistActiveContact("jd1234"))) + .setRegistrant(Key.create(persistActiveContact("jd1234"))) .setSmdId("smdzzzz") .setCreationClientId("TheRegistrar") .setApplicationTime(applicationTime); diff --git a/javatests/google/registry/tools/AllocateDomainCommandTest.java b/javatests/google/registry/tools/AllocateDomainCommandTest.java index b8f659ee4..3b2747dcb 100644 --- a/javatests/google/registry/tools/AllocateDomainCommandTest.java +++ b/javatests/google/registry/tools/AllocateDomainCommandTest.java @@ -35,7 +35,7 @@ import static google.registry.util.ResourceUtils.readResourceBytes; import com.beust.jcommander.ParameterException; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.flows.domain.DomainAllocateFlow; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainApplication; @@ -71,20 +71,20 @@ public class AllocateDomainCommandTest extends CommandTestCase> hostRefs = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> hostRefs = new ImmutableSet.Builder<>(); for (HostResource host : hosts) { - hostRefs.add(Ref.create(host)); + hostRefs.add(Key.create(host)); } persistResource(newDomainResource("evil.tld").asBuilder() .setNameservers(hostRefs.build()) diff --git a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java index 3d8f0765a..e9e4b09a0 100644 --- a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java +++ b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java @@ -36,7 +36,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.mapreduce.MapreduceRunner; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; @@ -70,8 +70,8 @@ public class GenerateZoneFilesActionTest extends MapreduceTestCase> nameservers = - ImmutableSet.of(Ref.create(host1), Ref.create(host2)); + ImmutableSet> nameservers = + ImmutableSet.of(Key.create(host1), Key.create(host2)); persistResource(newDomainResource("ns-and-ds.tld").asBuilder() .addNameservers(nameservers) .setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) diff --git a/javatests/google/registry/whois/DomainWhoisResponseTest.java b/javatests/google/registry/whois/DomainWhoisResponseTest.java index 6dca60e17..10c0aff71 100644 --- a/javatests/google/registry/whois/DomainWhoisResponseTest.java +++ b/javatests/google/registry/whois/DomainWhoisResponseTest.java @@ -22,7 +22,7 @@ import static google.registry.whois.WhoisHelper.loadWhoisTestFile; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; +import com.googlecode.objectify.Key; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactResource; @@ -205,11 +205,11 @@ public class DomainWhoisResponseTest { .setEmailAddress("EMAIL@EXAMPLE.tld") .build()); - Ref hostResource1Ref = Ref.create(hostResource1); - Ref hostResource2Ref = Ref.create(hostResource2); - Ref registrantResourceRef = Ref.create(registrant); - Ref adminResourceRef = Ref.create(adminContact); - Ref techResourceRef = Ref.create(techContact); + Key hostResource1Key = Key.create(hostResource1); + Key hostResource2Key = Key.create(hostResource2); + Key registrantResourceKey = Key.create(registrant); + Key adminResourceKey = Key.create(adminContact); + Key techResourceKey = Key.create(techContact); domainResource = persistResource(new DomainResource.Builder() .setFullyQualifiedDomainName("EXAMPLE.tld") @@ -223,11 +223,11 @@ public class DomainWhoisResponseTest { StatusValue.CLIENT_RENEW_PROHIBITED, StatusValue.CLIENT_TRANSFER_PROHIBITED, StatusValue.SERVER_UPDATE_PROHIBITED)) - .setRegistrant(registrantResourceRef) + .setRegistrant(registrantResourceKey) .setContacts(ImmutableSet.of( - DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceRef), - DesignatedContact.create(DesignatedContact.Type.TECH, techResourceRef))) - .setNameservers(ImmutableSet.of(hostResource1Ref, hostResource2Ref)) + DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey), + DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey))) + .setNameservers(ImmutableSet.of(hostResource1Key, hostResource2Key)) .setDsData(ImmutableSet.of(new DelegationSignerData())) .setGracePeriods(ImmutableSet.of( GracePeriod.create(GracePeriodStatus.ADD, END_OF_TIME, "", null), diff --git a/javatests/google/registry/whois/RegistrarWhoisResponseTest.java b/javatests/google/registry/whois/RegistrarWhoisResponseTest.java index 86d79f95e..554544ecf 100644 --- a/javatests/google/registry/whois/RegistrarWhoisResponseTest.java +++ b/javatests/google/registry/whois/RegistrarWhoisResponseTest.java @@ -62,7 +62,7 @@ public class RegistrarWhoisResponseTest { .setWhoisServer("whois.example-registrar.tld") .setReferralUrl("http://www.example-registrar.tld") .build(); - // Use the registrar ref for contacts' parent. + // Use the registrar key for contacts' parent. ImmutableList contacts = ImmutableList.of( new RegistrarContact.Builder() .setParent(registrar)