mirror of
https://github.com/google/nomulus.git
synced 2025-05-06 06:57:50 +02:00
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=136388057
This commit is contained in:
parent
d9dbf2ec1a
commit
361a53a3c9
6 changed files with 25 additions and 34 deletions
|
@ -347,12 +347,10 @@ public final class EppResourceUtils {
|
||||||
public static List<Key<DomainBase>> queryDomainsUsingResource(
|
public static List<Key<DomainBase>> queryDomainsUsingResource(
|
||||||
Class<? extends EppResource> clazz, Key<? extends EppResource> key, 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));
|
checkArgument(ContactResource.class.equals(clazz) || HostResource.class.equals(clazz));
|
||||||
return ofy().load().type(DomainBase.class)
|
return ofy()
|
||||||
.filter(
|
.load()
|
||||||
clazz.equals(ContactResource.class)
|
.type(DomainBase.class)
|
||||||
? "allContacts.contactId.linked"
|
.filter(clazz.equals(ContactResource.class) ? "allContacts.contact" : "nsHosts", key)
|
||||||
: "nameservers.linked",
|
|
||||||
key)
|
|
||||||
.filter("deletionTime >", now)
|
.filter("deletionTime >", now)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.keys()
|
.keys()
|
||||||
|
|
|
@ -72,6 +72,6 @@ public class DesignatedContact extends ImmutableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key<ContactResource> getContactKey() {
|
public Key<ContactResource> getContactKey() {
|
||||||
return contactId.getLinked();
|
return contact;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,11 +183,7 @@ public abstract class DomainBase extends EppResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableSet<Key<HostResource>> getNameservers() {
|
public ImmutableSet<Key<HostResource>> getNameservers() {
|
||||||
ImmutableSet.Builder<Key<HostResource>> builder = new ImmutableSet.Builder<>();
|
return nullToEmptyImmutableCopy(nsHosts);
|
||||||
for (ReferenceUnion<HostResource> union : nullToEmptyImmutableCopy(nameservers)) {
|
|
||||||
builder.add(union.getLinked());
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loads and returns the fully qualified host names of all linked nameservers. */
|
/** Loads and returns the fully qualified host names of all linked nameservers. */
|
||||||
|
@ -242,13 +238,13 @@ public abstract class DomainBase extends EppResource {
|
||||||
@OnSave
|
@OnSave
|
||||||
void dualSaveReferenceUnions() {
|
void dualSaveReferenceUnions() {
|
||||||
for (DesignatedContact contact : nullToEmptyImmutableCopy(allContacts)) {
|
for (DesignatedContact contact : nullToEmptyImmutableCopy(allContacts)) {
|
||||||
contact.contact = contact.contactId.getLinked();
|
contact.contactId = ReferenceUnion.create(contact.contact);
|
||||||
}
|
}
|
||||||
ImmutableSet.Builder<Key<HostResource>> hostKeys = new ImmutableSet.Builder<>();
|
ImmutableSet.Builder<ReferenceUnion<HostResource>> hosts = new ImmutableSet.Builder<>();
|
||||||
for (ReferenceUnion<HostResource> refUnion : nullToEmptyImmutableCopy(nameservers)) {
|
for (Key<HostResource> hostKey : nullToEmptyImmutableCopy(nsHosts)) {
|
||||||
hostKeys.add(refUnion.getLinked());
|
hosts.add(ReferenceUnion.create(hostKey));
|
||||||
}
|
}
|
||||||
nsHosts = hostKeys.build();
|
nameservers = hosts.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
|
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
|
||||||
|
@ -307,11 +303,7 @@ public abstract class DomainBase extends EppResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
||||||
ImmutableSet.Builder<ReferenceUnion<HostResource>> builder = new ImmutableSet.Builder<>();
|
getInstance().nsHosts = nameservers;
|
||||||
for (Key<HostResource> key : nullToEmpty(nameservers)) {
|
|
||||||
builder.add(ReferenceUnion.create(key));
|
|
||||||
}
|
|
||||||
getInstance().nameservers = builder.build();
|
|
||||||
return thisCastToDerived();
|
return thisCastToDerived();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,7 +269,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
|
||||||
for (List<Key<HostResource>> chunk : Iterables.partition(hostKeys, 30)) {
|
for (List<Key<HostResource>> chunk : Iterables.partition(hostKeys, 30)) {
|
||||||
for (DomainResource domain : ofy().load()
|
for (DomainResource domain : ofy().load()
|
||||||
.type(DomainResource.class)
|
.type(DomainResource.class)
|
||||||
.filter("nameservers.linked in", chunk)
|
.filter("nsHosts in", chunk)
|
||||||
.filter("deletionTime >", now)
|
.filter("deletionTime >", now)
|
||||||
.limit(rdapResultSetMaxSize + 1)) {
|
.limit(rdapResultSetMaxSize + 1)) {
|
||||||
if (!domains.contains(domain)) {
|
if (!domains.contains(domain)) {
|
||||||
|
|
|
@ -145,16 +145,16 @@ public class DomainApplicationTest extends EntityTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptySetsAndArraysBecomeNull() {
|
public void testEmptySetsAndArraysBecomeNull() {
|
||||||
assertThat(emptyBuilder().setNameservers(null).build().nameservers).isNull();
|
assertThat(emptyBuilder().setNameservers(null).build().nsHosts).isNull();
|
||||||
assertThat(emptyBuilder()
|
assertThat(emptyBuilder()
|
||||||
.setNameservers(ImmutableSet.<Key<HostResource>>of())
|
.setNameservers(ImmutableSet.<Key<HostResource>>of())
|
||||||
.build()
|
.build()
|
||||||
.nameservers)
|
.nsHosts)
|
||||||
.isNull();
|
.isNull();
|
||||||
assertThat(emptyBuilder()
|
assertThat(emptyBuilder()
|
||||||
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
||||||
.build()
|
.build()
|
||||||
.nameservers)
|
.nsHosts)
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
// This behavior should also hold true for ImmutableObjects nested in collections.
|
// This behavior should also hold true for ImmutableObjects nested in collections.
|
||||||
assertThat(emptyBuilder()
|
assertThat(emptyBuilder()
|
||||||
|
|
|
@ -207,13 +207,13 @@ public class DomainResourceTest extends EntityTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testEmptySetsAndArraysBecomeNull() {
|
public void testEmptySetsAndArraysBecomeNull() {
|
||||||
assertThat(newDomainResource("example.com").asBuilder()
|
assertThat(newDomainResource("example.com").asBuilder()
|
||||||
.setNameservers(null).build().nameservers).isNull();
|
.setNameservers(null).build().nsHosts).isNull();
|
||||||
assertThat(newDomainResource("example.com").asBuilder()
|
assertThat(newDomainResource("example.com").asBuilder()
|
||||||
.setNameservers(ImmutableSet.<Key<HostResource>>of()).build().nameservers)
|
.setNameservers(ImmutableSet.<Key<HostResource>>of()).build().nsHosts)
|
||||||
.isNull();
|
.isNull();
|
||||||
assertThat(newDomainResource("example.com").asBuilder()
|
assertThat(newDomainResource("example.com").asBuilder()
|
||||||
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
||||||
.build().nameservers)
|
.build().nsHosts)
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
// This behavior should also hold true for ImmutableObjects nested in collections.
|
// This behavior should also hold true for ImmutableObjects nested in collections.
|
||||||
assertThat(newDomainResource("example.com").asBuilder()
|
assertThat(newDomainResource("example.com").asBuilder()
|
||||||
|
@ -462,21 +462,22 @@ public class DomainResourceTest extends EntityTestCase {
|
||||||
public void testDualSavingOfDesignatedContact() {
|
public void testDualSavingOfDesignatedContact() {
|
||||||
ContactResource contact = persistActiveContact("time1006");
|
ContactResource contact = persistActiveContact("time1006");
|
||||||
DesignatedContact designatedContact = new DesignatedContact();
|
DesignatedContact designatedContact = new DesignatedContact();
|
||||||
designatedContact.contactId = ReferenceUnion.create(Key.create(contact));
|
designatedContact.contact = Key.create(contact);
|
||||||
designatedContact.type = Type.ADMIN;
|
designatedContact.type = Type.ADMIN;
|
||||||
DomainResource domainWithContact =
|
DomainResource domainWithContact =
|
||||||
domain.asBuilder().setContacts(ImmutableSet.of(designatedContact)).build();
|
domain.asBuilder().setContacts(ImmutableSet.of(designatedContact)).build();
|
||||||
assertThat(getOnlyElement(domainWithContact.getContacts()).contact).isNull();
|
assertThat(getOnlyElement(domainWithContact.getContacts()).contactId).isNull();
|
||||||
DomainResource reloadedDomain = persistResource(domainWithContact);
|
DomainResource reloadedDomain = persistResource(domainWithContact);
|
||||||
assertThat(getOnlyElement(reloadedDomain.getContacts()).contact).isEqualTo(Key.create(contact));
|
assertThat(getOnlyElement(reloadedDomain.getContacts()).contactId)
|
||||||
|
.isEqualTo(ReferenceUnion.create(Key.create(contact)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDualSavingOfNameservers() {
|
public void testDualSavingOfNameservers() {
|
||||||
HostResource host = persistActiveHost("zzz.xxx.yyy");
|
HostResource host = persistActiveHost("zzz.xxx.yyy");
|
||||||
DomainResource domain = newDomainResource("python-django-unchained.com", host);
|
DomainResource domain = newDomainResource("python-django-unchained.com", host);
|
||||||
assertThat(domain.nsHosts).isNull();
|
assertThat(domain.nameservers).isNull();
|
||||||
DomainResource djangoReloaded = persistResource(domain);
|
DomainResource djangoReloaded = persistResource(domain);
|
||||||
assertThat(djangoReloaded.nsHosts).containsExactly(Key.create(host));
|
assertThat(djangoReloaded.nameservers).containsExactly(ReferenceUnion.create(Key.create(host)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue