Switch over to non-ReferenceUnion fields on DomainBase

This is the second phase of a three phase migration to remove
ReferenceUnions. As of the end of this phase, ReferenceUnions are no longer read
from in any active code paths, but are still written to in case a rollback to
the previous version is necessary. The third and final phase will remove the
ReferenceUnions entirely.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137951076
This commit is contained in:
mcilwain 2016-11-02 08:55:46 -07:00 committed by Ben McIlwain
parent 59d998954c
commit f95f27ed72
6 changed files with 25 additions and 34 deletions

View file

@ -182,11 +182,7 @@ public abstract class DomainBase extends EppResource {
}
public ImmutableSet<Key<HostResource>> getNameservers() {
ImmutableSet.Builder<Key<HostResource>> builder = new ImmutableSet.Builder<>();
for (ReferenceUnion<HostResource> union : nullToEmptyImmutableCopy(nameservers)) {
builder.add(union.getLinked());
}
return builder.build();
return nullToEmptyImmutableCopy(nsHosts);
}
/** Loads and returns the fully qualified host names of all linked nameservers. */
@ -241,13 +237,13 @@ public abstract class DomainBase extends EppResource {
@OnSave
void dualSaveReferenceUnions() {
for (DesignatedContact contact : nullToEmptyImmutableCopy(allContacts)) {
contact.contact = contact.contactId.getLinked();
contact.contactId = ReferenceUnion.create(contact.contact);
}
ImmutableSet.Builder<Key<HostResource>> hostKeys = new ImmutableSet.Builder<>();
for (ReferenceUnion<HostResource> refUnion : nullToEmptyImmutableCopy(nameservers)) {
hostKeys.add(refUnion.getLinked());
ImmutableSet.Builder<ReferenceUnion<HostResource>> hosts = new ImmutableSet.Builder<>();
for (Key<HostResource> hostKey : nullToEmptyImmutableCopy(nsHosts)) {
hosts.add(ReferenceUnion.create(hostKey));
}
nsHosts = hostKeys.build();
nameservers = hosts.build();
}
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
@ -306,11 +302,7 @@ public abstract class DomainBase extends EppResource {
}
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
ImmutableSet.Builder<ReferenceUnion<HostResource>> builder = new ImmutableSet.Builder<>();
for (Key<HostResource> key : nullToEmpty(nameservers)) {
builder.add(ReferenceUnion.create(key));
}
getInstance().nameservers = builder.build();
getInstance().nsHosts = nameservers;
return thisCastToDerived();
}