Change BillingEvent parent to Key<DomainHistory> (#1178)

This commit is contained in:
Lai Jiang
2021-05-25 18:48:47 -04:00
committed by GitHub
parent 826320c7fd
commit 50f80744d8
32 changed files with 202 additions and 149 deletions
@@ -290,10 +290,7 @@ public final class DomainUpdateFlow implements TransactionalFlow {
/** Some status updates cost money. Bill only once no matter how many of them are changed. */
private Optional<BillingEvent.OneTime> createBillingEventForStatusUpdates(
DomainBase existingDomain,
DomainBase newDomain,
HistoryEntry historyEntry,
DateTime now) {
DomainBase existingDomain, DomainBase newDomain, DomainHistory historyEntry, DateTime now) {
Optional<MetadataExtension> metadataExtension =
eppInput.getSingleExtension(MetadataExtension.class);
if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) {
@@ -46,7 +46,6 @@ import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
import google.registry.persistence.BillingVKey.BillingEventVKey;
import google.registry.persistence.BillingVKey.BillingRecurrenceVKey;
@@ -115,7 +114,7 @@ public abstract class BillingEvent extends ImmutableObject
/** Entity id. */
@Id @javax.persistence.Id Long id;
@Parent @DoNotHydrate @Transient Key<? extends HistoryEntry> parent;
@Parent @DoNotHydrate @Transient Key<DomainHistory> parent;
/** The registrar to bill. */
@Index
@@ -154,7 +153,7 @@ public abstract class BillingEvent extends ImmutableObject
parent =
Key.create(
Key.create(DomainBase.class, domainRepoId),
HistoryEntry.class,
DomainHistory.class,
domainHistoryRevisionId);
}
@@ -192,7 +191,7 @@ public abstract class BillingEvent extends ImmutableObject
return targetId;
}
public Key<? extends HistoryEntry> getParentKey() {
public Key<DomainHistory> getParentKey() {
return parent;
}
@@ -254,12 +253,12 @@ public abstract class BillingEvent extends ImmutableObject
return thisCastToDerived();
}
public B setParent(HistoryEntry parent) {
public B setParent(DomainHistory parent) {
getInstance().parent = Key.create(parent);
return thisCastToDerived();
}
public B setParent(Key<? extends HistoryEntry> parentKey) {
public B setParent(Key<DomainHistory> parentKey) {
getInstance().parent = parentKey;
return thisCastToDerived();
}
@@ -735,7 +734,7 @@ public abstract class BillingEvent extends ImmutableObject
* because it is needed by one-off scrap tools that need to make billing adjustments.
*/
public static Modification createRefundFor(
OneTime billingEvent, HistoryEntry historyEntry, String description) {
OneTime billingEvent, DomainHistory historyEntry, String description) {
return new Builder()
.setClientId(billingEvent.getClientId())
.setFlags(billingEvent.getFlags())
@@ -222,9 +222,17 @@ public class DatastoreTransactionManager implements TransactionManager {
entry -> keyMap.get(entry.getKey()), entry -> toSqlEntity(entry.getValue())));
}
@SuppressWarnings("unchecked")
@Override
public <T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> entities) {
return ImmutableList.copyOf(getOfy().load().entities(entities).values());
return getOfy()
.load()
.entities(toDatastoreEntities(ImmutableList.copyOf(entities)))
.values()
.stream()
.map(DatastoreTransactionManager::toSqlEntity)
.map(entity -> (T) entity)
.collect(toImmutableList());
}
@Override
@@ -250,6 +258,7 @@ public class DatastoreTransactionManager implements TransactionManager {
return result;
}
@SuppressWarnings("unchecked")
@Override
public <T> T loadByEntity(T entity) {
return (T) toSqlEntity(auditedOfy().load().entity(toDatastoreEntity(entity)).now());
@@ -458,11 +458,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
assertInTransaction();
// If the caller requested a HistoryEntry, load the corresponding *History class
T possibleChild = toSqlEntity(entity);
return (T)
loadByKey(
VKey.createSql(
possibleChild.getClass(),
emf.getPersistenceUnitUtil().getIdentifier(possibleChild)));
@SuppressWarnings("unchecked")
T returnValue =
(T)
loadByKey(
VKey.createSql(
possibleChild.getClass(),
emf.getPersistenceUnitUtil().getIdentifier(possibleChild)));
return returnValue;
}
@Override