mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
The only remaining Ofy entity is GaeUserConverter after this PR. (#1838)
Therefore this PR also removed several classes and related tests that support the setup and verification of Ofy entities. In addition, support for creating a VKey from a string is limited to VKey<? extends EppResource> only because it is the only use case (to pass a key to an EPP resource in a web safe way to facilitate resave), and we do not want to keep an extra simple name to class mapping, in addition to what persistence.xml contains. I looked into using PersistenceXmlUtility to obtain the mapping, but the xml file contains classes with the same simple name (namely OneTime from both PollMessage and BillingEvent). It doesn't seem like a worthwhile investment to write more code to deal with that, when the fact is that we only need to consider EppResource.
This commit is contained in:
parent
558bfd1ca2
commit
536f82eb9a
105 changed files with 469 additions and 1618 deletions
|
@ -65,7 +65,7 @@ public final class AsyncTaskEnqueuer {
|
|||
private final Queue asyncDnsRefreshPullQueue;
|
||||
private final Retrier retrier;
|
||||
|
||||
private CloudTasksUtils cloudTasksUtils;
|
||||
private final CloudTasksUtils cloudTasksUtils;
|
||||
|
||||
@Inject
|
||||
public AsyncTaskEnqueuer(
|
||||
|
@ -82,7 +82,8 @@ public final class AsyncTaskEnqueuer {
|
|||
}
|
||||
|
||||
/** Enqueues a task to asynchronously re-save an entity at some point in the future. */
|
||||
public void enqueueAsyncResave(VKey<?> entityToResave, DateTime now, DateTime whenToResave) {
|
||||
public void enqueueAsyncResave(
|
||||
VKey<? extends EppResource> entityToResave, DateTime now, DateTime whenToResave) {
|
||||
enqueueAsyncResave(entityToResave, now, ImmutableSortedSet.of(whenToResave));
|
||||
}
|
||||
|
||||
|
@ -93,7 +94,9 @@ public final class AsyncTaskEnqueuer {
|
|||
* itself to run at the next time if there are remaining re-saves scheduled.
|
||||
*/
|
||||
public void enqueueAsyncResave(
|
||||
VKey<?> entityKey, DateTime now, ImmutableSortedSet<DateTime> whenToResave) {
|
||||
VKey<? extends EppResource> entityKey,
|
||||
DateTime now,
|
||||
ImmutableSortedSet<DateTime> whenToResave) {
|
||||
DateTime firstResave = whenToResave.first();
|
||||
checkArgument(isBeforeOrAt(now, firstResave), "Can't enqueue a resave to run in the past");
|
||||
Duration etaDuration = new Duration(now, firstResave);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class CheckPackagesComplianceAction implements Runnable {
|
|||
"FROM DomainHistory WHERE current_package_token = :token AND"
|
||||
+ " modificationTime >= :lastBilling AND type = 'DOMAIN_CREATE'",
|
||||
DomainHistory.class)
|
||||
.setParameter("token", packagePromo.getToken().getSqlKey().toString())
|
||||
.setParameter("token", packagePromo.getToken().getKey().toString())
|
||||
.setParameter(
|
||||
"lastBilling", packagePromo.getNextBillingDate().minusYears(1))
|
||||
.getResultList();
|
||||
|
@ -62,7 +62,7 @@ public class CheckPackagesComplianceAction implements Runnable {
|
|||
logger.atInfo().log(
|
||||
"Package with package token %s has exceeded their max domain creation limit"
|
||||
+ " by %d name(s).",
|
||||
packagePromo.getToken().getSqlKey(), overage);
|
||||
packagePromo.getToken().getKey(), overage);
|
||||
packagesOverCreateLimit.add(packagePromo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
|
|||
final ImmutableSet<DateTime> billingTimes =
|
||||
getBillingTimesInScope(eventTimes, cursorTime, executeTime, tld);
|
||||
|
||||
VKey<Domain> domainKey = VKey.createSql(Domain.class, recurring.getDomainRepoId());
|
||||
VKey<Domain> domainKey = VKey.create(Domain.class, recurring.getDomainRepoId());
|
||||
Iterable<OneTime> oneTimesForDomain;
|
||||
oneTimesForDomain =
|
||||
tm().createQueryComposer(OneTime.class)
|
||||
|
|
|
@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Action.Method;
|
||||
|
@ -75,14 +74,11 @@ public class ResaveEntityAction implements Runnable {
|
|||
"Re-saving entity %s which was enqueued at %s.", resourceKey, requestedTime);
|
||||
tm().transact(
|
||||
() -> {
|
||||
ImmutableObject entity = tm().loadByKey(VKey.create(resourceKey));
|
||||
tm().put(
|
||||
(entity instanceof EppResource)
|
||||
? ((EppResource) entity).cloneProjectedAtTime(tm().getTransactionTime())
|
||||
: entity);
|
||||
EppResource entity = tm().loadByKey(VKey.createEppVKeyFromString(resourceKey));
|
||||
tm().put(entity.cloneProjectedAtTime(tm().getTransactionTime()));
|
||||
if (!resaveTimes.isEmpty()) {
|
||||
asyncTaskEnqueuer.enqueueAsyncResave(
|
||||
VKey.create(resourceKey), requestedTime, resaveTimes);
|
||||
VKey.createEppVKeyFromString(resourceKey), requestedTime, resaveTimes);
|
||||
}
|
||||
});
|
||||
response.setPayload("Entity re-saved.");
|
||||
|
|
|
@ -303,7 +303,7 @@ public class RdePipeline implements Serializable {
|
|||
TypeDescriptor.of(DepositFragment.class)))
|
||||
.via(
|
||||
(String registrarRepoId) -> {
|
||||
VKey<Registrar> key = VKey.createSql(Registrar.class, registrarRepoId);
|
||||
VKey<Registrar> key = VKey.create(Registrar.class, registrarRepoId);
|
||||
includedRegistrarCounter.inc();
|
||||
Registrar registrar = jpaTm().transact(() -> jpaTm().loadByKey(key));
|
||||
DepositFragment fragment = marshaller.marshalRegistrar(registrar);
|
||||
|
@ -332,9 +332,9 @@ public class RdePipeline implements Serializable {
|
|||
("SELECT repoId, revisionId FROM %entity% WHERE (repoId, modificationTime) IN"
|
||||
+ " (SELECT repoId, MAX(modificationTime) FROM %entity% WHERE"
|
||||
+ " modificationTime <= :watermark GROUP BY repoId) AND resource.deletionTime"
|
||||
+ " > :watermark AND COALESCE(resource.creationClientId, '') NOT LIKE"
|
||||
+ " 'prober-%' AND COALESCE(resource.currentSponsorClientId, '') NOT LIKE"
|
||||
+ " 'prober-%' AND COALESCE(resource.lastEppUpdateClientId, '') NOT LIKE"
|
||||
+ " > :watermark AND COALESCE(resource.creationRegistrarId, '') NOT LIKE"
|
||||
+ " 'prober-%' AND COALESCE(resource.currentSponsorRegistrarId, '') NOT LIKE"
|
||||
+ " 'prober-%' AND COALESCE(resource.lastEppUpdateRegistrarId, '') NOT LIKE"
|
||||
+ " 'prober-%' "
|
||||
+ (historyClass == DomainHistory.class
|
||||
? "AND resource.tld IN " + "(SELECT id FROM Tld WHERE tldType = 'REAL')"
|
||||
|
@ -381,7 +381,7 @@ public class RdePipeline implements Serializable {
|
|||
() ->
|
||||
jpaTm()
|
||||
.loadByKey(
|
||||
VKey.createSql(historyEntryClazz, new HistoryEntryId(repoId, revisionId))))
|
||||
VKey.create(historyEntryClazz, new HistoryEntryId(repoId, revisionId))))
|
||||
.getResourceAtPointInTime()
|
||||
.map(resource -> resource.cloneProjectedAtTime(watermark))
|
||||
.get();
|
||||
|
@ -469,12 +469,12 @@ public class RdePipeline implements Serializable {
|
|||
// Contacts and hosts are only deposited in RDE, not BRDA.
|
||||
if (pendingDeposit.mode() == RdeMode.FULL) {
|
||||
HashSet<Serializable> contacts = new HashSet<>();
|
||||
contacts.add(domain.getAdminContact().getSqlKey());
|
||||
contacts.add(domain.getTechContact().getSqlKey());
|
||||
contacts.add(domain.getRegistrant().getSqlKey());
|
||||
contacts.add(domain.getAdminContact().getKey());
|
||||
contacts.add(domain.getTechContact().getKey());
|
||||
contacts.add(domain.getRegistrant().getKey());
|
||||
// Billing contact is not mandatory.
|
||||
if (domain.getBillingContact() != null) {
|
||||
contacts.add(domain.getBillingContact().getSqlKey());
|
||||
contacts.add(domain.getBillingContact().getKey());
|
||||
}
|
||||
referencedContactCounter.inc(contacts.size());
|
||||
contacts.forEach(
|
||||
|
@ -492,7 +492,7 @@ public class RdePipeline implements Serializable {
|
|||
.get(REFERENCED_HOSTS)
|
||||
.output(
|
||||
KV.of(
|
||||
(String) hostKey.getSqlKey(),
|
||||
(String) hostKey.getKey(),
|
||||
pendingDeposit)));
|
||||
}
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ public class RdePipeline implements Serializable {
|
|||
// The output are pairs of
|
||||
// (superordinateDomainRepoId,
|
||||
// (subordinateHostRepoId, (pendingDeposit, revisionId))).
|
||||
KV.of((String) host.getSuperordinateDomain().getSqlKey(), kv));
|
||||
KV.of((String) host.getSuperordinateDomain().getKey(), kv));
|
||||
} else {
|
||||
externalHostCounter.inc();
|
||||
DepositFragment fragment = marshaller.marshalExternalHost(host);
|
||||
|
|
|
@ -115,7 +115,7 @@ public class Spec11Pipeline implements Serializable {
|
|||
Read<Object[], KV<String, String>> read =
|
||||
RegistryJpaIO.read(
|
||||
"select d.repoId, r.emailAddress from Domain d join Registrar r on"
|
||||
+ " d.currentSponsorClientId = r.registrarId where r.type = 'REAL' and"
|
||||
+ " d.currentSponsorRegistrarId = r.registrarId where r.type = 'REAL' and"
|
||||
+ " d.deletionTime > now()",
|
||||
false,
|
||||
Spec11Pipeline::parseRow)
|
||||
|
@ -133,9 +133,7 @@ public class Spec11Pipeline implements Serializable {
|
|||
Domain domain =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.loadByKey(VKey.createSql(Domain.class, input.getKey())));
|
||||
() -> jpaTm().loadByKey(VKey.create(Domain.class, input.getKey())));
|
||||
String emailAddress = input.getValue();
|
||||
if (emailAddress == null) {
|
||||
emailAddress = "";
|
||||
|
|
|
@ -163,7 +163,7 @@ public final class ResourceFlowUtils {
|
|||
// The roid should match one of the contacts.
|
||||
Optional<VKey<Contact>> foundContact =
|
||||
domain.getReferencedContacts().stream()
|
||||
.filter(key -> key.getSqlKey().equals(authRepoId))
|
||||
.filter(key -> key.getKey().equals(authRepoId))
|
||||
.findFirst();
|
||||
if (!foundContact.isPresent()) {
|
||||
throw new BadAuthInfoForResourceException();
|
||||
|
|
|
@ -90,10 +90,10 @@ public final class ContactInfoFlow implements Flow {
|
|||
.setVoiceNumber(contact.getVoiceNumber())
|
||||
.setFaxNumber(contact.getFaxNumber())
|
||||
.setEmailAddress(contact.getEmailAddress())
|
||||
.setCurrentSponsorClientId(contact.getCurrentSponsorRegistrarId())
|
||||
.setCreationClientId(contact.getCreationRegistrarId())
|
||||
.setCurrentSponsorRegistrarId(contact.getCurrentSponsorRegistrarId())
|
||||
.setCreationRegistrarId(contact.getCreationRegistrarId())
|
||||
.setCreationTime(contact.getCreationTime())
|
||||
.setLastEppUpdateClientId(contact.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateRegistrarId(contact.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateTime(contact.getLastEppUpdateTime())
|
||||
.setLastTransferTime(contact.getLastTransferTime())
|
||||
.setAuthInfo(includeAuthInfo ? contact.getAuthInfo() : null)
|
||||
|
|
|
@ -608,7 +608,7 @@ public class DomainFlowUtils {
|
|||
historyId, "Cannot create a new autorenew poll message without a domain history id");
|
||||
updatedAutorenewPollMessage =
|
||||
newAutorenewPollMessage(domain)
|
||||
.setId((Long) domain.getAutorenewPollMessage().getSqlKey())
|
||||
.setId((Long) domain.getAutorenewPollMessage().getKey())
|
||||
.setAutorenewEndTime(newEndTime)
|
||||
.setDomainHistoryId(historyId)
|
||||
.build();
|
||||
|
|
|
@ -111,7 +111,7 @@ public final class DomainInfoFlow implements Flow {
|
|||
DomainInfoData.newBuilder()
|
||||
.setDomainName(domain.getDomainName())
|
||||
.setRepoId(domain.getRepoId())
|
||||
.setCurrentSponsorClientId(domain.getCurrentSponsorRegistrarId())
|
||||
.setCurrentSponsorRegistrarId(domain.getCurrentSponsorRegistrarId())
|
||||
.setRegistrant(
|
||||
tm().transact(() -> tm().loadByKey(domain.getRegistrant())).getContactId());
|
||||
// If authInfo is non-null, then the caller is authorized to see the full information since we
|
||||
|
@ -125,9 +125,9 @@ public final class DomainInfoFlow implements Flow {
|
|||
.setNameservers(hostsRequest.requestDelegated() ? domain.loadNameserverHostNames() : null)
|
||||
.setSubordinateHosts(
|
||||
hostsRequest.requestSubordinate() ? domain.getSubordinateHosts() : null)
|
||||
.setCreationClientId(domain.getCreationRegistrarId())
|
||||
.setCreationRegistrarId(domain.getCreationRegistrarId())
|
||||
.setCreationTime(domain.getCreationTime())
|
||||
.setLastEppUpdateClientId(domain.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateRegistrarId(domain.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateTime(domain.getLastEppUpdateTime())
|
||||
.setRegistrationExpirationTime(domain.getRegistrationExpirationTime())
|
||||
.setLastTransferTime(domain.getLastTransferTime())
|
||||
|
|
|
@ -151,7 +151,7 @@ public class AllocationTokenFlowUtils {
|
|||
}
|
||||
|
||||
maybeTokenEntity =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
|
||||
|
||||
if (!maybeTokenEntity.isPresent()) {
|
||||
throw new InvalidAllocationTokenException();
|
||||
|
|
|
@ -80,14 +80,14 @@ public final class HostInfoFlow implements Flow {
|
|||
tm().transact(
|
||||
() -> tm().loadByKey(host.getSuperordinateDomain()).cloneProjectedAtTime(now));
|
||||
hostInfoDataBuilder
|
||||
.setCurrentSponsorClientId(superordinateDomain.getCurrentSponsorRegistrarId())
|
||||
.setCurrentSponsorRegistrarId(superordinateDomain.getCurrentSponsorRegistrarId())
|
||||
.setLastTransferTime(host.computeLastTransferTime(superordinateDomain));
|
||||
if (superordinateDomain.getStatusValues().contains(StatusValue.PENDING_TRANSFER)) {
|
||||
statusValues.add(StatusValue.PENDING_TRANSFER);
|
||||
}
|
||||
} else {
|
||||
hostInfoDataBuilder
|
||||
.setCurrentSponsorClientId(host.getPersistedCurrentSponsorRegistrarId())
|
||||
.setCurrentSponsorRegistrarId(host.getPersistedCurrentSponsorRegistrarId())
|
||||
.setLastTransferTime(host.getLastTransferTime());
|
||||
}
|
||||
return responseBuilder
|
||||
|
@ -97,9 +97,9 @@ public final class HostInfoFlow implements Flow {
|
|||
.setRepoId(host.getRepoId())
|
||||
.setStatusValues(statusValues.build())
|
||||
.setInetAddresses(host.getInetAddresses())
|
||||
.setCreationClientId(host.getCreationRegistrarId())
|
||||
.setCreationRegistrarId(host.getCreationRegistrarId())
|
||||
.setCreationTime(host.getCreationTime())
|
||||
.setLastEppUpdateClientId(host.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateRegistrarId(host.getLastEppUpdateRegistrarId())
|
||||
.setLastEppUpdateTime(host.getLastEppUpdateTime())
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.model.common.GaeUserIdConverter;
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.host.Host;
|
||||
|
||||
/** Sets of classes of the Objectify-registered entities in use throughout the model. */
|
||||
@DeleteAfterMigration
|
||||
public final class EntityClasses {
|
||||
|
||||
/** Set of entity classes. */
|
||||
public static final ImmutableSet<Class<? extends ImmutableObject>> ALL_CLASSES =
|
||||
ImmutableSet.of(Contact.class, Domain.class, GaeUserIdConverter.class, Host.class);
|
||||
|
||||
private EntityClasses() {}
|
||||
}
|
|
@ -31,11 +31,9 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Ignore;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.model.CacheUtils.AppEngineEnvironmentCacheLoader;
|
||||
import google.registry.model.annotations.OfyIdAllocation;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.persistence.VKey;
|
||||
|
@ -47,7 +45,6 @@ import java.util.Set;
|
|||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
|
@ -55,7 +52,7 @@ import org.joda.time.DateTime;
|
|||
|
||||
/** An EPP entity object (i.e. a domain, contact, or host). */
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.FIELD) // otherwise it'll use the default if the repoId (property)
|
||||
@Access(AccessType.FIELD) // otherwise it'll use the default of the repoId (property)
|
||||
public abstract class EppResource extends UpdateAutoTimestampEntity implements Buildable {
|
||||
|
||||
private static final long serialVersionUID = -252782773382339534L;
|
||||
|
@ -70,7 +67,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc5730">RFC 5730</a>
|
||||
*/
|
||||
@Id @Transient String repoId;
|
||||
@OfyIdAllocation @Transient String repoId;
|
||||
|
||||
/**
|
||||
* The ID of the registrar that is currently sponsoring this resource.
|
||||
|
@ -78,9 +75,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
|
||||
* resource fields.
|
||||
*/
|
||||
@Index
|
||||
@Column(name = "currentSponsorRegistrarId")
|
||||
String currentSponsorClientId;
|
||||
String currentSponsorRegistrarId;
|
||||
|
||||
/**
|
||||
* The ID of the registrar that created this resource.
|
||||
|
@ -88,8 +83,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
|
||||
* resource fields.
|
||||
*/
|
||||
@Column(name = "creationRegistrarId")
|
||||
String creationClientId;
|
||||
String creationRegistrarId;
|
||||
|
||||
/**
|
||||
* The ID of the registrar that last updated this resource.
|
||||
|
@ -98,8 +92,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
* edits; it only includes EPP-visible modifications such as {@literal <update>}. Can be null if
|
||||
* the resource has never been modified.
|
||||
*/
|
||||
@Column(name = "lastEppUpdateRegistrarId")
|
||||
String lastEppUpdateClientId;
|
||||
String lastEppUpdateRegistrarId;
|
||||
|
||||
/**
|
||||
* The time when this resource was created.
|
||||
|
@ -111,8 +104,8 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
|
||||
* resource fields.
|
||||
*/
|
||||
@AttributeOverrides(@AttributeOverride(name = "creationTime", column = @Column))
|
||||
@Ignore
|
||||
// Need to override the default non-null column attribute.
|
||||
@AttributeOverride(name = "creationTime", column = @Column)
|
||||
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
|
||||
|
||||
/**
|
||||
|
@ -128,7 +121,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
* out of the index at that time, as long as we query for resources whose deletion time is before
|
||||
* now.
|
||||
*/
|
||||
@Index DateTime deletionTime;
|
||||
DateTime deletionTime;
|
||||
|
||||
/**
|
||||
* The time that this resource was last updated.
|
||||
|
@ -140,7 +133,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
DateTime lastEppUpdateTime;
|
||||
|
||||
/** Status values associated with this resource. */
|
||||
@Ignore Set<StatusValue> statuses;
|
||||
Set<StatusValue> statuses;
|
||||
|
||||
public String getRepoId() {
|
||||
return repoId;
|
||||
|
@ -164,7 +157,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
}
|
||||
|
||||
public String getCreationRegistrarId() {
|
||||
return creationClientId;
|
||||
return creationRegistrarId;
|
||||
}
|
||||
|
||||
public DateTime getLastEppUpdateTime() {
|
||||
|
@ -172,17 +165,17 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
}
|
||||
|
||||
public String getLastEppUpdateRegistrarId() {
|
||||
return lastEppUpdateClientId;
|
||||
return lastEppUpdateRegistrarId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored value of {@link #currentSponsorClientId}.
|
||||
* Get the stored value of {@link #currentSponsorRegistrarId}.
|
||||
*
|
||||
* <p>For subordinate hosts, this value may not represent the actual current client id, which is
|
||||
* the client id of the superordinate host. For all other resources this is the true client id.
|
||||
*/
|
||||
public final String getPersistedCurrentSponsorRegistrarId() {
|
||||
return currentSponsorClientId;
|
||||
return currentSponsorRegistrarId;
|
||||
}
|
||||
|
||||
public final ImmutableSet<StatusValue> getStatusValues() {
|
||||
|
@ -272,13 +265,13 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
|
||||
/** Set the current sponsoring registrar. */
|
||||
public B setPersistedCurrentSponsorRegistrarId(String currentSponsorRegistrarId) {
|
||||
getInstance().currentSponsorClientId = currentSponsorRegistrarId;
|
||||
getInstance().currentSponsorRegistrarId = currentSponsorRegistrarId;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
/** Set the registrar that created this resource. */
|
||||
public B setCreationRegistrarId(String creationRegistrarId) {
|
||||
getInstance().creationClientId = creationRegistrarId;
|
||||
getInstance().creationRegistrarId = creationRegistrarId;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
|
@ -290,7 +283,7 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
|
||||
/** Set the registrar who last performed a {@literal <update>} on this resource. */
|
||||
public B setLastEppUpdateRegistrarId(String lastEppUpdateRegistrarId) {
|
||||
getInstance().lastEppUpdateClientId = lastEppUpdateRegistrarId;
|
||||
getInstance().lastEppUpdateRegistrarId = lastEppUpdateRegistrarId;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
|
@ -320,14 +313,14 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
|
|||
|
||||
/** Add to this resource's status values. */
|
||||
public B addStatusValues(ImmutableSet<StatusValue> statusValues) {
|
||||
return setStatusValues(ImmutableSet.copyOf(
|
||||
union(getInstance().getStatusValues(), statusValues)));
|
||||
return setStatusValues(
|
||||
ImmutableSet.copyOf(union(getInstance().getStatusValues(), statusValues)));
|
||||
}
|
||||
|
||||
/** Remove from this resource's status values. */
|
||||
public B removeStatusValues(ImmutableSet<StatusValue> statusValues) {
|
||||
return setStatusValues(ImmutableSet.copyOf(
|
||||
difference(getInstance().getStatusValues(), statusValues)));
|
||||
return setStatusValues(
|
||||
ImmutableSet.copyOf(difference(getInstance().getStatusValues(), statusValues)));
|
||||
}
|
||||
|
||||
/** Set this resource's repoId. */
|
||||
|
|
|
@ -26,7 +26,6 @@ import static google.registry.util.DateTimeUtils.latestOf;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.model.EppResource.BuilderWithTransferData;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
|
@ -359,7 +358,7 @@ public final class EppResourceUtils {
|
|||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createNativeQuery(HOST_LINKED_DOMAIN_QUERY)
|
||||
.setParameter("fkRepoId", key.getSqlKey())
|
||||
.setParameter("fkRepoId", key.getKey())
|
||||
.setParameter("now", now.toDate());
|
||||
}
|
||||
if (limit != null) {
|
||||
|
@ -370,9 +369,7 @@ public final class EppResourceUtils {
|
|||
(ImmutableSet<VKey<Domain>>)
|
||||
query
|
||||
.getResultStream()
|
||||
.map(
|
||||
repoId ->
|
||||
Domain.createVKey(Key.create(Domain.class, (String) repoId)))
|
||||
.map(repoId -> Domain.createVKey((String) repoId))
|
||||
.collect(toImmutableSet());
|
||||
return domainKeySet;
|
||||
});
|
||||
|
|
|
@ -89,7 +89,7 @@ public final class ForeignKeyUtils {
|
|||
Class<E> clazz, Collection<String> foreignKeys, final DateTime now) {
|
||||
return load(clazz, foreignKeys, false).entrySet().stream()
|
||||
.filter(e -> now.isBefore(e.getValue().deletionTime()))
|
||||
.collect(toImmutableMap(Entry::getKey, e -> VKey.createSql(clazz, e.getValue().repoId())));
|
||||
.collect(toImmutableMap(Entry::getKey, e -> VKey.create(clazz, e.getValue().repoId())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,16 +146,14 @@ public final class ForeignKeyUtils {
|
|||
// called, it is always passed with a list of VKeys with the same type.
|
||||
Class<? extends EppResource> clazz = keys.iterator().next().getKind();
|
||||
ImmutableList<String> foreignKeys =
|
||||
Streams.stream(keys)
|
||||
.map(key -> (String) key.getSqlKey())
|
||||
.collect(toImmutableList());
|
||||
Streams.stream(keys).map(key -> (String) key.getKey()).collect(toImmutableList());
|
||||
ImmutableMap<String, MostRecentResource> existingKeys =
|
||||
ForeignKeyUtils.load(clazz, foreignKeys, true);
|
||||
// The above map only contains keys that exist in the database, so we re-add the
|
||||
// missing ones with Optional.empty() values for caching.
|
||||
return Maps.asMap(
|
||||
ImmutableSet.copyOf(keys),
|
||||
key -> Optional.ofNullable(existingKeys.get((String) key.getSqlKey())));
|
||||
key -> Optional.ofNullable(existingKeys.get((String) key.getKey())));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -211,15 +209,14 @@ public final class ForeignKeyUtils {
|
|||
return load(clazz, foreignKeys, now);
|
||||
}
|
||||
return foreignKeyCache
|
||||
.getAll(
|
||||
foreignKeys.stream().map(fk -> VKey.createSql(clazz, fk)).collect(toImmutableList()))
|
||||
.getAll(foreignKeys.stream().map(fk -> VKey.create(clazz, fk)).collect(toImmutableList()))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(e -> e.getValue().isPresent() && now.isBefore(e.getValue().get().deletionTime()))
|
||||
.collect(
|
||||
toImmutableMap(
|
||||
e -> (String) e.getKey().getSqlKey(),
|
||||
e -> VKey.createSql(clazz, e.getValue().get().repoId())));
|
||||
e -> (String) e.getKey().getKey(),
|
||||
e -> VKey.create(clazz, e.getValue().get().repoId())));
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
|
|
|
@ -183,11 +183,11 @@ public final class ResourceTransferUtils {
|
|||
* sets the last EPP update client id to the given client id.
|
||||
*/
|
||||
public static <R extends EppResource & ResourceWithTransferData> R denyPendingTransfer(
|
||||
R resource, TransferStatus transferStatus, DateTime now, String lastEppUpdateClientId) {
|
||||
R resource, TransferStatus transferStatus, DateTime now, String lastEppUpdateRegistrarId) {
|
||||
checkArgument(transferStatus.isDenied(), "Not a denial transfer status");
|
||||
return resolvePendingTransfer(resource, transferStatus, now)
|
||||
.setLastEppUpdateTime(now)
|
||||
.setLastEppUpdateRegistrarId(lastEppUpdateClientId)
|
||||
.setLastEppUpdateRegistrarId(lastEppUpdateRegistrarId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import static com.google.common.base.Predicates.or;
|
||||
import static com.google.common.base.Predicates.subtypeOf;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/** Utility methods for getting the version of the model schema from the model code. */
|
||||
@DeleteAfterMigration
|
||||
public final class SchemaVersion {
|
||||
|
||||
/**
|
||||
* Returns a set of classes corresponding to all types persisted within the model classes, sorted
|
||||
* by the string representation.
|
||||
*/
|
||||
private static SortedSet<Class<?>> getAllPersistedTypes() {
|
||||
SortedSet<Class<?>> persistedTypes = new TreeSet<>(Ordering.usingToString());
|
||||
// Do a breadth-first search for persisted types, starting with @Entity types and expanding each
|
||||
// ImmutableObject by querying it for all its persisted field types.
|
||||
persistedTypes.addAll(EntityClasses.ALL_CLASSES);
|
||||
Queue<Class<?>> queue = new ArrayDeque<>(persistedTypes);
|
||||
while (!queue.isEmpty()) {
|
||||
Class<?> clazz = queue.remove();
|
||||
if (ImmutableObject.class.isAssignableFrom(clazz)) {
|
||||
for (Class<?> persistedFieldType : ModelUtils.getPersistedFieldTypes(clazz)) {
|
||||
if (persistedTypes.add(persistedFieldType)) {
|
||||
// If we haven't seen this type before, add it to the queue to query its field types.
|
||||
queue.add(persistedFieldType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return persistedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representing the schema which includes the definition of all persisted entity
|
||||
* types (and their field types, recursively). Each definition contains the field names and their
|
||||
* types (for classes), or else a list of all possible values (for enums).
|
||||
*/
|
||||
public static String getSchema() {
|
||||
return getAllPersistedTypes().stream()
|
||||
.filter(or(subtypeOf(Enum.class), subtypeOf(ImmutableObject.class)))
|
||||
.map(ModelUtils::getSchema)
|
||||
.collect(joining("\n"));
|
||||
}
|
||||
|
||||
private SchemaVersion() {}
|
||||
}
|
|
@ -375,7 +375,7 @@ public abstract class BillingEvent extends ImmutableObject
|
|||
}
|
||||
|
||||
public static VKey<OneTime> createVKey(long id) {
|
||||
return VKey.createSql(OneTime.class, id);
|
||||
return VKey.create(OneTime.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -538,7 +538,7 @@ public abstract class BillingEvent extends ImmutableObject
|
|||
}
|
||||
|
||||
public static VKey<Recurring> createVKey(Long id) {
|
||||
return VKey.createSql(Recurring.class, id);
|
||||
return VKey.create(Recurring.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -682,7 +682,7 @@ public abstract class BillingEvent extends ImmutableObject
|
|||
}
|
||||
|
||||
public static VKey<Cancellation> createVKey(long id) {
|
||||
return VKey.createSql(Cancellation.class, id);
|
||||
return VKey.create(Cancellation.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.common;
|
||||
|
||||
import static com.google.common.base.Functions.identity;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.model.EntityClasses.ALL_CLASSES;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** A helper to manage class name and class path mapping. */
|
||||
public class ClassPathManager {
|
||||
/**
|
||||
* Class registry allowing us to restore the original class object from the unqualified class
|
||||
* name, which is all the datastore key gives us. Note that entities annotated
|
||||
* with @EntitySubclass are removed because they share the same kind of the key with their parent
|
||||
* class.
|
||||
*/
|
||||
public static final Map<String, Class<?>> CLASS_REGISTRY =
|
||||
ALL_CLASSES.stream()
|
||||
.filter(clazz -> !clazz.isAnnotationPresent(EntitySubclass.class))
|
||||
.collect(Collectors.toMap(com.googlecode.objectify.Key::getKind, identity()));
|
||||
|
||||
/**
|
||||
* Class name registry allowing us to obtain the class name the unqualified class, which is all
|
||||
* the datastore key gives us. Note that entities annotated with @EntitySubclass are removed
|
||||
* because they share the same kind of the key with their parent class.
|
||||
*/
|
||||
public static final Map<Class<?>, String> CLASS_NAME_REGISTRY =
|
||||
ALL_CLASSES.stream()
|
||||
.filter(clazz -> !clazz.isAnnotationPresent(EntitySubclass.class))
|
||||
.collect(Collectors.toMap(identity(), com.googlecode.objectify.Key::getKind));
|
||||
|
||||
@VisibleForTesting
|
||||
public static void addTestEntityClass(Class<?> clazz) {
|
||||
CLASS_REGISTRY.put(clazz.getSimpleName(), clazz);
|
||||
CLASS_NAME_REGISTRY.put(clazz, clazz.getSimpleName());
|
||||
}
|
||||
|
||||
public static <T> Class<T> getClass(String className) {
|
||||
checkArgument(
|
||||
CLASS_REGISTRY.containsKey(className), "Class %s not found in class registry", className);
|
||||
return (Class<T>) CLASS_REGISTRY.get(className);
|
||||
}
|
||||
|
||||
public static <T> String getClassName(Class<T> clazz) {
|
||||
checkArgument(
|
||||
CLASS_NAME_REGISTRY.containsKey(clazz),
|
||||
"Class %s not found in class name registry",
|
||||
clazz.getSimpleName());
|
||||
return CLASS_NAME_REGISTRY.get(clazz);
|
||||
}
|
||||
}
|
|
@ -14,22 +14,15 @@
|
|||
|
||||
package google.registry.model.common;
|
||||
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* A singleton entity in the database.
|
||||
*
|
||||
* <p>This class should not be deleted after the migration, because there is still a concept of
|
||||
* singleton in SQL. We should remove the ofy @Id annotation after all of its subclass are Ofy-free.
|
||||
*/
|
||||
@DeleteAfterMigration
|
||||
/** A singleton entity in the database. */
|
||||
@MappedSuperclass
|
||||
public abstract class CrossTldSingleton extends ImmutableObject {
|
||||
|
||||
public static final long SINGLETON_ID = 1; // There is always exactly one of these.
|
||||
|
||||
@Id @javax.persistence.Id long id = SINGLETON_ID;
|
||||
@Id long id = SINGLETON_ID;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ public class Cursor extends UpdateAutoTimestampEntity {
|
|||
|
||||
private static VKey<Cursor> createVKey(CursorType type, String scope) {
|
||||
checkValidCursorTypeForScope(type, scope);
|
||||
return VKey.createSql(Cursor.class, new CursorId(type, scope));
|
||||
return VKey.create(Cursor.class, new CursorId(type, scope));
|
||||
}
|
||||
|
||||
public DateTime getLastUpdateTime() {
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.model.contact;
|
|||
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.annotations.ExternalMessagingName;
|
||||
import google.registry.model.annotations.ReportedOn;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.WithVKey;
|
||||
import javax.persistence.Access;
|
||||
|
@ -32,9 +31,7 @@ import org.joda.time.DateTime;
|
|||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc5733">RFC 5733</a>
|
||||
*/
|
||||
@ReportedOn
|
||||
@Entity
|
||||
@com.googlecode.objectify.annotation.Entity
|
||||
@Table(
|
||||
name = "Contact",
|
||||
indexes = {
|
||||
|
@ -51,7 +48,7 @@ public class Contact extends ContactBase implements ForeignKeyedEppResource {
|
|||
|
||||
@Override
|
||||
public VKey<Contact> createVKey() {
|
||||
return VKey.createSql(Contact.class, getRepoId());
|
||||
return VKey.create(Contact.class, getRepoId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,11 +19,6 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
|||
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.annotation.Ignore;
|
||||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.annotation.OnLoad;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResource.ResourceWithTransferData;
|
||||
import google.registry.model.transfer.ContactTransferData;
|
||||
|
@ -54,7 +49,8 @@ import org.joda.time.DateTime;
|
|||
@MappedSuperclass
|
||||
@Embeddable
|
||||
@Access(AccessType.FIELD)
|
||||
public class ContactBase extends EppResource implements ResourceWithTransferData {
|
||||
public class ContactBase extends EppResource
|
||||
implements ResourceWithTransferData<ContactTransferData> {
|
||||
|
||||
/**
|
||||
* Unique identifier for this contact.
|
||||
|
@ -69,7 +65,6 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
* Localized postal info for the contact. All contained values must be representable in the 7-bit
|
||||
* US-ASCII character set. Personal info; cleared by {@link Contact.Builder#wipeOut}.
|
||||
*/
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "name", column = @Column(name = "addr_local_name")),
|
||||
|
@ -97,7 +92,6 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
* Internationalized postal info for the contact. Personal info; cleared by {@link
|
||||
* Contact.Builder#wipeOut}.
|
||||
*/
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "name", column = @Column(name = "addr_i18n_name")),
|
||||
|
@ -126,10 +120,9 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
* postal name, or if null, the localized postal name, or if that is null as well, null. Personal
|
||||
* info; cleared by {@link Contact.Builder#wipeOut}.
|
||||
*/
|
||||
@Index String searchName;
|
||||
String searchName;
|
||||
|
||||
/** Contact’s voice number. Personal info; cleared by {@link Contact.Builder#wipeOut}. */
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "phoneNumber", column = @Column(name = "voice_phone_number")),
|
||||
|
@ -138,7 +131,6 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
ContactPhoneNumber voice;
|
||||
|
||||
/** Contact’s fax number. Personal info; cleared by {@link Contact.Builder#wipeOut}. */
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "phoneNumber", column = @Column(name = "fax_phone_number")),
|
||||
|
@ -147,11 +139,9 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
ContactPhoneNumber fax;
|
||||
|
||||
/** Contact’s email address. Personal info; cleared by {@link Contact.Builder#wipeOut}. */
|
||||
@IgnoreSave(IfNull.class)
|
||||
String email;
|
||||
|
||||
/** Authorization info (aka transfer secret) of the contact. */
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "pw.value", column = @Column(name = "auth_info_value")),
|
||||
|
@ -160,7 +150,7 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
ContactAuthInfo authInfo;
|
||||
|
||||
/** Data about any pending or past transfers on this contact. */
|
||||
@Ignore ContactTransferData transferData;
|
||||
ContactTransferData transferData;
|
||||
|
||||
/**
|
||||
* The time that this resource was last transferred.
|
||||
|
@ -173,7 +163,6 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
// the wipeOut() function, so that data is not kept around for deleted contacts.
|
||||
|
||||
/** Disclosure policy. */
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "name", column = @Column(name = "disclose_types_name")),
|
||||
|
@ -193,17 +182,6 @@ public class ContactBase extends EppResource implements ResourceWithTransferData
|
|||
+ " use Contact instead");
|
||||
}
|
||||
|
||||
@OnLoad
|
||||
void onLoad() {
|
||||
if (voice != null && voice.hasNullFields()) {
|
||||
voice = null;
|
||||
}
|
||||
|
||||
if (fax != null && fax.hasNullFields()) {
|
||||
fax = null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ContactHistory extends HistoryEntry {
|
|||
/** Creates a {@link VKey} instance for this entity. */
|
||||
@Override
|
||||
public VKey<ContactHistory> createVKey() {
|
||||
return VKey.createSql(ContactHistory.class, getHistoryEntryId());
|
||||
return VKey.create(ContactHistory.class, getHistoryEntryId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,22 +30,24 @@ import org.joda.time.DateTime;
|
|||
|
||||
/** The {@link ResponseData} returned for an EPP info flow on a contact. */
|
||||
@XmlRootElement(name = "infData")
|
||||
@XmlType(propOrder = {
|
||||
"contactId",
|
||||
"repoId",
|
||||
"statusValues",
|
||||
"postalInfos",
|
||||
"voiceNumber",
|
||||
"faxNumber",
|
||||
"emailAddress",
|
||||
"currentSponsorClientId",
|
||||
"creationClientId",
|
||||
"creationTime",
|
||||
"lastEppUpdateClientId",
|
||||
"lastEppUpdateTime",
|
||||
"lastTransferTime",
|
||||
"authInfo",
|
||||
"disclose" })
|
||||
@XmlType(
|
||||
propOrder = {
|
||||
"contactId",
|
||||
"repoId",
|
||||
"statusValues",
|
||||
"postalInfos",
|
||||
"voiceNumber",
|
||||
"faxNumber",
|
||||
"emailAddress",
|
||||
"currentSponsorRegistrarId",
|
||||
"creationRegistrarId",
|
||||
"creationTime",
|
||||
"lastEppUpdateRegistrarId",
|
||||
"lastEppUpdateTime",
|
||||
"lastTransferTime",
|
||||
"authInfo",
|
||||
"disclose"
|
||||
})
|
||||
@AutoValue
|
||||
@CopyAnnotations
|
||||
public abstract class ContactInfoData implements ResponseData {
|
||||
|
@ -76,17 +78,17 @@ public abstract class ContactInfoData implements ResponseData {
|
|||
abstract String getEmailAddress();
|
||||
|
||||
@XmlElement(name = "clID")
|
||||
abstract String getCurrentSponsorClientId();
|
||||
abstract String getCurrentSponsorRegistrarId();
|
||||
|
||||
@XmlElement(name = "crID")
|
||||
abstract String getCreationClientId();
|
||||
abstract String getCreationRegistrarId();
|
||||
|
||||
@XmlElement(name = "crDate")
|
||||
abstract DateTime getCreationTime();
|
||||
|
||||
@XmlElement(name = "upID")
|
||||
@Nullable
|
||||
abstract String getLastEppUpdateClientId();
|
||||
abstract String getLastEppUpdateRegistrarId();
|
||||
|
||||
@XmlElement(name = "upDate")
|
||||
@Nullable
|
||||
|
@ -114,10 +116,15 @@ public abstract class ContactInfoData implements ResponseData {
|
|||
public abstract Builder setVoiceNumber(@Nullable ContactPhoneNumber voiceNumber);
|
||||
public abstract Builder setFaxNumber(@Nullable ContactPhoneNumber faxNumber);
|
||||
public abstract Builder setEmailAddress(@Nullable String emailAddress);
|
||||
public abstract Builder setCurrentSponsorClientId(String currentSponsorClientId);
|
||||
public abstract Builder setCreationClientId(String creationClientId);
|
||||
|
||||
public abstract Builder setCurrentSponsorRegistrarId(String currentSponsorRegistrarId);
|
||||
|
||||
public abstract Builder setCreationRegistrarId(String creationRegistrarId);
|
||||
|
||||
public abstract Builder setCreationTime(DateTime creationTime);
|
||||
public abstract Builder setLastEppUpdateClientId(@Nullable String lastEppUpdateClientId);
|
||||
|
||||
public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId);
|
||||
|
||||
public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime);
|
||||
public abstract Builder setLastTransferTime(@Nullable DateTime lastTransferTime);
|
||||
public abstract Builder setAuthInfo(@Nullable ContactAuthInfo authInfo);
|
||||
|
|
|
@ -16,9 +16,7 @@ package google.registry.model.domain;
|
|||
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Ignore;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.UnsafeSerializable;
|
||||
import google.registry.model.contact.Contact;
|
||||
|
@ -66,13 +64,11 @@ public class DesignatedContact extends ImmutableObject implements UnsafeSerializ
|
|||
DesignatedContact instance = new DesignatedContact();
|
||||
instance.type = type;
|
||||
instance.contactVKey = checkArgumentNotNull(contact, "Must specify contact key");
|
||||
instance.contact = contact.maybeGetOfyKey().orElse(null);
|
||||
return instance;
|
||||
}
|
||||
|
||||
Type type;
|
||||
|
||||
@Index Key<Contact> contact;
|
||||
@Ignore VKey<Contact> contactVKey;
|
||||
|
||||
public Type getType() {
|
||||
|
@ -82,8 +78,4 @@ public class DesignatedContact extends ImmutableObject implements UnsafeSerializ
|
|||
public VKey<Contact> getContactKey() {
|
||||
return contactVKey;
|
||||
}
|
||||
|
||||
public DesignatedContact reconstitute() {
|
||||
return create(type, VKey.from(contact));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
|
||||
package google.registry.model.domain;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.annotations.ExternalMessagingName;
|
||||
import google.registry.model.annotations.ReportedOn;
|
||||
import google.registry.model.domain.secdns.DomainDsData;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.persistence.VKey;
|
||||
|
@ -31,6 +29,7 @@ import javax.persistence.Column;
|
|||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
|
@ -45,8 +44,6 @@ import org.joda.time.DateTime;
|
|||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc5731">RFC 5731</a>
|
||||
*/
|
||||
@ReportedOn
|
||||
@com.googlecode.objectify.annotation.Entity
|
||||
@Entity
|
||||
@Table(
|
||||
name = "Domain",
|
||||
|
@ -72,7 +69,7 @@ import org.joda.time.DateTime;
|
|||
public class Domain extends DomainBase implements ForeignKeyedEppResource {
|
||||
|
||||
@Override
|
||||
@javax.persistence.Id
|
||||
@Id
|
||||
@Access(AccessType.PROPERTY)
|
||||
public String getRepoId() {
|
||||
return super.getRepoId();
|
||||
|
@ -110,7 +107,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
|
|||
referencedColumnName = "repoId",
|
||||
insertable = false,
|
||||
updatable = false)
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
@SuppressWarnings("unused")
|
||||
private Set<GracePeriod> getInternalGracePeriods() {
|
||||
return gracePeriods;
|
||||
}
|
||||
|
@ -132,7 +129,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
|
|||
referencedColumnName = "repoId",
|
||||
insertable = false,
|
||||
updatable = false)
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
@SuppressWarnings("unused")
|
||||
private Set<DomainDsData> getInternalDelegationSignerData() {
|
||||
return dsData;
|
||||
}
|
||||
|
@ -147,7 +144,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
|
|||
|
||||
@Override
|
||||
public VKey<Domain> createVKey() {
|
||||
return VKey.createSql(Domain.class, getRepoId());
|
||||
return VKey.create(Domain.class, getRepoId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,8 +152,8 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
|
|||
return cloneDomainProjectedAtTime(this, now);
|
||||
}
|
||||
|
||||
public static VKey<Domain> createVKey(Key<Domain> key) {
|
||||
return VKey.create(Domain.class, key.getName(), key);
|
||||
public static VKey<Domain> createVKey(String repoId) {
|
||||
return VKey.create(Domain.class, repoId);
|
||||
}
|
||||
|
||||
/** An override of {@link EppResource#asBuilder} with tighter typing. */
|
||||
|
|
|
@ -36,20 +36,15 @@ import static google.registry.util.DomainNameUtils.canonicalizeHostname;
|
|||
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.googlecode.objectify.annotation.Ignore;
|
||||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
import google.registry.dns.RefreshDnsAction;
|
||||
import google.registry.flows.ResourceFlowUtils;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResource.ResourceWithTransferData;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Recurring;
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.domain.launch.LaunchNotice;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
|
@ -59,16 +54,20 @@ import google.registry.model.domain.token.AllocationToken.TokenType;
|
|||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.poll.PollMessage.Autorenew;
|
||||
import google.registry.model.poll.PollMessage.OneTime;
|
||||
import google.registry.model.tld.Registry;
|
||||
import google.registry.model.transfer.DomainTransferData;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.tldconfig.idn.IdnLabelValidator;
|
||||
import google.registry.util.CollectionUtils;
|
||||
import google.registry.util.DateTimeUtils;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
|
@ -77,6 +76,7 @@ import javax.persistence.AttributeOverrides;
|
|||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
import org.hibernate.collection.internal.PersistentSet;
|
||||
|
@ -86,9 +86,9 @@ import org.joda.time.Interval;
|
|||
/**
|
||||
* A persistable domain resource including mutable and non-mutable fields.
|
||||
*
|
||||
* <p>This class deliberately does not include an {@link javax.persistence.Id} so that any
|
||||
* foreign-keyed fields can refer to the proper parent entity's ID, whether we're storing this in
|
||||
* the DB itself or as part of another entity.
|
||||
* <p>This class deliberately does not include an {@link Id} so that any foreign-keyed fields can
|
||||
* refer to the proper parent entity's ID, whether we're storing this in the DB itself or as part of
|
||||
* another entity.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc5731">RFC 5731</a>
|
||||
*/
|
||||
|
@ -118,13 +118,13 @@ public class DomainBase extends EppResource
|
|||
*
|
||||
* @invariant domainName == domainName.toLowerCase(Locale.ENGLISH)
|
||||
*/
|
||||
@Index String domainName;
|
||||
String domainName;
|
||||
|
||||
/** The top level domain this is under, dernormalized from {@link #domainName}. */
|
||||
@Index String tld;
|
||||
/** The top level domain this is under, de-normalized from {@link #domainName}. */
|
||||
String tld;
|
||||
|
||||
/** References to hosts that are the nameservers for the domain. */
|
||||
@EmptySetToNull @Index @Transient Set<VKey<Host>> nsHosts;
|
||||
@EmptySetToNull @Transient Set<VKey<Host>> nsHosts;
|
||||
|
||||
/** Contacts. */
|
||||
VKey<Contact> adminContact;
|
||||
|
@ -134,7 +134,6 @@ public class DomainBase extends EppResource
|
|||
VKey<Contact> registrantContact;
|
||||
|
||||
/** Authorization info (aka transfer secret) of the domain. */
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "pw.value", column = @Column(name = "auth_info_value")),
|
||||
|
@ -143,14 +142,13 @@ public class DomainBase extends EppResource
|
|||
DomainAuthInfo authInfo;
|
||||
|
||||
/** Data used to construct DS records for this domain. */
|
||||
@Ignore @Transient Set<DomainDsData> dsData;
|
||||
@Transient Set<DomainDsData> dsData;
|
||||
|
||||
/**
|
||||
* The claims notice supplied when this domain was created, if there was one.
|
||||
*
|
||||
* <p>It's {@literal @}XmlTransient because it's not returned in an info response.
|
||||
*/
|
||||
@Ignore
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "noticeId.tcnId", column = @Column(name = "launch_notice_tcn_id")),
|
||||
|
@ -169,9 +167,8 @@ public class DomainBase extends EppResource
|
|||
/**
|
||||
* Name of first IDN table associated with TLD that matched the characters in this domain label.
|
||||
*
|
||||
* @see google.registry.tldconfig.idn.IdnLabelValidator#findValidIdnTableForTld
|
||||
* @see IdnLabelValidator#findValidIdnTableForTld
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
String idnTableName;
|
||||
|
||||
/** Fully qualified host names of this domain's active subordinate hosts. */
|
||||
|
@ -188,44 +185,42 @@ public class DomainBase extends EppResource
|
|||
* restored, the message should be deleted.
|
||||
*/
|
||||
@Column(name = "deletion_poll_message_id")
|
||||
VKey<PollMessage.OneTime> deletePollMessage;
|
||||
VKey<OneTime> deletePollMessage;
|
||||
|
||||
/**
|
||||
* The recurring billing event associated with this domain's autorenewals.
|
||||
*
|
||||
* <p>The recurrence should be open ended unless the domain is in pending delete or fully deleted,
|
||||
* <p>The recurrence should be open-ended unless the domain is in pending delete or fully deleted,
|
||||
* in which case it should be closed at the time the delete was requested. Whenever the domain's
|
||||
* {@link #registrationExpirationTime} is changed the recurrence should be closed, a new one
|
||||
* should be created, and this field should be updated to point to the new one.
|
||||
*/
|
||||
@Column(name = "billing_recurrence_id")
|
||||
@Ignore
|
||||
VKey<BillingEvent.Recurring> autorenewBillingEvent;
|
||||
VKey<Recurring> autorenewBillingEvent;
|
||||
|
||||
/**
|
||||
* The recurring poll message associated with this domain's autorenewals.
|
||||
*
|
||||
* <p>The recurrence should be open ended unless the domain is in pending delete or fully deleted,
|
||||
* <p>The recurrence should be open-ended unless the domain is in pending delete or fully deleted,
|
||||
* in which case it should be closed at the time the delete was requested. Whenever the domain's
|
||||
* {@link #registrationExpirationTime} is changed the recurrence should be closed, a new one
|
||||
* should be created, and this field should be updated to point to the new one.
|
||||
*/
|
||||
@Column(name = "autorenew_poll_message_id")
|
||||
VKey<PollMessage.Autorenew> autorenewPollMessage;
|
||||
VKey<Autorenew> autorenewPollMessage;
|
||||
|
||||
/** The unexpired grace periods for this domain (some of which may not be active yet). */
|
||||
@Ignore @Transient Set<GracePeriod> gracePeriods;
|
||||
@Transient Set<GracePeriod> gracePeriods;
|
||||
|
||||
/**
|
||||
* The id of the signed mark that was used to create this domain in sunrise.
|
||||
*
|
||||
* <p>Will only be populated for domains created in sunrise.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
String smdId;
|
||||
|
||||
/** Data about any pending or past transfers on this domain. */
|
||||
@Ignore DomainTransferData transferData;
|
||||
DomainTransferData transferData;
|
||||
|
||||
/**
|
||||
* The time that this resource was last transferred.
|
||||
|
@ -249,12 +244,12 @@ public class DomainBase extends EppResource
|
|||
* difference domains that have reached their life and must be deleted now, and domains that
|
||||
* happen to be in the autorenew grace period now but should be deleted in roughly a year.
|
||||
*/
|
||||
@Index DateTime autorenewEndTime;
|
||||
DateTime autorenewEndTime;
|
||||
|
||||
/**
|
||||
* When this domain's DNS was requested to be refreshed, or null if its DNS is up-to-date.
|
||||
*
|
||||
* <p>This will almost always be null except in the couple minutes' interval between when a
|
||||
* <p>This will almost always be null except in the couple of minutes' interval between when a
|
||||
* DNS-affecting create or update operation takes place and when the {@link RefreshDnsAction}
|
||||
* runs, which resets this back to null upon completion of the DNS refresh task. This is a {@link
|
||||
* DateTime} rather than a simple dirty boolean so that the DNS refresh action can order by the
|
||||
|
@ -271,10 +266,10 @@ public class DomainBase extends EppResource
|
|||
* it remains as a permanent record of which actions were DNS-affecting and which were not.
|
||||
*/
|
||||
// TODO(mcilwain): Start using this field once we are further along in the DB migration.
|
||||
@Ignore DateTime dnsRefreshRequestTime;
|
||||
DateTime dnsRefreshRequestTime;
|
||||
|
||||
/** The {@link AllocationToken} for the package this domain is currently a part of. */
|
||||
@Ignore @Nullable VKey<AllocationToken> currentPackageToken;
|
||||
@Nullable VKey<AllocationToken> currentPackageToken;
|
||||
|
||||
/**
|
||||
* Returns the DNS refresh request time iff this domain's DNS needs refreshing, otherwise absent.
|
||||
|
@ -291,15 +286,15 @@ public class DomainBase extends EppResource
|
|||
return registrationExpirationTime;
|
||||
}
|
||||
|
||||
public VKey<PollMessage.OneTime> getDeletePollMessage() {
|
||||
public VKey<OneTime> getDeletePollMessage() {
|
||||
return deletePollMessage;
|
||||
}
|
||||
|
||||
public VKey<BillingEvent.Recurring> getAutorenewBillingEvent() {
|
||||
public VKey<Recurring> getAutorenewBillingEvent() {
|
||||
return autorenewBillingEvent;
|
||||
}
|
||||
|
||||
public VKey<PollMessage.Autorenew> getAutorenewPollMessage() {
|
||||
public VKey<Autorenew> getAutorenewPollMessage() {
|
||||
return autorenewPollMessage;
|
||||
}
|
||||
|
||||
|
@ -362,7 +357,7 @@ public class DomainBase extends EppResource
|
|||
}
|
||||
|
||||
// Hibernate needs this in order to populate nsHosts but no one else should ever use it
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
@SuppressWarnings("unused")
|
||||
private void setNsHosts(Set<VKey<Host>> nsHosts) {
|
||||
this.nsHosts = forceEmptyToNull(nsHosts);
|
||||
}
|
||||
|
@ -370,14 +365,14 @@ public class DomainBase extends EppResource
|
|||
// Note: for the two methods below, how we wish to treat the Hibernate setters depends on the
|
||||
// current state of the object and what's passed in. The key principle is that we wish to maintain
|
||||
// the link between parent and child objects, meaning that we should keep around whichever of the
|
||||
// two sets (the parameter vs the class variable and clear/populate that as appropriate.
|
||||
// two sets (the parameter vs the class variable and clear/populate that as appropriate).
|
||||
//
|
||||
// If the class variable is a PersistentSet and we overwrite it here, Hibernate will throw
|
||||
// If the class variable is a PersistentSet, and we overwrite it here, Hibernate will throw
|
||||
// an exception "A collection with cascade=”all-delete-orphan” was no longer referenced by the
|
||||
// owning entity instance". See https://stackoverflow.com/questions/5587482 for more details.
|
||||
|
||||
// Hibernate needs this in order to populate gracePeriods but no one else should ever use it
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
@SuppressWarnings("unused")
|
||||
private void setInternalGracePeriods(Set<GracePeriod> gracePeriods) {
|
||||
if (this.gracePeriods instanceof PersistentSet) {
|
||||
Set<GracePeriod> nonNullGracePeriods = nullToEmpty(gracePeriods);
|
||||
|
@ -389,7 +384,7 @@ public class DomainBase extends EppResource
|
|||
}
|
||||
|
||||
// Hibernate needs this in order to populate dsData but no one else should ever use it
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
@SuppressWarnings("unused")
|
||||
private void setInternalDelegationSignerData(Set<DomainDsData> dsData) {
|
||||
if (this.dsData instanceof PersistentSet) {
|
||||
Set<DomainDsData> nonNullDsData = nullToEmpty(dsData);
|
||||
|
@ -488,7 +483,7 @@ public class DomainBase extends EppResource
|
|||
.setAutorenewBillingEvent(transferData.getServerApproveAutorenewEvent())
|
||||
.setAutorenewPollMessage(transferData.getServerApproveAutorenewPollMessage());
|
||||
if (transferData.getTransferPeriod().getValue() == 1) {
|
||||
// Set the grace period using a key to the prescheduled transfer billing event. Not using
|
||||
// Set the grace period using a key to the pre-scheduled transfer billing event. Not using
|
||||
// GracePeriod.forBillingEvent() here in order to avoid the actual Datastore fetch.
|
||||
builder.setGracePeriods(
|
||||
ImmutableSet.of(
|
||||
|
@ -551,7 +546,7 @@ public class DomainBase extends EppResource
|
|||
}
|
||||
}
|
||||
|
||||
// It is possible that the lastEppUpdateClientId is different from current sponsor client
|
||||
// It is possible that the lastEppUpdateRegistrarId is different from current sponsor client
|
||||
// id, so we have to do the comparison instead of having one variable just storing the most
|
||||
// recent time.
|
||||
if (newLastEppUpdateTime.isPresent()) {
|
||||
|
@ -656,7 +651,7 @@ public class DomainBase extends EppResource
|
|||
if (includeRegistrant) {
|
||||
registrantContact = null;
|
||||
}
|
||||
HashSet<DesignatedContact.Type> contactsDiscovered = new HashSet<DesignatedContact.Type>();
|
||||
HashSet<DesignatedContact.Type> contactsDiscovered = new HashSet<>();
|
||||
for (DesignatedContact contact : contacts) {
|
||||
checkArgument(
|
||||
!contactsDiscovered.contains(contact.getType()),
|
||||
|
@ -851,17 +846,17 @@ public class DomainBase extends EppResource
|
|||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
public B setDeletePollMessage(VKey<PollMessage.OneTime> deletePollMessage) {
|
||||
public B setDeletePollMessage(VKey<OneTime> deletePollMessage) {
|
||||
getInstance().deletePollMessage = deletePollMessage;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
public B setAutorenewBillingEvent(VKey<BillingEvent.Recurring> autorenewBillingEvent) {
|
||||
public B setAutorenewBillingEvent(VKey<Recurring> autorenewBillingEvent) {
|
||||
getInstance().autorenewBillingEvent = autorenewBillingEvent;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
public B setAutorenewPollMessage(@Nullable VKey<PollMessage.Autorenew> autorenewPollMessage) {
|
||||
public B setAutorenewPollMessage(@Nullable VKey<Autorenew> autorenewPollMessage) {
|
||||
getInstance().autorenewPollMessage = autorenewPollMessage;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
@ -931,7 +926,7 @@ public class DomainBase extends EppResource
|
|||
new IllegalArgumentException(
|
||||
String.format(
|
||||
"The package token %s does not exist",
|
||||
currentPackageToken.getSqlKey())));
|
||||
currentPackageToken.getKey())));
|
||||
checkArgument(
|
||||
token.getTokenType().equals(TokenType.PACKAGE),
|
||||
"The currentPackageToken must have a PACKAGE TokenType");
|
||||
|
|
|
@ -186,7 +186,7 @@ public class DomainHistory extends HistoryEntry {
|
|||
/** Creates a {@link VKey} instance for this entity. */
|
||||
@Override
|
||||
public VKey<DomainHistory> createVKey() {
|
||||
return VKey.createSql(DomainHistory.class, getHistoryEntryId());
|
||||
return VKey.create(DomainHistory.class, getHistoryEntryId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,10 +39,10 @@ import org.joda.time.DateTime;
|
|||
"contacts",
|
||||
"nameservers",
|
||||
"subordinateHosts",
|
||||
"currentSponsorClientId",
|
||||
"creationClientId",
|
||||
"currentSponsorRegistrarId",
|
||||
"creationRegistrarId",
|
||||
"creationTime",
|
||||
"lastEppUpdateClientId",
|
||||
"lastEppUpdateRegistrarId",
|
||||
"lastEppUpdateTime",
|
||||
"registrationExpirationTime",
|
||||
"lastTransferTime",
|
||||
|
@ -79,11 +79,11 @@ public abstract class DomainInfoData implements ResponseData {
|
|||
abstract ImmutableSet<String> getSubordinateHosts();
|
||||
|
||||
@XmlElement(name = "clID")
|
||||
abstract String getCurrentSponsorClientId();
|
||||
abstract String getCurrentSponsorRegistrarId();
|
||||
|
||||
@XmlElement(name = "crID")
|
||||
@Nullable
|
||||
abstract String getCreationClientId();
|
||||
abstract String getCreationRegistrarId();
|
||||
|
||||
@XmlElement(name = "crDate")
|
||||
@Nullable
|
||||
|
@ -91,7 +91,7 @@ public abstract class DomainInfoData implements ResponseData {
|
|||
|
||||
@XmlElement(name = "upID")
|
||||
@Nullable
|
||||
abstract String getLastEppUpdateClientId();
|
||||
abstract String getLastEppUpdateRegistrarId();
|
||||
|
||||
@XmlElement(name = "upDate")
|
||||
@Nullable
|
||||
|
@ -121,10 +121,15 @@ public abstract class DomainInfoData implements ResponseData {
|
|||
@Nullable ImmutableSet<ForeignKeyedDesignatedContact> contacts);
|
||||
public abstract Builder setNameservers(@Nullable ImmutableSet<String> nameservers);
|
||||
public abstract Builder setSubordinateHosts(@Nullable ImmutableSet<String> subordinateHosts);
|
||||
public abstract Builder setCurrentSponsorClientId(String currentSponsorClientId);
|
||||
public abstract Builder setCreationClientId(@Nullable String creationClientId);
|
||||
|
||||
public abstract Builder setCurrentSponsorRegistrarId(String currentSponsorRegistrarId);
|
||||
|
||||
public abstract Builder setCreationRegistrarId(@Nullable String creationRegistrarId);
|
||||
|
||||
public abstract Builder setCreationTime(@Nullable DateTime creationTime);
|
||||
public abstract Builder setLastEppUpdateClientId(@Nullable String lastEppUpdateClientId);
|
||||
|
||||
public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId);
|
||||
|
||||
public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime);
|
||||
public abstract Builder setRegistrationExpirationTime(
|
||||
@Nullable DateTime registrationExpirationTime);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class PackageTokenResponseExtension extends ImmutableObject implements Re
|
|||
PackageTokenResponseExtension instance = new PackageTokenResponseExtension();
|
||||
instance.token = "";
|
||||
if (tokenKey.isPresent()) {
|
||||
instance.token = tokenKey.get().getSqlKey().toString();
|
||||
instance.token = tokenKey.get().getKey().toString();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
|
|||
throw new IllegalArgumentException(
|
||||
String.format("%s tokens are not stored in the database", getTokenBehavior()));
|
||||
}
|
||||
return VKey.createSql(AllocationToken.class, getToken());
|
||||
return VKey.create(AllocationToken.class, getToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -104,14 +104,14 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
|
|||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.query("FROM PackagePromotion WHERE token = :token", PackagePromotion.class)
|
||||
.setParameter("token", VKey.createSql(AllocationToken.class, tokenString))
|
||||
.setParameter("token", VKey.create(AllocationToken.class, tokenString))
|
||||
.getResultStream()
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VKey<PackagePromotion> createVKey() {
|
||||
return VKey.createSql(PackagePromotion.class, packagePromotionId);
|
||||
return VKey.create(PackagePromotion.class, packagePromotionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,7 +64,7 @@ public class Host extends HostBase implements ForeignKeyedEppResource {
|
|||
|
||||
@Override
|
||||
public VKey<Host> createVKey() {
|
||||
return VKey.createSql(Host.class, getRepoId());
|
||||
return VKey.create(Host.class, getRepoId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,9 +22,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
|||
import static google.registry.util.DomainNameUtils.canonicalizeHostname;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
|
@ -63,14 +60,12 @@ public class HostBase extends EppResource {
|
|||
* from (creationTime, deletionTime) there can only be one host in Datastore with this name.
|
||||
* However, there can be many hosts with the same name and non-overlapping lifetimes.
|
||||
*/
|
||||
@Index String hostName;
|
||||
String hostName;
|
||||
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@Index Set<InetAddress> inetAddresses;
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
/** The superordinate domain of this host, or null if this is an external host. */
|
||||
@Index
|
||||
@IgnoreSave(IfNull.class)
|
||||
@DoNotHydrate
|
||||
VKey<Domain> superordinateDomain;
|
||||
|
||||
|
@ -144,7 +139,8 @@ public class HostBase extends EppResource {
|
|||
* superordinate was transferred. If the last superordinate change was before this time, then the
|
||||
* host was attached to this superordinate domain during that transfer.
|
||||
*
|
||||
* <p>If the host is not subordinate the domain can be null and we just return last transfer time.
|
||||
* <p>If the host is not subordinate the domain can be null, and we just return last transfer
|
||||
* time.
|
||||
*
|
||||
* @param superordinateDomain the loaded superordinate domain, which must match the key in the
|
||||
* {@link #superordinateDomain} field. Passing it as a parameter allows the caller to control
|
||||
|
|
|
@ -66,7 +66,7 @@ public class HostHistory extends HistoryEntry {
|
|||
/** Creates a {@link VKey} instance for this entity. */
|
||||
@Override
|
||||
public VKey<HostHistory> createVKey() {
|
||||
return VKey.createSql(HostHistory.class, getHistoryEntryId());
|
||||
return VKey.create(HostHistory.class, getHistoryEntryId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,10 +34,10 @@ import org.joda.time.DateTime;
|
|||
"repoId",
|
||||
"statusValues",
|
||||
"inetAddresses",
|
||||
"currentSponsorClientId",
|
||||
"creationClientId",
|
||||
"currentSponsorRegistrarId",
|
||||
"creationRegistrarId",
|
||||
"creationTime",
|
||||
"lastEppUpdateClientId",
|
||||
"lastEppUpdateRegistrarId",
|
||||
"lastEppUpdateTime",
|
||||
"lastTransferTime"
|
||||
})
|
||||
|
@ -58,17 +58,17 @@ public abstract class HostInfoData implements ResponseData {
|
|||
abstract ImmutableSet<InetAddress> getInetAddresses();
|
||||
|
||||
@XmlElement(name = "clID")
|
||||
abstract String getCurrentSponsorClientId();
|
||||
abstract String getCurrentSponsorRegistrarId();
|
||||
|
||||
@XmlElement(name = "crID")
|
||||
abstract String getCreationClientId();
|
||||
abstract String getCreationRegistrarId();
|
||||
|
||||
@XmlElement(name = "crDate")
|
||||
abstract DateTime getCreationTime();
|
||||
|
||||
@XmlElement(name = "upID")
|
||||
@Nullable
|
||||
abstract String getLastEppUpdateClientId();
|
||||
abstract String getLastEppUpdateRegistrarId();
|
||||
|
||||
@XmlElement(name = "upDate")
|
||||
@Nullable
|
||||
|
@ -86,10 +86,15 @@ public abstract class HostInfoData implements ResponseData {
|
|||
public abstract Builder setRepoId(String repoId);
|
||||
public abstract Builder setStatusValues(ImmutableSet<StatusValue> statusValues);
|
||||
public abstract Builder setInetAddresses(ImmutableSet<InetAddress> inetAddresses);
|
||||
public abstract Builder setCurrentSponsorClientId(String currentSponsorClientId);
|
||||
public abstract Builder setCreationClientId(String creationClientId);
|
||||
|
||||
public abstract Builder setCurrentSponsorRegistrarId(String currentSponsorRegistrarId);
|
||||
|
||||
public abstract Builder setCreationRegistrarId(String creationRegistrarId);
|
||||
|
||||
public abstract Builder setCreationTime(DateTime creationTime);
|
||||
public abstract Builder setLastEppUpdateClientId(@Nullable String lastEppUpdateClientId);
|
||||
|
||||
public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId);
|
||||
|
||||
public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime);
|
||||
public abstract Builder setLastTransferTime(@Nullable DateTime lastTransferTime);
|
||||
public abstract HostInfoData build();
|
||||
|
|
|
@ -33,16 +33,15 @@ import com.googlecode.objectify.impl.translate.TranslatorFactory;
|
|||
import com.googlecode.objectify.impl.translate.opt.joda.MoneyStringTranslatorFactory;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.Buildable;
|
||||
import google.registry.model.EntityClasses;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.model.common.GaeUserIdConverter;
|
||||
import google.registry.model.translators.BloomFilterOfStringTranslatorFactory;
|
||||
import google.registry.model.translators.CidrAddressBlockTranslatorFactory;
|
||||
import google.registry.model.translators.CurrencyUnitTranslatorFactory;
|
||||
import google.registry.model.translators.DurationTranslatorFactory;
|
||||
import google.registry.model.translators.InetAddressTranslatorFactory;
|
||||
import google.registry.model.translators.ReadableInstantUtcTranslatorFactory;
|
||||
import google.registry.model.translators.VKeyTranslatorFactory;
|
||||
|
||||
/**
|
||||
* An instance of Ofy, obtained via {@code #auditedOfy()}, should be used to access all persistable
|
||||
|
@ -106,7 +105,7 @@ public class ObjectifyService {
|
|||
|
||||
// Translators must be registered before any entities can be registered.
|
||||
registerTranslators();
|
||||
registerEntityClasses(EntityClasses.ALL_CLASSES);
|
||||
registerEntityClasses(ImmutableSet.of(GaeUserIdConverter.class));
|
||||
}
|
||||
|
||||
/** Register translators that allow less common types to be stored directly in Datastore. */
|
||||
|
@ -119,8 +118,7 @@ public class ObjectifyService {
|
|||
new DurationTranslatorFactory(),
|
||||
new InetAddressTranslatorFactory(),
|
||||
new MoneyStringTranslatorFactory(),
|
||||
new ReadableInstantUtcTranslatorFactory(),
|
||||
new VKeyTranslatorFactory())) {
|
||||
new ReadableInstantUtcTranslatorFactory())) {
|
||||
factory().getTranslators().add(translatorFactory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ public abstract class PollMessage extends ImmutableObject
|
|||
|
||||
@Override
|
||||
public VKey<OneTime> createVKey() {
|
||||
return VKey.createSql(OneTime.class, getId());
|
||||
return VKey.create(OneTime.class, getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -563,7 +563,7 @@ public abstract class PollMessage extends ImmutableObject
|
|||
|
||||
@Override
|
||||
public VKey<Autorenew> createVKey() {
|
||||
return VKey.createSql(Autorenew.class, getId());
|
||||
return VKey.create(Autorenew.class, getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,7 @@ public final class PollMessageExternalKeyConverter {
|
|||
}
|
||||
try {
|
||||
Long id = Long.parseLong(idComponents.get(0));
|
||||
return VKey.createSql(PollMessage.class, id);
|
||||
return VKey.create(PollMessage.class, id);
|
||||
// Note that idComponents.get(1) is entirely ignored; we never use the year field internally.
|
||||
} catch (NumberFormatException e) {
|
||||
throw new PollMessageExternalKeyParseException();
|
||||
|
|
|
@ -85,7 +85,7 @@ public final class RdeRevision extends UpdateAutoTimestampEntity {
|
|||
public static int getNextRevision(String tld, DateTime date, RdeMode mode) {
|
||||
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
||||
Optional<RdeRevision> revisionOptional =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.createSql(RdeRevision.class, sqlKey)));
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(RdeRevision.class, sqlKey)));
|
||||
return revisionOptional.map(rdeRevision -> rdeRevision.revision + 1).orElse(0);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ public final class RdeRevision extends UpdateAutoTimestampEntity {
|
|||
tm().assertInTransaction();
|
||||
RdeRevisionId sqlKey = RdeRevisionId.create(tld, date.toLocalDate(), mode);
|
||||
Optional<RdeRevision> revisionOptional =
|
||||
tm().loadByKeyIfPresent(VKey.createSql(RdeRevision.class, sqlKey));
|
||||
tm().loadByKeyIfPresent(VKey.create(RdeRevision.class, sqlKey));
|
||||
if (revision == 0) {
|
||||
revisionOptional.ifPresent(
|
||||
rdeRevision -> {
|
||||
|
|
|
@ -656,7 +656,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J
|
|||
/** Creates a {@link VKey} for the given {@code registrarId}. */
|
||||
public static VKey<Registrar> createVKey(String registrarId) {
|
||||
checkArgumentNotNull(registrarId, "registrarId must be specified");
|
||||
return VKey.createSql(Registrar.class, registrarId);
|
||||
return VKey.create(Registrar.class, registrarId);
|
||||
}
|
||||
|
||||
/** A builder for constructing {@link Registrar}, since it is immutable. */
|
||||
|
|
|
@ -319,7 +319,7 @@ public class RegistrarPoc extends ImmutableObject implements Jsonifiable, Unsafe
|
|||
|
||||
@Override
|
||||
public VKey<RegistrarPoc> createVKey() {
|
||||
return VKey.createSql(RegistrarPoc.class, new RegistrarPocId(emailAddress, registrarId));
|
||||
return VKey.create(RegistrarPoc.class, new RegistrarPocId(emailAddress, registrarId));
|
||||
}
|
||||
|
||||
/** Class to represent the composite primary key for {@link RegistrarPoc} entity. */
|
||||
|
|
|
@ -149,7 +149,7 @@ public class HistoryEntryDao {
|
|||
CriteriaQueryBuilder.create(historyClass)
|
||||
.where("modificationTime", criteriaBuilder::greaterThanOrEqualTo, afterTime)
|
||||
.where("modificationTime", criteriaBuilder::lessThanOrEqualTo, beforeTime)
|
||||
.where("repoId", criteriaBuilder::equal, resourceKey.getSqlKey().toString())
|
||||
.where("repoId", criteriaBuilder::equal, resourceKey.getKey().toString())
|
||||
.orderByAsc("revisionId")
|
||||
.orderByAsc("modificationTime")
|
||||
.build();
|
||||
|
|
|
@ -217,7 +217,7 @@ public class Lock extends ImmutableObject implements Serializable {
|
|||
// Checking if an unexpired lock still exists - if so, the lock can't be acquired.
|
||||
Lock lock =
|
||||
jpaTm()
|
||||
.loadByKeyIfPresent(VKey.createSql(Lock.class, new LockId(resourceName, scope)))
|
||||
.loadByKeyIfPresent(VKey.create(Lock.class, new LockId(resourceName, scope)))
|
||||
.orElse(null);
|
||||
if (lock != null) {
|
||||
logger.atInfo().log(
|
||||
|
@ -257,7 +257,7 @@ public class Lock extends ImmutableObject implements Serializable {
|
|||
// delete it. If the lock in the database was different, then this lock is gone already;
|
||||
// this can happen if release() is called around the expiration time and the lock
|
||||
// expires underneath us.
|
||||
VKey<Lock> key = VKey.createSql(Lock.class, new LockId(resourceName, scope));
|
||||
VKey<Lock> key = VKey.create(Lock.class, new LockId(resourceName, scope));
|
||||
Lock loadedLock = jpaTm().loadByKeyIfPresent(key).orElse(null);
|
||||
if (equals(loadedLock)) {
|
||||
// Use deleteIgnoringReadOnly() so that we don't create a commit log entry for deleting
|
||||
|
|
|
@ -210,12 +210,12 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial
|
|||
});
|
||||
|
||||
public static VKey<Registry> createVKey(String tld) {
|
||||
return VKey.createSql(Registry.class, tld);
|
||||
return VKey.create(Registry.class, tld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VKey<Registry> createVKey() {
|
||||
return VKey.createSql(Registry.class, tldStr);
|
||||
return VKey.create(Registry.class, tldStr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,9 +88,9 @@ public abstract class TransferData extends BaseTransferObject implements Buildab
|
|||
public ImmutableSet<VKey<? extends TransferServerApproveEntity>> getServerApproveEntities() {
|
||||
return NullIgnoringCollectionBuilder.create(
|
||||
new ImmutableSet.Builder<VKey<? extends TransferServerApproveEntity>>())
|
||||
.add(pollMessageId1 != null ? VKey.createSql(PollMessage.class, pollMessageId1) : null)
|
||||
.add(pollMessageId2 != null ? VKey.createSql(PollMessage.class, pollMessageId2) : null)
|
||||
.add(pollMessageId3 != null ? VKey.createSql(PollMessage.class, pollMessageId3) : null)
|
||||
.add(pollMessageId1 != null ? VKey.create(PollMessage.class, pollMessageId1) : null)
|
||||
.add(pollMessageId2 != null ? VKey.create(PollMessage.class, pollMessageId2) : null)
|
||||
.add(pollMessageId3 != null ? VKey.create(PollMessage.class, pollMessageId3) : null)
|
||||
.getBuilder()
|
||||
.build();
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public abstract class TransferData extends BaseTransferObject implements Buildab
|
|||
Set<VKey<? extends TransferServerApproveEntity>> serverApproveEntities) {
|
||||
return nullToEmpty(serverApproveEntities).stream()
|
||||
.filter(vKey -> PollMessage.class.isAssignableFrom(vKey.getKind()))
|
||||
.map(vKey -> (long) vKey.getSqlKey())
|
||||
.map(vKey -> (long) vKey.getKey())
|
||||
.sorted()
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.translators;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.persistence.VKey;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Translator factory for VKey.
|
||||
*
|
||||
* <p>These get translated to a string containing the URL safe encoding of the objectify key
|
||||
* followed by a (url-unsafe) ampersand delimiter and the SQL key.
|
||||
*/
|
||||
public class VKeyTranslatorFactory extends AbstractSimpleTranslatorFactory<VKey, Key> {
|
||||
|
||||
public VKeyTranslatorFactory() {
|
||||
super(VKey.class);
|
||||
}
|
||||
|
||||
/** Create a VKey from a raw datastore key. */
|
||||
@Nullable
|
||||
public static VKey<?> createVKey(@Nullable Key datastoreKey) {
|
||||
if (datastoreKey == null) {
|
||||
return null;
|
||||
}
|
||||
return createVKey(com.googlecode.objectify.Key.create(datastoreKey));
|
||||
}
|
||||
|
||||
/** Create a VKey from an objectify Key. */
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> VKey<T> createVKey(@Nullable com.googlecode.objectify.Key<T> key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try to create the VKey from its reference type.
|
||||
Class<T> clazz = ClassPathManager.getClass(key.getKind());
|
||||
checkArgument(clazz != null, "Unknown Key type: %s", key.getKind());
|
||||
try {
|
||||
Method createVKeyMethod =
|
||||
clazz.getDeclaredMethod("createVKey", com.googlecode.objectify.Key.class);
|
||||
return (VKey<T>) createVKeyMethod.invoke(null, new Object[] {key});
|
||||
} catch (NoSuchMethodException e) {
|
||||
checkArgument(
|
||||
key.getParent() == null,
|
||||
"Cannot auto-convert key %s of kind %s because it has a parent. Add a createVKey(Key) "
|
||||
+ "method for it.",
|
||||
key,
|
||||
key.getKind());
|
||||
if (key.getName() != null) {
|
||||
return VKey.create(clazz, key.getName(), key);
|
||||
} else {
|
||||
return VKey.create(clazz, key.getId(), key);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
// If we have a createVKey(Key) method with incorrect permissions or that is non-static, this
|
||||
// is probably an error so let's reported.
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleTranslator<VKey, Key> createTranslator() {
|
||||
return new SimpleTranslator<VKey, Key>() {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VKey loadValue(@Nullable Key datastoreValue) {
|
||||
return createVKey(datastoreValue);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Key saveValue(@Nullable VKey key) {
|
||||
return key == null ? null : key.getOfyKey().getRaw();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -14,236 +14,89 @@
|
|||
|
||||
package google.registry.persistence;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.ImmutableMap.toImmutableMap;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
import static java.util.function.Function.identity;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.UpdateAutoTimestampEntity;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.model.translators.VKeyTranslatorFactory;
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.util.SerializeUtils;
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* VKey is an abstraction that encapsulates the key concept.
|
||||
*
|
||||
* <p>A VKey instance must contain both the JPA primary key for the referenced entity class and the
|
||||
* objectify key for the object.
|
||||
* <p>A VKey instance must contain the JPA primary key for the referenced entity class.
|
||||
*/
|
||||
public class VKey<T> extends ImmutableObject implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5291472863840231240L;
|
||||
|
||||
// Info that's stored in in vkey string generated via stringify().
|
||||
private static final String SQL_LOOKUP_KEY = "sql";
|
||||
private static final String OFY_LOOKUP_KEY = "ofy";
|
||||
// Info that's stored in VKey string generated via stringify().
|
||||
private static final String LOOKUP_KEY = "sql";
|
||||
private static final String CLASS_TYPE = "kind";
|
||||
|
||||
// Web safe delimiters that won't be used in base 64.
|
||||
private static final String KV_SEPARATOR = ":";
|
||||
private static final String DELIMITER = "@";
|
||||
|
||||
// The SQL key for the referenced entity.
|
||||
Serializable sqlKey;
|
||||
private static final ImmutableMap<String, Class<? extends EppResource>> EPP_RESOURCE_CLASS_MAP =
|
||||
ImmutableList.of(Domain.class, Host.class, Contact.class).stream()
|
||||
.collect(toImmutableMap(Class::getSimpleName, identity()));
|
||||
|
||||
// The objectify key for the referenced entity. Marked Insignificant to exclude it from
|
||||
// hashing/equality.
|
||||
@Insignificant Key<T> ofyKey;
|
||||
// The primary key for the referenced entity.
|
||||
Serializable key;
|
||||
|
||||
Class<? extends T> kind;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
VKey() {}
|
||||
|
||||
VKey(Class<? extends T> kind, Key<T> ofyKey, Serializable sqlKey) {
|
||||
VKey(Class<? extends T> kind, Serializable key) {
|
||||
this.kind = kind;
|
||||
this.ofyKey = ofyKey;
|
||||
this.sqlKey = sqlKey;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link VKey} which only contains the sql primary key.
|
||||
*
|
||||
* <p>Deprecated. Create symmetric keys with create() instead.
|
||||
*/
|
||||
public static <T> VKey<T> createSql(Class<T> kind, Serializable sqlKey) {
|
||||
/** Creates a {@link VKey} with supplied the SQL primary key. */
|
||||
public static <T> VKey<T> create(Class<T> kind, Serializable key) {
|
||||
checkArgumentNotNull(kind, "kind must not be null");
|
||||
checkArgumentNotNull(sqlKey, "sqlKey must not be null");
|
||||
return new VKey<T>(kind, null, sqlKey);
|
||||
}
|
||||
|
||||
/** Creates a {@link VKey} which only contains the ofy primary key. */
|
||||
public static <T> VKey<T> createOfy(Class<? extends T> kind, Key<T> ofyKey) {
|
||||
checkArgumentNotNull(kind, "kind must not be null");
|
||||
checkArgumentNotNull(ofyKey, "ofyKey must not be null");
|
||||
return new VKey<T>(kind, ofyKey, null);
|
||||
}
|
||||
|
||||
/** Creates a {@link VKey} which only contains both sql and ofy primary key. */
|
||||
public static <T> VKey<T> create(Class<T> kind, Serializable sqlKey, Key<T> ofyKey) {
|
||||
checkArgumentNotNull(kind, "kind must not be null");
|
||||
checkArgumentNotNull(sqlKey, "sqlKey must not be null");
|
||||
checkArgumentNotNull(ofyKey, "ofyKey must not be null");
|
||||
return new VKey<T>(kind, ofyKey, sqlKey);
|
||||
checkArgumentNotNull(key, "key must not be null");
|
||||
return new VKey<>(kind, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code id}.
|
||||
* Constructs a {@link VKey} for an {@link EppResource } from the string representation.
|
||||
*
|
||||
* <p>IMPORTANT USAGE NOTE: Datastore entities that are not roots of entity groups (i.e. those
|
||||
* that do not have a null parent in their Objectify keys) require the full entity group
|
||||
* inheritance chain to be specified and thus cannot use this create method. You need to use
|
||||
* {@link #create(Class, Serializable, Key)} instead and pass in the full, valid parent field in
|
||||
* the Datastore key.
|
||||
* <p>The string representation is obtained from the {@link #stringify()} function and like this:
|
||||
* {@code kind:TestObject@sql:rO0ABXQAA2Zvbw}
|
||||
*/
|
||||
public static <T> VKey<T> create(Class<T> kind, long id) {
|
||||
checkArgument(
|
||||
UpdateAutoTimestampEntity.class.isAssignableFrom(kind),
|
||||
"The kind %s is not a UpdateAutoTimestampEntity and thus needs its entire entity group"
|
||||
+ " chain specified in a parent",
|
||||
kind.getCanonicalName());
|
||||
return new VKey<T>(kind, Key.create(kind, id), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code name}.
|
||||
*
|
||||
* <p>IMPORTANT USAGE NOTE: Datastore entities that are not roots of entity groups (i.e. those
|
||||
* that do not have a null parent in their Objectify keys) require the full entity group
|
||||
* inheritance chain to be specified and thus cannot use this create method. You need to use
|
||||
* {@link #create(Class, Serializable, Key)} instead and pass in the full, valid parent field in
|
||||
* the Datastore key.
|
||||
*/
|
||||
public static <T> VKey<T> create(Class<T> kind, String name) {
|
||||
checkArgument(
|
||||
UpdateAutoTimestampEntity.class.isAssignableFrom(kind),
|
||||
"The kind %s is not a UpdateAutoTimestampEntity and thus needs its entire entity group"
|
||||
+ " chain specified in a parent",
|
||||
kind.getCanonicalName());
|
||||
return new VKey<T>(kind, Key.create(kind, name), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link VKey} from the string representation of a vkey.
|
||||
*
|
||||
* <p>There are two types of string representations: 1) existing ofy key string handled by
|
||||
* fromWebsafeKey() and 2) string encoded via stringify() where @ separates the substrings and
|
||||
* each of the substrings contains a look up key, ":", and its corresponding value. The key info
|
||||
* is encoded via Base64. The string begins with "kind:" and it must contains at least ofy key or
|
||||
* sql key.
|
||||
*
|
||||
* <p>Example of a Vkey string by fromWebsafeKey(): "agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM"
|
||||
*
|
||||
* <p>Example of a vkey string by stringify(): "kind:TestObject@sql:rO0ABXQAA2Zvbw" +
|
||||
* "@ofy:agR0ZXN0cjELEg9FbnRpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M", where sql
|
||||
* key and ofy key values are encoded in Base64.
|
||||
*/
|
||||
public static <T> VKey<T> create(String keyString) {
|
||||
if (!keyString.startsWith(CLASS_TYPE + KV_SEPARATOR)) {
|
||||
// handle the existing ofy key string
|
||||
return fromWebsafeKey(keyString);
|
||||
} else {
|
||||
ImmutableMap<String, String> kvs =
|
||||
ImmutableMap.copyOf(
|
||||
Splitter.on(DELIMITER).withKeyValueSeparator(KV_SEPARATOR).split(keyString));
|
||||
Class classType = ClassPathManager.getClass(kvs.get(CLASS_TYPE));
|
||||
|
||||
if (kvs.containsKey(SQL_LOOKUP_KEY) && kvs.containsKey(OFY_LOOKUP_KEY)) {
|
||||
return VKey.create(
|
||||
classType,
|
||||
SerializeUtils.parse(Serializable.class, kvs.get(SQL_LOOKUP_KEY)),
|
||||
Key.create(kvs.get(OFY_LOOKUP_KEY)));
|
||||
} else if (kvs.containsKey(SQL_LOOKUP_KEY)) {
|
||||
return VKey.createSql(
|
||||
classType, SerializeUtils.parse(Serializable.class, kvs.get(SQL_LOOKUP_KEY)));
|
||||
} else if (kvs.containsKey(OFY_LOOKUP_KEY)) {
|
||||
return VKey.createOfy(classType, Key.create(kvs.get(OFY_LOOKUP_KEY)));
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("Cannot parse key string: %s", keyString));
|
||||
}
|
||||
public static <T extends EppResource> VKey<T> createEppVKeyFromString(String keyString) {
|
||||
ImmutableMap<String, String> kvs =
|
||||
ImmutableMap.copyOf(
|
||||
Splitter.on(DELIMITER).withKeyValueSeparator(KV_SEPARATOR).split(keyString));
|
||||
String classString = kvs.get(CLASS_TYPE);
|
||||
if (classString == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("\"%s\" missing from the string: %s", CLASS_TYPE, keyString));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone with an ofy key restored from {@code ancestors}.
|
||||
*
|
||||
* <p>The arguments should generally consist of pairs of Class and value, where the Class is the
|
||||
* kind of the ancestor key and the value is either a String or a Long.
|
||||
*
|
||||
* <p>For example, to restore the objectify key for
|
||||
* Domain("COM-1234")/HistoryEntry(123)/PollEvent(567), one might use:
|
||||
*
|
||||
* <pre>{@code
|
||||
* pollEvent.restoreOfy(Domain.class, "COM-1234", HistoryEntry.class, 567)
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The final key id or name is obtained from the SQL key. It is assumed that this value must be
|
||||
* either a long integer or a {@code String} and that this proper identifier for the objectify
|
||||
* key.
|
||||
*
|
||||
* <p>As a special case, an objectify Key may be used as the first ancestor instead of a Class,
|
||||
* value pair.
|
||||
*/
|
||||
public VKey<T> restoreOfy(Object... ancestors) {
|
||||
Class lastClass = null;
|
||||
Key<?> lastKey = null;
|
||||
for (Object ancestor : ancestors) {
|
||||
if (ancestor instanceof Class) {
|
||||
if (lastClass != null) {
|
||||
throw new IllegalArgumentException(ancestor + " used as a key value.");
|
||||
}
|
||||
lastClass = (Class) ancestor;
|
||||
continue;
|
||||
} else if (ancestor instanceof Key) {
|
||||
if (lastKey != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Objectify keys may only be used for the first argument");
|
||||
}
|
||||
lastKey = (Key) ancestor;
|
||||
continue;
|
||||
}
|
||||
|
||||
// The argument should be a value.
|
||||
if (lastClass == null) {
|
||||
throw new IllegalArgumentException("Argument " + ancestor + " should be a class.");
|
||||
}
|
||||
if (ancestor instanceof Long) {
|
||||
lastKey = Key.create(lastKey, lastClass, (Long) ancestor);
|
||||
} else if (ancestor instanceof String) {
|
||||
lastKey = Key.create(lastKey, lastClass, (String) ancestor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key value " + ancestor + " must be a string or long.");
|
||||
}
|
||||
lastClass = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<T> classType = (Class<T>) EPP_RESOURCE_CLASS_MAP.get(classString);
|
||||
if (classType == null) {
|
||||
throw new IllegalArgumentException(String.format("%s is not an EppResource", classString));
|
||||
}
|
||||
|
||||
// Make sure we didn't end up with a dangling class with no value.
|
||||
if (lastClass != null) {
|
||||
throw new IllegalArgumentException("Missing value for last key of type " + lastClass);
|
||||
String encodedString = kvs.get(LOOKUP_KEY);
|
||||
if (encodedString == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("\"%s\" missing from the string: %s", LOOKUP_KEY, keyString));
|
||||
}
|
||||
|
||||
Serializable sqlKey = getSqlKey();
|
||||
Key<T> ofyKey =
|
||||
sqlKey instanceof Long
|
||||
? Key.create(lastKey, getKind(), (Long) sqlKey)
|
||||
: Key.create(lastKey, getKind(), (String) sqlKey);
|
||||
|
||||
return VKey.create((Class<T>) getKind(), sqlKey, ofyKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of {@code key} with an ofy key restored from {@code ancestors}.
|
||||
*
|
||||
* <p>This is the static form of the method restoreOfy() above. If {@code key} is null, it returns
|
||||
* null.
|
||||
*/
|
||||
public static <T> VKey<T> restoreOfyFrom(@Nullable VKey<T> key, Object... ancestors) {
|
||||
return key == null ? null : key.restoreOfy(ancestors);
|
||||
return VKey.create(classType, SerializeUtils.parse(Serializable.class, kvs.get(LOOKUP_KEY)));
|
||||
}
|
||||
|
||||
/** Returns the type of the entity. */
|
||||
|
@ -251,92 +104,27 @@ public class VKey<T> extends ImmutableObject implements Serializable {
|
|||
return this.kind;
|
||||
}
|
||||
|
||||
/** Returns the SQL primary key. */
|
||||
public Serializable getSqlKey() {
|
||||
checkState(sqlKey != null, "Attempting obtain a null SQL key.");
|
||||
return this.sqlKey;
|
||||
}
|
||||
|
||||
/** Returns the SQL primary key if it exists. */
|
||||
public Optional<Object> maybeGetSqlKey() {
|
||||
return Optional.ofNullable(this.sqlKey);
|
||||
}
|
||||
|
||||
/** Returns the objectify key. */
|
||||
public Key<T> getOfyKey() {
|
||||
checkState(ofyKey != null, "Attempting obtain a null Objectify key.");
|
||||
return this.ofyKey;
|
||||
}
|
||||
|
||||
/** Returns the objectify key if it exists. */
|
||||
public Optional<Key<T>> maybeGetOfyKey() {
|
||||
return Optional.ofNullable(this.ofyKey);
|
||||
}
|
||||
|
||||
/** Convenience method to construct a VKey from an objectify Key. */
|
||||
@Nullable
|
||||
public static <T> VKey<T> from(Key<T> key) {
|
||||
return VKeyTranslatorFactory.createVKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a VKey from the string representation of an ofy key.
|
||||
*
|
||||
* <p>TODO(b/184350590): After migration, we'll want remove the ofy key dependency from this.
|
||||
*/
|
||||
@Nullable
|
||||
public static <T> VKey<T> fromWebsafeKey(String ofyKeyRepr) {
|
||||
return from(Key.create(ofyKeyRepr));
|
||||
/** Returns the primary key. */
|
||||
public Serializable getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the string representation of a {@link VKey}.
|
||||
*
|
||||
* <p>The string representation of a vkey contains its kind, and sql key or ofy key, or both. Each
|
||||
* of the keys is first serialized into a byte array then encoded via Base64 into a web safe
|
||||
* string.
|
||||
*
|
||||
* <p>The string representation of a vkey contains key values pairs separated by delimiter "@".
|
||||
* Another delimiter ":" is put in between each key and value. The following is the complete
|
||||
* format of the string: "kind:class_name@sql:encoded_sqlKey@ofy:encoded_ofyKey", where kind is
|
||||
* required. The string representation may contain an encoded ofy key, or an encoded sql key, or
|
||||
* both.
|
||||
* <p>The string representation contains its kind and Base64 SQL key, in the following format:
|
||||
* {@code kind:class_name@sql:encoded_sqlKey}.
|
||||
*/
|
||||
public String stringify() {
|
||||
// class type is required to create a vkey
|
||||
String key = CLASS_TYPE + KV_SEPARATOR + ClassPathManager.getClassName(getKind());
|
||||
if (maybeGetSqlKey().isPresent()) {
|
||||
key += DELIMITER + SQL_LOOKUP_KEY + KV_SEPARATOR + SerializeUtils.stringify(getSqlKey());
|
||||
}
|
||||
// getString() method returns a Base64 encoded web safe of ofy key
|
||||
if (maybeGetOfyKey().isPresent()) {
|
||||
key += DELIMITER + OFY_LOOKUP_KEY + KV_SEPARATOR + getOfyKey().getString();
|
||||
}
|
||||
return key;
|
||||
return Joiner.on(DELIMITER)
|
||||
.join(
|
||||
CLASS_TYPE + KV_SEPARATOR + getKind().getSimpleName(),
|
||||
LOOKUP_KEY + KV_SEPARATOR + SerializeUtils.stringify(getKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the readable string representation of a {@link VKey}.
|
||||
*
|
||||
* <p>This readable string representation of a vkey contains its kind and its sql key or ofy key,
|
||||
* or both.
|
||||
*/
|
||||
/** Constructs the readable string representation of a {@link VKey}. */
|
||||
@Override
|
||||
public String toString() {
|
||||
if (maybeGetOfyKey().isPresent() && maybeGetSqlKey().isPresent()) {
|
||||
return String.format(
|
||||
"VKey<%s>(%s:%s,%s:%s)",
|
||||
getKind().getSimpleName(), SQL_LOOKUP_KEY, sqlKey, OFY_LOOKUP_KEY, ofyKeyToString());
|
||||
} else if (maybeGetSqlKey().isPresent()) {
|
||||
return String.format("VKey<%s>(%s:%s)", getKind().getSimpleName(), SQL_LOOKUP_KEY, sqlKey);
|
||||
} else if (maybeGetOfyKey().isPresent()) {
|
||||
return String.format("VKey<%s>(%s:%s)", ofyKey.getKind(), OFY_LOOKUP_KEY, ofyKeyToString());
|
||||
} else {
|
||||
throw new IllegalStateException("VKey should contain at least one form of key");
|
||||
}
|
||||
}
|
||||
|
||||
private String ofyKeyToString() {
|
||||
return ofyKey.getName() == null ? String.valueOf(ofyKey.getId()) : ofyKey.getName();
|
||||
return String.format("VKey<%s>(%s:%s)", getKind().getSimpleName(), LOOKUP_KEY, key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ public class TransferServerApproveEntitySetConverter
|
|||
|
||||
@Override
|
||||
String toString(VKey<? extends TransferServerApproveEntity> element) {
|
||||
return String.valueOf(element.getSqlKey());
|
||||
return String.valueOf(element.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
VKey<? extends TransferServerApproveEntity> fromString(String value) {
|
||||
return VKey.createSql(TransferServerApproveEntity.class, Long.parseLong(value));
|
||||
return VKey.create(TransferServerApproveEntity.class, Long.parseLong(value));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ public abstract class VKeyConverter<T, C extends Serializable>
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
return getKeyClass().cast(attribute.getSqlKey());
|
||||
return getKeyClass().cast(attribute.getKey());
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException(
|
||||
String.format(
|
||||
"Cannot cast SQL key %s of type %s to type %s",
|
||||
attribute.getSqlKey(), attribute.getSqlKey().getClass(), getKeyClass()),
|
||||
attribute.getKey(), attribute.getKey().getClass(), getKeyClass()),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public abstract class VKeyConverter<T, C extends Serializable>
|
|||
if (dbData == null) {
|
||||
return null;
|
||||
}
|
||||
return VKey.createSql(getEntityClass(), dbData);
|
||||
return VKey.create(getEntityClass(), dbData);
|
||||
}
|
||||
|
||||
/** Returns the class of the entity that the VKey represents. */
|
||||
|
|
|
@ -284,7 +284,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
public <T> boolean exists(VKey<T> key) {
|
||||
checkArgumentNotNull(key, "key must be specified");
|
||||
EntityType<?> entityType = getEntityType(key.getKind());
|
||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey());
|
||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getKey());
|
||||
return exists(entityType.getName(), entityIds);
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
public <T> Optional<T> loadByKeyIfPresent(VKey<T> key) {
|
||||
checkArgumentNotNull(key, "key must be specified");
|
||||
assertInTransaction();
|
||||
return Optional.ofNullable(getEntityManager().find(key.getKind(), key.getSqlKey()))
|
||||
return Optional.ofNullable(getEntityManager().find(key.getKind(), key.getKey()))
|
||||
.map(this::detach);
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
.map(
|
||||
key ->
|
||||
new SimpleEntry<VKey<? extends T>, T>(
|
||||
key, detach(getEntityManager().find(key.getKind(), key.getSqlKey()))))
|
||||
key, detach(getEntityManager().find(key.getKind(), key.getKey()))))
|
||||
.filter(entry -> entry.getValue() != null)
|
||||
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
public <T> T loadByKey(VKey<T> key) {
|
||||
checkArgumentNotNull(key, "key must be specified");
|
||||
assertInTransaction();
|
||||
T result = getEntityManager().find(key.getKind(), key.getSqlKey());
|
||||
T result = getEntityManager().find(key.getKind(), key.getKey());
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException(key.toString());
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
T returnValue =
|
||||
(T)
|
||||
loadByKey(
|
||||
VKey.createSql(
|
||||
VKey.create(
|
||||
entity.getClass(),
|
||||
// Casting to Serializable is safe according to JPA (JSR 338 sec. 2.4).
|
||||
(Serializable) emf.getPersistenceUnitUtil().getIdentifier(entity)));
|
||||
|
@ -418,7 +418,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
checkArgumentNotNull(key, "key must be specified");
|
||||
assertInTransaction();
|
||||
EntityType<?> entityType = getEntityType(key.getKind());
|
||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey());
|
||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getKey());
|
||||
String sql =
|
||||
String.format("DELETE FROM %s WHERE %s", entityType.getName(), getAndClause(entityIds));
|
||||
Query query = query(sql);
|
||||
|
@ -460,7 +460,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
public <T> void assertDelete(VKey<T> key) {
|
||||
if (internalDelete(key) != 1) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Error deleting the entity of the key: %s", key.getSqlKey()));
|
||||
String.format("Error deleting the entity of the key: %s", key.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
if (desiredRegistrar.isPresent()) {
|
||||
builder =
|
||||
builder.where(
|
||||
"currentSponsorClientId",
|
||||
"currentSponsorRegistrarId",
|
||||
replicaJpaTm().getEntityManager().getCriteriaBuilder()::equal,
|
||||
desiredRegistrar.get());
|
||||
}
|
||||
|
@ -437,22 +437,22 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
queryBuilder.append(" AND h.current_sponsor_registrar_id = :desiredRegistrar");
|
||||
parameters.put("desiredRegistrar", desiredRegistrar.get());
|
||||
}
|
||||
hostKeys =
|
||||
replicaJpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
javax.persistence.Query query =
|
||||
replicaJpaTm()
|
||||
.getEntityManager()
|
||||
.createNativeQuery(queryBuilder.toString())
|
||||
.setMaxResults(maxNameserversInFirstStage);
|
||||
parameters.build().forEach(query::setParameter);
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<String> resultStream = query.getResultStream();
|
||||
return resultStream
|
||||
.map(repoId -> VKey.create(Host.class, repoId))
|
||||
.collect(toImmutableSet());
|
||||
});
|
||||
hostKeys =
|
||||
replicaJpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
javax.persistence.Query query =
|
||||
replicaJpaTm()
|
||||
.getEntityManager()
|
||||
.createNativeQuery(queryBuilder.toString())
|
||||
.setMaxResults(maxNameserversInFirstStage);
|
||||
parameters.build().forEach(query::setParameter);
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<String> resultStream = query.getResultStream();
|
||||
return resultStream
|
||||
.map(repoId -> VKey.create(Host.class, repoId))
|
||||
.collect(toImmutableSet());
|
||||
});
|
||||
return searchByNameserverRefs(hostKeys);
|
||||
}
|
||||
|
||||
|
|
|
@ -273,7 +273,7 @@ public class RdapEntitySearchAction extends RdapSearchActionBase {
|
|||
if (!rdapAuthorization.role().equals(Role.ADMINISTRATOR)) {
|
||||
builder =
|
||||
builder.whereFieldIsIn(
|
||||
"currentSponsorClientId", rdapAuthorization.registrarIds());
|
||||
"currentSponsorRegistrarId", rdapAuthorization.registrarIds());
|
||||
}
|
||||
return getMatchingResources(builder, false, rdapResultSetMaxSize + 1);
|
||||
});
|
||||
|
|
|
@ -905,7 +905,7 @@ public class RdapJsonFormatter {
|
|||
String jpql =
|
||||
GET_LAST_HISTORY_BY_TYPE_JPQL_TEMPLATE
|
||||
.replace("%entityName%", entityName)
|
||||
.replace("%repoIdValue%", resourceVkey.getSqlKey().toString());
|
||||
.replace("%repoIdValue%", resourceVkey.getKey().toString());
|
||||
Iterable<HistoryEntry> historyEntries =
|
||||
replicaJpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -163,7 +163,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase {
|
|||
if (desiredRegistrar.isPresent()) {
|
||||
builder =
|
||||
builder.where(
|
||||
"currentSponsorClientId",
|
||||
"currentSponsorRegistrarId",
|
||||
replicaJpaTm().getEntityManager().getCriteriaBuilder()::equal,
|
||||
desiredRegistrar.get());
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
|
|||
/** Returns the allocation token object. */
|
||||
AllocationToken getAndCheckAllocationToken(String token) {
|
||||
Optional<AllocationToken> allocationToken =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
|
||||
checkArgument(
|
||||
allocationToken.isPresent(),
|
||||
"An allocation token with the token String %s does not exist. The package token must be"
|
||||
|
|
|
@ -87,8 +87,7 @@ final class DeleteAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
|
|||
System.out.printf(
|
||||
"%s tokens: %s\n",
|
||||
dryRun ? "Would delete" : "Deleted",
|
||||
JOINER.join(
|
||||
tokensToDelete.stream().map(VKey::getSqlKey).sorted().collect(toImmutableList())));
|
||||
JOINER.join(tokensToDelete.stream().map(VKey::getKey).sorted().collect(toImmutableList())));
|
||||
return tokensToDelete.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi {
|
|||
private ImmutableSet<String> getExistingTokenStrings(ImmutableSet<String> candidates) {
|
||||
ImmutableSet<VKey<AllocationToken>> existingTokenKeys =
|
||||
candidates.stream()
|
||||
.map(input -> VKey.createSql(AllocationToken.class, input))
|
||||
.map(input -> VKey.create(AllocationToken.class, input))
|
||||
.collect(toImmutableSet());
|
||||
return tm().transact(
|
||||
() ->
|
||||
|
|
|
@ -47,12 +47,12 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
|||
for (List<String> tokens : Lists.partition(mainParameters, BATCH_SIZE)) {
|
||||
ImmutableList<VKey<AllocationToken>> tokenKeys =
|
||||
tokens.stream()
|
||||
.map(t -> VKey.createSql(AllocationToken.class, t))
|
||||
.map(t -> VKey.create(AllocationToken.class, t))
|
||||
.collect(toImmutableList());
|
||||
tm().transact(
|
||||
() ->
|
||||
tm().loadByKeysIfPresent(tokenKeys)
|
||||
.forEach((k, v) -> builder.put(k.getSqlKey().toString(), v)));
|
||||
.forEach((k, v) -> builder.put(k.getKey().toString(), v)));
|
||||
}
|
||||
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
||||
ImmutableMap<VKey<Domain>, Domain> domains =
|
||||
|
@ -66,7 +66,7 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
|||
System.out.printf("Token %s was not redeemed.\n", token);
|
||||
} else {
|
||||
VKey<Domain> domainKey =
|
||||
VKey.createSql(Domain.class, loadedToken.getRedemptionHistoryId().get().getRepoId());
|
||||
VKey.create(Domain.class, loadedToken.getRedemptionHistoryId().get().getRepoId());
|
||||
Domain domain = domains.get(domainKey);
|
||||
if (domain == null) {
|
||||
System.out.printf("ERROR: Token %s was redeemed but domain can't be loaded.\n", token);
|
||||
|
@ -91,8 +91,8 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
|||
.map(AllocationToken::getRedemptionHistoryId)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(hi -> tm().loadByKey(VKey.createSql(DomainHistory.class, hi)))
|
||||
.map(dh -> VKey.createSql(Domain.class, dh.getRepoId()))
|
||||
.map(hi -> tm().loadByKey(VKey.create(DomainHistory.class, hi)))
|
||||
.map(dh -> VKey.create(Domain.class, dh.getRepoId()))
|
||||
.collect(toImmutableList());
|
||||
ImmutableMap.Builder<VKey<Domain>, Domain> domainsBuilder = new ImmutableMap.Builder<>();
|
||||
for (List<VKey<Domain>> keys : Lists.partition(domainKeys, BATCH_SIZE)) {
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.model.SchemaVersion;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
/** Generates the schema file used for model versioning. */
|
||||
@DeleteAfterMigration
|
||||
@Parameters(commandDescription = "Generate a model schema file")
|
||||
final class GetSchemaCommand implements Command {
|
||||
|
||||
@Parameter(
|
||||
names = {"-o", "--out_file"},
|
||||
description = "Name of the output file.")
|
||||
String outFile;
|
||||
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
String schema = SchemaVersion.getSchema();
|
||||
if (outFile == null) {
|
||||
System.out.println(schema);
|
||||
} else {
|
||||
File file = new File(outFile);
|
||||
file.createNewFile(); // Create the output file if it doesn't already exist.
|
||||
Files.write(file.toPath(), schema.getBytes(UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,7 +89,7 @@ public abstract class MutatingCommand extends ConfirmingCommand implements Comma
|
|||
|
||||
/** Returns a human-readable ID string for the entity being changed. */
|
||||
String getEntityId() {
|
||||
return String.format("%s@%s", vKey.getKind().getSimpleName(), vKey.getSqlKey().toString());
|
||||
return String.format("%s@%s", vKey.getKind().getSimpleName(), vKey.getKey().toString());
|
||||
}
|
||||
|
||||
/** Returns a string representation of this entity change. */
|
||||
|
|
|
@ -78,7 +78,6 @@ public final class RegistryTool {
|
|||
.put("get_registrar", GetRegistrarCommand.class)
|
||||
.put("get_reserved_list", GetReservedListCommand.class)
|
||||
.put("get_routing_map", GetRoutingMapCommand.class)
|
||||
.put("get_schema", GetSchemaCommand.class)
|
||||
.put("get_sql_credential", GetSqlCredentialCommand.class)
|
||||
.put("get_tld", GetTldCommand.class)
|
||||
.put("ghostryde", GhostrydeCommand.class)
|
||||
|
|
|
@ -55,7 +55,7 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand
|
|||
if (tokens != null) {
|
||||
ImmutableSet<VKey<AllocationToken>> keys =
|
||||
tokens.stream()
|
||||
.map(token -> VKey.createSql(AllocationToken.class, token))
|
||||
.map(token -> VKey.create(AllocationToken.class, token))
|
||||
.collect(toImmutableSet());
|
||||
ImmutableSet<VKey<AllocationToken>> nonexistentKeys =
|
||||
tm().transact(
|
||||
|
|
|
@ -56,7 +56,7 @@ public class CreateCancellationsForOneTimesCommand extends ConfirmingCommand
|
|||
tm().transact(
|
||||
() -> {
|
||||
for (Long billingEventId : ImmutableSet.copyOf(mainParameters)) {
|
||||
VKey<OneTime> key = VKey.createSql(OneTime.class, billingEventId);
|
||||
VKey<OneTime> key = VKey.create(OneTime.class, billingEventId);
|
||||
if (tm().exists(key)) {
|
||||
OneTime oneTime = tm().loadByKey(key);
|
||||
if (alreadyCancelled(oneTime)) {
|
||||
|
|
|
@ -138,7 +138,7 @@ public class CreateSyntheticDomainHistoriesCommand extends ConfirmingCommand
|
|||
.transact(
|
||||
() -> {
|
||||
Domain domain =
|
||||
jpaTm().loadByKey(VKey.createSql(Domain.class, domainRepoId));
|
||||
jpaTm().loadByKey(VKey.create(Domain.class, domainRepoId));
|
||||
jpaTm()
|
||||
.put(
|
||||
HistoryEntry.createBuilderForResource(domain)
|
||||
|
|
|
@ -112,7 +112,7 @@ public class RegistryJpaReadTest {
|
|||
Read<Object[], String> read =
|
||||
RegistryJpaIO.read(
|
||||
"select d, r.emailAddress from Domain d join Registrar r on"
|
||||
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
|
||||
+ " d.currentSponsorRegistrarId = r.registrarId where r.type = :type"
|
||||
+ " and d.deletionTime > now()",
|
||||
ImmutableMap.of("type", Registrar.Type.REAL),
|
||||
false,
|
||||
|
@ -156,7 +156,7 @@ public class RegistryJpaReadTest {
|
|||
Read<Domain, String> read =
|
||||
RegistryJpaIO.read(
|
||||
"select d from Domain d join Registrar r on"
|
||||
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
|
||||
+ " d.currentSponsorRegistrarId = r.registrarId where r.type = :type"
|
||||
+ " and d.deletionTime > now()",
|
||||
ImmutableMap.of("type", Registrar.Type.REAL),
|
||||
Domain.class,
|
||||
|
|
|
@ -561,7 +561,7 @@ public class RdePipelineTest {
|
|||
return tm().transact(
|
||||
() ->
|
||||
tm().loadByKey(
|
||||
VKey.createSql(
|
||||
VKey.create(
|
||||
RdeRevision.class,
|
||||
RdeRevisionId.create("soy", now.toLocalDate(), mode)))
|
||||
.getRevision());
|
||||
|
|
|
@ -1353,7 +1353,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
|
||||
private void assertAllocationTokenWasRedeemed(String token) throws Exception {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isTrue();
|
||||
assertThat(reloadedToken.getRedemptionHistoryId())
|
||||
.hasValue(getHistoryEntries(reloadResourceByForeignKey()).get(0).getHistoryEntryId());
|
||||
|
@ -1361,7 +1361,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
|
||||
private void assertAllocationTokenWasNotRedeemed(String token) {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
@ -382,7 +382,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
|||
Domain domainAtRedemptionTime = domain.cloneProjectedAtTime(redemptionEndTime);
|
||||
assertAboutDomains()
|
||||
.that(domainAtRedemptionTime)
|
||||
.hasLastEppUpdateClientId("TheRegistrar")
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar")
|
||||
.and()
|
||||
.hasLastEppUpdateTime(redemptionEndTime);
|
||||
}
|
||||
|
@ -930,7 +930,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertAboutHistoryEntries()
|
||||
.that(getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE))
|
||||
.hasType(DOMAIN_DELETE)
|
||||
|
|
|
@ -267,7 +267,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId(renewalClientId);
|
||||
.hasLastEppUpdateRegistrarId(renewalClientId);
|
||||
assertAboutHistoryEntries().that(historyEntryDomainRenew).hasPeriodYears(renewalYears);
|
||||
BillingEvent.OneTime renewBillingEvent =
|
||||
new BillingEvent.OneTime.Builder()
|
||||
|
@ -332,7 +332,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
|
|||
@Test
|
||||
private void assertAllocationTokenWasNotRedeemed(String token) {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
|
@ -255,7 +255,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
|
|
|
@ -138,7 +138,7 @@ class DomainTransferApproveFlowTest
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
// The domain TransferData should reflect the approved transfer as we expect, with
|
||||
// all the speculative server-approve fields nulled out.
|
||||
assertThat(domain.getTransferData())
|
||||
|
|
|
@ -138,7 +138,7 @@ class DomainTransferCancelFlowTest
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
final HistoryEntry historyEntryTransferCancel =
|
||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL);
|
||||
assertAboutHistoryEntries()
|
||||
|
|
|
@ -108,7 +108,7 @@ class DomainTransferRejectFlowTest
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
final HistoryEntry historyEntryTransferRejected =
|
||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REJECT);
|
||||
assertAboutHistoryEntries()
|
||||
|
|
|
@ -192,7 +192,7 @@ class DomainTransferRequestFlowTest
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
Trid expectedTrid =
|
||||
Trid.create(
|
||||
getClientTrid(),
|
||||
|
@ -449,7 +449,7 @@ class DomainTransferRequestFlowTest
|
|||
.and()
|
||||
.hasLastEppUpdateTime(implicitTransferTime)
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
assertThat(loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
|
||||
.isEqualTo(expectedExpirationTime);
|
||||
// And after the expected grace time, the grace period should be gone.
|
||||
|
|
|
@ -56,7 +56,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.EppException.UnimplementedExtensionException;
|
||||
|
@ -90,6 +89,7 @@ import google.registry.flows.domain.DomainFlowUtils.UrgentAttributeNotSupportedE
|
|||
import google.registry.flows.exceptions.OnlyToolCanPassMetadataException;
|
||||
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
||||
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.contact.Contact;
|
||||
|
@ -214,7 +214,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar")
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar")
|
||||
.and()
|
||||
.hasNoAutorenewEndTime();
|
||||
assertNoBillingEvents();
|
||||
|
@ -1656,7 +1656,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
runFlow();
|
||||
assertThat(reloadResourceByForeignKey().getNameservers())
|
||||
.doesNotContain(
|
||||
Key.create(loadByForeignKey(Host.class, "ns1.example.foo", clock.nowUtc()).get()));
|
||||
loadByForeignKey(Host.class, "ns1.example.foo", clock.nowUtc())
|
||||
.map(ImmutableObject::createVKey)
|
||||
.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.truth.StreamSubject.streams;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.EntityClasses.ALL_CLASSES;
|
||||
import static google.registry.util.TypeUtils.hasAnnotation;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link EntityClasses}. */
|
||||
class EntityClassesTest {
|
||||
|
||||
// This implements the manual ordering we've been using for the EntityClasses class lists.
|
||||
private static final Ordering<Class<?>> QUALIFIED_CLASS_NAME_ORDERING =
|
||||
Ordering.natural()
|
||||
.onResultOf(
|
||||
clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length()));
|
||||
|
||||
@Test
|
||||
void testEntityClasses_inAlphabeticalOrder() {
|
||||
assertThat(ALL_CLASSES).isInStrictOrder(QUALIFIED_CLASS_NAME_ORDERING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_baseEntitiesHaveUniqueKinds() {
|
||||
assertWithMessage("base entity kinds")
|
||||
.about(streams())
|
||||
.that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
|
||||
.containsNoDuplicates();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() {
|
||||
Set<String> baseEntityKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.map(Key::getKind)
|
||||
.collect(toImmutableSet());
|
||||
Set<String> entitySubclassKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(EntitySubclass.class))
|
||||
.map(Key::getKind)
|
||||
.collect(toImmutableSet());
|
||||
assertWithMessage("base entity kinds")
|
||||
.that(baseEntityKinds)
|
||||
.containsAtLeastElementsIn(entitySubclassKinds);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_eitherBaseEntityOrEntitySubclass() {
|
||||
for (Class<?> clazz : ALL_CLASSES) {
|
||||
boolean isEntityXorEntitySubclass =
|
||||
clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class);
|
||||
assertWithMessage("class " + clazz.getSimpleName() + " is @Entity or @EntitySubclass")
|
||||
.that(isEntityXorEntitySubclass)
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.GoldenFileTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SchemaVersion}.
|
||||
*
|
||||
* <p>If the test breaks, the instructions below will be printed.
|
||||
*/
|
||||
@DeleteAfterMigration
|
||||
public class SchemaVersionTest {
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine = AppEngineExtension.builder().withCloudSql().build();
|
||||
|
||||
@Test
|
||||
void testGoldenSchemaFile() {
|
||||
GoldenFileTestHelper.assertThat(SchemaVersion.getSchema())
|
||||
.describedAs("Datastore schema")
|
||||
.createdByNomulusCommand("get_schema")
|
||||
.isEqualToGolden(SchemaVersionTest.class, "schema.txt");
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ public class UpdateAutoTimestampTest {
|
|||
|
||||
private static UpdateAutoTimestampTestObject reload() {
|
||||
return tm().transact(
|
||||
() -> tm().loadByKey(VKey.createSql(UpdateAutoTimestampTestObject.class, 1L)));
|
||||
() -> tm().loadByKey(VKey.create(UpdateAutoTimestampTestObject.class, 1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.domain.DomainHistory;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link ClassPathManager}. */
|
||||
public class ClassPathManagerTest {
|
||||
@Test
|
||||
void getClass_classInClassRegistry_returnsClass() throws ClassNotFoundException {
|
||||
/*
|
||||
* Class names are used in stringified vkeys, which can be present in task queues. Class name is
|
||||
* required to create a vkey. Changing these names could break task queue entries that are
|
||||
* present during a rollout. If you want to change the names of any of the classses supported in
|
||||
* CLASS_REGISTRY, you'll need to introduce some mechanism to deal with this. One way is to find
|
||||
* the corresponding class name by calling ClassPathManager.getClassName(clazz). The classes
|
||||
* below are all classes supported in CLASS_REGISTRY. This test breaks if someone changes a
|
||||
* classname without preserving the original name.
|
||||
*/
|
||||
assertThat(ClassPathManager.getClass("Host")).isEqualTo(Host.class);
|
||||
assertThat(ClassPathManager.getClass("Contact")).isEqualTo(Contact.class);
|
||||
assertThat(ClassPathManager.getClass("GaeUserIdConverter")).isEqualTo(GaeUserIdConverter.class);
|
||||
assertThat(ClassPathManager.getClass("Domain")).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClass_classNotInClassRegistry_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> ClassPathManager.getClass("DomainHistory"));
|
||||
assertThat(thrown).hasMessageThat().contains("Class DomainHistory not found in class registry");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassName_classNotInClassRegistry_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ClassPathManager.getClassName(DomainHistory.class));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Class DomainHistory not found in class name registry");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassName() {
|
||||
/*
|
||||
* Class names are used in stringified vkeys, which can be present in task queues. Class name is
|
||||
* required to create a vkey. Changing these names could break task queue entries that are
|
||||
* present during a rollout. If you want to change the names of any of the classses supported in
|
||||
* CLASS_NAME_REGISTRY, you'll need to introduce some mechanism to deal with this.
|
||||
* ClassPathManager.getClassName(clazz) allows you to verify the corresponding name of a class.
|
||||
* The classes below are all classes supported in CLASS_NAME_REGISTRY. This test breaks if
|
||||
* someone changes a classname without preserving the original name.
|
||||
*/
|
||||
assertThat(ClassPathManager.getClassName(Host.class)).isEqualTo("Host");
|
||||
assertThat(ClassPathManager.getClassName(Contact.class)).isEqualTo("Contact");
|
||||
assertThat(ClassPathManager.getClassName(GaeUserIdConverter.class))
|
||||
.isEqualTo("GaeUserIdConverter");
|
||||
assertThat(ClassPathManager.getClassName(Domain.class)).isEqualTo("Domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
void addTestEntityClass_success() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
assertThat(ClassPathManager.getClass("TestObject")).isEqualTo(TestObject.class);
|
||||
}
|
||||
}
|
|
@ -401,7 +401,7 @@ public class DomainSqlTest {
|
|||
}
|
||||
|
||||
private <T> VKey<T> createKey(Class<T> clazz, String key) {
|
||||
return VKey.createSql(clazz, key);
|
||||
return VKey.create(clazz, key);
|
||||
}
|
||||
|
||||
private void assertEqualDomainExcept(Domain thatDomain, String... excepts) {
|
||||
|
|
|
@ -166,8 +166,8 @@ public class DomainTest {
|
|||
.build();
|
||||
insertInDb(historyEntry, oneTimeBill, recurringBill);
|
||||
recurringBillKey = recurringBill.createVKey();
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey = VKey.createSql(PollMessage.Autorenew.class, 3L);
|
||||
VKey<PollMessage.OneTime> onetimePollKey = VKey.createSql(PollMessage.OneTime.class, 1L);
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey = VKey.create(PollMessage.Autorenew.class, 3L);
|
||||
VKey<PollMessage.OneTime> onetimePollKey = VKey.create(PollMessage.OneTime.class, 1L);
|
||||
// Set up a new persisted domain entity.
|
||||
domain =
|
||||
persistResource(
|
||||
|
@ -524,7 +524,7 @@ public class DomainTest {
|
|||
assertThat(beforeAutoRenew.getLastEppUpdateRegistrarId()).isEqualTo("TheRegistrar");
|
||||
|
||||
// If autorenew happens before transfer succeeds(before transfer grace period starts as well),
|
||||
// lastEppUpdateClientId should still be the current sponsor client id
|
||||
// lastEppUpdateRegistrarId should still be the current sponsor client id
|
||||
Domain afterAutoRenew = domain.cloneProjectedAtTime(autorenewDateTime.plusDays(1));
|
||||
assertThat(afterAutoRenew.getLastEppUpdateTime()).isEqualTo(autorenewDateTime);
|
||||
assertThat(afterAutoRenew.getLastEppUpdateRegistrarId()).isEqualTo("NewRegistrar");
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.model.ofy;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.initOfy;
|
||||
import static google.registry.testing.DatabaseHelper.newContact;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
|
||||
|
@ -27,7 +26,7 @@ import com.googlecode.objectify.ObjectifyFilter;
|
|||
import com.googlecode.objectify.ObjectifyService;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.common.GaeUserIdConverter;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -81,8 +80,9 @@ class OfyFilterTest {
|
|||
@Test
|
||||
void testKeyCreateAfterFilter() {
|
||||
new OfyFilter().init(null);
|
||||
Contact contact = newContact("contact1234");
|
||||
Key.create(contact);
|
||||
GaeUserIdConverter userIdConverter = new GaeUserIdConverter();
|
||||
userIdConverter.id = 1;
|
||||
Key.create(userIdConverter);
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -140,6 +140,6 @@ public class PollMessageExternalKeyConverterTest {
|
|||
one.getKind().isAssignableFrom(two.getKind())
|
||||
|| two.getKind().isAssignableFrom(one.getKind()))
|
||||
.isTrue();
|
||||
assertThat(one.getSqlKey()).isEqualTo(two.getSqlKey());
|
||||
assertThat(one.getKey()).isEqualTo(two.getKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,13 +91,12 @@ public class PollMessageTest extends EntityTestCase {
|
|||
@Test
|
||||
void testCloudSqlSupportForPolymorphicVKey() {
|
||||
insertInDb(oneTime);
|
||||
PollMessage persistedOneTime = loadByKey(VKey.createSql(PollMessage.class, oneTime.getId()));
|
||||
PollMessage persistedOneTime = loadByKey(VKey.create(PollMessage.class, oneTime.getId()));
|
||||
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
|
||||
assertThat(persistedOneTime).isEqualTo(oneTime);
|
||||
|
||||
insertInDb(autoRenew);
|
||||
PollMessage persistedAutoRenew =
|
||||
loadByKey(VKey.createSql(PollMessage.class, autoRenew.getId()));
|
||||
PollMessage persistedAutoRenew = loadByKey(VKey.create(PollMessage.class, autoRenew.getId()));
|
||||
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
|
||||
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ public final class Spec11ThreatMatchTest extends EntityTestCase {
|
|||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
VKey<Host> hostVKey = VKey.createSql(Host.class, "host");
|
||||
VKey<Contact> registrantContactVKey = VKey.createSql(Contact.class, "contact_id");
|
||||
VKey<Host> hostVKey = VKey.create(Host.class, "host");
|
||||
VKey<Contact> registrantContactVKey = VKey.create(Contact.class, "contact_id");
|
||||
String domainRepoId = "4-TLD";
|
||||
createTld("tld");
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ public class TransferDataTest {
|
|||
transferBillingEventKey = OneTime.createVKey(12345L);
|
||||
otherServerApproveBillingEventKey = Cancellation.createVKey(2468L);
|
||||
recurringBillingEventKey = Recurring.createVKey(13579L);
|
||||
autorenewPollMessageKey = VKey.createSql(PollMessage.Autorenew.class, 67890L);
|
||||
otherServerApprovePollMessageKey = VKey.createSql(PollMessage.OneTime.class, 314159L);
|
||||
autorenewPollMessageKey = VKey.create(PollMessage.Autorenew.class, 67890L);
|
||||
otherServerApprovePollMessageKey = VKey.create(PollMessage.OneTime.class, 314159L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -51,9 +51,9 @@ public class StatusValueAdapterTest {
|
|||
new EppResponse.Builder()
|
||||
.setResData(
|
||||
HostInfoData.newBuilder()
|
||||
.setCreationClientId("")
|
||||
.setCreationRegistrarId("")
|
||||
.setCreationTime(START_OF_TIME)
|
||||
.setCurrentSponsorClientId("")
|
||||
.setCurrentSponsorRegistrarId("")
|
||||
.setHostName("")
|
||||
.setInetAddresses(ImmutableSet.of())
|
||||
.setRepoId("")
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.translators;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatabaseHelper.newDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link VKeyTranslatorFactory}. */
|
||||
public class VKeyTranslatorFactoryTest {
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine =
|
||||
AppEngineExtension.builder().withCloudSql().withOfyTestEntities(TestObject.class).build();
|
||||
|
||||
VKeyTranslatorFactoryTest() {}
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityWithFlatKey() {
|
||||
// Creating an objectify key instead of a datastore key as this should get a correctly formatted
|
||||
// key path.
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKeyTranslatorFactory.createVKey(key);
|
||||
assertThat(vkey.getKind()).isEqualTo(Domain.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(key);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtraEntityClass() {
|
||||
TestObject testObject = TestObject.create("id", "field");
|
||||
Key<TestObject> key = Key.create(testObject);
|
||||
assertThat(VKeyTranslatorFactory.createVKey(key).getSqlKey()).isEqualTo("id");
|
||||
}
|
||||
}
|
|
@ -68,14 +68,14 @@ class EntityCallbacksListenerTest {
|
|||
checkAll(updated, 0, 1, 0, 1);
|
||||
|
||||
TestEntity testLoad =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
checkAll(testLoad, 0, 0, 0, 1);
|
||||
|
||||
TestEntity testRemove =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.create(TestEntity.class, "id"));
|
||||
return jpaTm().delete(removed);
|
||||
});
|
||||
checkAll(testRemove, 0, 0, 1, 1);
|
||||
|
@ -105,10 +105,10 @@ class EntityCallbacksListenerTest {
|
|||
insertInDb(new TestEntity());
|
||||
|
||||
TestEntity testLoad =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
assertThat(testLoad.entityPreUpdate).isEqualTo(0);
|
||||
|
||||
testLoad = jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
testLoad = jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
|
||||
// Verify that post-load happened but pre-update didn't.
|
||||
assertThat(testLoad.entityPostLoad).isEqualTo(1);
|
||||
|
|
|
@ -14,21 +14,12 @@
|
|||
package google.registry.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.DatabaseHelper.newDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import google.registry.model.billing.BillingEvent.OneTime;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.registrar.RegistrarPoc;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
|
@ -36,303 +27,80 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||
class VKeyTest {
|
||||
|
||||
@RegisterExtension
|
||||
final AppEngineExtension appEngineExtension =
|
||||
AppEngineExtension.builder().withCloudSql().withOfyTestEntities(TestObject.class).build();
|
||||
final JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
@Test
|
||||
void testSuccess_createWithLongKey() {
|
||||
VKey<PollMessage> key = VKey.create(PollMessage.class, 5L);
|
||||
assertThat(key.getKey()).isEqualTo(5L);
|
||||
assertThat(key.getKind()).isEqualTo(PollMessage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOptionalAccessors() {
|
||||
VKey<TestObject> key =
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo")));
|
||||
assertThat(key.maybeGetSqlKey().isPresent()).isTrue();
|
||||
assertThat(key.maybeGetOfyKey().isPresent()).isTrue();
|
||||
assertThat(VKey.createSql(TestObject.class, "foo").maybeGetSqlKey()).hasValue("foo");
|
||||
void testSuccess_createWithStringKey() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
assertThat(key.getKey()).isEqualTo("blah");
|
||||
assertThat(key.getKind()).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateById_failsWhenParentIsNullButShouldntBe() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> VKey.create(OneTime.class, 134L));
|
||||
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateByName_failsWhenParentIsNullButShouldntBe() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.create(RegistrarPoc.class, "fake@example.com"));
|
||||
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRestoreOfy() {
|
||||
assertThat(VKey.restoreOfyFrom(null, TestObject.class, 100)).isNull();
|
||||
|
||||
VKey<TestObject> key = VKey.createSql(TestObject.class, "foo");
|
||||
VKey<TestObject> restored = key.restoreOfy(TestObject.class, "bar");
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(Key.create(Key.create(TestObject.class, "bar"), TestObject.class, "foo"));
|
||||
assertThat(restored.getSqlKey()).isEqualTo("foo");
|
||||
|
||||
assertThat(VKey.restoreOfyFrom(key).getOfyKey()).isEqualTo(Key.create(TestObject.class, "foo"));
|
||||
|
||||
restored = key.restoreOfy(OtherObject.class, "baz", TestObject.class, "bar");
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(
|
||||
Key.create(
|
||||
Key.create(Key.create(OtherObject.class, "baz"), TestObject.class, "bar"),
|
||||
TestObject.class,
|
||||
"foo"));
|
||||
|
||||
// Verify that we can use a key as the first argument.
|
||||
restored = key.restoreOfy(Key.create(TestObject.class, "bar"));
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(Key.create(Key.create(TestObject.class, "bar"), TestObject.class, "foo"));
|
||||
|
||||
// Verify that we get an exception when a key is not the first argument.
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> key.restoreOfy(TestObject.class, "foo", Key.create(TestObject.class, "bar")));
|
||||
assertThat(thrown)
|
||||
void testFailure_missingArguments() {
|
||||
assertThat(assertThrows(IllegalArgumentException.class, () -> VKey.create(null, "blah")))
|
||||
.hasMessageThat()
|
||||
.contains("Objectify keys may only be used for the first argument");
|
||||
|
||||
// Verify other exception cases.
|
||||
thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> key.restoreOfy(TestObject.class, TestObject.class));
|
||||
assertThat(thrown)
|
||||
.isEqualTo("kind must not be null");
|
||||
assertThat(assertThrows(IllegalArgumentException.class, () -> VKey.create(Domain.class, null)))
|
||||
.hasMessageThat()
|
||||
.contains("class google.registry.testing.TestObject used as a key value.");
|
||||
.isEqualTo("key must not be null");
|
||||
}
|
||||
|
||||
thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> key.restoreOfy(TestObject.class, 1.5));
|
||||
assertThat(thrown).hasMessageThat().contains("Key value 1.5 must be a string or long.");
|
||||
@Test
|
||||
void testSuccess_createFromString() {
|
||||
VKey<Domain> key = VKey.createEppVKeyFromString("kind:Domain@sql:rO0ABXQABGJsYWg");
|
||||
assertThat(key.getKey()).isEqualTo("blah");
|
||||
assertThat(key.getKind()).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
thrown = assertThrows(IllegalArgumentException.class, () -> key.restoreOfy(TestObject.class));
|
||||
assertThat(thrown)
|
||||
@Test
|
||||
void testFailure_createFromString_missingKind() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.createEppVKeyFromString("sql:rO0ABXQABGJsYWg")))
|
||||
.hasMessageThat()
|
||||
.contains("Missing value for last key of type class google.registry.testing.TestObject");
|
||||
.isEqualTo("\"kind\" missing from the string: sql:rO0ABXQABGJsYWg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromWebsafeKey() {
|
||||
// Creating an objectify key instead of a datastore key as this should get a correctly formatted
|
||||
// key path. We have to one of our actual model object classes for this, TestObject can not be
|
||||
// reconstructed by the VKeyTranslatorFactory.
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKey.fromWebsafeKey(key.getString());
|
||||
assertThat(vkey.getKind()).isEqualTo(Domain.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(key);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
|
||||
}
|
||||
|
||||
/** Test stringify() with vkey created via different ways. */
|
||||
@Test
|
||||
void testStringify_sqlOnlyVKey() {
|
||||
assertThat(VKey.createSql(TestObject.class, "foo").stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQAA2Zvbw");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_ofyOnlyVKey() {
|
||||
assertThat(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")).stringify())
|
||||
.isEqualTo("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_vkeyFromWebsafeKey() {
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKey.fromWebsafeKey(key.getString());
|
||||
assertThat(vkey.stringify())
|
||||
.isEqualTo(
|
||||
"kind:Domain" + "@sql:rO0ABXQABlJPSUQtMQ" + "@ofy:agR0ZXN0chILEgZEb21haW4iBlJPSUQtMQw");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_sqlAndOfyVKey() {
|
||||
void testFailure_createFromString_missingKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_asymmetricVKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
/** Test create() via different vkey string representations. */
|
||||
@Test
|
||||
void testCreate_stringifedVKey_sqlOnlyVKeyString() {
|
||||
assertThat(VKey.create("kind:TestObject@sql:rO0ABXQAA2Zvbw"))
|
||||
.isEqualTo(VKey.createSql(TestObject.class, "foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifiedVKey_resourceKeyFromTaskQueue() throws Exception {
|
||||
VKey<Host> vkeyFromNewWebsafeKey =
|
||||
VKey.create(
|
||||
"kind:Host@sql:rO0ABXQADzZCQjJGNDc2LUdPT0dMRQ@ofy:ahdzfm"
|
||||
+ "RvbWFpbi1yZWdpc3RyeS1hbHBoYXIhCxIMSG9zdFJlc291cmNlIg82QkIyRjQ3Ni1HT09HTEUM");
|
||||
|
||||
assertThat(vkeyFromNewWebsafeKey.getSqlKey()).isEqualTo("6BB2F476-GOOGLE");
|
||||
assertThat(vkeyFromNewWebsafeKey.getOfyKey().getString())
|
||||
.isEqualTo(
|
||||
"ahdzfmRvbWFpbi1yZWdpc3RyeS1hbHBoYXIhCxIMSG9zdFJlc291cmNlIg82QkIyRjQ3Ni1HT09HTEUM");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_ofyOnlyVKeyString() {
|
||||
assertThat(VKey.create("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_asymmetricVKeyString() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9Fb"
|
||||
+ "nRpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_sqlAndOfyVKeyString() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9Fbn"
|
||||
+ "RpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifyVkey_fromWebsafeKey() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:Domain@sql:rO0ABXQABlJPSUQtMQ"
|
||||
+ "@ofy:agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM"))
|
||||
.isEqualTo(
|
||||
VKey.fromWebsafeKey(
|
||||
Key.create(newDomain("example.com", "ROID-1", persistActiveContact("contact-1")))
|
||||
.getString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_websafeKey() {
|
||||
assertThat(VKey.create("agR0ZXN0chkLEgZEb21haW4iDUdBU0RHSDQyMkQtSUQM"))
|
||||
.isEqualTo(VKey.fromWebsafeKey("agR0ZXN0chkLEgZEb21haW4iDUdBU0RHSDQyMkQtSUQM"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_invalidStringifiedVKey_failure() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> VKey.create("kind:TestObject@sq:l@ofya:bc"));
|
||||
assertThat(thrown)
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> VKey.createEppVKeyFromString("kind:Domain")))
|
||||
.hasMessageThat()
|
||||
.contains("Cannot parse key string: kind:TestObject@sq:l@ofya:bc");
|
||||
.isEqualTo("\"sql\" missing from the string: kind:Domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_invalidOfyKeyString_failure() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> VKey.create("invalid"));
|
||||
assertThat(thrown).hasMessageThat().contains("Could not parse Reference");
|
||||
}
|
||||
|
||||
/** Test stringify() then create() flow. */
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlOnlyVKey_testObject_stringKey_success() {
|
||||
VKey<TestObject> vkey = VKey.createSql(TestObject.class, "foo");
|
||||
VKey<TestObject> newVkey = VKey.create(vkey.stringify());
|
||||
assertThat(newVkey).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlOnlyVKey_testObject_longKey_success() {
|
||||
VKey<TestObject> vkey = VKey.createSql(TestObject.class, (long) 12345);
|
||||
VKey<TestObject> newVkey = VKey.create(vkey.stringify());
|
||||
assertThat(newVkey).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_createFromExistingOfyKey_success() {
|
||||
String keyString =
|
||||
Key.create(newDomain("example.com", "ROID-1", persistActiveContact("contact-1")))
|
||||
.getString();
|
||||
assertThat(VKey.fromWebsafeKey(keyString)).isEqualTo(VKey.create(keyString));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_ofyOnlyVKey_testObject_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.createOfy(TestObject.class, Key.create(TestObject.class, "tmpKey"));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_ofyOnlyVKey_testObject_websafeString_success() {
|
||||
VKey<TestObject> vkey = VKey.fromWebsafeKey(Key.create(TestObject.create("foo")).getString());
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlAndOfyVKey_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo")));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_asymmetricVKey_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.create(TestObject.class, "sqlKey", Key.create(TestObject.create("foo")));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_symmetricVKey_success() {
|
||||
VKey<TestObject> vkey = TestObject.create("foo").key();
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_sqlOnlyVKey() {
|
||||
assertThat(VKey.createSql(TestObject.class, "testId").toString())
|
||||
.isEqualTo("VKey<TestObject>(sql:testId)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_ofyOnlyVKey_withName() {
|
||||
void testFailure_createFromString_wrongKind() {
|
||||
assertThat(
|
||||
VKey.createOfy(TestObject.class, Key.create(TestObject.class, "testName")).toString())
|
||||
.isEqualTo("VKey<TestObject>(ofy:testName)");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.createEppVKeyFromString("kind:Registry@sql:rO0ABXQABGJsYWg")))
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Registry is not an EppResource");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_ofyOnlyVKey_withId() {
|
||||
assertThat(VKey.createOfy(TestObject.class, Key.create(TestObject.class, 12345)).toString())
|
||||
.isEqualTo("VKey<TestObject>(ofy:12345)");
|
||||
void testSuccess_stringify() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
String keyString = key.stringify();
|
||||
assertThat(keyString).isEqualTo("kind:Domain@sql:rO0ABXQABGJsYWg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_sqlAndOfyVKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("ofy"))).toString())
|
||||
.isEqualTo("VKey<TestObject>(sql:foo,ofy:ofy)");
|
||||
void testSuccess_toString() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
String keyString = key.toString();
|
||||
assertThat(keyString).isEqualTo("VKey<Domain>(sql:blah)");
|
||||
}
|
||||
|
||||
@Entity
|
||||
static class OtherObject {}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,7 @@ public class InetAddressSetConverterTest {
|
|||
insertInDb(testEntity);
|
||||
InetAddressSetTestEntity persisted =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().loadByKey(VKey.createSql(InetAddressSetTestEntity.class, "id")));
|
||||
.transact(() -> jpaTm().loadByKey(VKey.create(InetAddressSetTestEntity.class, "id")));
|
||||
assertThat(persisted.addresses).isEqualTo(inetAddresses);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ public class LocalDateConverterTest {
|
|||
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
|
||||
insertInDb(entity);
|
||||
return jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
||||
.transact(() -> jpaTm().loadByKey(VKey.create(LocalDateConverterTestEntity.class, "id")));
|
||||
}
|
||||
|
||||
/** Override entity name to avoid the nested class reference. */
|
||||
|
|
|
@ -46,9 +46,9 @@ public class VKeyConverterTest {
|
|||
@Test
|
||||
void testRoundTrip() {
|
||||
TestStringEntity stringEntity = new TestStringEntity("TheRealSpartacus");
|
||||
VKey<TestStringEntity> stringKey = VKey.createSql(TestStringEntity.class, "TheRealSpartacus");
|
||||
VKey<TestStringEntity> stringKey = VKey.create(TestStringEntity.class, "TheRealSpartacus");
|
||||
TestLongEntity longEntity = new TestLongEntity(300L);
|
||||
VKey<TestLongEntity> longKey = VKey.createSql(TestLongEntity.class, 300L);
|
||||
VKey<TestLongEntity> longKey = VKey.create(TestLongEntity.class, 300L);
|
||||
TestEntity original = new TestEntity(1984L, stringKey, longKey);
|
||||
insertInDb(stringEntity, longEntity, original);
|
||||
|
||||
|
|
|
@ -60,11 +60,11 @@ class JpaTransactionManagerImplTest {
|
|||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
private final TestEntity theEntity = new TestEntity("theEntity", "foo");
|
||||
private final VKey<TestEntity> theEntityKey = VKey.createSql(TestEntity.class, "theEntity");
|
||||
private final VKey<TestEntity> theEntityKey = VKey.create(TestEntity.class, "theEntity");
|
||||
private final TestCompoundIdEntity compoundIdEntity =
|
||||
new TestCompoundIdEntity("compoundIdEntity", 10, "foo");
|
||||
private final VKey<TestCompoundIdEntity> compoundIdEntityKey =
|
||||
VKey.createSql(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10));
|
||||
VKey.create(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10));
|
||||
private final ImmutableList<TestEntity> moreEntities =
|
||||
ImmutableList.of(
|
||||
new TestEntity("entity1", "foo"),
|
||||
|
@ -228,8 +228,7 @@ class JpaTransactionManagerImplTest {
|
|||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
assertThat(existsInDb(entity)).isTrue();
|
||||
assertThat(
|
||||
loadByKey(
|
||||
VKey.createSql(TestNamedCompoundIdEntity.class, new NamedCompoundId("foo", 1))))
|
||||
loadByKey(VKey.create(TestNamedCompoundIdEntity.class, new NamedCompoundId("foo", 1))))
|
||||
.isEqualTo(entity);
|
||||
}
|
||||
|
||||
|
@ -289,7 +288,7 @@ class JpaTransactionManagerImplTest {
|
|||
void update_succeeds() {
|
||||
insertInDb(theEntity);
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "theEntity")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "theEntity")));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
jpaTm().transact(() -> jpaTm().update(theEntity));
|
||||
|
@ -415,7 +414,7 @@ class JpaTransactionManagerImplTest {
|
|||
jpaTm()
|
||||
.loadByKeysIfPresent(
|
||||
ImmutableList.of(
|
||||
theEntityKey, VKey.createSql(TestEntity.class, "does-not-exist")));
|
||||
theEntityKey, VKey.create(TestEntity.class, "does-not-exist")));
|
||||
|
||||
assertThat(results).containsExactly(theEntityKey, theEntity);
|
||||
assertDetachedFromEntityManager(results.get(theEntityKey));
|
||||
|
|
|
@ -23,18 +23,17 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.truth.Truth8;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -53,13 +52,11 @@ public class TransactionManagerTest {
|
|||
new TestEntity("entity3", "qux"));
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine =
|
||||
AppEngineExtension.builder()
|
||||
public final JpaUnitTestExtension jpa =
|
||||
new JpaTestExtensions.Builder()
|
||||
.withClock(fakeClock)
|
||||
.withCloudSql()
|
||||
.withOfyTestEntities(TestEntity.class)
|
||||
.withJpaUnitTestEntities(TestEntity.class, TestEntityBase.class)
|
||||
.build();
|
||||
.withEntityClass(TestEntity.class, TestEntityBase.class)
|
||||
.buildUnitTestExtension();
|
||||
|
||||
TransactionManagerTest() {}
|
||||
|
||||
|
@ -116,7 +113,7 @@ public class TransactionManagerTest {
|
|||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey()))).isEqualTo(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,17 +128,17 @@ public class TransactionManagerTest {
|
|||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().put(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey()))).isEqualTo(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveNewOrUpdate_updatesExistingEntity() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
tm().transact(() -> tm().put(theEntity));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("bar");
|
||||
}
|
||||
|
||||
|
@ -156,14 +153,11 @@ public class TransactionManagerTest {
|
|||
void update_succeeds() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted =
|
||||
tm().transact(
|
||||
() ->
|
||||
tm().loadByKey(
|
||||
VKey.create(TestEntity.class, theEntity.name, Key.create(theEntity))));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, theEntity.name)));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
tm().transact(() -> tm().update(theEntity));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("bar");
|
||||
}
|
||||
|
||||
|
@ -171,7 +165,7 @@ public class TransactionManagerTest {
|
|||
void load_succeeds() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.name).isEqualTo("theEntity");
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
}
|
||||
|
@ -180,14 +174,16 @@ public class TransactionManagerTest {
|
|||
void load_throwsOnMissingElement() {
|
||||
assertEntityNotExist(theEntity);
|
||||
assertThrows(
|
||||
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKey(theEntity.key())));
|
||||
NoSuchElementException.class,
|
||||
() -> tm().transact(() -> tm().loadByKey(theEntity.createVKey())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void maybeLoad_succeeds() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key()).get());
|
||||
TestEntity persisted =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(theEntity.createVKey()).get());
|
||||
assertThat(persisted.name).isEqualTo("theEntity");
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
}
|
||||
|
@ -195,21 +191,22 @@ public class TransactionManagerTest {
|
|||
@Test
|
||||
void maybeLoad_nonExistentObject() {
|
||||
assertEntityNotExist(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key())).isPresent()).isFalse();
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.createVKey())).isPresent())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_succeeds() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
tm().transact(() -> tm().delete(theEntity.key()));
|
||||
tm().transact(() -> tm().delete(theEntity.createVKey()));
|
||||
assertEntityNotExist(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_doNothingWhenEntityNotExist() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().delete(theEntity.key()));
|
||||
tm().transact(() -> tm().delete(theEntity.createVKey()));
|
||||
assertEntityNotExist(theEntity);
|
||||
}
|
||||
|
||||
|
@ -218,7 +215,7 @@ public class TransactionManagerTest {
|
|||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
Set<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableSet());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableSet());
|
||||
assertAllEntitiesExist(moreEntities);
|
||||
tm().transact(() -> tm().delete(keys));
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
|
@ -229,7 +226,7 @@ public class TransactionManagerTest {
|
|||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
assertAllEntitiesExist(moreEntities);
|
||||
tm().transact(() -> tm().delete(keys.get(0)));
|
||||
assertEntityNotExist(moreEntities.get(0));
|
||||
|
@ -250,9 +247,9 @@ public class TransactionManagerTest {
|
|||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeys(keys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -260,11 +257,11 @@ public class TransactionManagerTest {
|
|||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
ImmutableList<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
ImmutableList<VKey<TestEntity>> doubleKeys =
|
||||
Stream.concat(keys.stream(), keys.stream()).collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeys(doubleKeys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -273,7 +270,7 @@ public class TransactionManagerTest {
|
|||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||
.map(TestEntity::key)
|
||||
.map(TestEntity::createVKey)
|
||||
.collect(toImmutableList());
|
||||
assertThat(
|
||||
assertThrows(
|
||||
|
@ -288,10 +285,10 @@ public class TransactionManagerTest {
|
|||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||
.map(TestEntity::key)
|
||||
.map(TestEntity::createVKey)
|
||||
.collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeysIfPresent(keys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -322,8 +319,8 @@ public class TransactionManagerTest {
|
|||
tm().transact(
|
||||
() ->
|
||||
tm().loadByEntitiesIfPresent(moreEntities).stream()
|
||||
.map(TestEntity::key)
|
||||
.map(VKey::getSqlKey)
|
||||
.map(TestEntity::createVKey)
|
||||
.map(VKey::getKey)
|
||||
.collect(toImmutableList())))
|
||||
.containsExactly("entity2", "entity3");
|
||||
}
|
||||
|
@ -355,10 +352,10 @@ public class TransactionManagerTest {
|
|||
tm().transact(() -> tm().insert(theEntity));
|
||||
tm().transact(
|
||||
() -> {
|
||||
TestEntity e = tm().loadByKey(theEntity.key());
|
||||
TestEntity e = tm().loadByKey(theEntity.createVKey());
|
||||
e.data = "some other data!";
|
||||
});
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key())).data).isEqualTo("foo");
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey())).data).isEqualTo("foo");
|
||||
}
|
||||
|
||||
private static void assertEntityExists(TestEntity entity) {
|
||||
|
@ -383,7 +380,7 @@ public class TransactionManagerTest {
|
|||
@MappedSuperclass
|
||||
@Embeddable
|
||||
private static class TestEntityBase extends ImmutableObject {
|
||||
@Id @javax.persistence.Id protected String name;
|
||||
@Id protected String name;
|
||||
|
||||
TestEntityBase(String name) {
|
||||
this.name = name;
|
||||
|
@ -392,8 +389,7 @@ public class TransactionManagerTest {
|
|||
TestEntityBase() {}
|
||||
}
|
||||
|
||||
@Entity(name = "TxnMgrTestEntity")
|
||||
@javax.persistence.Entity(name = "TestEntity")
|
||||
@Entity(name = "TestEntity")
|
||||
private static class TestEntity extends TestEntityBase {
|
||||
|
||||
private String data;
|
||||
|
@ -405,8 +401,9 @@ public class TransactionManagerTest {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public VKey<TestEntity> key() {
|
||||
return VKey.create(TestEntity.class, name, Key.create(this));
|
||||
@Override
|
||||
public VKey<TestEntity> createVKey() {
|
||||
return VKey.create(TestEntity.class, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class RegistrarDaoTest {
|
|||
JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
private final VKey<Registrar> registrarKey = VKey.createSql(Registrar.class, "registrarId");
|
||||
private final VKey<Registrar> registrarKey = VKey.create(Registrar.class, "registrarId");
|
||||
|
||||
private Registrar testRegistrar;
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ abstract class AbstractEppResourceSubject<
|
|||
return andChainer();
|
||||
}
|
||||
|
||||
public And<S> hasLastEppUpdateClientId(String registrarId) {
|
||||
public And<S> hasLastEppUpdateRegistrarId(String registrarId) {
|
||||
return hasValue(
|
||||
registrarId, actual.getLastEppUpdateRegistrarId(), "getLastEppUpdateRegistrarId()");
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue