mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 16:30:12 +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
|
@ -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<DateTime, Ref<CommitLogManifest>> revisions = ImmutableSortedMap.of();
|
||||
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> 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<DateTime, Ref<CommitLogManifest>> getRevisions() {
|
||||
public ImmutableSortedMap<DateTime, Key<CommitLogManifest>> getRevisions() {
|
||||
return nullToEmptyImmutableCopy(revisions);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 extends EppResource> T loadByUniqueId(
|
||||
Class<T> 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<T> 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<T> 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 <T extends EppResource> Result<T> loadMostRecentRevisionAtTime(
|
||||
final T resource, final DateTime timestamp) {
|
||||
final Key<T> resourceKey = Key.create(resource);
|
||||
final Ref<CommitLogManifest> revision = findMostRecentRevisionAtTime(resource, timestamp);
|
||||
final Key<CommitLogManifest> 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<CommitLogMutation> mutationResult =
|
||||
ofy().load().key(CommitLogMutation.createKey(revision.getKey(), resourceKey));
|
||||
ofy().load().key(CommitLogMutation.createKey(revision, resourceKey));
|
||||
return new Result<T>() {
|
||||
@Override
|
||||
public T now() {
|
||||
|
@ -310,10 +309,10 @@ public final class EppResourceUtils {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends EppResource> Ref<CommitLogManifest>
|
||||
private static <T extends EppResource> Key<CommitLogManifest>
|
||||
findMostRecentRevisionAtTime(final T resource, final DateTime timestamp) {
|
||||
final Key<T> resourceKey = Key.create(resource);
|
||||
Entry<?, Ref<CommitLogManifest>> revision = resource.getRevisions().floorEntry(timestamp);
|
||||
Entry<?, Key<CommitLogManifest>> 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 {
|
|||
* <p>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<Key<DomainBase>> queryDomainsUsingResource(
|
||||
Class<? extends EppResource> clazz, Ref<? extends EppResource> ref, DateTime now, int limit) {
|
||||
Class<? extends EppResource> clazz, Key<? extends EppResource> 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);
|
||||
|
|
|
@ -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<Object, Object>() {
|
||||
@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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <p>Although the type is {@link Key} the name "ref" is preserved for historical reasons.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
Ref<BillingEvent.OneTime> refOneTime = null;
|
||||
Key<BillingEvent.OneTime> 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.
|
||||
*
|
||||
* <p>Although the type is {@link Key} the name "ref" is preserved for historical reasons.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
Ref<BillingEvent.Recurring> refRecurring = null;
|
||||
Key<BillingEvent.Recurring> refRecurring = null;
|
||||
|
||||
public DateTime getBillingTime() {
|
||||
return billingTime;
|
||||
}
|
||||
|
||||
public Ref<? extends BillingEvent> getEventRef() {
|
||||
public Key<? extends BillingEvent> 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<BillingEvent.OneTime> eventRef) {
|
||||
getInstance().refOneTime = eventRef;
|
||||
public Builder setOneTimeEventKey(Key<BillingEvent.OneTime> eventKey) {
|
||||
getInstance().refOneTime = eventKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRecurringEventRef(Ref<BillingEvent.Recurring> eventRef) {
|
||||
getInstance().refRecurring = eventRef;
|
||||
public Builder setRecurringEventKey(Key<BillingEvent.Recurring> 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<BillingEvent.OneTime> eventRef;
|
||||
Key<BillingEvent.OneTime> 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<BillingEvent.OneTime> getEventRef() {
|
||||
public Key<BillingEvent.OneTime> 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<BillingEvent.OneTime> eventRef) {
|
||||
getInstance().eventRef = eventRef;
|
||||
public Builder setEventKey(Key<BillingEvent.OneTime> 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()),
|
||||
|
|
|
@ -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<Registrar> parent;
|
||||
Key<Registrar> parent;
|
||||
|
||||
/** The type of credit. */
|
||||
CreditType type;
|
||||
|
@ -95,7 +95,7 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable
|
|||
*/
|
||||
String tld;
|
||||
|
||||
public Ref<Registrar> getParent() {
|
||||
public Key<Registrar> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RegistrarCredit> parent;
|
||||
Key<RegistrarCredit> 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<RegistrarCredit> getParent() {
|
||||
public Key<RegistrarCredit> 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<RegistrarCreditBalance> {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<DomainResource> superordinateDomain;
|
||||
Key<DomainResource> 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<DomainResource> getSuperordinateDomain() {
|
||||
public Key<DomainResource> 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<DomainResource> superordinateDomain) {
|
||||
public Builder setSuperordinateDomain(Key<DomainResource> superordinateDomain) {
|
||||
getInstance().superordinateDomain = superordinateDomain;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <p>Although this stores {@link Key}s it is named "references" for historical reasons.
|
||||
*/
|
||||
Set<Ref<DomainApplication>> references;
|
||||
Set<Key<DomainApplication>> references;
|
||||
|
||||
/** Returns a cloned list of all references on this index. */
|
||||
public ImmutableSet<Ref<DomainApplication>> getReferences() {
|
||||
/** Returns a cloned list of all keys on this index. */
|
||||
public ImmutableSet<Key<DomainApplication>> 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<Ref<DomainApplication>> references) {
|
||||
ImmutableSet<Key<DomainApplication>> 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<DomainApplication> 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<Ref<DomainApplication>> newReferences = CollectionUtils.union(
|
||||
(existing == null ? ImmutableSet.<Ref<DomainApplication>>of() : existing.getReferences()),
|
||||
Ref.create(application));
|
||||
return createWithSpecifiedReferences(application.getFullyQualifiedDomainName(), newReferences);
|
||||
ImmutableSet<Key<DomainApplication>> newKeys = CollectionUtils.union(
|
||||
(existing == null ? ImmutableSet.<Key<DomainApplication>>of() : existing.getKeys()),
|
||||
Key.create(application));
|
||||
return createWithSpecifiedKeys(application.getFullyQualifiedDomainName(), newKeys);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<EppResourceIndexBucket> bucket;
|
||||
|
||||
Ref<? extends EppResource> reference;
|
||||
/** Although this field holds a {@link Key} it is named "reference" for historical reasons. */
|
||||
Key<? extends EppResource> reference;
|
||||
|
||||
@Index
|
||||
String kind;
|
||||
|
@ -49,7 +49,7 @@ public class EppResourceIndex extends BackupGroupRoot {
|
|||
return kind;
|
||||
}
|
||||
|
||||
public Ref<? extends EppResource> getReference() {
|
||||
public Key<? extends EppResource> getKey() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class EppResourceIndex extends BackupGroupRoot {
|
|||
public static <T extends EppResource> EppResourceIndex create(
|
||||
Key<EppResourceIndexBucket> bucket, Key<T> 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;
|
||||
|
|
|
@ -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<E extends EppResource> extends BackupGroup
|
|||
/**
|
||||
* The referenced resource.
|
||||
*
|
||||
* <p>This field holds the only reference. It is named "topReference" for historical reasons.
|
||||
* <p>This field holds a key to the only referenced resource. It is named "topReference" for
|
||||
* historical reasons.
|
||||
*/
|
||||
Ref<E> topReference;
|
||||
Key<E> topReference;
|
||||
|
||||
public String getForeignKey() {
|
||||
return foreignKey;
|
||||
|
@ -93,7 +93,7 @@ public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroup
|
|||
return deletionTime;
|
||||
}
|
||||
|
||||
public Ref<E> getReference() {
|
||||
public Key<E> getResourceKey() {
|
||||
return topReference;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroup
|
|||
public static <E extends EppResource> ForeignKeyIndex<E> create(
|
||||
E resource, DateTime deletionTime) {
|
||||
ForeignKeyIndex<E> 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<E extends EppResource> 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.
|
||||
*
|
||||
* <p>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<E extends EppResource> extends BackupGroup
|
|||
* @param now the current logical time to use when checking for soft deletion of the foreign key
|
||||
* index
|
||||
*/
|
||||
public static <E extends EppResource> Ref<E> loadAndGetReference(
|
||||
public static <E extends EppResource> Key<E> loadAndGetKey(
|
||||
Class<E> clazz, String foreignKey, DateTime now) {
|
||||
ForeignKeyIndex<E> index = load(clazz, foreignKey, now);
|
||||
return (index == null) ? null : index.getReference();
|
||||
return (index == null) ? null : index.getResourceKey();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,14 +130,14 @@ public abstract class BaseDomainLabelList<T extends Comparable<?>, R extends Dom
|
|||
ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();
|
||||
Key<? extends BaseDomainLabelList<?, ?>> 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<? extends BaseDomainLabelList<?, ?>> key);
|
||||
|
||||
protected static <R> Optional<R> getFromCache(String listName, LoadingCache<String, R> cache) {
|
||||
|
|
|
@ -306,7 +306,7 @@ public final class PremiumList extends BaseDomainLabelList<Money, PremiumList.Pr
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReference(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
|
||||
public boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
|
||||
return Objects.equals(registry.getPremiumList(), key);
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public final class ReservedList
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasReference(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
|
||||
protected boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
|
||||
return registry.getReservedLists().contains(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<? extends EppResource> parent;
|
||||
Key<? extends EppResource> 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<? extends EppResource> getParent() {
|
||||
public Key<? extends EppResource> 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<? extends EppResource> parentKey) {
|
||||
getInstance().parent = Ref.create(parentKey);
|
||||
getInstance().parent = parentKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <p>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<Key<? extends TransferServerApproveEntity>> serverApproveEntities;
|
||||
|
@ -62,7 +58,7 @@ public class TransferData extends BaseTransferObject implements Buildable {
|
|||
* being transferred is not a domain.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
Ref<BillingEvent.OneTime> serverApproveBillingEvent;
|
||||
Key<BillingEvent.OneTime> 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<BillingEvent.Recurring> serverApproveAutorenewEvent;
|
||||
Key<BillingEvent.Recurring> 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<PollMessage.Autorenew> serverApproveAutorenewPollMessage;
|
||||
Key<PollMessage.Autorenew> 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<BillingEvent.OneTime> getServerApproveBillingEvent() {
|
||||
public Key<BillingEvent.OneTime> getServerApproveBillingEvent() {
|
||||
return serverApproveBillingEvent;
|
||||
}
|
||||
|
||||
public Ref<BillingEvent.Recurring> getServerApproveAutorenewEvent() {
|
||||
public Key<BillingEvent.Recurring> getServerApproveAutorenewEvent() {
|
||||
return serverApproveAutorenewEvent;
|
||||
}
|
||||
|
||||
public Ref<PollMessage.Autorenew> getServerApproveAutorenewPollMessage() {
|
||||
public Key<PollMessage.Autorenew> getServerApproveAutorenewPollMessage() {
|
||||
return serverApproveAutorenewPollMessage;
|
||||
}
|
||||
|
||||
|
@ -138,19 +134,19 @@ public class TransferData extends BaseTransferObject implements Buildable {
|
|||
}
|
||||
|
||||
public Builder setServerApproveBillingEvent(
|
||||
Ref<BillingEvent.OneTime> serverApproveBillingEvent) {
|
||||
Key<BillingEvent.OneTime> serverApproveBillingEvent) {
|
||||
getInstance().serverApproveBillingEvent = serverApproveBillingEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setServerApproveAutorenewEvent(
|
||||
Ref<BillingEvent.Recurring> serverApproveAutorenewEvent) {
|
||||
Key<BillingEvent.Recurring> serverApproveAutorenewEvent) {
|
||||
getInstance().serverApproveAutorenewEvent = serverApproveAutorenewEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setServerApproveAutorenewPollMessage(
|
||||
Ref<PollMessage.Autorenew> serverApproveAutorenewPollMessage) {
|
||||
Key<PollMessage.Autorenew> serverApproveAutorenewPollMessage) {
|
||||
getInstance().serverApproveAutorenewPollMessage = serverApproveAutorenewPollMessage;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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<DateTime, Ref<CommitLogManifest>>} fields.
|
||||
* Objectify translator for {@code ImmutableSortedMap<DateTime, Key<CommitLogManifest>>} fields.
|
||||
*
|
||||
* <p>This translator is responsible for doing three things:
|
||||
* <ol>
|
||||
* <li>Translating the data into two lists of {@code Date} and {@code Key} objects, in a manner
|
||||
* similar to {@code @Mapify}.
|
||||
* <li>Inserting a reference to the transaction's {@link CommitLogManifest} on save.
|
||||
* <li>Inserting a key to the transaction's {@link CommitLogManifest} on save.
|
||||
* <li>Truncating the map to include only the last key per day for the last 30 days.
|
||||
* </ol>
|
||||
*
|
||||
|
@ -45,7 +45,7 @@ import org.joda.time.DateTime;
|
|||
* @see google.registry.model.EppResource
|
||||
*/
|
||||
public final class CommitLogRevisionsTranslatorFactory
|
||||
extends ImmutableSortedMapTranslatorFactory<DateTime, Ref<CommitLogManifest>> {
|
||||
extends ImmutableSortedMapTranslatorFactory<DateTime, Key<CommitLogManifest>> {
|
||||
|
||||
private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get();
|
||||
|
||||
|
@ -62,14 +62,14 @@ public final class CommitLogRevisionsTranslatorFactory
|
|||
* @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention()
|
||||
*/
|
||||
@Override
|
||||
ImmutableSortedMap<DateTime, Ref<CommitLogManifest>> transformBeforeSave(
|
||||
ImmutableSortedMap<DateTime, Ref<CommitLogManifest>> revisions) {
|
||||
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> transformBeforeSave(
|
||||
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> 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<DateTime, Ref<CommitLogManifest>>(Ordering.natural())
|
||||
return new ImmutableSortedMap.Builder<DateTime, Key<CommitLogManifest>>(Ordering.natural())
|
||||
.putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false))
|
||||
.put(now, Ref.create(ofy().getCommitLogManifestKey()))
|
||||
.put(now, ofy().getCommitLogManifestKey())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue