Replace loadByUniqueId() with methods that don't overload unique id

It is replaced by loadByForeignKey(), which does the same thing that
loadByUniqueId() did for contacts, hosts, and domains, and also
loadDomainApplication(), which loads domain application by ROID. This eliminates
the ugly mode-switching of attemping to load by other foreign key or ROID.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133980156
This commit is contained in:
mcilwain 2016-09-22 11:45:58 -07:00 committed by Ben McIlwain
parent 025a4ae012
commit 21a98b899c
57 changed files with 367 additions and 340 deletions

View file

@ -14,7 +14,7 @@
package google.registry.dns;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import google.registry.dns.DnsConstants.TargetType;
import google.registry.model.EppResource;
@ -58,7 +58,7 @@ public final class RefreshDnsAction implements Runnable {
throw new BadRequestException("Unsupported type: " + type);
}
EppResource eppResource = loadByUniqueId(clazz, domainOrHostName, clock.nowUtc());
EppResource eppResource = loadByForeignKey(clazz, domainOrHostName, clock.nowUtc());
if (eppResource == null) {
throw new NotFoundException(
String.format("%s %s not found", type, domainOrHostName));

View file

@ -15,7 +15,7 @@
package google.registry.dns.writer.clouddns;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
@ -110,7 +110,7 @@ class CloudDnsWriter implements DnsWriter {
// Load the target domain. Note that it can be null if this domain was just deleted.
Optional<DomainResource> domainResource =
Optional.fromNullable(loadByUniqueId(DomainResource.class, domainName, clock.nowUtc()));
Optional.fromNullable(loadByForeignKey(DomainResource.class, domainName, clock.nowUtc()));
// Return early if no DNS records should be published.
// desiredRecordsBuilder is populated with an empty set to indicate that all existing records
@ -180,7 +180,7 @@ class CloudDnsWriter implements DnsWriter {
// desiredRecords is populated with an empty set to indicate that all existing records
// should be deleted.
Optional<HostResource> host =
Optional.fromNullable(loadByUniqueId(HostResource.class, hostName, clock.nowUtc()));
Optional.fromNullable(loadByForeignKey(HostResource.class, hostName, clock.nowUtc()));
// Return early if the host is deleted.
if (!host.isPresent()) {

View file

@ -17,7 +17,7 @@ package google.registry.dns.writer.dnsupdate;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
@ -111,7 +111,7 @@ public class DnsUpdateWriter implements DnsWriter {
* this domain refresh request
*/
private void publishDomain(String domainName, String requestingHostName) {
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, clock.nowUtc());
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, clock.nowUtc());
try {
Update update = new Update(toAbsoluteName(findTldFromName(domainName)));
update.delete(toAbsoluteName(domainName), Type.ANY);
@ -202,7 +202,7 @@ public class DnsUpdateWriter implements DnsWriter {
for (String hostName :
intersection(
domain.loadNameserverFullyQualifiedHostNames(), domain.getSubordinateHosts())) {
HostResource host = loadByUniqueId(HostResource.class, hostName, clock.nowUtc());
HostResource host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc());
update.add(makeAddressSet(host));
update.add(makeV6AddressSet(host));
}