mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 02:36:03 +02:00
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<T> 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<T> and Key<T> 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<T> for every Ref<T> you want to pass in - Creating a Ref<T> is more cumbersome, since it doesn't have all the create() overloads that Key<T> has, only create(Key<T>) 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
This commit is contained in:
parent
1a60073b24
commit
5098b03af4
119 changed files with 772 additions and 817 deletions
|
@ -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<ContactResource> contact) {
|
||||
public static DesignatedContact create(Type type, Key<ContactResource> 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<ContactResource>.
|
||||
//TODO(b/28713909): Make this a Key<ContactResource>.
|
||||
ReferenceUnion<ContactResource> contactId;
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Ref<ContactResource> getContactRef() {
|
||||
public Key<ContactResource> getContactKey() {
|
||||
return contactId.getLinked();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ContactResource> foundContact = null;
|
||||
for (Ref<ContactResource> contact : domain.getReferencedContacts()) {
|
||||
String contactRepoId = contact.getKey().getName();
|
||||
Key<ContactResource> foundContact = null;
|
||||
for (Key<ContactResource> 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();
|
||||
}
|
||||
|
|
|
@ -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<Ref<HostResource>>.
|
||||
//TODO(b/28713909): Make this a Set<Key<HostResource>>.
|
||||
Set<ReferenceUnion<HostResource>> 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<Ref<HostResource>> getNameservers() {
|
||||
ImmutableSet.Builder<Ref<HostResource>> builder = new ImmutableSet.Builder<>();
|
||||
public ImmutableSet<Key<HostResource>> getNameservers() {
|
||||
ImmutableSet.Builder<Key<HostResource>> builder = new ImmutableSet.Builder<>();
|
||||
for (ReferenceUnion<HostResource> 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<String> loadNameserverFullyQualifiedHostNames() {
|
||||
return FluentIterable.from(ofy().load().refs(getNameservers()).values())
|
||||
return FluentIterable.from(ofy().load().keys(getNameservers()).values())
|
||||
.transform(
|
||||
new Function<HostResource, String>() {
|
||||
@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<ContactResource> getRegistrant() {
|
||||
/** A key to the registrant who registered this domain. */
|
||||
public Key<ContactResource> 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<Ref<ContactResource>> getReferencedContacts() {
|
||||
ImmutableSet.Builder<Ref<ContactResource>> contactsBuilder =
|
||||
public ImmutableSet<Key<ContactResource>> getReferencedContacts() {
|
||||
ImmutableSet.Builder<Key<ContactResource>> 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<ContactResource> registrant) {
|
||||
public B setRegistrant(Key<ContactResource> 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<Ref<HostResource>> nameservers) {
|
||||
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
||||
ImmutableSet.Builder<ReferenceUnion<HostResource>> builder = new ImmutableSet.Builder<>();
|
||||
for (Ref<HostResource> ref : nullToEmpty(nameservers)) {
|
||||
builder.add(ReferenceUnion.create(ref));
|
||||
for (Key<HostResource> key : nullToEmpty(nameservers)) {
|
||||
builder.add(ReferenceUnion.create(key));
|
||||
}
|
||||
getInstance().nameservers = builder.build();
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
public B addNameservers(ImmutableSet<Ref<HostResource>> nameservers) {
|
||||
public B addNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
||||
return setNameservers(
|
||||
ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers)));
|
||||
}
|
||||
|
||||
public B removeNameservers(ImmutableSet<Ref<HostResource>> nameservers) {
|
||||
public B removeNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
||||
return setNameservers(
|
||||
ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers)));
|
||||
}
|
||||
|
|
|
@ -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<ContactResource> registrant;
|
||||
Key<ContactResource> registrant;
|
||||
|
||||
/** Authorization info (aka transfer secret) of the domain. */
|
||||
DomainAuthInfo authInfo;
|
||||
|
@ -94,7 +94,7 @@ public class DomainCommand {
|
|||
return registrantContactId;
|
||||
}
|
||||
|
||||
public Ref<ContactResource> getRegistrant() {
|
||||
public Key<ContactResource> getRegistrant() {
|
||||
return registrant;
|
||||
}
|
||||
|
||||
|
@ -134,15 +134,15 @@ public class DomainCommand {
|
|||
@XmlElement(name = "hostObj")
|
||||
Set<String> 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<Ref<HostResource>> nameservers;
|
||||
Set<Key<HostResource>> nameservers;
|
||||
|
||||
/** Foreign keyed associated contacts for the domain (other than registrant). */
|
||||
@XmlElement(name = "contact")
|
||||
Set<ForeignKeyedDesignatedContact> 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<DesignatedContact> contacts;
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class DomainCommand {
|
|||
return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames);
|
||||
}
|
||||
|
||||
public ImmutableSet<Ref<HostResource>> getNameservers() {
|
||||
public ImmutableSet<Key<HostResource>> 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<String> 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<Ref<HostResource>> nameservers;
|
||||
Set<Key<HostResource>> nameservers;
|
||||
|
||||
/** Foreign keyed associated contacts for the domain (other than registrant). */
|
||||
@XmlElement(name = "contact")
|
||||
Set<ForeignKeyedDesignatedContact> 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<DesignatedContact> contacts;
|
||||
|
||||
|
@ -389,7 +389,7 @@ public class DomainCommand {
|
|||
return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames);
|
||||
}
|
||||
|
||||
public ImmutableSet<Ref<HostResource>> getNameservers() {
|
||||
public ImmutableSet<Key<HostResource>> 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<Ref<HostResource>> linkHosts(
|
||||
private static Set<Key<HostResource>> linkHosts(
|
||||
Set<String> 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<DesignatedContact> linkContacts(
|
||||
|
@ -474,8 +474,8 @@ public class DomainCommand {
|
|||
for (ForeignKeyedDesignatedContact contact : contacts) {
|
||||
foreignKeys.add(contact.contactId);
|
||||
}
|
||||
ImmutableMap<String, Ref<ContactResource>> loadedContacts =
|
||||
loadReferences(foreignKeys.build(), ContactResource.class, now);
|
||||
ImmutableMap<String, Key<ContactResource>> loadedContacts =
|
||||
loadByForeignKey(foreignKeys.build(), ContactResource.class, now);
|
||||
ImmutableSet.Builder<DesignatedContact> 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 <T extends EppResource> ImmutableMap<String, Ref<T>> loadReferences(
|
||||
/** Load keys to resources by their foreign keys. */
|
||||
private static <T extends EppResource> ImmutableMap<String, Key<T>> loadByForeignKey(
|
||||
final Set<String> foreignKeys, final Class<T> clazz, final DateTime now)
|
||||
throws InvalidReferencesException {
|
||||
Map<String, ForeignKeyIndex<T>> fkis = ofy().doTransactionless(
|
||||
|
@ -500,10 +500,10 @@ public class DomainCommand {
|
|||
}
|
||||
return ImmutableMap.copyOf(transformValues(
|
||||
fkis,
|
||||
new Function<ForeignKeyIndex<T>, Ref<T>>() {
|
||||
new Function<ForeignKeyIndex<T>, Key<T>>() {
|
||||
@Override
|
||||
public Ref<T> apply(ForeignKeyIndex<T> fki) {
|
||||
return fki.getReference();
|
||||
public Key<T> apply(ForeignKeyIndex<T> fki) {
|
||||
return fki.getResourceKey();
|
||||
}}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<BillingEvent.Recurring> autorenewBillingEvent;
|
||||
Key<BillingEvent.Recurring> 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<PollMessage.Autorenew> autorenewPollMessage;
|
||||
Key<PollMessage.Autorenew> 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<DomainApplication> application;
|
||||
Key<DomainApplication> application;
|
||||
|
||||
public ImmutableSet<String> getSubordinateHosts() {
|
||||
return nullToEmptyImmutableCopy(subordinateHosts);
|
||||
|
@ -165,11 +164,11 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
return deletePollMessage;
|
||||
}
|
||||
|
||||
public Ref<BillingEvent.Recurring> getAutorenewBillingEvent() {
|
||||
public Key<BillingEvent.Recurring> getAutorenewBillingEvent() {
|
||||
return autorenewBillingEvent;
|
||||
}
|
||||
|
||||
public Ref<PollMessage.Autorenew> getAutorenewPollMessage() {
|
||||
public Key<PollMessage.Autorenew> getAutorenewPollMessage() {
|
||||
return autorenewPollMessage;
|
||||
}
|
||||
|
||||
|
@ -185,7 +184,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
return applicationTime;
|
||||
}
|
||||
|
||||
public Ref<DomainApplication> getApplication() {
|
||||
public Key<DomainApplication> 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<BillingEvent.Recurring> autorenewBillingEvent) {
|
||||
public Builder setAutorenewBillingEvent(Key<BillingEvent.Recurring> autorenewBillingEvent) {
|
||||
getInstance().autorenewBillingEvent = autorenewBillingEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAutorenewPollMessage(Ref<PollMessage.Autorenew> autorenewPollMessage) {
|
||||
public Builder setAutorenewPollMessage(Key<PollMessage.Autorenew> autorenewPollMessage) {
|
||||
getInstance().autorenewPollMessage = autorenewPollMessage;
|
||||
return this;
|
||||
}
|
||||
|
@ -418,7 +417,7 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setApplication(Ref<DomainApplication> application) {
|
||||
public Builder setApplication(Key<DomainApplication> application) {
|
||||
getInstance().application = application;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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<BillingEvent.OneTime> billingEventOneTime = null;
|
||||
Key<BillingEvent.OneTime> 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<BillingEvent.Recurring> billingEventRecurring = null;
|
||||
Key<BillingEvent.Recurring> 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<BillingEvent.OneTime> getOneTimeBillingEvent() {
|
||||
public Key<BillingEvent.OneTime> 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<BillingEvent.Recurring> getRecurringBillingEvent() {
|
||||
public Key<BillingEvent.Recurring> getRecurringBillingEvent() {
|
||||
return billingEventRecurring;
|
||||
}
|
||||
|
||||
|
@ -101,8 +101,8 @@ public class GracePeriod extends ImmutableObject {
|
|||
GracePeriodStatus type,
|
||||
DateTime expirationTime,
|
||||
String clientId,
|
||||
@Nullable Ref<BillingEvent.OneTime> billingEventOneTime,
|
||||
@Nullable Ref<BillingEvent.Recurring> billingEventRecurring) {
|
||||
@Nullable Key<BillingEvent.OneTime> billingEventOneTime,
|
||||
@Nullable Key<BillingEvent.Recurring> 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<BillingEvent.OneTime> billingEventOneTime) {
|
||||
@Nullable Key<BillingEvent.OneTime> billingEventOneTime) {
|
||||
return createInternal(type, expirationTime, clientId, billingEventOneTime, null);
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class GracePeriod extends ImmutableObject {
|
|||
GracePeriodStatus type,
|
||||
DateTime expirationTime,
|
||||
String clientId,
|
||||
Ref<BillingEvent.Recurring> billingEventRecurring) {
|
||||
Key<BillingEvent.Recurring> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <T> the type being referenced
|
||||
*/
|
||||
|
@ -30,13 +30,13 @@ import google.registry.model.ImmutableObject;
|
|||
public class ReferenceUnion<T extends EppResource> extends ImmutableObject {
|
||||
|
||||
@Index
|
||||
Ref<T> linked;
|
||||
Key<T> linked;
|
||||
|
||||
public Ref<T> getLinked() {
|
||||
public Key<T> getLinked() {
|
||||
return linked;
|
||||
}
|
||||
|
||||
public static <T extends EppResource> ReferenceUnion<T> create(Ref<T> linked) {
|
||||
public static <T extends EppResource> ReferenceUnion<T> create(Key<T> linked) {
|
||||
ReferenceUnion<T> instance = new ReferenceUnion<>();
|
||||
instance.linked = linked;
|
||||
return instance;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue