incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1360713 [3/4] - in /incubator/isis/trunk/framework: runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/ runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apach...
Date Thu, 12 Jul 2012 15:05:46 GMT
Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/IsisLifecycleListener.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/IsisLifecycleListener.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/IsisLifecycleListener.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/IsisLifecycleListener.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/IsisLifecycleListener.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/IsisLifecycleListener.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/IsisLifecycleListener.java Thu Jul 12 15:05:44 2012
@@ -1,370 +1,395 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence;
-
-import java.text.MessageFormat;
-import java.util.Map;
-
-import javax.jdo.listener.AttachLifecycleListener;
-import javax.jdo.listener.ClearLifecycleListener;
-import javax.jdo.listener.CreateLifecycleListener;
-import javax.jdo.listener.DeleteLifecycleListener;
-import javax.jdo.listener.DetachLifecycleListener;
-import javax.jdo.listener.DirtyLifecycleListener;
-import javax.jdo.listener.InstanceLifecycleEvent;
-import javax.jdo.listener.LoadLifecycleListener;
-import javax.jdo.listener.StoreLifecycleListener;
-import javax.jdo.spi.PersistenceCapable;
-
-import com.google.common.collect.Maps;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.ResolveState;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.facets.object.callbacks.CallbackUtils;
-import org.apache.isis.core.metamodel.facets.object.callbacks.PersistedCallbackFacet;
-import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatedCallbackFacet;
-import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.AdapterManagerExtended;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionHydrator;
-
-public class IsisLifecycleListener implements AttachLifecycleListener, ClearLifecycleListener, CreateLifecycleListener, DeleteLifecycleListener, DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLifecycleListener, SuspendableListener {
-
-    private static final Logger LOG = Logger.getLogger(IsisLifecycleListener.class);
-
-    private boolean suspended;
-
-    @Override
-    public void postCreate(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preAttach(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postAttach(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postLoad(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-
-        final Object pojo = persistenceCapableFor(event);
-
-        final OidGenerator oidGenerator = getOidGenerator();
-        final RootOid oid = oidGenerator.createPersistent(pojo, null);
-
-        PersistenceSessionHydrator hydrator = getPersistenceSession();
-        hydrator.recreateAdapter(oid, pojo);
-
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preStore(InstanceLifecycleEvent event) {
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postStore(InstanceLifecycleEvent event) {
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-
-        final PersistenceCapable pojo = persistenceCapableFor(event);
-        
-        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
-        if(!pojo.jdoIsPersistent()) {
-            final RootOid transientOid = (RootOid) adapter.getOid();
-            final RootOid persistentOid = getOidGenerator().createPersistent(pojo, transientOid);
-    
-            // most of the magic is here...
-            getAdapterManager().remapAsPersistent(adapter, persistentOid);
-    
-            clearDirtyFor(adapter);
-            CallbackUtils.callCallback(adapter, PersistedCallbackFacet.class);
-        } else {
-
-            clearDirtyFor(adapter);
-            CallbackUtils.callCallback(adapter, UpdatedCallbackFacet.class);
-        }
-
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preDirty(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postDirty(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preDelete(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postDelete(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preClear(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postClear(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void preDetach(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.PRE, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    @Override
-    public void postDetach(InstanceLifecycleEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug(logString(Phase.POST, event));
-        }
-        if (isSuspended()) {
-            LOG.debug(" [currently suspended - ignoring]");
-            return;
-        }
-        ensureRootObject(event);
-        ensureFrameworksInAgreement(event);
-    }
-
-    // /////////////////////////////////////////////////////////
-    // SuspendListener
-    // /////////////////////////////////////////////////////////
-
-    @Override
-    public boolean isSuspended() {
-        return suspended;
-    }
-
-    @Override
-    public void setSuspended(boolean suspended) {
-        this.suspended = suspended;
-    }
-
-    // /////////////////////////////////////////////////////////
-    // Helpers
-    // /////////////////////////////////////////////////////////
-
-    private void ensureFrameworksInAgreement(InstanceLifecycleEvent event) {
-        final PersistenceCapable pojo = persistenceCapableFor(event);
-        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
-        final Oid oid = adapter.getOid();
-
-        if(!pojo.jdoIsPersistent()) {
-            // make sure the adapter is transient
-            if (!adapter.getResolveState().isTransient()) {
-                throw new IsisException(MessageFormat.format("adapter is in invalid state; should be {0} but is {1}", ResolveState.TRANSIENT, adapter.getResolveState()));
-            }
-
-            // make sure the oid is transient
-            if (!oid.isTransient()) {
-                throw new IsisException(MessageFormat.format("Not transient: oid={0}, for {1}", oid, pojo));
-            }
-
-        } else {
-            // make sure the adapter is persistent
-            if (!adapter.getResolveState().representsPersistent()) {
-                throw new IsisException(MessageFormat.format("adapter is in invalid state; should be in a persistent state but is {1}", ResolveState.RESOLVED, adapter.getResolveState()));
-            }
-
-            // make sure the oid is persistent
-            if (oid.isTransient()) {
-                throw new IsisException(MessageFormat.format("Transient: oid={0}, for {1}", oid, pojo));
-            }
-
-        }
-    }
-
-    // make sure the entity is a root
-    // TODO: will probably need to handle aggregated entities at some point...
-    private void ensureRootObject(InstanceLifecycleEvent event) {
-        final PersistenceCapable pojo2 = persistenceCapableFor(event);
-        final ObjectAdapter adapter2 = getAdapterManager().getAdapterFor(pojo2);
-        final Oid oid2 = adapter2.getOid();
-        if (!(oid2 instanceof RootOid)) {
-            throw new IsisException(MessageFormat.format("Not a RootOid: oid={0}, for {1}", oid2, pojo2));
-        }
-    }
-
-
-    
-    private enum Phase {
-        PRE, POST
-    }
-    
-    private static Map<Integer, LifecycleEventType> events = Maps.newHashMap();
-
-    private enum LifecycleEventType {
-        CREATE(0), LOAD(1), STORE(2), CLEAR(3), DELETE(4), DIRTY(5), DETACH(6), ATTACH(7);
-
-        private LifecycleEventType(int code) {
-            events.put(code, this);
-        }
-
-        public static LifecycleEventType lookup(int code) {
-            return events.get(code);
-        }
-    }
-
-    private static String logString(Phase phase, InstanceLifecycleEvent event) {
-        return phase + " " + LifecycleEventType.lookup(event.getEventType()) + ": pojo " + event.getSource();
-    }
-
-    private static void clearDirtyFor(final ObjectAdapter adapter) {
-        adapter.getSpecification().clearDirty(adapter);
-    }
-
-    private static PersistenceCapable persistenceCapableFor(InstanceLifecycleEvent event) {
-        return (PersistenceCapable)event.getSource();
-    }
-
-    @SuppressWarnings("unused")
-    private static Object jdoObjectIdFor(InstanceLifecycleEvent event) {
-        PersistenceCapable persistenceCapable = persistenceCapableFor(event);
-        Object jdoObjectId = persistenceCapable.jdoGetObjectId();
-        return jdoObjectId;
-    }
-
-    // /////////////////////////////////////////////////////////
-    // Dependencies (from context)
-    // /////////////////////////////////////////////////////////
-
-    protected AdapterManagerExtended getAdapterManager() {
-        return getPersistenceSession().getAdapterManager();
-    }
-
-    protected OidGenerator getOidGenerator() {
-        return getPersistenceSession().getOidGenerator();
-    }
-
-    protected PersistenceSession getPersistenceSession() {
-        return IsisContext.getPersistenceSession();
-    }
-
-}
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence;
+
+import java.text.MessageFormat;
+import java.util.Map;
+
+import javax.jdo.listener.AttachLifecycleListener;
+import javax.jdo.listener.ClearLifecycleListener;
+import javax.jdo.listener.CreateLifecycleListener;
+import javax.jdo.listener.DeleteLifecycleListener;
+import javax.jdo.listener.DetachLifecycleListener;
+import javax.jdo.listener.DirtyLifecycleListener;
+import javax.jdo.listener.InstanceLifecycleEvent;
+import javax.jdo.listener.LoadLifecycleListener;
+import javax.jdo.listener.StoreLifecycleListener;
+import javax.jdo.spi.PersistenceCapable;
+
+import com.google.common.collect.Maps;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.facets.object.callbacks.CallbackUtils;
+import org.apache.isis.core.metamodel.facets.object.callbacks.PersistedCallbackFacet;
+import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatedCallbackFacet;
+import org.apache.isis.runtimes.dflt.runtime.persistence.PersistorUtil;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.AdapterManagerExtended;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionHydrator;
+
+public class IsisLifecycleListener implements AttachLifecycleListener, ClearLifecycleListener, CreateLifecycleListener, DeleteLifecycleListener, DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLifecycleListener, SuspendableListener {
+
+    private static final Logger LOG = Logger.getLogger(IsisLifecycleListener.class);
+
+    private boolean suspended;
+
+    @Override
+    public void postCreate(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+
+        ensureRootObject(event);
+
+        final PersistenceCapable pojo = persistenceCapableFor(event);
+        
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
+        final RootOid transientOid = (RootOid) adapter.getOid();
+        final RootOid persistentOid = getOidGenerator().createPersistent(pojo, transientOid);
+
+        // most of the magic is here...
+        getAdapterManager().remapAsPersistent(adapter, persistentOid);
+
+        clearDirtyFor(adapter);
+        CallbackUtils.callCallback(adapter, PersistedCallbackFacet.class);
+
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preAttach(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postAttach(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postLoad(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        
+        final PersistenceCapable pojo1 = persistenceCapableFor(event);
+        
+        final RootOid oid ;
+        final ObjectAdapter existingAdapterIfAny = getAdapterManager().getAdapterFor(pojo1);
+        if(existingAdapterIfAny != null) {
+            ensureRootObject(event);
+            oid = (RootOid) existingAdapterIfAny.getOid();
+        } else {
+            final Object pojo = persistenceCapableFor(event);
+            
+            final OidGenerator oidGenerator = getOidGenerator();
+            oid = oidGenerator.createPersistent(pojo, null);
+            
+            PersistenceSessionHydrator hydrator = getPersistenceSession();
+            ObjectAdapter adapter = hydrator.recreateAdapter(oid, pojo);
+            PersistorUtil.startResolving(adapter);
+            PersistorUtil.endResolving(adapter);
+        }
+
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preStore(InstanceLifecycleEvent event) {
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postStore(InstanceLifecycleEvent event) {
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+
+        ensureRootObject(event);
+
+        final PersistenceCapable pojo = persistenceCapableFor(event);
+        
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
+
+        clearDirtyFor(adapter);
+        CallbackUtils.callCallback(adapter, UpdatedCallbackFacet.class);
+
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preDirty(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postDirty(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preDelete(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postDelete(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preClear(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postClear(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void preDetach(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.PRE, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    @Override
+    public void postDetach(InstanceLifecycleEvent event) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(logString(Phase.POST, event));
+        }
+        if (isSuspended()) {
+            LOG.debug(" [currently suspended - ignoring]");
+            return;
+        }
+        ensureRootObject(event);
+        ensureFrameworksInAgreement(event);
+    }
+
+    // /////////////////////////////////////////////////////////
+    // SuspendListener
+    // /////////////////////////////////////////////////////////
+
+    @Override
+    public boolean isSuspended() {
+        return suspended;
+    }
+
+    @Override
+    public void setSuspended(boolean suspended) {
+        this.suspended = suspended;
+    }
+
+    // /////////////////////////////////////////////////////////
+    // Helpers
+    // /////////////////////////////////////////////////////////
+
+    private void ensureFrameworksInAgreement(InstanceLifecycleEvent event) {
+        final PersistenceCapable pojo = persistenceCapableFor(event);
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
+        final Oid oid = adapter.getOid();
+
+        if(!pojo.jdoIsPersistent()) {
+            // make sure the adapter is transient
+            if (!adapter.getResolveState().isTransient()) {
+                throw new IsisException(MessageFormat.format("adapter is in invalid state; should be {0} but is {1}", ResolveState.TRANSIENT, adapter.getResolveState()));
+            }
+
+            // make sure the oid is transient
+            if (!oid.isTransient()) {
+                throw new IsisException(MessageFormat.format("Not transient: oid={0}, for {1}", oid, pojo));
+            }
+
+        } else {
+            // make sure the adapter is persistent
+            if (!adapter.getResolveState().representsPersistent()) {
+                throw new IsisException(MessageFormat.format("adapter is in invalid state; should be in a persistent state but is {1}", ResolveState.RESOLVED, adapter.getResolveState()));
+            }
+
+            // make sure the oid is persistent
+            if (oid.isTransient()) {
+                throw new IsisException(MessageFormat.format("Transient: oid={0}, for {1}", oid, pojo));
+            }
+
+        }
+    }
+
+    // make sure the entity is known to Isis and is a root
+    // TODO: will probably need to handle aggregated entities at some point...
+    private void ensureRootObject(InstanceLifecycleEvent event) {
+        final PersistenceCapable pojo = persistenceCapableFor(event);
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
+        if(adapter == null) {
+            throw new IsisException(MessageFormat.format("Object not yet known to Isis: {0}", pojo));
+        }
+        final Oid oid = adapter.getOid();
+        if (!(oid instanceof RootOid)) {
+            throw new IsisException(MessageFormat.format("Not a RootOid: oid={0}, for {1}", oid, pojo));
+        }
+    }
+
+
+
+    private void ensureObjectNotLoaded(InstanceLifecycleEvent event) {
+        final PersistenceCapable pojo = persistenceCapableFor(event);
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(pojo);
+        if(adapter != null) {
+            final Oid oid = adapter.getOid();
+            throw new IsisException(MessageFormat.format("Object is already mapped in Isis: oid={0}, for {1}", oid, pojo));
+        }
+    }
+
+    
+    private enum Phase {
+        PRE, POST
+    }
+    
+    private static Map<Integer, LifecycleEventType> events = Maps.newHashMap();
+
+    private enum LifecycleEventType {
+        CREATE(0), LOAD(1), STORE(2), CLEAR(3), DELETE(4), DIRTY(5), DETACH(6), ATTACH(7);
+
+        private LifecycleEventType(int code) {
+            events.put(code, this);
+        }
+
+        public static LifecycleEventType lookup(int code) {
+            return events.get(code);
+        }
+    }
+
+    private static String logString(Phase phase, InstanceLifecycleEvent event) {
+        return phase + " " + LifecycleEventType.lookup(event.getEventType()) + ": pojo " + event.getSource();
+    }
+
+    private static void clearDirtyFor(final ObjectAdapter adapter) {
+        adapter.getSpecification().clearDirty(adapter);
+    }
+
+    private static PersistenceCapable persistenceCapableFor(InstanceLifecycleEvent event) {
+        return (PersistenceCapable)event.getSource();
+    }
+
+    @SuppressWarnings("unused")
+    private static Object jdoObjectIdFor(InstanceLifecycleEvent event) {
+        PersistenceCapable persistenceCapable = persistenceCapableFor(event);
+        Object jdoObjectId = persistenceCapable.jdoGetObjectId();
+        return jdoObjectId;
+    }
+
+    // /////////////////////////////////////////////////////////
+    // Dependencies (from context)
+    // /////////////////////////////////////////////////////////
+
+    protected AdapterManagerExtended getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
+
+    protected OidGenerator getOidGenerator() {
+        return getPersistenceSession().getOidGenerator();
+    }
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/SuspendableListener.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/SuspendableListener.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/SuspendableListener.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/SuspendableListener.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/SuspendableListener.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/SuspendableListener.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/SuspendableListener.java Thu Jul 12 15:05:44 2012
@@ -1,9 +1,9 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence;
-
-public interface SuspendableListener {
-
-    boolean isSuspended();
-
-    void setSuspended(boolean suspend);
-
-}
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence;
+
+public interface SuspendableListener {
+
+    boolean isSuspended();
+
+    void setSuspended(boolean suspend);
+
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/AbstractDataNucleusObjectCommand.java Thu Jul 12 15:05:44 2012
@@ -1,26 +1,26 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.commands;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandAbstract;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public abstract class AbstractDataNucleusObjectCommand extends PersistenceCommandAbstract {
-    
-    private final PersistenceManager persistenceManager;
-
-    AbstractDataNucleusObjectCommand(final ObjectAdapter adapter,
-            final PersistenceManager persistenceManager) {
-        super(adapter);
-        this.persistenceManager = persistenceManager;
-        
-    }
-
-    protected PersistenceManager getPersistenceManager() {
-        return persistenceManager;
-    }
-    
-    public abstract void execute(final PersistenceCommandContext context);
-
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.commands;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandAbstract;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+
+public abstract class AbstractDataNucleusObjectCommand extends PersistenceCommandAbstract {
+    
+    private final PersistenceManager persistenceManager;
+
+    AbstractDataNucleusObjectCommand(final ObjectAdapter adapter,
+            final PersistenceManager persistenceManager) {
+        super(adapter);
+        this.persistenceManager = persistenceManager;
+        
+    }
+
+    protected PersistenceManager getPersistenceManager() {
+        return persistenceManager;
+    }
+    
+    public abstract void execute(final PersistenceCommandContext context);
+
 }
\ No newline at end of file

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusCreateObjectCommand.java Thu Jul 12 15:05:44 2012
@@ -1,37 +1,37 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.commands;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public class DataNucleusCreateObjectCommand extends AbstractDataNucleusObjectCommand implements CreateObjectCommand {
-
-    private static final Logger LOG = Logger
-            .getLogger(DataNucleusCreateObjectCommand.class);
-
-    public DataNucleusCreateObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
-        super(adapter, persistenceManager);
-    }
-
-
-    @Override
-    public void execute(final PersistenceCommandContext context) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("create object - executing command for: " + onAdapter());
-        }
-        final ObjectAdapter adapter = onAdapter();
-        final Object domainObject = adapter.getObject();
-
-        getPersistenceManager().makePersistent(domainObject);
-    }
-
-    @Override
-    public String toString() {
-        return "CreateObjectCommand [adapter=" + onAdapter() + "]";
-    }
-
-}
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.commands;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+
+public class DataNucleusCreateObjectCommand extends AbstractDataNucleusObjectCommand implements CreateObjectCommand {
+
+    private static final Logger LOG = Logger
+            .getLogger(DataNucleusCreateObjectCommand.class);
+
+    public DataNucleusCreateObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
+        super(adapter, persistenceManager);
+    }
+
+
+    @Override
+    public void execute(final PersistenceCommandContext context) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("create object - executing command for: " + onAdapter());
+        }
+        final ObjectAdapter adapter = onAdapter();
+        final Object domainObject = adapter.getObject();
+
+        getPersistenceManager().makePersistent(domainObject);
+    }
+
+    @Override
+    public String toString() {
+        return "CreateObjectCommand [adapter=" + onAdapter() + "]";
+    }
+
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusDeleteObjectCommand.java Thu Jul 12 15:05:44 2012
@@ -1,32 +1,32 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.commands;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public class DataNucleusDeleteObjectCommand extends AbstractDataNucleusObjectCommand implements DestroyObjectCommand {
-
-    private static final Logger LOG = Logger.getLogger(DataNucleusDeleteObjectCommand.class);
-
-    public DataNucleusDeleteObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
-        super(adapter, persistenceManager);
-    }
-
-    @Override
-    public void execute(final PersistenceCommandContext context) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("destroy object - executing command for " + onAdapter());
-        }
-        getPersistenceManager().deletePersistent(onAdapter().getObject());
-    }
-
-    @Override
-    public String toString() {
-        return "DestroyObjectCommand [adapter=" + onAdapter() + "]";
-    }
-
-}
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.commands;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+
+public class DataNucleusDeleteObjectCommand extends AbstractDataNucleusObjectCommand implements DestroyObjectCommand {
+
+    private static final Logger LOG = Logger.getLogger(DataNucleusDeleteObjectCommand.class);
+
+    public DataNucleusDeleteObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
+        super(adapter, persistenceManager);
+    }
+
+    @Override
+    public void execute(final PersistenceCommandContext context) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("destroy object - executing command for " + onAdapter());
+        }
+        getPersistenceManager().deletePersistent(onAdapter().getObject());
+    }
+
+    @Override
+    public String toString() {
+        return "DestroyObjectCommand [adapter=" + onAdapter() + "]";
+    }
+
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/commands/DataNucleusUpdateObjectCommand.java Thu Jul 12 15:05:44 2012
@@ -1,33 +1,33 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.commands;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-
-public class DataNucleusUpdateObjectCommand extends AbstractDataNucleusObjectCommand implements SaveObjectCommand {
-    private static final Logger LOG = Logger
-            .getLogger(DataNucleusDeleteObjectCommand.class);
-
-    public DataNucleusUpdateObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
-        super(adapter, persistenceManager);
-    }
-
-    @Override
-    public void execute(final PersistenceCommandContext context) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("save object - executing command for: " + onAdapter());
-        }
-        
-        // TODO: this might be a no-op; JDO doesn't seem to have an equivalent of JPA's merge() ...
-        // getEntityManager().merge(onAdapter().getObject());
-    }
-
-    @Override
-    public String toString() {
-        return "SaveObjectCommand [adapter=" + onAdapter() + "]";
-    }
-}
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.commands;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+
+public class DataNucleusUpdateObjectCommand extends AbstractDataNucleusObjectCommand implements SaveObjectCommand {
+    private static final Logger LOG = Logger
+            .getLogger(DataNucleusDeleteObjectCommand.class);
+
+    public DataNucleusUpdateObjectCommand(ObjectAdapter adapter, PersistenceManager persistenceManager) {
+        super(adapter, persistenceManager);
+    }
+
+    @Override
+    public void execute(final PersistenceCommandContext context) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("save object - executing command for: " + onAdapter());
+        }
+        
+        // TODO: this might be a no-op; JDO doesn't seem to have an equivalent of JPA's merge() ...
+        // getEntityManager().merge(onAdapter().getObject());
+    }
+
+    @Override
+    public String toString() {
+        return "SaveObjectCommand [adapter=" + onAdapter() + "]";
+    }
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindAllInstancesProcessor.java Thu Jul 12 15:05:44 2012
@@ -1,42 +1,38 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-
-import org.apache.commons.lang.ClassUtils;
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.lang.ClassUtil;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindAllInstances;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
-
-public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindAllInstances> {
-
-    private static final Logger LOG = Logger.getLogger(PersistenceQueryFindAllInstancesProcessor.class);
-
-    public PersistenceQueryFindAllInstancesProcessor(final AdapterManager adapterManager, final PersistenceManager persistenceManager) {
-        super(adapterManager, persistenceManager);
-    }
-
-    public List<ObjectAdapter> process(final PersistenceQueryFindAllInstances persistenceQuery) {
-
-        final ObjectSpecification specification = persistenceQuery.getSpecification();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("getInstances: class=" + specification.getFullIdentifier());
-        }
-        
-//        Class<?> cls = specification.getCorrespondingClass();
-//        final Query query = getPersistenceManager().newQuery(cls);
-        
-        final Query query = QueryUtil.createQuery(getPersistenceManager(), "o", null, specification, null);
-
-        final List<?> pojos = (List<?>) query.execute();
-        return loadAdapters(specification, pojos);
-    }
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindAllInstances;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+
+public class PersistenceQueryFindAllInstancesProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindAllInstances> {
+
+    private static final Logger LOG = Logger.getLogger(PersistenceQueryFindAllInstancesProcessor.class);
+
+    public PersistenceQueryFindAllInstancesProcessor(final AdapterManager adapterManager, final PersistenceManager persistenceManager) {
+        super(adapterManager, persistenceManager);
+    }
+
+    public List<ObjectAdapter> process(final PersistenceQueryFindAllInstances persistenceQuery) {
+
+        final ObjectSpecification specification = persistenceQuery.getSpecification();
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("getInstances: class=" + specification.getFullIdentifier());
+        }
+        
+        Class<?> cls = specification.getCorrespondingClass();
+        final Query query = getPersistenceManager().newQuery(cls);
+        
+        final List<?> pojos = (List<?>) query.execute();
+        return loadAdapters(specification, pojos);
+    }
+}
+
+// Copyright (c) Naked Objects Group Ltd.

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByPatternProcessor.java Thu Jul 12 15:05:44 2012
@@ -1,41 +1,41 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
-
-public class PersistenceQueryFindByPatternProcessor extends
-        PersistenceQueryProcessorAbstract<PersistenceQueryFindByPattern> {
-
-    public PersistenceQueryFindByPatternProcessor(
-            final AdapterManager objectManager, final PersistenceManager persistenceManager) {
-        super(objectManager, persistenceManager);
-    }
-
-    public List<ObjectAdapter> process(
-            final PersistenceQueryFindByPattern persistenceQuery) {
-
-        
-
-        
-//        final Object pojoPattern = persistenceQuery.getPattern().getObject();
-//        
-//        final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
-//        
-//        
-//        final CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
-//        
-//        final Query query = getEntityManager().createQuery(criteriaQuery);
-//        final List<?> results = query.getResultList();
-//        return loadAdapters(persistenceQuery.getSpecification(), results);
-        
-        throw new NotYetImplementedException();
-    }
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+
+public class PersistenceQueryFindByPatternProcessor extends
+        PersistenceQueryProcessorAbstract<PersistenceQueryFindByPattern> {
+
+    public PersistenceQueryFindByPatternProcessor(
+            final AdapterManager objectManager, final PersistenceManager persistenceManager) {
+        super(objectManager, persistenceManager);
+    }
+
+    public List<ObjectAdapter> process(
+            final PersistenceQueryFindByPattern persistenceQuery) {
+
+        
+
+        
+//        final Object pojoPattern = persistenceQuery.getPattern().getObject();
+//        
+//        final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
+//        
+//        
+//        final CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
+//        
+//        final Query query = getEntityManager().createQuery(criteriaQuery);
+//        final List<?> results = query.getResultList();
+//        return loadAdapters(persistenceQuery.getSpecification(), results);
+        
+        throw new NotYetImplementedException();
+    }
+}
+
+// Copyright (c) Naked Objects Group Ltd.

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindByTitleProcessor.java Thu Jul 12 15:05:44 2012
@@ -1,45 +1,45 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import javax.jdo.PersistenceManager;
-
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
-
-public class PersistenceQueryFindByTitleProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindByTitle> {
-
-    public PersistenceQueryFindByTitleProcessor(final AdapterManager adapterManager, final PersistenceManager persistenceManager) {
-        super(adapterManager, persistenceManager);
-    }
-
-    public List<ObjectAdapter> process(final PersistenceQueryFindByTitle persistenceQuery) {
-        final ObjectSpecification objectSpec = persistenceQuery.getSpecification();
-        final Class<?> correspondingClass = objectSpec.getCorrespondingClass();
-        return process(persistenceQuery, correspondingClass);
-    }
-
-    private <Z> List<ObjectAdapter> process(final PersistenceQueryFindByTitle persistenceQuery, Class<Z> correspondingClass) {
-        // TODO
-        throw new NotYetImplementedException();
-
-//        final CriteriaQuery<Z> criteriaQuery = getEntityManager().getCriteriaBuilder().createQuery(correspondingClass);
-//
-//        final ObjectSpecification objectSpec = persistenceQuery.getSpecification();
-//        final Root<Z> from = criteriaQuery.from(correspondingClass);
-//        
-//        final EntityType<Z> model = from.getModel();
-//        final SingularAttribute<? super Z, String> titleAttribute = model.getSingularAttribute("title", String.class);
-//        final Path<String> titlePath = from.get(titleAttribute);
-//        titlePath.equals(persistenceQuery.getTitle());
-//        
-//        final TypedQuery<Z> query = getPersistenceManager().createQuery(criteriaQuery);
-//        final List<Z> pojos = query.getResultList();
-//        return loadAdapters(objectSpec, pojos);
-    }
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+
+public class PersistenceQueryFindByTitleProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindByTitle> {
+
+    public PersistenceQueryFindByTitleProcessor(final AdapterManager adapterManager, final PersistenceManager persistenceManager) {
+        super(adapterManager, persistenceManager);
+    }
+
+    public List<ObjectAdapter> process(final PersistenceQueryFindByTitle persistenceQuery) {
+        final ObjectSpecification objectSpec = persistenceQuery.getSpecification();
+        final Class<?> correspondingClass = objectSpec.getCorrespondingClass();
+        return process(persistenceQuery, correspondingClass);
+    }
+
+    private <Z> List<ObjectAdapter> process(final PersistenceQueryFindByTitle persistenceQuery, Class<Z> correspondingClass) {
+        // TODO
+        throw new NotYetImplementedException();
+
+//        final CriteriaQuery<Z> criteriaQuery = getEntityManager().getCriteriaBuilder().createQuery(correspondingClass);
+//
+//        final ObjectSpecification objectSpec = persistenceQuery.getSpecification();
+//        final Root<Z> from = criteriaQuery.from(correspondingClass);
+//        
+//        final EntityType<Z> model = from.getModel();
+//        final SingularAttribute<? super Z, String> titleAttribute = model.getSingularAttribute("title", String.class);
+//        final Path<String> titlePath = from.get(titleAttribute);
+//        titlePath.equals(persistenceQuery.getTitle());
+//        
+//        final TypedQuery<Z> query = getPersistenceManager().createQuery(criteriaQuery);
+//        final List<Z> pojos = query.getResultList();
+//        return loadAdapters(objectSpec, pojos);
+    }
+}
+
+// Copyright (c) Naked Objects Group Ltd.

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryFindUsingApplibQueryProcessor.java Thu Jul 12 15:05:44 2012
@@ -1,88 +1,88 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.jdo.PersistenceManager;
-
-import com.google.common.collect.Maps;
-
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.services.container.query.QueryCardinality;
-import org.apache.isis.core.metamodel.spec.ObjectAdapterUtils;
-import org.apache.isis.runtimes.dflt.objectstores.datanucleus.DataNucleusObjectStore;
-import org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.query.JdoNamedQuery;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindUsingApplibQueryDefault;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
-
-public class PersistenceQueryFindUsingApplibQueryProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindUsingApplibQueryDefault> {
-    
-    public PersistenceQueryFindUsingApplibQueryProcessor(final AdapterManager objectManager, final PersistenceManager persistenceManager) {
-        super(objectManager, persistenceManager);
-    }
-
-    public List<ObjectAdapter> process(final PersistenceQueryFindUsingApplibQueryDefault persistenceQuery) {
-        final String queryName = persistenceQuery.getQueryName();
-        final Map<String, Object> map = unwrap(persistenceQuery.getArgumentsAdaptersByParameterName());
-        final QueryCardinality cardinality = persistenceQuery.getCardinality();
-        final List<?> results = getResults(queryName, map, cardinality);
-        return loadAdapters(persistenceQuery.getSpecification(), results);
-    }
-
-    public List<?> getResults(final String queryName, final Map<String, Object> argumentsByParameterName, final QueryCardinality cardinality) {
-        final JdoNamedQuery namedQuery = getNamedQuery(queryName);
-
-        throw new NotYetImplementedException();
-        
-//        final PersistenceManager persistenceManager = getJdoObjectStore().getPersistenceManager();
-//        final Query emQuery = persistenceManager.createNamedQuery(namedQuery.getName());
-//        
-//        for (final Map.Entry<String, Object> argumentByParameterName : argumentsByParameterName.entrySet()) {
-//            final String parameterName = argumentByParameterName.getKey();
-//            final Object argument = argumentByParameterName.getValue();
-//            emQuery.setParameter(parameterName, argument);
-//        }
-//
-//        if (cardinality == QueryCardinality.MULTIPLE) {
-//            return emQuery.getResultList();
-//        }
-//        if (cardinality == QueryCardinality.SINGLE) {
-//            final Object result = emQuery.getSingleResult();
-//            return result == null ? Collections.EMPTY_LIST : Arrays.asList(result);
-//        }
-//        // should never get here
-//        return Collections.EMPTY_LIST;
-    }
-
-    private JdoNamedQuery getNamedQuery(final String queryName) {
-        return getJdoObjectStore().getNamedQuery(queryName);
-    }
-
-    private static Map<String, Object> unwrap(final Map<String, ObjectAdapter> argumentAdaptersByParameterName) {
-        final Map<String, Object> argumentsByParameterName = Maps.newHashMap();
-        for (final String parameterName : argumentAdaptersByParameterName.keySet()) {
-            final ObjectAdapter argumentAdapter = argumentAdaptersByParameterName.get(parameterName);
-            final Object argument = ObjectAdapterUtils.unwrapObject(argumentAdapter);
-            argumentsByParameterName.put(parameterName, argument);
-        }
-        return argumentsByParameterName;
-    }
-
-    // /////////////////////////////////////////////////////////////
-    // Dependencies (from context)
-    // /////////////////////////////////////////////////////////////
-
-    private DataNucleusObjectStore getJdoObjectStore() {
-        return (DataNucleusObjectStore) getPersistenceSession().getObjectStore();
-    }
-
-    private PersistenceSession getPersistenceSession() {
-        return IsisContext.getPersistenceSession();
-    }
-
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.jdo.PersistenceManager;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.services.container.query.QueryCardinality;
+import org.apache.isis.core.metamodel.spec.ObjectAdapterUtils;
+import org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.DataNucleusObjectStore;
+import org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.query.JdoNamedQuery;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindUsingApplibQueryDefault;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+
+public class PersistenceQueryFindUsingApplibQueryProcessor extends PersistenceQueryProcessorAbstract<PersistenceQueryFindUsingApplibQueryDefault> {
+    
+    public PersistenceQueryFindUsingApplibQueryProcessor(final AdapterManager objectManager, final PersistenceManager persistenceManager) {
+        super(objectManager, persistenceManager);
+    }
+
+    public List<ObjectAdapter> process(final PersistenceQueryFindUsingApplibQueryDefault persistenceQuery) {
+        final String queryName = persistenceQuery.getQueryName();
+        final Map<String, Object> map = unwrap(persistenceQuery.getArgumentsAdaptersByParameterName());
+        final QueryCardinality cardinality = persistenceQuery.getCardinality();
+        final List<?> results = getResults(queryName, map, cardinality);
+        return loadAdapters(persistenceQuery.getSpecification(), results);
+    }
+
+    public List<?> getResults(final String queryName, final Map<String, Object> argumentsByParameterName, final QueryCardinality cardinality) {
+        final JdoNamedQuery namedQuery = getNamedQuery(queryName);
+
+        throw new NotYetImplementedException();
+        
+//        final PersistenceManager persistenceManager = getJdoObjectStore().getPersistenceManager();
+//        final Query emQuery = persistenceManager.createNamedQuery(namedQuery.getName());
+//        
+//        for (final Map.Entry<String, Object> argumentByParameterName : argumentsByParameterName.entrySet()) {
+//            final String parameterName = argumentByParameterName.getKey();
+//            final Object argument = argumentByParameterName.getValue();
+//            emQuery.setParameter(parameterName, argument);
+//        }
+//
+//        if (cardinality == QueryCardinality.MULTIPLE) {
+//            return emQuery.getResultList();
+//        }
+//        if (cardinality == QueryCardinality.SINGLE) {
+//            final Object result = emQuery.getSingleResult();
+//            return result == null ? Collections.EMPTY_LIST : Arrays.asList(result);
+//        }
+//        // should never get here
+//        return Collections.EMPTY_LIST;
+    }
+
+    private JdoNamedQuery getNamedQuery(final String queryName) {
+        return getJdoObjectStore().getNamedQuery(queryName);
+    }
+
+    private static Map<String, Object> unwrap(final Map<String, ObjectAdapter> argumentAdaptersByParameterName) {
+        final Map<String, Object> argumentsByParameterName = Maps.newHashMap();
+        for (final String parameterName : argumentAdaptersByParameterName.keySet()) {
+            final ObjectAdapter argumentAdapter = argumentAdaptersByParameterName.get(parameterName);
+            final Object argument = ObjectAdapterUtils.unwrapObject(argumentAdapter);
+            argumentsByParameterName.put(parameterName, argument);
+        }
+        return argumentsByParameterName;
+    }
+
+    // /////////////////////////////////////////////////////////////
+    // Dependencies (from context)
+    // /////////////////////////////////////////////////////////////
+
+    private DataNucleusObjectStore getJdoObjectStore() {
+        return (DataNucleusObjectStore) getPersistenceSession().getObjectStore();
+    }
+
+    private PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+}
+
+// Copyright (c) Naked Objects Group Ltd.

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessor.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessor.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java Thu Jul 12 15:05:44 2012
@@ -1,12 +1,12 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
-
-public interface PersistenceQueryProcessor<T extends PersistenceQuery> {
-	List<ObjectAdapter> process(T query);
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
+
+public interface PersistenceQueryProcessor<T extends PersistenceQuery> {
+	List<ObjectAdapter> process(T query);
+}
+
+// Copyright (c) Naked Objects Group Ltd.

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java Thu Jul 12 15:05:44 2012
@@ -1,59 +1,65 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
-import javax.jdo.metadata.TypeMetadata;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.core.commons.ensure.Assert;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
-
-public abstract class PersistenceQueryProcessorAbstract<T extends PersistenceQuery>
-        implements PersistenceQueryProcessor<T> {
-
-    private final AdapterManager adapterManager;
-    private final PersistenceManager persistenceManager;
-
-    protected PersistenceQueryProcessorAbstract(
-            final AdapterManager objectManager , final PersistenceManager persistenceManager) {
-        this.adapterManager = objectManager;
-        this.persistenceManager = persistenceManager;
-    }
-
-    protected PersistenceManagerFactory getPersistenceManagerFactory() {
-        return getPersistenceManager().getPersistenceManagerFactory();
-    }
-
-    protected PersistenceManager getPersistenceManager() {
-        return persistenceManager;
-    }
-    
-    protected TypeMetadata getTypeMetadata(final String classFullName) {
-        return getPersistenceManagerFactory().getMetadata(classFullName);
-    }
-
-
-    protected List<ObjectAdapter> loadAdapters(
-            final ObjectSpecification specification, final List<?> pojos) {
-        final List<ObjectAdapter> adapters = Lists.newArrayList();
-        for (final Object pojo : pojos) {
-            ObjectAdapter adapter = adapterManager.getAdapterFor(pojo);
-            Assert.assertNotNull(adapter);
-            adapters.add( adapter );
-        }
-        return adapters;
-    }
-
-    protected AdapterManager getAdapterManager() {
-        return adapterManager;
-    }
-
-}
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.listener.InstanceLifecycleEvent;
+import javax.jdo.listener.InstanceLifecycleListener;
+import javax.jdo.metadata.TypeMetadata;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.IsisLifecycleListener;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
+
+public abstract class PersistenceQueryProcessorAbstract<T extends PersistenceQuery>
+        implements PersistenceQueryProcessor<T> {
+
+    private final AdapterManager adapterManager;
+    private final PersistenceManager persistenceManager;
+
+    protected PersistenceQueryProcessorAbstract(
+            final AdapterManager objectManager , final PersistenceManager persistenceManager) {
+        this.adapterManager = objectManager;
+        this.persistenceManager = persistenceManager;
+    }
+
+    protected PersistenceManagerFactory getPersistenceManagerFactory() {
+        return getPersistenceManager().getPersistenceManagerFactory();
+    }
+
+    protected PersistenceManager getPersistenceManager() {
+        return persistenceManager;
+    }
+    
+    protected TypeMetadata getTypeMetadata(final String classFullName) {
+        return getPersistenceManagerFactory().getMetadata(classFullName);
+    }
+
+    /**
+     * Traversing the provided list causes the
+     * {@link IsisLifecycleListener#postLoad(InstanceLifecycleEvent) {
+     * to be called.
+     * @param specification
+     * @param pojos returned from DataNucleus.
+     */
+    protected List<ObjectAdapter> loadAdapters(
+            final ObjectSpecification specification, final List<?> pojos) {
+        final List<ObjectAdapter> adapters = Lists.newArrayList();
+        for (final Object pojo : pojos) {
+            ObjectAdapter adapter = adapterManager.getAdapterFor(pojo);
+            Assert.assertNotNull(adapter);
+            adapters.add(adapter);
+        }
+        return adapters;
+    }
+
+    protected AdapterManager getAdapterManager() {
+        return adapterManager;
+    }
+}

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/QueryUtil.java (from r1359418, incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/QueryUtil.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/QueryUtil.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/QueryUtil.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/QueryUtil.java&r1=1359418&r2=1360713&rev=1360713&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/datanucleus/persistence/queries/QueryUtil.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/persistence/queries/QueryUtil.java Thu Jul 12 15:05:44 2012
@@ -1,71 +1,71 @@
-package org.apache.isis.runtimes.dflt.objectstores.datanucleus.persistence.queries;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-
-public final class QueryUtil {
-
-    private static final Logger LOG = Logger.getLogger(QueryUtil.class);
-
-    private QueryUtil() {}
-
-    public static Query createQuery(
-            final PersistenceManager persistenceManager,
-            final String alias,
-            final String select,
-            final ObjectSpecification specification,
-            final String whereClause) {
-
-        final StringBuilder buf = new StringBuilder(128);
-        appendSelect(buf, select, alias);
-        appendFrom(buf, specification, alias);
-        appendWhere(buf, whereClause);
-
-        final String queryString = buf.toString();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("creating query: " + queryString);
-        }
-
-        return persistenceManager.newQuery(queryString);
-    }
-
-    private static StringBuilder appendSelect(
-            final StringBuilder buf,
-            final String select, 
-            String alias) {
-        if (select != null) {
-            buf.append(select);
-        } else {
-            buf.append("select ");
-            // not required in JDOQL (cf JPA QL)
-            // buf.append(alias);
-        }
-        buf.append(" ");
-        return buf;
-    }
-
-    private static void appendWhere(StringBuilder buf, String whereClause) {
-        if(whereClause == null) {
-            return;
-        }
-        buf.append(" where ").append(whereClause);
-    }
-
-
-    private static StringBuilder appendFrom(
-            final StringBuilder buf,
-            final ObjectSpecification specification,
-            final String alias) {
-        return buf.append("from ")
-                .append(specification.getFullIdentifier())
-                .append(" as ")
-                .append(alias);
-    }
-}
-
-
-// Copyright (c) Naked Objects Group Ltd.
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.persistence.queries;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public final class QueryUtil {
+
+    private static final Logger LOG = Logger.getLogger(QueryUtil.class);
+
+    private QueryUtil() {}
+
+    public static Query createQuery(
+            final PersistenceManager persistenceManager,
+            final String alias,
+            final String select,
+            final ObjectSpecification specification,
+            final String whereClause) {
+
+        final StringBuilder buf = new StringBuilder(128);
+        appendSelect(buf, select, alias);
+        appendFrom(buf, specification, alias);
+        appendWhere(buf, whereClause);
+
+        final String queryString = buf.toString();
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("creating query: " + queryString);
+        }
+
+        return persistenceManager.newQuery(queryString);
+    }
+
+    private static StringBuilder appendSelect(
+            final StringBuilder buf,
+            final String select, 
+            String alias) {
+        if (select != null) {
+            buf.append(select);
+        } else {
+            buf.append("select ");
+            // not required in JDOQL (cf JPA QL)
+            // buf.append(alias);
+        }
+        buf.append(" ");
+        return buf;
+    }
+
+    private static void appendWhere(StringBuilder buf, String whereClause) {
+        if(whereClause == null) {
+            return;
+        }
+        buf.append(" where ").append(whereClause);
+    }
+
+
+    private static StringBuilder appendFrom(
+            final StringBuilder buf,
+            final ObjectSpecification specification,
+            final String alias) {
+        return buf.append("from ")
+                .append(specification.getFullIdentifier())
+                .append(" as ")
+                .append(alias);
+    }
+}
+
+
+// Copyright (c) Naked Objects Group Ltd.



Mime
View raw message