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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 07c0603  ISIS-1841 fixes invalid ObjectAdapter recreation
     new 7f4c902  Merge branch 'master' of https://github.com/apache/isis
07c0603 is described below

commit 07c06039e91069c53a562c0e15be6343e74fb12c
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Wed Mar 7 12:40:38 2018 +0100

    ISIS-1841 fixes invalid ObjectAdapter recreation
    
    reason: a public method with specialising argument got hidden behind
    PersistenceSession, which recently was refactored from concrete class
    into an interface:
    
    Adding this declaration to the interface fixed this.
    ObjectAdapter adapterFor(RootOid rootOid);
    
    slightly cleaning up PersistenceSession4+5 by introducing a common
    abstract base class
    de-duplicate: interface PersistenceQueryProcessor
    removing finalize hooks: don't interfere with garbage collection
---
 .../system/persistence/PersistenceSession4.java    | 375 +++-----------------
 .../queries/PersistenceQueryProcessor.java         |  30 --
 .../system/persistence/PersistenceSession5.java    | 376 +++------------------
 .../system/persistence/PersistenceSession.java     | 106 ++++--
 .../system/persistence/PersistenceSessionBase.java | 277 +++++++++++++++
 .../queries/PersistenceQueryProcessor.java         |   0
 6 files changed, 451 insertions(+), 713 deletions(-)

diff --git 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
index 3a9404c..691e06e 100644
--- 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
+++ 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
@@ -44,25 +44,15 @@ import org.apache.isis.applib.internal.collections._Maps;
 import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.services.bookmark.Bookmark;
 import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.applib.services.clock.ClockService;
 import org.apache.isis.applib.services.command.Command;
-import org.apache.isis.applib.services.command.CommandContext;
-import org.apache.isis.applib.services.command.spi.CommandService;
 import org.apache.isis.applib.services.eventbus.AbstractLifecycleEvent;
-import org.apache.isis.applib.services.eventbus.EventBusService;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
-import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.iactn.Interaction;
-import org.apache.isis.applib.services.iactn.InteractionContext;
-import org.apache.isis.applib.services.metrics.MetricsService;
-import org.apache.isis.applib.services.user.UserService;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.commons.ensure.Assert;
 import org.apache.isis.core.commons.ensure.IsisAssertException;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.commons.factory.InstanceUtil;
-import org.apache.isis.core.commons.util.ToString;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
@@ -101,7 +91,6 @@ import 
org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.Contributed;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.core.runtime.persistence.FixturesInstalledFlag;
 import org.apache.isis.core.runtime.persistence.NotPersistableException;
 import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
@@ -114,9 +103,7 @@ import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyO
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
 import 
org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
 import 
org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindUsingApplibQueryDefault;
-import org.apache.isis.core.runtime.runner.opts.OptionHandlerFixtureAbstract;
 import org.apache.isis.core.runtime.services.RequestScopedService;
-import 
org.apache.isis.core.runtime.services.changes.ChangedObjectsServiceInternal;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.OidAdapterHashMap;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.PojoAdapterHashMap;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.RootAndCollectionAdapters;
@@ -144,76 +131,12 @@ import com.google.common.collect.Maps;
  * and maintains an identity map of {@link ObjectAdapter adapter}s and {@link 
Oid
  * identities} for each and every POJO that is being used by the framework.
  */
-public class PersistenceSession4 implements PersistenceSession,
-        IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
+public class PersistenceSession4 extends PersistenceSessionBase
+implements IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
 
-    // -- constants
     private static final Logger LOG = 
LoggerFactory.getLogger(PersistenceSession4.class);
 
     /**
-     * @see #isFixturesInstalled()
-     */
-    public static final String INSTALL_FIXTURES_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_INSTALL_FIXTURES_KEY;
-    public static final boolean INSTALL_FIXTURES_DEFAULT = false;
-
-    private static final String ROOT_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_ROOT_KEY;
-
-    /**
-     * Append regular <a 
href="http://www.datanucleus.org/products/accessplatform/persistence_properties.html";>datanucleus
 properties</a> to this key
-     */
-    public static final String DATANUCLEUS_PROPERTIES_ROOT = ROOT_KEY + 
"impl.";
-
-    //defined on PersistenceSession interface 
-    //public static final String SERVICE_IDENTIFIER = "1";
-    
-
-    // -- constructor, fields, finalize()
-
-    private final FixturesInstalledFlag fixturesInstalledFlag;
-
-    private final PersistenceQueryFactory persistenceQueryFactory;
-    private final IsisConfiguration configuration;
-    private final SpecificationLoader specificationLoader;
-    private final AuthenticationSession authenticationSession;
-
-    private final ServicesInjector servicesInjector;
-
-    private final CommandContext commandContext;
-    private final CommandService commandService;
-
-    private final InteractionContext interactionContext;
-    private final EventBusService eventBusService ;
-    private final ChangedObjectsServiceInternal changedObjectsServiceInternal;
-    private final FactoryService factoryService;
-    private final MetricsService metricsService;
-    private final ClockService clockService;
-    private final UserService userService;
-
-
-    /**
-     * Used to create the {@link #persistenceManager} when {@link #open()}ed.
-     */
-    private final PersistenceManagerFactory jdoPersistenceManagerFactory;
-
-    // not final only for testing purposes
-    private IsisTransactionManager transactionManager;
-
-
-    /**
-     * populated only when {@link #open()}ed.
-     */
-    private PersistenceManager persistenceManager;
-
-    /**
-     * populated only when {@link #open()}ed.
-     */
-    private final Map<Class<?>, PersistenceQueryProcessor<?>> 
persistenceQueryProcessorByClass = _Maps.newHashMap();
-
-
-    private final boolean concurrencyCheckingGloballyEnabled;
-
-
-    /**
      * Initialize the object store so that calls to this object store access
      * persisted objects and persist changes to the object that are saved.
      */
@@ -222,65 +145,17 @@ public class PersistenceSession4 implements 
PersistenceSession,
             final AuthenticationSession authenticationSession,
             final PersistenceManagerFactory jdoPersistenceManagerFactory,
             final FixturesInstalledFlag fixturesInstalledFlag) {
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("creating {}", this);
-        }
-
-        this.servicesInjector = servicesInjector;
-        this.jdoPersistenceManagerFactory = jdoPersistenceManagerFactory;
-        this.fixturesInstalledFlag = fixturesInstalledFlag;
-
-        // injected
-        this.configuration = 
servicesInjector.getConfigurationServiceInternal();
-        this.specificationLoader = servicesInjector.getSpecificationLoader();
-        this.authenticationSession = authenticationSession;
-
-        this.commandContext = lookupService(CommandContext.class);
-        this.commandService = lookupService(CommandService.class);
-        this.interactionContext = lookupService(InteractionContext.class);
-        this.eventBusService = lookupService(EventBusService.class);
-        this.changedObjectsServiceInternal = 
lookupService(ChangedObjectsServiceInternal.class);
-        this.metricsService = lookupService(MetricsService.class);
-        this.factoryService = lookupService(FactoryService.class);
-        this.clockService = lookupService(ClockService.class);
-        this.userService = lookupService(UserService.class);
-
-        // sub-components
-        final AdapterManager adapterManager = this;
-        this.persistenceQueryFactory = new 
PersistenceQueryFactory(adapterManager, this.specificationLoader);
-        this.transactionManager = new IsisTransactionManager(this, 
authenticationSession, servicesInjector);
-
-        this.state = State.NOT_INITIALIZED;
-
-        final boolean concurrencyCheckingGloballyDisabled =
-                
this.configuration.getBoolean("isis.persistor.disableConcurrencyChecking", 
false);
-        this.concurrencyCheckingGloballyEnabled = 
!concurrencyCheckingGloballyDisabled;
-
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        super.finalize();
-        LOG.debug("finalizing persistence session");
+       
+       super(servicesInjector, authenticationSession, 
jdoPersistenceManagerFactory, fixturesInstalledFlag);
     }
 
