Use ReplaySpecializer to fix DomainBase replays (#991)

* Use ReplaySpecializer to fix DomainBase replays

DomainBase currently has a number of ancillary objects that require a
cascading delete that doesn't get propagated.  Implement beforeSqlDelete() in
DomainContent to delete these child entities.

* Remove unnecessary Query variable

* Fix rebase error
This commit is contained in:
Michael Muller
2021-03-10 17:24:23 -05:00
committed by GitHub
parent 79b4cb0d82
commit 7b673c90db
8 changed files with 85 additions and 19 deletions
@@ -24,6 +24,7 @@ import static com.google.common.collect.Sets.intersection;
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
import static google.registry.model.EppResourceUtils.setAutomaticTransferSuccessProperties;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
@@ -378,6 +379,25 @@ public class DomainContent extends EppResource
}
}
/**
* Callback to delete grace periods and DelegationSignerData records prior to domain delete.
*
* <p>See {@link google.registry.schema.replay.ReplaySpecializer}.
*/
public static void beforeSqlDelete(VKey<DomainBase> key) {
// Delete all grace periods associated with the domain.
jpaTm()
.getEntityManager()
.createQuery("DELETE FROM GracePeriod WHERE domain_repo_id = :repo_id")
.setParameter("repo_id", key.getSqlKey())
.executeUpdate();
jpaTm()
.getEntityManager()
.createQuery("DELETE FROM DelegationSignerData WHERE domain_repo_id = :repo_id")
.setParameter("repo_id", key.getSqlKey())
.executeUpdate();
}
public static <T> VKey<T> restoreOfyFrom(Key<DomainBase> domainKey, VKey<T> key, Long historyId) {
if (historyId == null) {
// This is a legacy key (or a null key, in which case this works too)