From 536f82eb9ae8cf521ebe9b84b83338779d80607e Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Fri, 4 Nov 2022 12:47:11 -0400 Subject: [PATCH] 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 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. --- .../registry/batch/AsyncTaskEnqueuer.java | 9 +- .../batch/CheckPackagesComplianceAction.java | 4 +- .../ExpandRecurringBillingEventsAction.java | 2 +- .../registry/batch/ResaveEntityAction.java | 10 +- .../google/registry/beam/rde/RdePipeline.java | 22 +- .../registry/beam/spec11/Spec11Pipeline.java | 6 +- .../registry/flows/ResourceFlowUtils.java | 2 +- .../flows/contact/ContactInfoFlow.java | 6 +- .../flows/domain/DomainFlowUtils.java | 2 +- .../registry/flows/domain/DomainInfoFlow.java | 6 +- .../token/AllocationTokenFlowUtils.java | 2 +- .../registry/flows/host/HostInfoFlow.java | 8 +- .../google/registry/model/EntityClasses.java | 33 -- .../google/registry/model/EppResource.java | 49 ++- .../registry/model/EppResourceUtils.java | 7 +- .../registry/model/ForeignKeyUtils.java | 15 +- .../registry/model/ResourceTransferUtils.java | 4 +- .../google/registry/model/SchemaVersion.java | 69 ---- .../registry/model/billing/BillingEvent.java | 6 +- .../model/common/ClassPathManager.java | 68 ---- .../model/common/CrossTldSingleton.java | 13 +- .../google/registry/model/common/Cursor.java | 2 +- .../registry/model/contact/Contact.java | 5 +- .../registry/model/contact/ContactBase.java | 30 +- .../model/contact/ContactHistory.java | 2 +- .../model/contact/ContactInfoData.java | 51 +-- .../model/domain/DesignatedContact.java | 8 - .../google/registry/model/domain/Domain.java | 17 +- .../registry/model/domain/DomainBase.java | 87 +++-- .../registry/model/domain/DomainHistory.java | 2 +- .../registry/model/domain/DomainInfoData.java | 23 +- .../PackageTokenResponseExtension.java | 2 +- .../model/domain/token/AllocationToken.java | 2 +- .../model/domain/token/PackagePromotion.java | 4 +- .../java/google/registry/model/host/Host.java | 2 +- .../google/registry/model/host/HostBase.java | 12 +- .../registry/model/host/HostHistory.java | 2 +- .../registry/model/host/HostInfoData.java | 23 +- .../registry/model/ofy/ObjectifyService.java | 8 +- .../registry/model/poll/PollMessage.java | 4 +- .../poll/PollMessageExternalKeyConverter.java | 2 +- .../registry/model/rde/RdeRevision.java | 4 +- .../registry/model/registrar/Registrar.java | 2 +- .../model/registrar/RegistrarPoc.java | 2 +- .../model/reporting/HistoryEntryDao.java | 2 +- .../google/registry/model/server/Lock.java | 4 +- .../google/registry/model/tld/Registry.java | 4 +- .../registry/model/transfer/TransferData.java | 8 +- .../translators/VKeyTranslatorFactory.java | 98 ----- .../google/registry/persistence/VKey.java | 320 +++-------------- ...ansferServerApproveEntitySetConverter.java | 4 +- .../persistence/converter/VKeyConverter.java | 6 +- .../JpaTransactionManagerImpl.java | 14 +- .../registry/rdap/RdapDomainSearchAction.java | 34 +- .../registry/rdap/RdapEntitySearchAction.java | 2 +- .../registry/rdap/RdapJsonFormatter.java | 2 +- .../registry/rdap/RdapSearchActionBase.java | 2 +- ...CreateOrUpdatePackagePromotionCommand.java | 2 +- .../tools/DeleteAllocationTokensCommand.java | 3 +- .../GenerateAllocationTokensCommand.java | 2 +- .../tools/GetAllocationTokenCommand.java | 10 +- .../registry/tools/GetSchemaCommand.java | 48 --- .../registry/tools/MutatingCommand.java | 2 +- .../google/registry/tools/RegistryTool.java | 1 - ...UpdateOrDeleteAllocationTokensCommand.java | 2 +- ...CreateCancellationsForOneTimesCommand.java | 2 +- ...CreateSyntheticDomainHistoriesCommand.java | 2 +- .../beam/common/RegistryJpaReadTest.java | 4 +- .../registry/beam/rde/RdePipelineTest.java | 2 +- .../flows/domain/DomainCreateFlowTest.java | 4 +- .../flows/domain/DomainDeleteFlowTest.java | 4 +- .../flows/domain/DomainRenewFlowTest.java | 4 +- .../domain/DomainRestoreRequestFlowTest.java | 4 +- .../domain/DomainTransferApproveFlowTest.java | 2 +- .../domain/DomainTransferCancelFlowTest.java | 2 +- .../domain/DomainTransferRejectFlowTest.java | 2 +- .../domain/DomainTransferRequestFlowTest.java | 4 +- .../flows/domain/DomainUpdateFlowTest.java | 8 +- .../registry/model/EntityClassesTest.java | 82 ----- .../registry/model/SchemaVersionTest.java | 41 --- .../model/UpdateAutoTimestampTest.java | 2 +- .../model/common/ClassPathManagerTest.java | 88 ----- .../registry/model/domain/DomainSqlTest.java | 2 +- .../registry/model/domain/DomainTest.java | 6 +- .../registry/model/ofy/OfyFilterTest.java | 8 +- .../PollMessageExternalKeyConverterTest.java | 2 +- .../registry/model/poll/PollMessageTest.java | 5 +- .../reporting/Spec11ThreatMatchTest.java | 4 +- .../model/transfer/TransferDataTest.java | 4 +- .../translators/StatusValueAdapterTest.java | 4 +- .../VKeyTranslatorFactoryTest.java | 63 ---- .../EntityCallbacksListenerTest.java | 8 +- .../google/registry/persistence/VKeyTest.java | 334 +++--------------- .../InetAddressSetConverterTest.java | 3 +- .../converter/LocalDateConverterTest.java | 3 +- .../converter/VKeyConverterTest.java | 4 +- .../JpaTransactionManagerImplTest.java | 11 +- .../transaction/TransactionManagerTest.java | 83 +++-- .../schema/registrar/RegistrarDaoTest.java | 2 +- .../testing/AbstractEppResourceSubject.java | 2 +- .../google/registry/testing/TestObject.java | 9 +- .../registry/tools/GetDomainCommandTest.java | 4 +- .../registry/tools/MutatingCommandTest.java | 6 +- ...teCancellationsForOneTimesCommandTest.java | 2 +- .../google/registry/model/schema.txt | 52 --- 105 files changed, 469 insertions(+), 1618 deletions(-) delete mode 100644 core/src/main/java/google/registry/model/EntityClasses.java delete mode 100644 core/src/main/java/google/registry/model/SchemaVersion.java delete mode 100644 core/src/main/java/google/registry/model/common/ClassPathManager.java delete mode 100644 core/src/main/java/google/registry/model/translators/VKeyTranslatorFactory.java delete mode 100644 core/src/main/java/google/registry/tools/GetSchemaCommand.java delete mode 100644 core/src/test/java/google/registry/model/EntityClassesTest.java delete mode 100644 core/src/test/java/google/registry/model/SchemaVersionTest.java delete mode 100644 core/src/test/java/google/registry/model/common/ClassPathManagerTest.java delete mode 100644 core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java delete mode 100644 core/src/test/resources/google/registry/model/schema.txt diff --git a/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java b/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java index 0483e1472..ffc8df4a8 100644 --- a/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java +++ b/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java @@ -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 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 whenToResave) { + VKey entityKey, + DateTime now, + ImmutableSortedSet 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); diff --git a/core/src/main/java/google/registry/batch/CheckPackagesComplianceAction.java b/core/src/main/java/google/registry/batch/CheckPackagesComplianceAction.java index aa07d4600..623bc3f2f 100644 --- a/core/src/main/java/google/registry/batch/CheckPackagesComplianceAction.java +++ b/core/src/main/java/google/registry/batch/CheckPackagesComplianceAction.java @@ -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); } } diff --git a/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java b/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java index 977da622f..34c1f2845 100644 --- a/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java +++ b/core/src/main/java/google/registry/batch/ExpandRecurringBillingEventsAction.java @@ -253,7 +253,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable { final ImmutableSet billingTimes = getBillingTimesInScope(eventTimes, cursorTime, executeTime, tld); - VKey domainKey = VKey.createSql(Domain.class, recurring.getDomainRepoId()); + VKey domainKey = VKey.create(Domain.class, recurring.getDomainRepoId()); Iterable oneTimesForDomain; oneTimesForDomain = tm().createQueryComposer(OneTime.class) diff --git a/core/src/main/java/google/registry/batch/ResaveEntityAction.java b/core/src/main/java/google/registry/batch/ResaveEntityAction.java index 480e5a5c1..fc74a2d81 100644 --- a/core/src/main/java/google/registry/batch/ResaveEntityAction.java +++ b/core/src/main/java/google/registry/batch/ResaveEntityAction.java @@ -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."); diff --git a/core/src/main/java/google/registry/beam/rde/RdePipeline.java b/core/src/main/java/google/registry/beam/rde/RdePipeline.java index 1233cd4c7..50f4a1736 100644 --- a/core/src/main/java/google/registry/beam/rde/RdePipeline.java +++ b/core/src/main/java/google/registry/beam/rde/RdePipeline.java @@ -303,7 +303,7 @@ public class RdePipeline implements Serializable { TypeDescriptor.of(DepositFragment.class))) .via( (String registrarRepoId) -> { - VKey key = VKey.createSql(Registrar.class, registrarRepoId); + VKey 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 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); diff --git a/core/src/main/java/google/registry/beam/spec11/Spec11Pipeline.java b/core/src/main/java/google/registry/beam/spec11/Spec11Pipeline.java index f9aafaa9c..d012bd649 100644 --- a/core/src/main/java/google/registry/beam/spec11/Spec11Pipeline.java +++ b/core/src/main/java/google/registry/beam/spec11/Spec11Pipeline.java @@ -115,7 +115,7 @@ public class Spec11Pipeline implements Serializable { Read> 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 = ""; diff --git a/core/src/main/java/google/registry/flows/ResourceFlowUtils.java b/core/src/main/java/google/registry/flows/ResourceFlowUtils.java index ff8e20959..9f1f1a9c5 100644 --- a/core/src/main/java/google/registry/flows/ResourceFlowUtils.java +++ b/core/src/main/java/google/registry/flows/ResourceFlowUtils.java @@ -163,7 +163,7 @@ public final class ResourceFlowUtils { // The roid should match one of the contacts. Optional> foundContact = domain.getReferencedContacts().stream() - .filter(key -> key.getSqlKey().equals(authRepoId)) + .filter(key -> key.getKey().equals(authRepoId)) .findFirst(); if (!foundContact.isPresent()) { throw new BadAuthInfoForResourceException(); diff --git a/core/src/main/java/google/registry/flows/contact/ContactInfoFlow.java b/core/src/main/java/google/registry/flows/contact/ContactInfoFlow.java index c042621ee..d749c51c4 100644 --- a/core/src/main/java/google/registry/flows/contact/ContactInfoFlow.java +++ b/core/src/main/java/google/registry/flows/contact/ContactInfoFlow.java @@ -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) diff --git a/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java b/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java index 0ded6c8f0..2e4e019cf 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java @@ -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(); diff --git a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java index 167f46643..4275ec245 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java @@ -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()) diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java index a87c81f64..a3ff9c371 100644 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java @@ -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(); diff --git a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java index 5f62ced2b..dd343a065 100644 --- a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java @@ -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(); diff --git a/core/src/main/java/google/registry/model/EntityClasses.java b/core/src/main/java/google/registry/model/EntityClasses.java deleted file mode 100644 index 371e2f097..000000000 --- a/core/src/main/java/google/registry/model/EntityClasses.java +++ /dev/null @@ -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> ALL_CLASSES = - ImmutableSet.of(Contact.class, Domain.class, GaeUserIdConverter.class, Host.class); - - private EntityClasses() {} -} diff --git a/core/src/main/java/google/registry/model/EppResource.java b/core/src/main/java/google/registry/model/EppResource.java index 0696e1ef6..54e499265 100644 --- a/core/src/main/java/google/registry/model/EppResource.java +++ b/core/src/main/java/google/registry/model/EppResource.java @@ -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 RFC 5730 */ - @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 *

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 *

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 }. 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 *

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 statuses; + Set 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}. * *

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 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 } 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 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 statusValues) { - return setStatusValues(ImmutableSet.copyOf( - difference(getInstance().getStatusValues(), statusValues))); + return setStatusValues( + ImmutableSet.copyOf(difference(getInstance().getStatusValues(), statusValues))); } /** Set this resource's repoId. */ diff --git a/core/src/main/java/google/registry/model/EppResourceUtils.java b/core/src/main/java/google/registry/model/EppResourceUtils.java index bf27458cd..669112f15 100644 --- a/core/src/main/java/google/registry/model/EppResourceUtils.java +++ b/core/src/main/java/google/registry/model/EppResourceUtils.java @@ -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>) query .getResultStream() - .map( - repoId -> - Domain.createVKey(Key.create(Domain.class, (String) repoId))) + .map(repoId -> Domain.createVKey((String) repoId)) .collect(toImmutableSet()); return domainKeySet; }); diff --git a/core/src/main/java/google/registry/model/ForeignKeyUtils.java b/core/src/main/java/google/registry/model/ForeignKeyUtils.java index cd3072200..da7a3bde9 100644 --- a/core/src/main/java/google/registry/model/ForeignKeyUtils.java +++ b/core/src/main/java/google/registry/model/ForeignKeyUtils.java @@ -89,7 +89,7 @@ public final class ForeignKeyUtils { Class clazz, Collection 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 clazz = keys.iterator().next().getKind(); ImmutableList foreignKeys = - Streams.stream(keys) - .map(key -> (String) key.getSqlKey()) - .collect(toImmutableList()); + Streams.stream(keys).map(key -> (String) key.getKey()).collect(toImmutableList()); ImmutableMap 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 diff --git a/core/src/main/java/google/registry/model/ResourceTransferUtils.java b/core/src/main/java/google/registry/model/ResourceTransferUtils.java index a27814175..378d084ed 100644 --- a/core/src/main/java/google/registry/model/ResourceTransferUtils.java +++ b/core/src/main/java/google/registry/model/ResourceTransferUtils.java @@ -183,11 +183,11 @@ public final class ResourceTransferUtils { * sets the last EPP update client id to the given client id. */ public static 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(); } } diff --git a/core/src/main/java/google/registry/model/SchemaVersion.java b/core/src/main/java/google/registry/model/SchemaVersion.java deleted file mode 100644 index 49251832e..000000000 --- a/core/src/main/java/google/registry/model/SchemaVersion.java +++ /dev/null @@ -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> getAllPersistedTypes() { - SortedSet> 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> 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() {} -} diff --git a/core/src/main/java/google/registry/model/billing/BillingEvent.java b/core/src/main/java/google/registry/model/billing/BillingEvent.java index f3dd36a0c..c9f8f6cc8 100644 --- a/core/src/main/java/google/registry/model/billing/BillingEvent.java +++ b/core/src/main/java/google/registry/model/billing/BillingEvent.java @@ -375,7 +375,7 @@ public abstract class BillingEvent extends ImmutableObject } public static VKey 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 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 createVKey(long id) { - return VKey.createSql(Cancellation.class, id); + return VKey.create(Cancellation.class, id); } @Override diff --git a/core/src/main/java/google/registry/model/common/ClassPathManager.java b/core/src/main/java/google/registry/model/common/ClassPathManager.java deleted file mode 100644 index 59af3c2cb..000000000 --- a/core/src/main/java/google/registry/model/common/ClassPathManager.java +++ /dev/null @@ -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> 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, 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 Class getClass(String className) { - checkArgument( - CLASS_REGISTRY.containsKey(className), "Class %s not found in class registry", className); - return (Class) CLASS_REGISTRY.get(className); - } - - public static String getClassName(Class clazz) { - checkArgument( - CLASS_NAME_REGISTRY.containsKey(clazz), - "Class %s not found in class name registry", - clazz.getSimpleName()); - return CLASS_NAME_REGISTRY.get(clazz); - } -} diff --git a/core/src/main/java/google/registry/model/common/CrossTldSingleton.java b/core/src/main/java/google/registry/model/common/CrossTldSingleton.java index ed23ae0f4..3dc6f4cce 100644 --- a/core/src/main/java/google/registry/model/common/CrossTldSingleton.java +++ b/core/src/main/java/google/registry/model/common/CrossTldSingleton.java @@ -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. - * - *

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; } diff --git a/core/src/main/java/google/registry/model/common/Cursor.java b/core/src/main/java/google/registry/model/common/Cursor.java index a79a496bd..2965c2b91 100644 --- a/core/src/main/java/google/registry/model/common/Cursor.java +++ b/core/src/main/java/google/registry/model/common/Cursor.java @@ -141,7 +141,7 @@ public class Cursor extends UpdateAutoTimestampEntity { private static VKey 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() { diff --git a/core/src/main/java/google/registry/model/contact/Contact.java b/core/src/main/java/google/registry/model/contact/Contact.java index 5a3bbf971..4b3897094 100644 --- a/core/src/main/java/google/registry/model/contact/Contact.java +++ b/core/src/main/java/google/registry/model/contact/Contact.java @@ -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 RFC 5733 */ -@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 createVKey() { - return VKey.createSql(Contact.class, getRepoId()); + return VKey.create(Contact.class, getRepoId()); } @Override diff --git a/core/src/main/java/google/registry/model/contact/ContactBase.java b/core/src/main/java/google/registry/model/contact/ContactBase.java index cfee5fc12..4514ff2c6 100644 --- a/core/src/main/java/google/registry/model/contact/ContactBase.java +++ b/core/src/main/java/google/registry/model/contact/ContactBase.java @@ -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 { /** * 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; } diff --git a/core/src/main/java/google/registry/model/contact/ContactHistory.java b/core/src/main/java/google/registry/model/contact/ContactHistory.java index a6f7983b3..03e7a7b44 100644 --- a/core/src/main/java/google/registry/model/contact/ContactHistory.java +++ b/core/src/main/java/google/registry/model/contact/ContactHistory.java @@ -68,7 +68,7 @@ public class ContactHistory extends HistoryEntry { /** Creates a {@link VKey} instance for this entity. */ @Override public VKey createVKey() { - return VKey.createSql(ContactHistory.class, getHistoryEntryId()); + return VKey.create(ContactHistory.class, getHistoryEntryId()); } @Override diff --git a/core/src/main/java/google/registry/model/contact/ContactInfoData.java b/core/src/main/java/google/registry/model/contact/ContactInfoData.java index 3009a02f2..9ec131a42 100644 --- a/core/src/main/java/google/registry/model/contact/ContactInfoData.java +++ b/core/src/main/java/google/registry/model/contact/ContactInfoData.java @@ -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); diff --git a/core/src/main/java/google/registry/model/domain/DesignatedContact.java b/core/src/main/java/google/registry/model/domain/DesignatedContact.java index 5b5135c2b..ad9084e60 100644 --- a/core/src/main/java/google/registry/model/domain/DesignatedContact.java +++ b/core/src/main/java/google/registry/model/domain/DesignatedContact.java @@ -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; @Ignore VKey contactVKey; public Type getType() { @@ -82,8 +78,4 @@ public class DesignatedContact extends ImmutableObject implements UnsafeSerializ public VKey getContactKey() { return contactVKey; } - - public DesignatedContact reconstitute() { - return create(type, VKey.from(contact)); - } } diff --git a/core/src/main/java/google/registry/model/domain/Domain.java b/core/src/main/java/google/registry/model/domain/Domain.java index 3ce4259fb..b485cbd1c 100644 --- a/core/src/main/java/google/registry/model/domain/Domain.java +++ b/core/src/main/java/google/registry/model/domain/Domain.java @@ -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 RFC 5731 */ -@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 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 getInternalDelegationSignerData() { return dsData; } @@ -147,7 +144,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource { @Override public VKey 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 createVKey(Key key) { - return VKey.create(Domain.class, key.getName(), key); + public static VKey createVKey(String repoId) { + return VKey.create(Domain.class, repoId); } /** An override of {@link EppResource#asBuilder} with tighter typing. */ diff --git a/core/src/main/java/google/registry/model/domain/DomainBase.java b/core/src/main/java/google/registry/model/domain/DomainBase.java index e42eadf64..8aa995bd1 100644 --- a/core/src/main/java/google/registry/model/domain/DomainBase.java +++ b/core/src/main/java/google/registry/model/domain/DomainBase.java @@ -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. * - *

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. + *

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 RFC 5731 */ @@ -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> nsHosts; + @EmptySetToNull @Transient Set> nsHosts; /** Contacts. */ VKey adminContact; @@ -134,7 +134,6 @@ public class DomainBase extends EppResource VKey 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 dsData; + @Transient Set dsData; /** * The claims notice supplied when this domain was created, if there was one. * *

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 deletePollMessage; + VKey deletePollMessage; /** * The recurring billing event associated with this domain's autorenewals. * - *

The recurrence should be open ended unless the domain is in pending delete or fully deleted, + *

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 autorenewBillingEvent; + VKey autorenewBillingEvent; /** * The recurring poll message associated with this domain's autorenewals. * - *

The recurrence should be open ended unless the domain is in pending delete or fully deleted, + *

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 autorenewPollMessage; + VKey autorenewPollMessage; /** The unexpired grace periods for this domain (some of which may not be active yet). */ - @Ignore @Transient Set gracePeriods; + @Transient Set gracePeriods; /** * The id of the signed mark that was used to create this domain in sunrise. * *

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. * - *

This will almost always be null except in the couple minutes' interval between when a + *

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 currentPackageToken; + @Nullable VKey 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 getDeletePollMessage() { + public VKey getDeletePollMessage() { return deletePollMessage; } - public VKey getAutorenewBillingEvent() { + public VKey getAutorenewBillingEvent() { return autorenewBillingEvent; } - public VKey getAutorenewPollMessage() { + public VKey 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> 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 gracePeriods) { if (this.gracePeriods instanceof PersistentSet) { Set 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 dsData) { if (this.dsData instanceof PersistentSet) { Set 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 contactsDiscovered = new HashSet(); + HashSet 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 deletePollMessage) { + public B setDeletePollMessage(VKey deletePollMessage) { getInstance().deletePollMessage = deletePollMessage; return thisCastToDerived(); } - public B setAutorenewBillingEvent(VKey autorenewBillingEvent) { + public B setAutorenewBillingEvent(VKey autorenewBillingEvent) { getInstance().autorenewBillingEvent = autorenewBillingEvent; return thisCastToDerived(); } - public B setAutorenewPollMessage(@Nullable VKey autorenewPollMessage) { + public B setAutorenewPollMessage(@Nullable VKey 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"); diff --git a/core/src/main/java/google/registry/model/domain/DomainHistory.java b/core/src/main/java/google/registry/model/domain/DomainHistory.java index a18e05810..39a1415b7 100644 --- a/core/src/main/java/google/registry/model/domain/DomainHistory.java +++ b/core/src/main/java/google/registry/model/domain/DomainHistory.java @@ -186,7 +186,7 @@ public class DomainHistory extends HistoryEntry { /** Creates a {@link VKey} instance for this entity. */ @Override public VKey createVKey() { - return VKey.createSql(DomainHistory.class, getHistoryEntryId()); + return VKey.create(DomainHistory.class, getHistoryEntryId()); } @Override diff --git a/core/src/main/java/google/registry/model/domain/DomainInfoData.java b/core/src/main/java/google/registry/model/domain/DomainInfoData.java index 02c7116c6..7ba90e76f 100644 --- a/core/src/main/java/google/registry/model/domain/DomainInfoData.java +++ b/core/src/main/java/google/registry/model/domain/DomainInfoData.java @@ -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 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 contacts); public abstract Builder setNameservers(@Nullable ImmutableSet nameservers); public abstract Builder setSubordinateHosts(@Nullable ImmutableSet 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); diff --git a/core/src/main/java/google/registry/model/domain/packagetoken/PackageTokenResponseExtension.java b/core/src/main/java/google/registry/model/domain/packagetoken/PackageTokenResponseExtension.java index 3d5240c90..9be11d543 100644 --- a/core/src/main/java/google/registry/model/domain/packagetoken/PackageTokenResponseExtension.java +++ b/core/src/main/java/google/registry/model/domain/packagetoken/PackageTokenResponseExtension.java @@ -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; } diff --git a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java index 5a7ec6f94..f0656a381 100644 --- a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java +++ b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java @@ -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 diff --git a/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java b/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java index 3b209ede3..f04a22255 100644 --- a/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java +++ b/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java @@ -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 createVKey() { - return VKey.createSql(PackagePromotion.class, packagePromotionId); + return VKey.create(PackagePromotion.class, packagePromotionId); } @Override diff --git a/core/src/main/java/google/registry/model/host/Host.java b/core/src/main/java/google/registry/model/host/Host.java index 2d9cfde80..aed2d8aff 100644 --- a/core/src/main/java/google/registry/model/host/Host.java +++ b/core/src/main/java/google/registry/model/host/Host.java @@ -64,7 +64,7 @@ public class Host extends HostBase implements ForeignKeyedEppResource { @Override public VKey createVKey() { - return VKey.createSql(Host.class, getRepoId()); + return VKey.create(Host.class, getRepoId()); } @Override diff --git a/core/src/main/java/google/registry/model/host/HostBase.java b/core/src/main/java/google/registry/model/host/HostBase.java index b4b44b59f..c415b6d4d 100644 --- a/core/src/main/java/google/registry/model/host/HostBase.java +++ b/core/src/main/java/google/registry/model/host/HostBase.java @@ -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 inetAddresses; + Set inetAddresses; /** The superordinate domain of this host, or null if this is an external host. */ - @Index - @IgnoreSave(IfNull.class) @DoNotHydrate VKey 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. * - *

If the host is not subordinate the domain can be null and we just return last transfer time. + *

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 diff --git a/core/src/main/java/google/registry/model/host/HostHistory.java b/core/src/main/java/google/registry/model/host/HostHistory.java index 96c7a6460..da8196eee 100644 --- a/core/src/main/java/google/registry/model/host/HostHistory.java +++ b/core/src/main/java/google/registry/model/host/HostHistory.java @@ -66,7 +66,7 @@ public class HostHistory extends HistoryEntry { /** Creates a {@link VKey} instance for this entity. */ @Override public VKey createVKey() { - return VKey.createSql(HostHistory.class, getHistoryEntryId()); + return VKey.create(HostHistory.class, getHistoryEntryId()); } @Override diff --git a/core/src/main/java/google/registry/model/host/HostInfoData.java b/core/src/main/java/google/registry/model/host/HostInfoData.java index 8358c6e62..043e5a1df 100644 --- a/core/src/main/java/google/registry/model/host/HostInfoData.java +++ b/core/src/main/java/google/registry/model/host/HostInfoData.java @@ -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 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 statusValues); public abstract Builder setInetAddresses(ImmutableSet 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(); diff --git a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java index e7c2310c9..5c1862c7a 100644 --- a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java +++ b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java @@ -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); } } diff --git a/core/src/main/java/google/registry/model/poll/PollMessage.java b/core/src/main/java/google/registry/model/poll/PollMessage.java index 2656aff18..cc8371cf9 100644 --- a/core/src/main/java/google/registry/model/poll/PollMessage.java +++ b/core/src/main/java/google/registry/model/poll/PollMessage.java @@ -398,7 +398,7 @@ public abstract class PollMessage extends ImmutableObject @Override public VKey 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 createVKey() { - return VKey.createSql(Autorenew.class, getId()); + return VKey.create(Autorenew.class, getId()); } @Override diff --git a/core/src/main/java/google/registry/model/poll/PollMessageExternalKeyConverter.java b/core/src/main/java/google/registry/model/poll/PollMessageExternalKeyConverter.java index a27f7d066..215ec0674 100644 --- a/core/src/main/java/google/registry/model/poll/PollMessageExternalKeyConverter.java +++ b/core/src/main/java/google/registry/model/poll/PollMessageExternalKeyConverter.java @@ -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(); diff --git a/core/src/main/java/google/registry/model/rde/RdeRevision.java b/core/src/main/java/google/registry/model/rde/RdeRevision.java index fdb58dd61..e2b26f30c 100644 --- a/core/src/main/java/google/registry/model/rde/RdeRevision.java +++ b/core/src/main/java/google/registry/model/rde/RdeRevision.java @@ -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 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 revisionOptional = - tm().loadByKeyIfPresent(VKey.createSql(RdeRevision.class, sqlKey)); + tm().loadByKeyIfPresent(VKey.create(RdeRevision.class, sqlKey)); if (revision == 0) { revisionOptional.ifPresent( rdeRevision -> { diff --git a/core/src/main/java/google/registry/model/registrar/Registrar.java b/core/src/main/java/google/registry/model/registrar/Registrar.java index 6432f9e09..8032ee0fd 100644 --- a/core/src/main/java/google/registry/model/registrar/Registrar.java +++ b/core/src/main/java/google/registry/model/registrar/Registrar.java @@ -656,7 +656,7 @@ public class Registrar extends UpdateAutoTimestampEntity implements Buildable, J /** Creates a {@link VKey} for the given {@code registrarId}. */ public static VKey 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. */ diff --git a/core/src/main/java/google/registry/model/registrar/RegistrarPoc.java b/core/src/main/java/google/registry/model/registrar/RegistrarPoc.java index fff09d7d5..fb5acec16 100644 --- a/core/src/main/java/google/registry/model/registrar/RegistrarPoc.java +++ b/core/src/main/java/google/registry/model/registrar/RegistrarPoc.java @@ -319,7 +319,7 @@ public class RegistrarPoc extends ImmutableObject implements Jsonifiable, Unsafe @Override public VKey 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. */ diff --git a/core/src/main/java/google/registry/model/reporting/HistoryEntryDao.java b/core/src/main/java/google/registry/model/reporting/HistoryEntryDao.java index 8c00edf39..9633e8a27 100644 --- a/core/src/main/java/google/registry/model/reporting/HistoryEntryDao.java +++ b/core/src/main/java/google/registry/model/reporting/HistoryEntryDao.java @@ -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(); diff --git a/core/src/main/java/google/registry/model/server/Lock.java b/core/src/main/java/google/registry/model/server/Lock.java index a583c8128..9393cb2b1 100644 --- a/core/src/main/java/google/registry/model/server/Lock.java +++ b/core/src/main/java/google/registry/model/server/Lock.java @@ -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 key = VKey.createSql(Lock.class, new LockId(resourceName, scope)); + VKey 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 diff --git a/core/src/main/java/google/registry/model/tld/Registry.java b/core/src/main/java/google/registry/model/tld/Registry.java index e9eb75ce2..4d6643d91 100644 --- a/core/src/main/java/google/registry/model/tld/Registry.java +++ b/core/src/main/java/google/registry/model/tld/Registry.java @@ -210,12 +210,12 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial }); public static VKey createVKey(String tld) { - return VKey.createSql(Registry.class, tld); + return VKey.create(Registry.class, tld); } @Override public VKey createVKey() { - return VKey.createSql(Registry.class, tldStr); + return VKey.create(Registry.class, tldStr); } /** diff --git a/core/src/main/java/google/registry/model/transfer/TransferData.java b/core/src/main/java/google/registry/model/transfer/TransferData.java index 55c56103b..84dfa1585 100644 --- a/core/src/main/java/google/registry/model/transfer/TransferData.java +++ b/core/src/main/java/google/registry/model/transfer/TransferData.java @@ -88,9 +88,9 @@ public abstract class TransferData extends BaseTransferObject implements Buildab public ImmutableSet> getServerApproveEntities() { return NullIgnoringCollectionBuilder.create( new ImmutableSet.Builder>()) - .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> 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()); } diff --git a/core/src/main/java/google/registry/model/translators/VKeyTranslatorFactory.java b/core/src/main/java/google/registry/model/translators/VKeyTranslatorFactory.java deleted file mode 100644 index 192c429e4..000000000 --- a/core/src/main/java/google/registry/model/translators/VKeyTranslatorFactory.java +++ /dev/null @@ -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. - * - *

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 { - - 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 VKey createVKey(@Nullable com.googlecode.objectify.Key key) { - if (key == null) { - return null; - } - - // Try to create the VKey from its reference type. - Class 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) 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 createTranslator() { - return new SimpleTranslator() { - - @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(); - } - }; - } -} diff --git a/core/src/main/java/google/registry/persistence/VKey.java b/core/src/main/java/google/registry/persistence/VKey.java index bf5aecd40..36cd5150a 100644 --- a/core/src/main/java/google/registry/persistence/VKey.java +++ b/core/src/main/java/google/registry/persistence/VKey.java @@ -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. * - *

A VKey instance must contain both the JPA primary key for the referenced entity class and the - * objectify key for the object. + *

A VKey instance must contain the JPA primary key for the referenced entity class. */ public class VKey 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> 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 ofyKey; + // The primary key for the referenced entity. + Serializable key; Class kind; + @SuppressWarnings("unused") VKey() {} - VKey(Class kind, Key ofyKey, Serializable sqlKey) { + VKey(Class 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. - * - *

Deprecated. Create symmetric keys with create() instead. - */ - public static VKey createSql(Class kind, Serializable sqlKey) { + /** Creates a {@link VKey} with supplied the SQL primary key. */ + public static VKey create(Class kind, Serializable key) { checkArgumentNotNull(kind, "kind must not be null"); - checkArgumentNotNull(sqlKey, "sqlKey must not be null"); - return new VKey(kind, null, sqlKey); - } - - /** Creates a {@link VKey} which only contains the ofy primary key. */ - public static VKey createOfy(Class kind, Key ofyKey) { - checkArgumentNotNull(kind, "kind must not be null"); - checkArgumentNotNull(ofyKey, "ofyKey must not be null"); - return new VKey(kind, ofyKey, null); - } - - /** Creates a {@link VKey} which only contains both sql and ofy primary key. */ - public static VKey create(Class kind, Serializable sqlKey, Key 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(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. * - *

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. + *

The string representation is obtained from the {@link #stringify()} function and like this: + * {@code kind:TestObject@sql:rO0ABXQAA2Zvbw} */ - public static VKey create(Class 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(kind, Key.create(kind, id), id); - } - - /** - * Creates a symmetric {@link VKey} in which both sql and ofy keys are {@code name}. - * - *

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 VKey create(Class 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(kind, Key.create(kind, name), name); - } - - /** - * Constructs a {@link VKey} from the string representation of a vkey. - * - *

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. - * - *

Example of a Vkey string by fromWebsafeKey(): "agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM" - * - *

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 VKey create(String keyString) { - if (!keyString.startsWith(CLASS_TYPE + KV_SEPARATOR)) { - // handle the existing ofy key string - return fromWebsafeKey(keyString); - } else { - ImmutableMap 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 VKey createEppVKeyFromString(String keyString) { + ImmutableMap 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}. - * - *

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. - * - *

For example, to restore the objectify key for - * Domain("COM-1234")/HistoryEntry(123)/PollEvent(567), one might use: - * - *

{@code
-   * pollEvent.restoreOfy(Domain.class, "COM-1234", HistoryEntry.class, 567)
-   * }
- * - *

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. - * - *

As a special case, an objectify Key may be used as the first ancestor instead of a Class, - * value pair. - */ - public VKey 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 classType = (Class) 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 ofyKey = - sqlKey instanceof Long - ? Key.create(lastKey, getKind(), (Long) sqlKey) - : Key.create(lastKey, getKind(), (String) sqlKey); - - return VKey.create((Class) getKind(), sqlKey, ofyKey); - } - - /** - * Returns a clone of {@code key} with an ofy key restored from {@code ancestors}. - * - *

This is the static form of the method restoreOfy() above. If {@code key} is null, it returns - * null. - */ - public static VKey restoreOfyFrom(@Nullable VKey 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 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 maybeGetSqlKey() { - return Optional.ofNullable(this.sqlKey); - } - - /** Returns the objectify key. */ - public Key getOfyKey() { - checkState(ofyKey != null, "Attempting obtain a null Objectify key."); - return this.ofyKey; - } - - /** Returns the objectify key if it exists. */ - public Optional> maybeGetOfyKey() { - return Optional.ofNullable(this.ofyKey); - } - - /** Convenience method to construct a VKey from an objectify Key. */ - @Nullable - public static VKey from(Key key) { - return VKeyTranslatorFactory.createVKey(key); - } - - /** - * Construct a VKey from the string representation of an ofy key. - * - *

TODO(b/184350590): After migration, we'll want remove the ofy key dependency from this. - */ - @Nullable - public static VKey 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}. * - *

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. - * - *

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. + *

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}. - * - *

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); } } diff --git a/core/src/main/java/google/registry/persistence/converter/TransferServerApproveEntitySetConverter.java b/core/src/main/java/google/registry/persistence/converter/TransferServerApproveEntitySetConverter.java index 67f1f6a22..b42ec0bc5 100644 --- a/core/src/main/java/google/registry/persistence/converter/TransferServerApproveEntitySetConverter.java +++ b/core/src/main/java/google/registry/persistence/converter/TransferServerApproveEntitySetConverter.java @@ -27,11 +27,11 @@ public class TransferServerApproveEntitySetConverter @Override String toString(VKey element) { - return String.valueOf(element.getSqlKey()); + return String.valueOf(element.getKey()); } @Override VKey fromString(String value) { - return VKey.createSql(TransferServerApproveEntity.class, Long.parseLong(value)); + return VKey.create(TransferServerApproveEntity.class, Long.parseLong(value)); } } diff --git a/core/src/main/java/google/registry/persistence/converter/VKeyConverter.java b/core/src/main/java/google/registry/persistence/converter/VKeyConverter.java index 39e8eec11..9a123b426 100644 --- a/core/src/main/java/google/registry/persistence/converter/VKeyConverter.java +++ b/core/src/main/java/google/registry/persistence/converter/VKeyConverter.java @@ -34,12 +34,12 @@ public abstract class VKeyConverter 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 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. */ diff --git a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java index ca2425c96..18e471073 100644 --- a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java +++ b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java @@ -284,7 +284,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager { public boolean exists(VKey key) { checkArgumentNotNull(key, "key must be specified"); EntityType entityType = getEntityType(key.getKind()); - ImmutableSet entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey()); + ImmutableSet entityIds = getEntityIdsFromSqlKey(entityType, key.getKey()); return exists(entityType.getName(), entityIds); } @@ -311,7 +311,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager { public Optional loadByKeyIfPresent(VKey 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, 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 loadByKey(VKey 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 entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey()); + ImmutableSet 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 void assertDelete(VKey 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())); } } diff --git a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java index f83a6d099..abc4e236c 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java @@ -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 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 resultStream = query.getResultStream(); + return resultStream + .map(repoId -> VKey.create(Host.class, repoId)) + .collect(toImmutableSet()); + }); return searchByNameserverRefs(hostKeys); } diff --git a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java index 7a7bc340d..6fb129798 100644 --- a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java @@ -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); }); diff --git a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java index df79debe6..af17549b8 100644 --- a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java +++ b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java @@ -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 historyEntries = replicaJpaTm() .transact( diff --git a/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java b/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java index 5603daa03..7ace2df3c 100644 --- a/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java +++ b/core/src/main/java/google/registry/rdap/RdapSearchActionBase.java @@ -163,7 +163,7 @@ public abstract class RdapSearchActionBase extends RdapActionBase { if (desiredRegistrar.isPresent()) { builder = builder.where( - "currentSponsorClientId", + "currentSponsorRegistrarId", replicaJpaTm().getEntityManager().getCriteriaBuilder()::equal, desiredRegistrar.get()); } diff --git a/core/src/main/java/google/registry/tools/CreateOrUpdatePackagePromotionCommand.java b/core/src/main/java/google/registry/tools/CreateOrUpdatePackagePromotionCommand.java index 7cc10f5d8..43088daf3 100644 --- a/core/src/main/java/google/registry/tools/CreateOrUpdatePackagePromotionCommand.java +++ b/core/src/main/java/google/registry/tools/CreateOrUpdatePackagePromotionCommand.java @@ -67,7 +67,7 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand { /** Returns the allocation token object. */ AllocationToken getAndCheckAllocationToken(String token) { Optional 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" diff --git a/core/src/main/java/google/registry/tools/DeleteAllocationTokensCommand.java b/core/src/main/java/google/registry/tools/DeleteAllocationTokensCommand.java index 8dd6472f7..0b7d9a6e7 100644 --- a/core/src/main/java/google/registry/tools/DeleteAllocationTokensCommand.java +++ b/core/src/main/java/google/registry/tools/DeleteAllocationTokensCommand.java @@ -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(); } } diff --git a/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java b/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java index da643ee7b..2c2fe66e2 100644 --- a/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java +++ b/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java @@ -314,7 +314,7 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi { private ImmutableSet getExistingTokenStrings(ImmutableSet candidates) { ImmutableSet> existingTokenKeys = candidates.stream() - .map(input -> VKey.createSql(AllocationToken.class, input)) + .map(input -> VKey.create(AllocationToken.class, input)) .collect(toImmutableSet()); return tm().transact( () -> diff --git a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java index 5190e7362..6800d894e 100644 --- a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java +++ b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java @@ -47,12 +47,12 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi { for (List tokens : Lists.partition(mainParameters, BATCH_SIZE)) { ImmutableList> 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 loadedTokens = builder.build(); ImmutableMap, Domain> domains = @@ -66,7 +66,7 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi { System.out.printf("Token %s was not redeemed.\n", token); } else { VKey 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, Domain> domainsBuilder = new ImmutableMap.Builder<>(); for (List> keys : Lists.partition(domainKeys, BATCH_SIZE)) { diff --git a/core/src/main/java/google/registry/tools/GetSchemaCommand.java b/core/src/main/java/google/registry/tools/GetSchemaCommand.java deleted file mode 100644 index 3e2e77fa4..000000000 --- a/core/src/main/java/google/registry/tools/GetSchemaCommand.java +++ /dev/null @@ -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)); - } - } -} diff --git a/core/src/main/java/google/registry/tools/MutatingCommand.java b/core/src/main/java/google/registry/tools/MutatingCommand.java index 4b623c987..4fc738a86 100644 --- a/core/src/main/java/google/registry/tools/MutatingCommand.java +++ b/core/src/main/java/google/registry/tools/MutatingCommand.java @@ -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. */ diff --git a/core/src/main/java/google/registry/tools/RegistryTool.java b/core/src/main/java/google/registry/tools/RegistryTool.java index 20f9a2bac..3dca22fa2 100644 --- a/core/src/main/java/google/registry/tools/RegistryTool.java +++ b/core/src/main/java/google/registry/tools/RegistryTool.java @@ -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) diff --git a/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java b/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java index 9bb2f786e..acb9310fc 100644 --- a/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java +++ b/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java @@ -55,7 +55,7 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand if (tokens != null) { ImmutableSet> keys = tokens.stream() - .map(token -> VKey.createSql(AllocationToken.class, token)) + .map(token -> VKey.create(AllocationToken.class, token)) .collect(toImmutableSet()); ImmutableSet> nonexistentKeys = tm().transact( diff --git a/core/src/main/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommand.java b/core/src/main/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommand.java index b9d823f1d..4f967d2d6 100644 --- a/core/src/main/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommand.java +++ b/core/src/main/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommand.java @@ -56,7 +56,7 @@ public class CreateCancellationsForOneTimesCommand extends ConfirmingCommand tm().transact( () -> { for (Long billingEventId : ImmutableSet.copyOf(mainParameters)) { - VKey key = VKey.createSql(OneTime.class, billingEventId); + VKey key = VKey.create(OneTime.class, billingEventId); if (tm().exists(key)) { OneTime oneTime = tm().loadByKey(key); if (alreadyCancelled(oneTime)) { diff --git a/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticDomainHistoriesCommand.java b/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticDomainHistoriesCommand.java index 81b843c16..494270891 100644 --- a/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticDomainHistoriesCommand.java +++ b/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticDomainHistoriesCommand.java @@ -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) diff --git a/core/src/test/java/google/registry/beam/common/RegistryJpaReadTest.java b/core/src/test/java/google/registry/beam/common/RegistryJpaReadTest.java index ce215cd8f..25a8b5122 100644 --- a/core/src/test/java/google/registry/beam/common/RegistryJpaReadTest.java +++ b/core/src/test/java/google/registry/beam/common/RegistryJpaReadTest.java @@ -112,7 +112,7 @@ public class RegistryJpaReadTest { Read 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 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, diff --git a/core/src/test/java/google/registry/beam/rde/RdePipelineTest.java b/core/src/test/java/google/registry/beam/rde/RdePipelineTest.java index de2c024df..8af151afa 100644 --- a/core/src/test/java/google/registry/beam/rde/RdePipelineTest.java +++ b/core/src/test/java/google/registry/beam/rde/RdePipelineTest.java @@ -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()); diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index 885c35778..8bea45fb8 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -1353,7 +1353,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase 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 tm().loadByKey(VKey.createSql(AllocationToken.class, token))); + tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token))); assertThat(reloadedToken.isRedeemed()).isFalse(); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java index 3745befc7..c42f36284 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -382,7 +382,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase .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 @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(); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java index c49fec83c..aa1b9b0af 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java @@ -186,7 +186,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase> 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 baseEntityKinds = - ALL_CLASSES - .stream() - .filter(hasAnnotation(Entity.class)) - .map(Key::getKind) - .collect(toImmutableSet()); - Set 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(); - } - } -} diff --git a/core/src/test/java/google/registry/model/SchemaVersionTest.java b/core/src/test/java/google/registry/model/SchemaVersionTest.java deleted file mode 100644 index 8b8b0c120..000000000 --- a/core/src/test/java/google/registry/model/SchemaVersionTest.java +++ /dev/null @@ -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}. - * - *

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"); - } -} diff --git a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java index e9f9a29d4..2b089c5c4 100644 --- a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java +++ b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java @@ -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 diff --git a/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java b/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java deleted file mode 100644 index b3e398bce..000000000 --- a/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java +++ /dev/null @@ -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); - } -} diff --git a/core/src/test/java/google/registry/model/domain/DomainSqlTest.java b/core/src/test/java/google/registry/model/domain/DomainSqlTest.java index 862218ba0..cc01d7052 100644 --- a/core/src/test/java/google/registry/model/domain/DomainSqlTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainSqlTest.java @@ -401,7 +401,7 @@ public class DomainSqlTest { } private VKey createKey(Class clazz, String key) { - return VKey.createSql(clazz, key); + return VKey.create(clazz, key); } private void assertEqualDomainExcept(Domain thatDomain, String... excepts) { diff --git a/core/src/test/java/google/registry/model/domain/DomainTest.java b/core/src/test/java/google/registry/model/domain/DomainTest.java index d6f510091..dec30a9ac 100644 --- a/core/src/test/java/google/registry/model/domain/DomainTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainTest.java @@ -166,8 +166,8 @@ public class DomainTest { .build(); insertInDb(historyEntry, oneTimeBill, recurringBill); recurringBillKey = recurringBill.createVKey(); - VKey autorenewPollKey = VKey.createSql(PollMessage.Autorenew.class, 3L); - VKey onetimePollKey = VKey.createSql(PollMessage.OneTime.class, 1L); + VKey autorenewPollKey = VKey.create(PollMessage.Autorenew.class, 3L); + VKey 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"); diff --git a/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java b/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java index 730b30fd5..89a52bbef 100644 --- a/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java +++ b/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java @@ -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 diff --git a/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java b/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java index 2837e519c..6fc1459c1 100644 --- a/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java +++ b/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java @@ -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()); } } diff --git a/core/src/test/java/google/registry/model/poll/PollMessageTest.java b/core/src/test/java/google/registry/model/poll/PollMessageTest.java index 82a097d74..f08a41b9f 100644 --- a/core/src/test/java/google/registry/model/poll/PollMessageTest.java +++ b/core/src/test/java/google/registry/model/poll/PollMessageTest.java @@ -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); } diff --git a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java index 5bf87923a..f4d90268c 100644 --- a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java +++ b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java @@ -54,8 +54,8 @@ public final class Spec11ThreatMatchTest extends EntityTestCase { @BeforeEach void setUp() { - VKey hostVKey = VKey.createSql(Host.class, "host"); - VKey registrantContactVKey = VKey.createSql(Contact.class, "contact_id"); + VKey hostVKey = VKey.create(Host.class, "host"); + VKey registrantContactVKey = VKey.create(Contact.class, "contact_id"); String domainRepoId = "4-TLD"; createTld("tld"); diff --git a/core/src/test/java/google/registry/model/transfer/TransferDataTest.java b/core/src/test/java/google/registry/model/transfer/TransferDataTest.java index 54f523375..07262810e 100644 --- a/core/src/test/java/google/registry/model/transfer/TransferDataTest.java +++ b/core/src/test/java/google/registry/model/transfer/TransferDataTest.java @@ -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 diff --git a/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java b/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java index 9bd3f69cf..ea9174d2f 100644 --- a/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java +++ b/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java @@ -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("") diff --git a/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java b/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java deleted file mode 100644 index bb3c34263..000000000 --- a/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java +++ /dev/null @@ -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 key = Key.create(domain); - VKey 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 key = Key.create(testObject); - assertThat(VKeyTranslatorFactory.createVKey(key).getSqlKey()).isEqualTo("id"); - } -} diff --git a/core/src/test/java/google/registry/persistence/EntityCallbacksListenerTest.java b/core/src/test/java/google/registry/persistence/EntityCallbacksListenerTest.java index 607f0fbe0..9fc1eb04d 100644 --- a/core/src/test/java/google/registry/persistence/EntityCallbacksListenerTest.java +++ b/core/src/test/java/google/registry/persistence/EntityCallbacksListenerTest.java @@ -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); diff --git a/core/src/test/java/google/registry/persistence/VKeyTest.java b/core/src/test/java/google/registry/persistence/VKeyTest.java index 66c35f876..7a3152edd 100644 --- a/core/src/test/java/google/registry/persistence/VKeyTest.java +++ b/core/src/test/java/google/registry/persistence/VKeyTest.java @@ -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 key = VKey.create(PollMessage.class, 5L); + assertThat(key.getKey()).isEqualTo(5L); + assertThat(key.getKind()).isEqualTo(PollMessage.class); } @Test - void testOptionalAccessors() { - VKey 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 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 key = VKey.createSql(TestObject.class, "foo"); - VKey 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 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 key = Key.create(domain); - VKey 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 key = Key.create(domain); - VKey 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 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 vkey = VKey.createSql(TestObject.class, "foo"); - VKey newVkey = VKey.create(vkey.stringify()); - assertThat(newVkey).isEqualTo(vkey); - } - - @Test - void testStringifyThenCreate_sqlOnlyVKey_testObject_longKey_success() { - VKey vkey = VKey.createSql(TestObject.class, (long) 12345); - VKey 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 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 vkey = VKey.fromWebsafeKey(Key.create(TestObject.create("foo")).getString()); - assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey); - } - - @Test - void testStringifyThenCreate_sqlAndOfyVKey_success() { - VKey vkey = - VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))); - assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey); - } - - @Test - void testStringifyThenCreate_asymmetricVKey_success() { - VKey vkey = - VKey.create(TestObject.class, "sqlKey", Key.create(TestObject.create("foo"))); - assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey); - } - - @Test - void testStringifyThenCreate_symmetricVKey_success() { - VKey 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(sql:testId)"); - } - - @Test - void testToString_ofyOnlyVKey_withName() { + void testFailure_createFromString_wrongKind() { assertThat( - VKey.createOfy(TestObject.class, Key.create(TestObject.class, "testName")).toString()) - .isEqualTo("VKey(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(ofy:12345)"); + void testSuccess_stringify() { + VKey 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(sql:foo,ofy:ofy)"); + void testSuccess_toString() { + VKey key = VKey.create(Domain.class, "blah"); + String keyString = key.toString(); + assertThat(keyString).isEqualTo("VKey(sql:blah)"); } - - @Entity - static class OtherObject {} } diff --git a/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java b/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java index 6c9d82d87..80cac0c8c 100644 --- a/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java @@ -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); } diff --git a/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java b/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java index 15a1e51ac..a2d8aa965 100644 --- a/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java @@ -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. */ diff --git a/core/src/test/java/google/registry/persistence/converter/VKeyConverterTest.java b/core/src/test/java/google/registry/persistence/converter/VKeyConverterTest.java index 1a74212c2..0ac6faa42 100644 --- a/core/src/test/java/google/registry/persistence/converter/VKeyConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/VKeyConverterTest.java @@ -46,9 +46,9 @@ public class VKeyConverterTest { @Test void testRoundTrip() { TestStringEntity stringEntity = new TestStringEntity("TheRealSpartacus"); - VKey stringKey = VKey.createSql(TestStringEntity.class, "TheRealSpartacus"); + VKey stringKey = VKey.create(TestStringEntity.class, "TheRealSpartacus"); TestLongEntity longEntity = new TestLongEntity(300L); - VKey longKey = VKey.createSql(TestLongEntity.class, 300L); + VKey longKey = VKey.create(TestLongEntity.class, 300L); TestEntity original = new TestEntity(1984L, stringKey, longKey); insertInDb(stringEntity, longEntity, original); diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java index e03748e98..4fb6037ff 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java @@ -60,11 +60,11 @@ class JpaTransactionManagerImplTest { private final FakeClock fakeClock = new FakeClock(); private final TestEntity theEntity = new TestEntity("theEntity", "foo"); - private final VKey theEntityKey = VKey.createSql(TestEntity.class, "theEntity"); + private final VKey theEntityKey = VKey.create(TestEntity.class, "theEntity"); private final TestCompoundIdEntity compoundIdEntity = new TestCompoundIdEntity("compoundIdEntity", 10, "foo"); private final VKey compoundIdEntityKey = - VKey.createSql(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10)); + VKey.create(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10)); private final ImmutableList 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)); diff --git a/core/src/test/java/google/registry/persistence/transaction/TransactionManagerTest.java b/core/src/test/java/google/registry/persistence/transaction/TransactionManagerTest.java index c1d6e8ad3..05979d6c6 100644 --- a/core/src/test/java/google/registry/persistence/transaction/TransactionManagerTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/TransactionManagerTest.java @@ -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> 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> 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> 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> keys = - moreEntities.stream().map(TestEntity::key).collect(toImmutableList()); + moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList()); ImmutableList> 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> 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> 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 key() { - return VKey.create(TestEntity.class, name, Key.create(this)); + @Override + public VKey createVKey() { + return VKey.create(TestEntity.class, name); } } } diff --git a/core/src/test/java/google/registry/schema/registrar/RegistrarDaoTest.java b/core/src/test/java/google/registry/schema/registrar/RegistrarDaoTest.java index 6ab068d7a..352751cd0 100644 --- a/core/src/test/java/google/registry/schema/registrar/RegistrarDaoTest.java +++ b/core/src/test/java/google/registry/schema/registrar/RegistrarDaoTest.java @@ -49,7 +49,7 @@ public class RegistrarDaoTest { JpaIntegrationWithCoverageExtension jpa = new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension(); - private final VKey registrarKey = VKey.createSql(Registrar.class, "registrarId"); + private final VKey registrarKey = VKey.create(Registrar.class, "registrarId"); private Registrar testRegistrar; diff --git a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java index 2aa6a86a1..baebec91b 100644 --- a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java +++ b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java @@ -161,7 +161,7 @@ abstract class AbstractEppResourceSubject< return andChainer(); } - public And hasLastEppUpdateClientId(String registrarId) { + public And hasLastEppUpdateRegistrarId(String registrarId) { return hasValue( registrarId, actual.getLastEppUpdateRegistrarId(), "getLastEppUpdateRegistrarId()"); } diff --git a/core/src/test/java/google/registry/testing/TestObject.java b/core/src/test/java/google/registry/testing/TestObject.java index 127d6904d..9d4b12997 100644 --- a/core/src/test/java/google/registry/testing/TestObject.java +++ b/core/src/test/java/google/registry/testing/TestObject.java @@ -18,12 +18,13 @@ 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.model.annotations.DeleteAfterMigration; import google.registry.model.annotations.VirtualEntity; import google.registry.persistence.VKey; /** A test model object that can be persisted in any entity group. */ +@DeleteAfterMigration @Entity -@javax.persistence.Entity public class TestObject extends ImmutableObject { @Id @javax.persistence.Id String id; @@ -39,11 +40,7 @@ public class TestObject extends ImmutableObject { } public VKey key() { - return VKey.create(TestObject.class, id, Key.create(this)); - } - - public static VKey createVKey(Key key) { - return VKey.create(TestObject.class, key.getName(), key); + return VKey.create(TestObject.class, id); } public static TestObject create(String id) { diff --git a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java index cf945664d..353c60fbd 100644 --- a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java @@ -48,7 +48,7 @@ class GetDomainCommandTest extends CommandTestCase { persistActiveDomain("example.tld"); runCommand("example.tld", "--expand"); assertInStdout("domainName=example.tld"); - assertInStdout("sqlKey=3-ROID"); + assertInStdout("key=3-ROID"); assertInStdout("Websafe key: " + "kind:Domain" + "@sql:rO0ABXQABTItVExE"); assertNotInStdout("LiveRef"); } @@ -59,7 +59,7 @@ class GetDomainCommandTest extends CommandTestCase { persistActiveDomain("xn--aualito-txac.xn--q9jyb4c"); runCommand("çauçalito.みんな", "--expand"); assertInStdout("domainName=xn--aualito-txac.xn--q9jyb4c"); - assertInStdout("sqlKey=4-ROID"); + assertInStdout("key=4-ROID"); } @Test diff --git a/core/src/test/java/google/registry/tools/MutatingCommandTest.java b/core/src/test/java/google/registry/tools/MutatingCommandTest.java index 3fd812ac9..38d3c8d3c 100644 --- a/core/src/test/java/google/registry/tools/MutatingCommandTest.java +++ b/core/src/test/java/google/registry/tools/MutatingCommandTest.java @@ -101,7 +101,7 @@ public class MutatingCommandTest { + "lastEppUpdateTime: null -> 2014-09-09T09:09:09.000Z\n" + "\n" + "Update Host@3-ROID\n" - + "currentSponsorClientId: TheRegistrar -> Registrar2\n" + + "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n" + "\n" + "Update Registrar@Registrar1\n" + "poNumber: null -> 23\n" @@ -246,7 +246,7 @@ public class MutatingCommandTest { + "\n" + "\n" + "Update Host@3-ROID\n" - + "currentSponsorClientId: TheRegistrar -> Registrar2\n" + + "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n" + "\n" + "Delete Registrar@Registrar1\n" + registrar1 @@ -289,7 +289,7 @@ public class MutatingCommandTest { + "\n" + "\n" + "Update Host@3-ROID\n" - + "currentSponsorClientId: TheRegistrar -> Registrar2\n" + + "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n" + "\n" + "Delete Registrar@Registrar1\n" + registrar1 diff --git a/core/src/test/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommandTest.java b/core/src/test/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommandTest.java index 56ffbd26d..932716c29 100644 --- a/core/src/test/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommandTest.java +++ b/core/src/test/java/google/registry/tools/javascrap/CreateCancellationsForOneTimesCommandTest.java @@ -145,7 +145,7 @@ public class CreateCancellationsForOneTimesCommandTest private void assertBillingEventCancelled(long oneTimeId) { assertThat( DatabaseHelper.loadAllOf(Cancellation.class).stream() - .anyMatch(c -> c.getEventKey().equals(VKey.createSql(OneTime.class, oneTimeId)))) + .anyMatch(c -> c.getEventKey().equals(VKey.create(OneTime.class, oneTimeId)))) .isTrue(); } } diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt deleted file mode 100644 index 0d84cabee..000000000 --- a/core/src/test/resources/google/registry/model/schema.txt +++ /dev/null @@ -1,52 +0,0 @@ -class google.registry.model.common.GaeUserIdConverter { - @Id long id; - com.google.appengine.api.users.User user; -} -class google.registry.model.contact.Contact { - @Id java.lang.String repoId; - java.lang.String contactId; - java.lang.String creationClientId; - java.lang.String currentSponsorClientId; - java.lang.String email; - java.lang.String lastEppUpdateClientId; - java.lang.String searchName; - org.joda.time.DateTime deletionTime; - org.joda.time.DateTime lastEppUpdateTime; - org.joda.time.DateTime lastTransferTime; -} -class google.registry.model.domain.Domain { - @Id java.lang.String repoId; - google.registry.persistence.VKey adminContact; - google.registry.persistence.VKey billingContact; - google.registry.persistence.VKey registrantContact; - google.registry.persistence.VKey techContact; - google.registry.persistence.VKey autorenewPollMessage; - google.registry.persistence.VKey deletePollMessage; - java.lang.String creationClientId; - java.lang.String currentSponsorClientId; - java.lang.String domainName; - java.lang.String idnTableName; - java.lang.String lastEppUpdateClientId; - java.lang.String smdId; - java.lang.String tld; - java.util.Set> nsHosts; - java.util.Set subordinateHosts; - org.joda.time.DateTime autorenewEndTime; - org.joda.time.DateTime deletionTime; - org.joda.time.DateTime lastEppUpdateTime; - org.joda.time.DateTime lastTransferTime; - org.joda.time.DateTime registrationExpirationTime; -} -class google.registry.model.host.Host { - @Id java.lang.String repoId; - google.registry.persistence.VKey superordinateDomain; - java.lang.String creationClientId; - java.lang.String currentSponsorClientId; - java.lang.String hostName; - java.lang.String lastEppUpdateClientId; - java.util.Set inetAddresses; - org.joda.time.DateTime deletionTime; - org.joda.time.DateTime lastEppUpdateTime; - org.joda.time.DateTime lastSuperordinateChange; - org.joda.time.DateTime lastTransferTime; -}