You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/07/06 12:36:13 UTC

[isis] 08/11: ISIS-2789: for preUpdate, populates the map of _PropertyChangeRecord according to the preValues provided to us.

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2789
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 22230768706f9aa1a72a8e14813480141b2f123d
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Jul 6 13:25:57 2021 +0100

    ISIS-2789: for preUpdate, populates the map of _PropertyChangeRecord according to the preValues provided to us.
---
 .../changetracking/EntityChangeTrackerDefault.java | 29 +++++++++++++++-------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/EntityChangeTrackerDefault.java b/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/EntityChangeTrackerDefault.java
index 9eaa9ba..d94b3b8 100644
--- a/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/EntityChangeTrackerDefault.java
+++ b/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/EntityChangeTrackerDefault.java
@@ -19,7 +19,6 @@
 package org.apache.isis.core.transaction.changetracking;
 
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -74,14 +73,16 @@ import org.apache.isis.core.metamodel.facets.object.publish.entitychange.EntityC
 import org.apache.isis.core.metamodel.spec.ManagedObject;
 import org.apache.isis.core.metamodel.spec.ManagedObjects;
 import org.apache.isis.core.metamodel.spec.feature.MixedIn;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
 import org.apache.isis.core.transaction.changetracking.events.IsisTransactionPlaceholder;
 import org.apache.isis.core.transaction.events.TransactionBeforeCompletionEvent;
 
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NonNull;
-import lombok.val;
 import lombok.extern.log4j.Log4j2;
+import lombok.val;
 
 /**
  * @since 2.0 {@index}
@@ -162,13 +163,23 @@ implements
         enlistForChangeKindPublishing(adapter, EntityChangeKind.UPDATE);
 
         if(propertyIdIfAny != null) {
-            enlistForPreAndPostValuePublishing(adapter, propertyChangeRecord -> {
-                // if we've been provided with the preValue, then just save it
-                // in the appropriate PropertyChangeRecord
-                if(Objects.equals(propertyChangeRecord.getPropertyId(), propertyIdIfAny)) {
-                    propertyChangeRecord.setPreValue(preValue);
-                }
-            });
+            // if we've been provided with the preValue, then just save it
+            // in the appropriate PropertyChangeRecord
+
+            if(propertyChangeRecordsById.containsKey(propertyIdIfAny)) {
+                return;
+            }
+            adapter.getSpecification().getAssociation(propertyIdIfAny)
+                .filter(assoc -> !assoc.isMixedIn())
+                .filter(ObjectMember::isOneToOneAssociation)
+                .map(OneToOneAssociation.class::cast)
+                .filter(property->!property.isNotPersisted())
+                .map(property->_PropertyChangeRecord.of(adapter, property))
+                .ifPresent(record -> {
+                    record.setPreValue(preValue);
+                    propertyChangeRecordsById.put(propertyIdIfAny, record);
+                });
+
         } else {
             // read from the pojo using the Isis MM.
             enlistForPreAndPostValuePublishing(adapter, _PropertyChangeRecord::updatePreValue);