-    
-
-
     // -- open
 
     /**
-     * Only populated once {@link #open()}'d
-     */
-    public PersistenceManager getPersistenceManager() {
-        return persistenceManager;
-    }
-
-    /**
      * Injects components, calls open on subcomponents, and then creates 
service
      * adapters.
      */
+    @Override
     public void open() {
         ensureNotOpened();
 
@@ -394,6 +269,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * <p>
      * The corresponding DataNucleus entity is then closed.
      */
+    @Override
     public void close() {
 
         if (state == State.CLOSED) {
@@ -512,12 +388,12 @@ public class PersistenceSession4 implements 
PersistenceSession,
     
 
     // -- QuerySubmitter impl, findInstancesInTransaction
-
+    @Override
     public <T> List<ObjectAdapter> allMatchingQuery(final Query<T> query) {
         final ObjectAdapter instances = findInstancesInTransaction(query, 
QueryCardinality.MULTIPLE);
         return CollectionFacetUtils.convertToAdapterList(instances);
     }
-
+    @Override
     public <T> ObjectAdapter firstMatchingQuery(final Query<T> query) {
         final ObjectAdapter instances = findInstancesInTransaction(query, 
QueryCardinality.SINGLE);
         final List<ObjectAdapter> list = 
CollectionFacetUtils.convertToAdapterList(instances);
@@ -593,41 +469,6 @@ public class PersistenceSession4 implements 
PersistenceSession,
         return persistenceQueryProcessor.process((Q) persistenceQuery);
     }
 
-    public IsisConfiguration getConfiguration() {
-        return configuration;
-    }
-
-
-    
-
-    // -- State
-
-    private enum State {
-        NOT_INITIALIZED, OPEN, CLOSED
-    }
-
-    private State state;
-
-    protected void ensureNotOpened() {
-        if (state != State.NOT_INITIALIZED) {
-            throw new IllegalStateException("Persistence session has already 
been initialized");
-        }
-    }
-
-    public void ensureOpened() {
-        ensureStateIs(State.OPEN);
-    }
-
-    private void ensureStateIs(final State stateRequired) {
-        if (state == stateRequired) {
-            return;
-        }
-        throw new IllegalStateException("State is: " + state + "; should be: " 
+ stateRequired);
-    }
-
-
-    
-
     // -- createTransientInstance, createViewModelInstance
 
     /**
@@ -648,19 +489,16 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * This method is ultimately delegated to by the
      * {@link org.apache.isis.applib.DomainObjectContainer}.
      */
+    @Override
     public ObjectAdapter createTransientInstance(final ObjectSpecification 
objectSpec) {
         return createInstance(objectSpec, Variant.TRANSIENT, null);
     }
 
+    @Override
     public ObjectAdapter createViewModelInstance(final ObjectSpecification 
objectSpec, final String memento) {
         return createInstance(objectSpec, Variant.VIEW_MODEL, memento);
     }
 
-    private enum Variant {
-        TRANSIENT,
-        VIEW_MODEL
-    }
-
     private ObjectAdapter createInstance(
             final ObjectSpecification spec,
             final Variant variant,
@@ -697,6 +535,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
         return viewModelPojo;
     }
 
+    @Override
     public Object instantiateAndInjectServices(final ObjectSpecification 
objectSpec) {
 
         final Class<?> correspondingClass = objectSpec.getCorrespondingClass();
@@ -761,25 +600,6 @@ public class PersistenceSession4 implements 
PersistenceSession,
     }
 
 
-    
-
-    // -- getServices, getService
-
-    public List<ObjectAdapter> getServices() {
-        final List<Object> services = servicesInjector.getRegisteredServices();
-        final List<ObjectAdapter> serviceAdapters = _Lists.newArrayList();
-        for (final Object servicePojo : services) {
-            ObjectAdapter serviceAdapter = getAdapterFor(servicePojo);
-            if(serviceAdapter == null) {
-                throw new IllegalStateException("ObjectAdapter for service " + 
servicePojo + " does not exist?!?");
-            }
-            serviceAdapters.add(serviceAdapter);
-        }
-        return serviceAdapters;
-    }
-
-    
-
     // -- helper: postEvent
 
     void postLifecycleEventIfRequired(
@@ -824,6 +644,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * 
      * @see FixturesInstalledFlag
      */
+    @Override
     public boolean isFixturesInstalled() {
         if (fixturesInstalledFlag.isFixturesInstalled() == null) {
             
fixturesInstalledFlag.setFixturesInstalled(objectStoreIsFixturesInstalled());
@@ -847,14 +668,12 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * By default this is not expected to be there, but utilities can add in on
      * the fly during bootstrapping if required.
      */
-    public boolean objectStoreIsFixturesInstalled() {
+    private boolean objectStoreIsFixturesInstalled() {
         final boolean installFixtures = 
configuration.getBoolean(INSTALL_FIXTURES_KEY, INSTALL_FIXTURES_DEFAULT);
         LOG.info("isFixturesInstalled: {} = {}", INSTALL_FIXTURES_KEY, 
installFixtures);
         return !installFixtures;
     }
 
-    
-
     // -- loadObject
 
     /**
@@ -900,7 +719,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * @throws org.apache.isis.core.runtime.persistence.ObjectNotFoundException
      *             when no object corresponding to the oid can be found
      */
-    public ObjectAdapter loadObjectInTransaction(final RootOid oid) {
+    private ObjectAdapter loadObjectInTransaction(final RootOid oid) {
 
         // can be either a view model or a persistent entity.
 
@@ -1026,8 +845,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
 
     // -- lazilyLoaded
 
-
-    public ObjectAdapter mapPersistent(final Persistable pojo) {
+    private ObjectAdapter mapPersistent(final Persistable pojo) {
         if (persistenceManager.getObjectId(pojo) == null) {
             return null;
         }
@@ -1046,7 +864,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * the object's missing data should be retrieved from the persistence
      * mechanism and be used to set up the value objects and associations.
      */
-    public void refreshRootInTransaction(final ObjectAdapter adapter) {
+    private void refreshRootInTransaction(final ObjectAdapter adapter) {
         Assert.assertTrue("only resolve object that is persistent", adapter, 
adapter.representsPersistent());
         getTransactionManager().executeWithinTransaction(new 
TransactionalClosure() {
 
@@ -1073,6 +891,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
     /**
      * Forces a reload (refresh in JDO terminology) of the domain object 
wrapped in the {@link ObjectAdapter}.
      */
+    @Override
     public void refreshRoot(final ObjectAdapter adapter) {
 
         final Object domainObject = adapter.getObject();
@@ -1093,6 +912,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
         initializeMapAndCheckConcurrency((Persistable) domainObject);
     }
 
+    @Override
     public void resolve(final Object parent) {
         final ObjectAdapter adapter = adapterFor(parent);
         refreshRootInTransaction(adapter);
@@ -1118,6 +938,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * collection, that is not already persistent, should be made persistent by
      * recursively calling this method.
      */
+    @Override
     public void makePersistentInTransaction(final ObjectAdapter adapter) {
         if (adapter.representsPersistent()) {
             throw new NotPersistableException("Object already persistent: " + 
adapter);
@@ -1179,18 +1000,16 @@ public class PersistenceSession4 implements 
PersistenceSession,
     }
 
 
-    
-
     // -- ObjectPersistor impl
-    public void makePersistent(final ObjectAdapter adapter) {
+    
+    private void makePersistent(final ObjectAdapter adapter) {
         makePersistentInTransaction(adapter);
     }
 
-    public void remove(final ObjectAdapter adapter) {
+    
+    private void remove(final ObjectAdapter adapter) {
         destroyObjectInTransaction(adapter);
     }
-    
-
 
     // -- destroyObjectInTransaction
 
@@ -1198,6 +1017,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * Removes the specified object from the system. The specified object's 
data
      * should be removed from the persistence mechanism.
      */
+    @Override
     public void destroyObjectInTransaction(final ObjectAdapter adapter) {
         final ObjectSpecification spec = adapter.getSpecification();
         if (spec.isParented()) {
@@ -1258,6 +1078,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
     
 
     // -- execute
+    @Override
     public void execute(final List<PersistenceCommand> commands) {
 
         // previously we used to check that there were some commands, and skip 
processing otherwise.
@@ -1280,6 +1101,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
 
     private Map<Oid, Oid> persistentByTransient = _Maps.newHashMap();
 
+    @Override
     public ObjectAdapter getAggregateRoot(final ParentedCollectionOid 
collectionOid) {
         final Oid rootOid = collectionOid.getRootOid();
         ObjectAdapter rootadapter = getAdapterFor(rootOid);
@@ -1298,87 +1120,6 @@ public class PersistenceSession4 implements 
PersistenceSession,
         return persistentByTransient.get(transientOid);
     }
 
-
-    
-
-    // -- transactions
-    public void startTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            throw new IllegalStateException("Transaction already active");
-        }
-        transaction.begin();
-    }
-
-    public void endTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.commit();
-        }
-    }
-
-    public void abortTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.rollback();
-        }
-    }
-
-    
-
-
-    // -- dependencies (from constructor)
-
-    protected SpecificationLoader getSpecificationLoader() {
-        return specificationLoader;
-    }
-    protected AuthenticationSession getAuthenticationSession() {
-        return authenticationSession;
-    }
-
-    /**
-     * The configured {@link ServicesInjector}.
-     */
-    public ServicesInjector getServicesInjector() {
-        return servicesInjector;
-    }
-
-
-    
-
-    // -- transactionManager
-
-
-    /**
-     * The configured {@link IsisTransactionManager}.
-     */
-    public IsisTransactionManager getTransactionManager() {
-        return transactionManager;
-    }
-
-//    // for testing only
-//    void setTransactionManager(final IsisTransactionManager 
transactionManager) {
-//        this.transactionManager = transactionManager;
-//    }
-
-
-    
-
-
-    // -- jdoPersistenceManager delegate methods
-    public javax.jdo.Query newJdoQuery(Class<?> cls) {
-        return persistenceManager.newQuery(cls);
-    }
-
-    public javax.jdo.Query newJdoNamedQuery (Class<?> cls, String queryName) {
-        return persistenceManager.newNamedQuery(cls, queryName);
-    }
-
-    public javax.jdo.Query newJdoQuery (Class<?> cls, String filter) {
-        return persistenceManager.newQuery(cls, filter);
-    }
-    // endregion
-
     // -- AdapterManager implementation
 
     private final PojoAdapterHashMap pojoAdapterMap = new PojoAdapterHashMap();
@@ -1508,6 +1249,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
                         + "but map's adapter's OID was: " + 
adapterAccordingToMap.getOid());
     }
 
+    @Override
     public ObjectAdapter adapterForAny(RootOid rootOid) {
 
         final ObjectSpecId specId = rootOid.getObjectSpecId();
@@ -1542,12 +1284,13 @@ public class PersistenceSession4 implements 
PersistenceSession,
             }
         }
     }
-
+    
+    @Override
     public Map<RootOid, ObjectAdapter> adaptersFor(final List<RootOid> 
rootOids) {
         return adaptersFor(rootOids, ConcurrencyChecking.NO_CHECK);
     }
 
-    public Map<RootOid,ObjectAdapter> adaptersFor(
+    private Map<RootOid,ObjectAdapter> adaptersFor(
             final List<RootOid> rootOids,
             final ConcurrencyChecking concurrencyChecking) {
 
@@ -1607,6 +1350,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * know that the oid does indeed represent an object you know exists.
      * </p>
      */
+    @Override 
     public ObjectAdapter adapterFor(final RootOid rootOid) {
         return adapterFor(rootOid, ConcurrencyChecking.NO_CHECK);
     }
@@ -1639,6 +1383,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      *
      * @throws {@link 
org.apache.isis.core.runtime.persistence.ObjectNotFoundException} if the object 
does not exist.
      */
+    @Override
     public ObjectAdapter adapterFor(
             final RootOid rootOid,
             final ConcurrencyChecking concurrencyChecking) {
@@ -1816,7 +1561,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      *
      * @param hintRootOid - allow a different persistent root oid to be 
provided.
      */
-    public void remapAsPersistent(final ObjectAdapter adapter, RootOid 
hintRootOid) {
+    private void remapAsPersistent(final ObjectAdapter adapter, RootOid 
hintRootOid) {
 
         final ObjectAdapter rootAdapter = adapter.getAggregateRoot();  // 
TODO: REVIEW: think this is redundant; would seem this method is only ever 
called for roots anyway.
         final RootOid transientRootOid = (RootOid) rootAdapter.getOid();
@@ -1990,8 +1735,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
         pojoAdapterMap.remove(adapter);
     }
 
-
-    public void remapRecreatedPojo(ObjectAdapter adapter, final Object pojo) {
+    private void remapRecreatedPojo(ObjectAdapter adapter, final Object pojo) {
         removeAdapter(adapter);
         adapter.replacePojo(pojo);
         mapAndInjectServices(adapter);
@@ -2116,6 +1860,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
 
     // -- FrameworkSynchronizer delegate methods
 
+    @Override
     public void enlistDeletingAndInvokeIsisRemovingCallbackFacet(final 
Persistable pojo) {
         ObjectAdapter adapter = adapterFor(pojo);
 
@@ -2125,7 +1870,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
         postLifecycleEventIfRequired(adapter, 
RemovingLifecycleEventFacet.class);
     }
 
-
+    @Override
     public void initializeMapAndCheckConcurrency(final Persistable pojo) {
         final Persistable pc = pojo;
 
@@ -2191,7 +1936,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * Create a new {@link Oid#isTransient() transient} {@link Oid} for the
      * supplied pojo, uniquely distinguishable from any other {@link Oid}.
      */
-    public final RootOid createTransientOrViewModelOid(final Object pojo) {
+    private final RootOid createTransientOrViewModelOid(final Object pojo) {
         return newIdentifier(pojo, Type.TRANSIENT);
     }
 
@@ -2206,15 +1951,11 @@ public class PersistenceSession4 implements 
PersistenceSession,
      *
      * @param pojo - being persisted
      */
+    @Override
     public final RootOid createPersistentOrViewModelOid(Object pojo) {
         return newIdentifier(pojo, Type.PERSISTENT);
     }
 
-    enum Type {
-        TRANSIENT,
-        PERSISTENT
-    }
-
     private RootOid newIdentifier(final Object pojo, final Type type) {
         final ObjectSpecification spec = objectSpecFor(pojo);
         if(spec.isService()) {
@@ -2262,6 +2003,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * The implementation therefore uses Isis' {@link 
org.apache.isis.core.metamodel.adapter.oid.Oid#isTransient() oid}
      * to determine which callback to fire.
      */
+    @Override
     public void invokeIsisPersistingCallback(final Persistable pojo) {
         final ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter == null) {
@@ -2293,6 +2035,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * The implementation therefore uses Isis' {@link 
org.apache.isis.core.metamodel.adapter.oid.Oid#isTransient() oid}
      * to determine which callback to fire.
      */
+    @Override
     public void 
enlistCreatedAndRemapIfRequiredThenInvokeIsisInvokePersistingOrUpdatedCallback(final
 Persistable pojo) {
         final ObjectAdapter adapter = adapterFor(pojo);
 
@@ -2321,6 +2064,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
         adapter.setVersion(versionIfAny);
     }
 
+    @Override
     public void enlistUpdatingAndInvokeIsisUpdatingCallback(final Persistable 
pojo) {
         ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter == null) {
@@ -2367,6 +2111,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
      * makes sure the entity is known to Isis and is a root
      * @param pojo
      */
+    @Override
     public void ensureRootObject(final Persistable pojo) {
         final Oid oid = adapterFor(pojo).getOid();
         if (!(oid instanceof RootOid)) {
@@ -2383,7 +2128,7 @@ public class PersistenceSession4 implements 
PersistenceSession,
 
     // -- DomainObjectServices impl
 
-
+    @Override
     public Object lookup(
             final Bookmark bookmark,
             final BookmarkService.FieldResetPolicy fieldResetPolicy) {
@@ -2400,44 +2145,12 @@ public class PersistenceSession4 implements 
PersistenceSession,
         return adapter.getObject();
     }
 
+    @Override
     public boolean flush() {
         return getTransactionManager().flushTransaction();
     }
 
 
-    
-
-    // -- helpers: lookupService, lookupServices
-
-    private <T> T lookupService(Class<T> serviceType) {
-        T service = lookupServiceIfAny(serviceType);
-        if(service == null) {
-            throw new IllegalStateException("Could not locate service of type 
'" + serviceType + "'");
-        }
-        return service;
-    }
-
-    private <T> T lookupServiceIfAny(final Class<T> serviceType) {
-        return servicesInjector.lookupService(serviceType);
-    }
-
-    private <T> List<T> lookupServices(final Class<T> serviceClass) {
-        return servicesInjector.lookupServices(serviceClass);
-    }
-    
-
-    // -- toString
-
-    @Override
-    public String toString() {
-        return new ToString(this).toString();
-    }
-
-
-    
-
-
-
 }
 
 
diff --git 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
deleted file mode 100644
index 6f9f187..0000000
--- 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.objectstore.jdo.datanucleus.persistence.queries;
-
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
-
-public interface PersistenceQueryProcessor<T extends PersistenceQuery> {
-       List<ObjectAdapter> process(T query);
-}
-
-// Copyright (c) Naked Objects Group Ltd.
diff --git 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
index 39fba0e..b2cc655 100644
--- 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
+++ 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
@@ -44,25 +44,15 @@ import org.apache.isis.applib.internal.collections._Maps;
 import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.services.bookmark.Bookmark;
 import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.applib.services.clock.ClockService;
 import org.apache.isis.applib.services.command.Command;
-import org.apache.isis.applib.services.command.CommandContext;
-import org.apache.isis.applib.services.command.spi.CommandService;
 import org.apache.isis.applib.services.eventbus.AbstractLifecycleEvent;
-import org.apache.isis.applib.services.eventbus.EventBusService;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
-import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.iactn.Interaction;
-import org.apache.isis.applib.services.iactn.InteractionContext;
-import org.apache.isis.applib.services.metrics.MetricsService;
-import org.apache.isis.applib.services.user.UserService;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.commons.ensure.Assert;
 import org.apache.isis.core.commons.ensure.IsisAssertException;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.commons.factory.InstanceUtil;
-import org.apache.isis.core.commons.util.ToString;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
@@ -101,7 +91,6 @@ import 
org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.Contributed;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.core.runtime.persistence.FixturesInstalledFlag;
 import org.apache.isis.core.runtime.persistence.NotPersistableException;
 import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
@@ -114,9 +103,7 @@ import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyO
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
 import 
org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
 import 
org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindUsingApplibQueryDefault;
-import org.apache.isis.core.runtime.runner.opts.OptionHandlerFixtureAbstract;
 import org.apache.isis.core.runtime.services.RequestScopedService;
-import 
org.apache.isis.core.runtime.services.changes.ChangedObjectsServiceInternal;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.OidAdapterHashMap;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.PojoAdapterHashMap;
 import 
org.apache.isis.core.runtime.system.persistence.adaptermanager.RootAndCollectionAdapters;
@@ -144,77 +131,12 @@ import com.google.common.collect.Maps;
  * and maintains an identity map of {@link ObjectAdapter adapter}s and {@link 
Oid
  * identities} for each and every POJO that is being used by the framework.
  */
-public class PersistenceSession5 implements PersistenceSession,
-        IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
+public class PersistenceSession5 extends PersistenceSessionBase
+implements IsisLifecycleListener2.PersistenceSessionLifecycleManagement {
 
-    // -- constants
     private static final Logger LOG = 
LoggerFactory.getLogger(PersistenceSession5.class);
 
     /**
-     * @see #isFixturesInstalled()
-     */
-    public static final String INSTALL_FIXTURES_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_INSTALL_FIXTURES_KEY;
-    public static final boolean INSTALL_FIXTURES_DEFAULT = false;
-
-    private static final String ROOT_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_ROOT_KEY;
-
-    /**
-     * Append regular <a 
href="http://www.datanucleus.org/products/accessplatform/persistence_properties.html";>datanucleus
 properties</a> to this key
-     */
-    public static final String DATANUCLEUS_PROPERTIES_ROOT = ROOT_KEY + 
"impl.";
-
-    //defined on PersistenceSession interface 
-    //public static final String SERVICE_IDENTIFIER = "1";
-
-    
-
-    // -- constructor, fields, finalize()
-
-    private final FixturesInstalledFlag fixturesInstalledFlag;
-
-    private final PersistenceQueryFactory persistenceQueryFactory;
-    private final IsisConfiguration configuration;
-    private final SpecificationLoader specificationLoader;
-    private final AuthenticationSession authenticationSession;
-
-    private final ServicesInjector servicesInjector;
-
-    private final CommandContext commandContext;
-    private final CommandService commandService;
-
-    private final InteractionContext interactionContext;
-    private final EventBusService eventBusService ;
-    private final ChangedObjectsServiceInternal changedObjectsServiceInternal;
-    private final FactoryService factoryService;
-    private final MetricsService metricsService;
-    private final ClockService clockService;
-    private final UserService userService;
-
-
-    /**
-     * Used to create the {@link #persistenceManager} when {@link #open()}ed.
-     */
-    private final PersistenceManagerFactory jdoPersistenceManagerFactory;
-
-    // not final only for testing purposes
-    private IsisTransactionManager transactionManager;
-
-
-    /**
-     * populated only when {@link #open()}ed.
-     */
-    private PersistenceManager persistenceManager;
-
-    /**
-     * populated only when {@link #open()}ed.
-     */
-    private final Map<Class<?>, PersistenceQueryProcessor<?>> 
persistenceQueryProcessorByClass = _Maps.newHashMap();
-
-
-    private final boolean concurrencyCheckingGloballyEnabled;
-
-
-    /**
      * Initialize the object store so that calls to this object store access
      * persisted objects and persist changes to the object that are saved.
      */
@@ -223,65 +145,17 @@ public class PersistenceSession5 implements 
PersistenceSession,
             final AuthenticationSession authenticationSession,
             final PersistenceManagerFactory jdoPersistenceManagerFactory,
             final FixturesInstalledFlag fixturesInstalledFlag) {
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("creating {}", this);
-        }
-
-        this.servicesInjector = servicesInjector;
-        this.jdoPersistenceManagerFactory = jdoPersistenceManagerFactory;
-        this.fixturesInstalledFlag = fixturesInstalledFlag;
-
-        // injected
-        this.configuration = 
servicesInjector.getConfigurationServiceInternal();
-        this.specificationLoader = servicesInjector.getSpecificationLoader();
-        this.authenticationSession = authenticationSession;
-
-        this.commandContext = lookupService(CommandContext.class);
-        this.commandService = lookupService(CommandService.class);
-        this.interactionContext = lookupService(InteractionContext.class);
-        this.eventBusService = lookupService(EventBusService.class);
-        this.changedObjectsServiceInternal = 
lookupService(ChangedObjectsServiceInternal.class);
-        this.metricsService = lookupService(MetricsService.class);
-        this.factoryService = lookupService(FactoryService.class);
-        this.clockService = lookupService(ClockService.class);
-        this.userService = lookupService(UserService.class);
-
-        // sub-components
-        final AdapterManager adapterManager = this;
-        this.persistenceQueryFactory = new 
PersistenceQueryFactory(adapterManager, this.specificationLoader);
-        this.transactionManager = new IsisTransactionManager(this, 
authenticationSession, servicesInjector);
-
-        this.state = State.NOT_INITIALIZED;
-
-        final boolean concurrencyCheckingGloballyDisabled =
-                
this.configuration.getBoolean("isis.persistor.disableConcurrencyChecking", 
false);
-        this.concurrencyCheckingGloballyEnabled = 
!concurrencyCheckingGloballyDisabled;
-
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        super.finalize();
-        LOG.debug("finalizing persistence session");
+       
+       super(servicesInjector, authenticationSession, 
jdoPersistenceManagerFactory, fixturesInstalledFlag);
     }
 
-    
-
-
     // -- open
 
     /**
-     * Only populated once {@link #open()}'d
-     */
-    public PersistenceManager getPersistenceManager() {
-        return persistenceManager;
-    }
-
-    /**
      * Injects components, calls open on subcomponents, and then creates 
service
      * adapters.
      */
+    @Override
     public void open() {
         ensureNotOpened();
 
@@ -395,6 +269,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * <p>
      * The corresponding DataNucleus entity is then closed.
      */
+    @Override
     public void close() {
 
         if (state == State.CLOSED) {
@@ -513,12 +388,12 @@ public class PersistenceSession5 implements 
PersistenceSession,
     
 
     // -- QuerySubmitter impl, findInstancesInTransaction
-
+    @Override
     public <T> List<ObjectAdapter> allMatchingQuery(final Query<T> query) {
         final ObjectAdapter instances = findInstancesInTransaction(query, 
QueryCardinality.MULTIPLE);
         return CollectionFacetUtils.convertToAdapterList(instances);
     }
-
+    @Override
     public <T> ObjectAdapter firstMatchingQuery(final Query<T> query) {
         final ObjectAdapter instances = findInstancesInTransaction(query, 
QueryCardinality.SINGLE);
         final List<ObjectAdapter> list = 
CollectionFacetUtils.convertToAdapterList(instances);
@@ -594,41 +469,6 @@ public class PersistenceSession5 implements 
PersistenceSession,
         return persistenceQueryProcessor.process((Q) persistenceQuery);
     }
 
-    public IsisConfiguration getConfiguration() {
-        return configuration;
-    }
-
-
-    
-
-    // -- State
-
-    private enum State {
-        NOT_INITIALIZED, OPEN, CLOSED
-    }
-
-    private State state;
-
-    protected void ensureNotOpened() {
-        if (state != State.NOT_INITIALIZED) {
-            throw new IllegalStateException("Persistence session has already 
been initialized");
-        }
-    }
-
-    public void ensureOpened() {
-        ensureStateIs(State.OPEN);
-    }
-
-    private void ensureStateIs(final State stateRequired) {
-        if (state == stateRequired) {
-            return;
-        }
-        throw new IllegalStateException("State is: " + state + "; should be: " 
+ stateRequired);
-    }
-
-
-    
-
     // -- createTransientInstance, createViewModelInstance
 
     /**
@@ -649,19 +489,16 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * This method is ultimately delegated to by the
      * {@link org.apache.isis.applib.DomainObjectContainer}.
      */
+    @Override
     public ObjectAdapter createTransientInstance(final ObjectSpecification 
objectSpec) {
         return createInstance(objectSpec, Variant.TRANSIENT, null);
     }
 
+    @Override
     public ObjectAdapter createViewModelInstance(final ObjectSpecification 
objectSpec, final String memento) {
         return createInstance(objectSpec, Variant.VIEW_MODEL, memento);
     }
 
-    private enum Variant {
-        TRANSIENT,
-        VIEW_MODEL
-    }
-
     private ObjectAdapter createInstance(
             final ObjectSpecification spec,
             final Variant variant,
@@ -698,6 +535,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
         return viewModelPojo;
     }
 
+    @Override
     public Object instantiateAndInjectServices(final ObjectSpecification 
objectSpec) {
 
         final Class<?> correspondingClass = objectSpec.getCorrespondingClass();
@@ -762,25 +600,6 @@ public class PersistenceSession5 implements 
PersistenceSession,
     }
 
 
-    
-
-    // -- getServices, getService
-
-    public List<ObjectAdapter> getServices() {
-        final List<Object> services = servicesInjector.getRegisteredServices();
-        final List<ObjectAdapter> serviceAdapters = _Lists.newArrayList();
-        for (final Object servicePojo : services) {
-            ObjectAdapter serviceAdapter = getAdapterFor(servicePojo);
-            if(serviceAdapter == null) {
-                throw new IllegalStateException("ObjectAdapter for service " + 
servicePojo + " does not exist?!?");
-            }
-            serviceAdapters.add(serviceAdapter);
-        }
-        return serviceAdapters;
-    }
-
-    
-
     // -- helper: postEvent
 
     void postLifecycleEventIfRequired(
@@ -825,6 +644,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * 
      * @see FixturesInstalledFlag
      */
+    @Override
     public boolean isFixturesInstalled() {
         if (fixturesInstalledFlag.isFixturesInstalled() == null) {
             
fixturesInstalledFlag.setFixturesInstalled(objectStoreIsFixturesInstalled());
@@ -848,14 +668,12 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * By default this is not expected to be there, but utilities can add in on
      * the fly during bootstrapping if required.
      */
-    public boolean objectStoreIsFixturesInstalled() {
+    private boolean objectStoreIsFixturesInstalled() {
         final boolean installFixtures = 
configuration.getBoolean(INSTALL_FIXTURES_KEY, INSTALL_FIXTURES_DEFAULT);
         LOG.info("isFixturesInstalled: {} = {}", INSTALL_FIXTURES_KEY, 
installFixtures);
         return !installFixtures;
     }
 
-    
-
     // -- loadObject
 
     /**
@@ -901,7 +719,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * @throws org.apache.isis.core.runtime.persistence.ObjectNotFoundException
      *             when no object corresponding to the oid can be found
      */
-    public ObjectAdapter loadObjectInTransaction(final RootOid oid) {
+    private ObjectAdapter loadObjectInTransaction(final RootOid oid) {
 
         // can be either a view model or a persistent entity.
 
@@ -1027,8 +845,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
 
     // -- lazilyLoaded
 
-
-    public ObjectAdapter mapPersistent(final Persistable pojo) {
+    private ObjectAdapter mapPersistent(final Persistable pojo) {
         if (persistenceManager.getObjectId(pojo) == null) {
             return null;
         }
@@ -1047,7 +864,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * the object's missing data should be retrieved from the persistence
      * mechanism and be used to set up the value objects and associations.
      */
-    public void refreshRootInTransaction(final ObjectAdapter adapter) {
+    private void refreshRootInTransaction(final ObjectAdapter adapter) {
         Assert.assertTrue("only resolve object that is persistent", adapter, 
adapter.representsPersistent());
         getTransactionManager().executeWithinTransaction(new 
TransactionalClosure() {
 
@@ -1074,6 +891,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
     /**
      * Forces a reload (refresh in JDO terminology) of the domain object 
wrapped in the {@link ObjectAdapter}.
      */
+    @Override
     public void refreshRoot(final ObjectAdapter adapter) {
 
         final Object domainObject = adapter.getObject();
@@ -1094,6 +912,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
         initializeMapAndCheckConcurrency((Persistable) domainObject);
     }
 
+    @Override
     public void resolve(final Object parent) {
         final ObjectAdapter adapter = adapterFor(parent);
         refreshRootInTransaction(adapter);
@@ -1119,6 +938,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * collection, that is not already persistent, should be made persistent by
      * recursively calling this method.
      */
+    @Override
     public void makePersistentInTransaction(final ObjectAdapter adapter) {
         if (adapter.representsPersistent()) {
             throw new NotPersistableException("Object already persistent: " + 
adapter);
@@ -1180,18 +1000,16 @@ public class PersistenceSession5 implements 
PersistenceSession,
     }
 
 
-    
-
     // -- ObjectPersistor impl
-    public void makePersistent(final ObjectAdapter adapter) {
+    
+    private void makePersistent(final ObjectAdapter adapter) {
         makePersistentInTransaction(adapter);
     }
 
-    public void remove(final ObjectAdapter adapter) {
+    
+    private void remove(final ObjectAdapter adapter) {
         destroyObjectInTransaction(adapter);
     }
-    
-
 
     // -- destroyObjectInTransaction
 
@@ -1199,6 +1017,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * Removes the specified object from the system. The specified object's 
data
      * should be removed from the persistence mechanism.
      */
+    @Override
     public void destroyObjectInTransaction(final ObjectAdapter adapter) {
         final ObjectSpecification spec = adapter.getSpecification();
         if (spec.isParented()) {
@@ -1259,6 +1078,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
     
 
     // -- execute
+    @Override
     public void execute(final List<PersistenceCommand> commands) {
 
         // previously we used to check that there were some commands, and skip 
processing otherwise.
@@ -1281,6 +1101,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
 
     private Map<Oid, Oid> persistentByTransient = _Maps.newHashMap();
 
+    @Override
     public ObjectAdapter getAggregateRoot(final ParentedCollectionOid 
collectionOid) {
         final Oid rootOid = collectionOid.getRootOid();
         ObjectAdapter rootadapter = getAdapterFor(rootOid);
@@ -1299,87 +1120,6 @@ public class PersistenceSession5 implements 
PersistenceSession,
         return persistentByTransient.get(transientOid);
     }
 
-
-    
-
-    // -- transactions
-    public void startTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            throw new IllegalStateException("Transaction already active");
-        }
-        transaction.begin();
-    }
-
-    public void endTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.commit();
-        }
-    }
-
-    public void abortTransaction() {
-        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.rollback();
-        }
-    }
-
-    
-
-
-    // -- dependencies (from constructor)
-
-    protected SpecificationLoader getSpecificationLoader() {
-        return specificationLoader;
-    }
-    protected AuthenticationSession getAuthenticationSession() {
-        return authenticationSession;
-    }
-
-    /**
-     * The configured {@link ServicesInjector}.
-     */
-    public ServicesInjector getServicesInjector() {
-        return servicesInjector;
-    }
-
-
-    
-
-    // -- transactionManager
-
-
-    /**
-     * The configured {@link IsisTransactionManager}.
-     */
-    public IsisTransactionManager getTransactionManager() {
-        return transactionManager;
-    }
-
-//    // for testing only
-//    void setTransactionManager(final IsisTransactionManager 
transactionManager) {
-//        this.transactionManager = transactionManager;
-//    }
-
-
-    
-
-
-    // -- jdoPersistenceManager delegate methods
-    public javax.jdo.Query newJdoQuery(Class<?> cls) {
-        return persistenceManager.newQuery(cls);
-    }
-
-    public javax.jdo.Query newJdoNamedQuery (Class<?> cls, String queryName) {
-        return persistenceManager.newNamedQuery(cls, queryName);
-    }
-
-    public javax.jdo.Query newJdoQuery (Class<?> cls, String filter) {
-        return persistenceManager.newQuery(cls, filter);
-    }
-    // endregion
-
     // -- AdapterManager implementation
 
     private final PojoAdapterHashMap pojoAdapterMap = new PojoAdapterHashMap();
@@ -1509,6 +1249,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
                         + "but map's adapter's OID was: " + 
adapterAccordingToMap.getOid());
     }
 
+    @Override
     public ObjectAdapter adapterForAny(RootOid rootOid) {
 
         final ObjectSpecId specId = rootOid.getObjectSpecId();
@@ -1543,12 +1284,13 @@ public class PersistenceSession5 implements 
PersistenceSession,
             }
         }
     }
-
+    
+    @Override
     public Map<RootOid, ObjectAdapter> adaptersFor(final List<RootOid> 
rootOids) {
         return adaptersFor(rootOids, ConcurrencyChecking.NO_CHECK);
     }
 
-    public Map<RootOid,ObjectAdapter> adaptersFor(
+    private Map<RootOid,ObjectAdapter> adaptersFor(
             final List<RootOid> rootOids,
             final ConcurrencyChecking concurrencyChecking) {
 
@@ -1608,6 +1350,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * know that the oid does indeed represent an object you know exists.
      * </p>
      */
+    @Override 
     public ObjectAdapter adapterFor(final RootOid rootOid) {
         return adapterFor(rootOid, ConcurrencyChecking.NO_CHECK);
     }
@@ -1640,6 +1383,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      *
      * @throws {@link 
org.apache.isis.core.runtime.persistence.ObjectNotFoundException} if the object 
does not exist.
      */
+    @Override
     public ObjectAdapter adapterFor(
             final RootOid rootOid,
             final ConcurrencyChecking concurrencyChecking) {
@@ -1817,7 +1561,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      *
      * @param hintRootOid - allow a different persistent root oid to be 
provided.
      */
-    public void remapAsPersistent(final ObjectAdapter adapter, RootOid 
hintRootOid) {
+    private void remapAsPersistent(final ObjectAdapter adapter, RootOid 
hintRootOid) {
 
         final ObjectAdapter rootAdapter = adapter.getAggregateRoot();  // 
TODO: REVIEW: think this is redundant; would seem this method is only ever 
called for roots anyway.
         final RootOid transientRootOid = (RootOid) rootAdapter.getOid();
@@ -1991,8 +1735,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
         pojoAdapterMap.remove(adapter);
     }
 
-
-    public void remapRecreatedPojo(ObjectAdapter adapter, final Object pojo) {
+    private void remapRecreatedPojo(ObjectAdapter adapter, final Object pojo) {
         removeAdapter(adapter);
         adapter.replacePojo(pojo);
         mapAndInjectServices(adapter);
@@ -2117,6 +1860,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
 
     // -- FrameworkSynchronizer delegate methods
 
+    @Override
     public void enlistDeletingAndInvokeIsisRemovingCallbackFacet(final 
Persistable pojo) {
         ObjectAdapter adapter = adapterFor(pojo);
 
@@ -2126,7 +1870,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
         postLifecycleEventIfRequired(adapter, 
RemovingLifecycleEventFacet.class);
     }
 
-
+    @Override
     public void initializeMapAndCheckConcurrency(final Persistable pojo) {
         final Persistable pc = pojo;
 
@@ -2192,7 +1936,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * Create a new {@link Oid#isTransient() transient} {@link Oid} for the
      * supplied pojo, uniquely distinguishable from any other {@link Oid}.
      */
-    public final RootOid createTransientOrViewModelOid(final Object pojo) {
+    private final RootOid createTransientOrViewModelOid(final Object pojo) {
         return newIdentifier(pojo, Type.TRANSIENT);
     }
 
@@ -2207,15 +1951,11 @@ public class PersistenceSession5 implements 
PersistenceSession,
      *
      * @param pojo - being persisted
      */
+    @Override
     public final RootOid createPersistentOrViewModelOid(Object pojo) {
         return newIdentifier(pojo, Type.PERSISTENT);
     }
 
-    enum Type {
-        TRANSIENT,
-        PERSISTENT
-    }
-
     private RootOid newIdentifier(final Object pojo, final Type type) {
         final ObjectSpecification spec = objectSpecFor(pojo);
         if(spec.isService()) {
@@ -2263,6 +2003,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * The implementation therefore uses Isis' {@link 
org.apache.isis.core.metamodel.adapter.oid.Oid#isTransient() oid}
      * to determine which callback to fire.
      */
+    @Override
     public void invokeIsisPersistingCallback(final Persistable pojo) {
         final ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter == null) {
@@ -2294,6 +2035,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * The implementation therefore uses Isis' {@link 
org.apache.isis.core.metamodel.adapter.oid.Oid#isTransient() oid}
      * to determine which callback to fire.
      */
+    @Override
     public void 
enlistCreatedAndRemapIfRequiredThenInvokeIsisInvokePersistingOrUpdatedCallback(final
 Persistable pojo) {
         final ObjectAdapter adapter = adapterFor(pojo);
 
@@ -2322,6 +2064,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
         adapter.setVersion(versionIfAny);
     }
 
+    @Override
     public void enlistUpdatingAndInvokeIsisUpdatingCallback(final Persistable 
pojo) {
         ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter == null) {
@@ -2368,6 +2111,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
      * makes sure the entity is known to Isis and is a root
      * @param pojo
      */
+    @Override
     public void ensureRootObject(final Persistable pojo) {
         final Oid oid = adapterFor(pojo).getOid();
         if (!(oid instanceof RootOid)) {
@@ -2384,7 +2128,7 @@ public class PersistenceSession5 implements 
PersistenceSession,
 
     // -- DomainObjectServices impl
 
-
+    @Override
     public Object lookup(
             final Bookmark bookmark,
             final BookmarkService.FieldResetPolicy fieldResetPolicy) {
@@ -2401,44 +2145,12 @@ public class PersistenceSession5 implements 
PersistenceSession,
         return adapter.getObject();
     }
 
+    @Override
     public boolean flush() {
         return getTransactionManager().flushTransaction();
     }
 
 
-    
-
-    // -- helpers: lookupService, lookupServices
-
-    private <T> T lookupService(Class<T> serviceType) {
-        T service = lookupServiceIfAny(serviceType);
-        if(service == null) {
-            throw new IllegalStateException("Could not locate service of type 
'" + serviceType + "'");
-        }
-        return service;
-    }
-
-    private <T> T lookupServiceIfAny(final Class<T> serviceType) {
-        return servicesInjector.lookupService(serviceType);
-    }
-
-    private <T> List<T> lookupServices(final Class<T> serviceClass) {
-        return servicesInjector.lookupServices(serviceClass);
-    }
-    
-
-    // -- toString
-
-    @Override
-    public String toString() {
-        return new ToString(this).toString();
-    }
-
-
-    
-
-
-
 }
 
 
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 5ce1987..11386f0 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
@@ -12,58 +12,124 @@ import 
org.apache.isis.core.commons.components.SessionScopedComponent;
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.ParentedCollectionOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.services.ServicesInjector;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
 import 
org.apache.isis.core.runtime.persistence.objectstore.transaction.TransactionalResource;
+import org.apache.isis.core.runtime.runner.opts.OptionHandlerFixtureAbstract;
 import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
 
 public interface PersistenceSession extends AdapterManager, 
TransactionalResource, SessionScopedComponent {
 
-       String SERVICE_IDENTIFIER = "1";
+       // -- CONSTANTS
+       
+       public static final String SERVICE_IDENTIFIER = "1";
 
-       boolean isFixturesInstalled();
+       /**
+        * @see #isFixturesInstalled()
+        */
+       public static final String INSTALL_FIXTURES_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_INSTALL_FIXTURES_KEY;
+       public static final boolean INSTALL_FIXTURES_DEFAULT = false;
 
-       IsisTransactionManager getTransactionManager();
+       // [ahuber] could as well be 'protected', not referenced from other 
then implementing classes
+       public static final String ROOT_KEY = 
OptionHandlerFixtureAbstract.DATANUCLEUS_ROOT_KEY;
 
-       Object instantiateAndInjectServices(ObjectSpecification spec);
+       /**
+        * Append regular <a 
href="http://www.datanucleus.org/products/accessplatform/persistence_properties.html";>datanucleus
 properties</a> to this key
+        */
+       public static final String DATANUCLEUS_PROPERTIES_ROOT = ROOT_KEY + 
"impl.";
 
-       List<ObjectAdapter> getServices();
 
-       void makePersistentInTransaction(ObjectAdapter adapter);
+       // -- INTERFACE DECLARATION
 
-       void destroyObjectInTransaction(ObjectAdapter adapter);
+       ObjectAdapter adapterFor(RootOid rootOid);
 
-       ObjectAdapter createTransientInstance(ObjectSpecification spec);
-
-       ObjectAdapter createViewModelInstance(ObjectSpecification spec, String 
memento);
+       ObjectAdapter adapterFor(RootOid oid, ConcurrencyChecking 
concurrencyChecking);
 
-       Object lookup(Bookmark bookmark, FieldResetPolicy fieldResetPolicy);
+       ObjectAdapter adapterForAny(RootOid rootOid);
 
-       void resolve(Object parent);
+       Map<RootOid, ObjectAdapter> adaptersFor(List<RootOid> rootOids);
 
        <T> List<ObjectAdapter> allMatchingQuery(final Query<T> query);
-       <T> ObjectAdapter firstMatchingQuery(final Query<T> query);
 
-       ServicesInjector getServicesInjector();
+       void close();
 
-       void execute(List<PersistenceCommand> persistenceCommandList);
+       RootOid createPersistentOrViewModelOid(Object pojo);
 
-       void open();
+       ObjectAdapter createTransientInstance(ObjectSpecification spec);
 
-       void close();
+       ObjectAdapter createViewModelInstance(ObjectSpecification spec, String 
memento);
 
-       ObjectAdapter adapterForAny(RootOid rootOid);
+       void destroyObjectInTransaction(ObjectAdapter adapter);
 
-       ObjectAdapter adapterFor(RootOid oid, ConcurrencyChecking 
concurrencyChecking);
+       void execute(List<PersistenceCommand> persistenceCommandList);
+       <T> ObjectAdapter firstMatchingQuery(final Query<T> query);
 
-       Map<RootOid, ObjectAdapter> adaptersFor(List<RootOid> rootOids);
+       boolean flush();
+
+       ObjectAdapter getAggregateRoot(ParentedCollectionOid collectionOid);
 
        IsisConfiguration getConfiguration();
 
        PersistenceManager getPersistenceManager();
+       
+       /**
+        * Convenient equivalent to {@code getPersistenceManager()}. 
+        * @return
+        */
+       PersistenceManager pm();
+
+       List<ObjectAdapter> getServices();
+
+       ServicesInjector getServicesInjector();
+
+       IsisTransactionManager getTransactionManager();
+
+       Object instantiateAndInjectServices(ObjectSpecification spec);
+
+       boolean isFixturesInstalled();
+
+       Object lookup(Bookmark bookmark, FieldResetPolicy fieldResetPolicy);
+
+       void makePersistentInTransaction(ObjectAdapter adapter);
+
+       /**
+        * Not type safe. For type-safe queries use <br/><br/> {@code 
pm().newNamedQuery(cls, queryName)}
+        * @param cls
+        * @param queryName
+        * @return
+        */
+       default <T> javax.jdo.Query newJdoNamedQuery(Class<T> cls, String 
queryName){
+               return pm().newNamedQuery(cls, queryName);
+       }
+       
+       /**
+        * Not type safe. For type-safe queries use <br/><br/> {@code 
pm().newQuery(cls, queryName)}
+        * @param cls
+        * @return
+        */
+       default <T> javax.jdo.Query newJdoQuery(Class<T> cls){
+               return pm().newQuery(cls);
+       }
+       
+       /**
+        * Not type safe. For type-safe queries use <br/><br/> {@code 
pm().newQuery(cls, filter)}
+        * @param cls
+        * @param filter
+        * @return
+        */
+       default <T> javax.jdo.Query newJdoQuery(Class<T> cls, String filter){
+               return pm().newQuery(cls, filter);
+       }
+
+       void open();
 
        void refreshRoot(ObjectAdapter adapter);
 
+       void resolve(Object parent);
+
+       
+
 }
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
new file mode 100644
index 0000000..3de3097
--- /dev/null
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
@@ -0,0 +1,277 @@
+package org.apache.isis.core.runtime.system.persistence;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+
+import org.apache.isis.applib.internal.collections._Lists;
+import org.apache.isis.applib.internal.collections._Maps;
+import org.apache.isis.applib.services.clock.ClockService;
+import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.applib.services.command.spi.CommandService;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.applib.services.iactn.InteractionContext;
+import org.apache.isis.applib.services.metrics.MetricsService;
+import org.apache.isis.applib.services.user.UserService;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.util.ToString;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.runtime.persistence.FixturesInstalledFlag;
+import 
org.apache.isis.core.runtime.services.changes.ChangedObjectsServiceInternal;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import 
org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class PersistenceSessionBase implements PersistenceSession {
+
+       // -- CONSTANTS
+       
+    protected static final Logger LOG = 
LoggerFactory.getLogger(PersistenceSession.class);
+
+    // -- FIELDS
+
+    protected final FixturesInstalledFlag fixturesInstalledFlag;
+
+    protected final PersistenceQueryFactory persistenceQueryFactory;
+    protected final IsisConfiguration configuration;
+    protected final SpecificationLoader specificationLoader;
+    protected final AuthenticationSession authenticationSession;
+
+    protected final ServicesInjector servicesInjector;
+
+    protected final CommandContext commandContext;
+    protected final CommandService commandService;
+
+    protected final InteractionContext interactionContext;
+    protected final EventBusService eventBusService ;
+    protected final ChangedObjectsServiceInternal 
changedObjectsServiceInternal;
+    protected final FactoryService factoryService;
+    protected final MetricsService metricsService;
+    protected final ClockService clockService;
+    protected final UserService userService;
+
+
+    /**
+     * Used to create the {@link #persistenceManager} when {@link #open()}ed.
+     */
+    protected final PersistenceManagerFactory jdoPersistenceManagerFactory;
+
+    // not final only for testing purposes
+    protected IsisTransactionManager transactionManager;
+
+
+    /**
+     * populated only when {@link #open()}ed.
+     */
+    protected PersistenceManager persistenceManager;
+
+    /**
+     * populated only when {@link #open()}ed.
+     */
+    protected final Map<Class<?>, PersistenceQueryProcessor<?>> 
persistenceQueryProcessorByClass = _Maps.newHashMap();
+
+
+    protected final boolean concurrencyCheckingGloballyEnabled;
+
+    // -- CONSTRUCTOR
+
+    /**
+     * Initialize the object store so that calls to this object store access
+     * persisted objects and persist changes to the object that are saved.
+     */
+    protected PersistenceSessionBase(
+            final ServicesInjector servicesInjector,
+            final AuthenticationSession authenticationSession,
+            final PersistenceManagerFactory jdoPersistenceManagerFactory,
+            final FixturesInstalledFlag fixturesInstalledFlag) {
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("creating {}", this);
+        }
+
+        this.servicesInjector = servicesInjector;
+        this.jdoPersistenceManagerFactory = jdoPersistenceManagerFactory;
+        this.fixturesInstalledFlag = fixturesInstalledFlag;
+
+        // injected
+        this.configuration = 
servicesInjector.getConfigurationServiceInternal();
+        this.specificationLoader = servicesInjector.getSpecificationLoader();
+        this.authenticationSession = authenticationSession;
+
+        this.commandContext = lookupService(CommandContext.class);
+        this.commandService = lookupService(CommandService.class);
+        this.interactionContext = lookupService(InteractionContext.class);
+        this.eventBusService = lookupService(EventBusService.class);
+        this.changedObjectsServiceInternal = 
lookupService(ChangedObjectsServiceInternal.class);
+        this.metricsService = lookupService(MetricsService.class);
+        this.factoryService = lookupService(FactoryService.class);
+        this.clockService = lookupService(ClockService.class);
+        this.userService = lookupService(UserService.class);
+
+        // sub-components
+        final AdapterManager adapterManager = this;
+        this.persistenceQueryFactory = new 
PersistenceQueryFactory(adapterManager, this.specificationLoader);
+        this.transactionManager = new IsisTransactionManager(this, 
authenticationSession, servicesInjector);
+
+        this.state = State.NOT_INITIALIZED;
+
+        final boolean concurrencyCheckingGloballyDisabled =
+                
this.configuration.getBoolean("isis.persistor.disableConcurrencyChecking", 
false);
+        this.concurrencyCheckingGloballyEnabled = 
!concurrencyCheckingGloballyDisabled;
+
+    }
+    
+    // -- GETTERS
+    
+    protected SpecificationLoader getSpecificationLoader() {
+        return specificationLoader;
+    }
+    protected AuthenticationSession getAuthenticationSession() {
+        return authenticationSession;
+    }
+
+    /**
+     * The configured {@link ServicesInjector}.
+     */
+    @Override
+    public ServicesInjector getServicesInjector() {
+        return servicesInjector;
+    }
+
+    /**
+     * The configured {@link IsisTransactionManager}.
+     */
+    @Override
+    public IsisTransactionManager getTransactionManager() {
+        return transactionManager;
+    }
+    
+    /**
+     * Only populated once {@link #open()}'d
+     */
+    @Override
+    public PersistenceManager getPersistenceManager() {
+        return persistenceManager;
+    }
+    
+    @Override
+    public PersistenceManager pm() {
+        return persistenceManager;
+    }
+    
+    @Override
+    public IsisConfiguration getConfiguration() {
+        return configuration;
+    }
+    
+    @Override
+    public List<ObjectAdapter> getServices() {
+        final List<Object> services = servicesInjector.getRegisteredServices();
+        final List<ObjectAdapter> serviceAdapters = _Lists.newArrayList();
+        for (final Object servicePojo : services) {
+            ObjectAdapter serviceAdapter = getAdapterFor(servicePojo);
+            if(serviceAdapter == null) {
+                throw new IllegalStateException("ObjectAdapter for service " + 
servicePojo + " does not exist?!?");
+            }
+            serviceAdapters.add(serviceAdapter);
+        }
+        return serviceAdapters;
+    }
+    
+    // -- ENUMS
+
+    protected enum Type {
+        TRANSIENT,
+        PERSISTENT
+    }
+    
+    protected enum Variant {
+        TRANSIENT,
+        VIEW_MODEL
+    }
+
+    protected enum State {
+        NOT_INITIALIZED, OPEN, CLOSED
+    }
+    
+    // -- STATE
+
+    protected State state;
+
+    protected void ensureNotOpened() {
+        if (state != State.NOT_INITIALIZED) {
+            throw new IllegalStateException("Persistence session has already 
been initialized");
+        }
+    }
+
+    protected void ensureOpened() {
+        ensureStateIs(State.OPEN);
+    }
+
+    private void ensureStateIs(final State stateRequired) {
+        if (state == stateRequired) {
+            return;
+        }
+        throw new IllegalStateException("State is: " + state + "; should be: " 
+ stateRequired);
+    }
+    
+    // -- TRANSACTIONS
+    
+    @Override
+    public void startTransaction() {
+        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            throw new IllegalStateException("Transaction already active");
+        }
+        transaction.begin();
+    }
+
+    @Override
+    public void endTransaction() {
+        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            transaction.commit();
+        }
+    }
+
+    @Override
+    public void abortTransaction() {
+        final javax.jdo.Transaction transaction = 
persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            transaction.rollback();
+        }
+    }
+
+    // -- HELPERS - SERVICE LOOKUP
+
+    private <T> T lookupService(Class<T> serviceType) {
+        T service = lookupServiceIfAny(serviceType);
+        if(service == null) {
+            throw new IllegalStateException("Could not locate service of type 
'" + serviceType + "'");
+        }
+        return service;
+    }
+
+    private <T> T lookupServiceIfAny(final Class<T> serviceType) {
+        return servicesInjector.lookupService(serviceType);
+    }
+
+    protected <T> List<T> lookupServices(final Class<T> serviceClass) {
+        return servicesInjector.lookupServices(serviceClass);
+    }
+
+    @Override
+    public String toString() {
+        return new ToString(this).toString();
+    }
+
+    
+}
diff --git 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
 
b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
similarity index 100%
rename from 
core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java
rename to 
core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessor.java

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to