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 2015/09/11 00:09:01 UTC
[37/50] isis git commit: ISIS-1194: inlining preDirtyProcessing from
FrameworkSynchroizer to PersistenceSession
ISIS-1194: inlining preDirtyProcessing from FrameworkSynchroizer to PersistenceSession
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/fe62380a
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/fe62380a
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/fe62380a
Branch: refs/heads/master
Commit: fe62380a2e818f42e69473eec8820b792621a747
Parents: 2fad991
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Sep 10 16:41:25 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Sep 10 16:41:25 2015 +0100
----------------------------------------------------------------------
.../persistence/FrameworkSynchronizer.java | 38 ----------
.../system/persistence/PersistenceSession.java | 75 +++++++++++++++++++-
2 files changed, 74 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/fe62380a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/FrameworkSynchronizer.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/FrameworkSynchronizer.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/FrameworkSynchronizer.java
index 5a4e321..51aff7e 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/FrameworkSynchronizer.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/FrameworkSynchronizer.java
@@ -41,7 +41,6 @@ import org.apache.isis.core.metamodel.facets.object.callbacks.PersistedCallbackF
import org.apache.isis.core.metamodel.facets.object.callbacks.PersistingCallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.RemovingCallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatedCallbackFacet;
-import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatingCallbackFacet;
import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
public class FrameworkSynchronizer {
@@ -223,43 +222,6 @@ public class FrameworkSynchronizer {
}, calledFrom);
}
- public void preDirtyProcessingFor(final Persistable pojo, CalledFrom calledFrom) {
- withLogging(pojo, new Runnable() {
- @Override
- public void run() {
- ObjectAdapter adapter = persistenceSession.getAdapterFor(pojo);
- if (adapter == null) {
- // seen this happen in the case when a parent entity (LeaseItem) has a collection of children
- // objects (LeaseTerm) for which we haven't had a loaded callback fired and so are not yet
- // mapped.
-
- // it seems reasonable in this case to simply map into Isis here ("just-in-time"); presumably
- // DN would not be calling this callback if the pojo was not persistent.
-
- adapter = lazilyLoaded(pojo, CalledFrom.EVENT_PREDIRTY);
- if(adapter == null) {
- throw new RuntimeException("DN could not find objectId for pojo (unexpected) and so could not map into Isis; pojo=[" + pojo + "]");
- }
- }
- if(adapter.isTransient()) {
- // seen this happen in the case when there's a 1<->m bidirectional collection, and we're
- // attaching the child object, which is being persisted by DN as a result of persistence-by-reachability,
- // and it "helpfully" sets up the parent attribute on the child, causing this callback to fire.
- //
- // however, at the same time, Isis has only queued up a CreateObjectCommand for the transient object, but it
- // hasn't yet executed, so thinks that the adapter is still transient.
- return;
- }
-
- CallbackFacet.Util.callCallback(adapter, UpdatingCallbackFacet.class);
-
- final IsisTransaction transaction = persistenceSession.getCurrentTransaction();
- transaction.enlistUpdating(adapter);
-
- ensureRootObject(pojo);
- }
- }, calledFrom);
- }
public ObjectAdapter lazilyLoaded(final Persistable pojo, CalledFrom calledFrom) {
http://git-wip-us.apache.org/repos/asf/isis/blob/fe62380a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
index bc559fc..a4081a1 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Modifier;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
import javax.jdo.FetchGroup;
import javax.jdo.FetchPlan;
@@ -55,6 +56,7 @@ import org.apache.isis.core.metamodel.adapter.oid.ParentedCollectionOid;
import org.apache.isis.core.metamodel.adapter.oid.RootOid;
import org.apache.isis.core.metamodel.facets.object.callbacks.CallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.CreatedCallbackFacet;
+import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatingCallbackFacet;
import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
import org.apache.isis.core.metamodel.services.ServiceUtil;
import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
@@ -1214,8 +1216,79 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
}
public void preDirtyProcessingFor(final Persistable pojo, FrameworkSynchronizer.CalledFrom calledFrom) {
- frameworkSynchronizer.preDirtyProcessingFor(pojo, calledFrom);
+ withLogging(pojo, new Runnable() {
+ @Override
+ public void run() {
+ ObjectAdapter adapter = getAdapterFor(pojo);
+ if (adapter == null) {
+ // seen this happen in the case when a parent entity (LeaseItem) has a collection of children
+ // objects (LeaseTerm) for which we haven't had a loaded callback fired and so are not yet
+ // mapped.
+
+ // it seems reasonable in this case to simply map into Isis here ("just-in-time"); presumably
+ // DN would not be calling this callback if the pojo was not persistent.
+
+ adapter = frameworkSynchronizer.lazilyLoaded(pojo, FrameworkSynchronizer.CalledFrom.EVENT_PREDIRTY);
+ if (adapter == null) {
+ throw new RuntimeException(
+ "DN could not find objectId for pojo (unexpected) and so could not map into Isis; pojo=["
+ + pojo + "]");
+ }
+ }
+ if (adapter.isTransient()) {
+ // seen this happen in the case when there's a 1<->m bidirectional collection, and we're
+ // attaching the child object, which is being persisted by DN as a result of persistence-by-reachability,
+ // and it "helpfully" sets up the parent attribute on the child, causing this callback to fire.
+ //
+ // however, at the same time, Isis has only queued up a CreateObjectCommand for the transient object, but it
+ // hasn't yet executed, so thinks that the adapter is still transient.
+ return;
+ }
+
+ CallbackFacet.Util.callCallback(adapter, UpdatingCallbackFacet.class);
+
+ final IsisTransaction transaction = getCurrentTransaction();
+ transaction.enlistUpdating(adapter);
+
+ ensureRootObject(pojo);
+ }
+ }, calledFrom);
+ }
+
+ private <T> T withLogging(Persistable pojo, Callable<T> runnable, FrameworkSynchronizer.CalledFrom calledFrom) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(logString(calledFrom, LoggingLocation.ENTRY, pojo));
+ }
+ try {
+ return runnable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(logString(calledFrom, LoggingLocation.EXIT, pojo));
+ }
+ }
}
+
+ private void withLogging(Persistable pojo, final Runnable runnable, FrameworkSynchronizer.CalledFrom calledFrom) {
+ withLogging(pojo, new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ runnable.run();
+ return null;
+ }
+
+ }, calledFrom);
+ }
+
+ private String logString(FrameworkSynchronizer.CalledFrom calledFrom, LoggingLocation location, Persistable pojo) {
+ final ObjectAdapter adapter = getAdapterFor(pojo);
+ // initial spaces just to look better in log when wrapped by IsisLifecycleListener...
+ return calledFrom.name() + " " + location.prefix + " oid=" + (adapter !=null? adapter.getOid(): "(null)") + " ,pojo " + pojo;
+ }
+
+
public void ensureRootObject(final Persistable pojo) {
frameworkSynchronizer.ensureRootObject(pojo);
}