You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/09/10 14:07:26 UTC

[27/50] [abbrv] isis git commit: ISIS-1194: moved isFixturesInstalled and transaction management stuff from ObjectStore to PersistenceSession

ISIS-1194: moved isFixturesInstalled and transaction management stuff from ObjectStore to PersistenceSession


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/459a7319
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/459a7319
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/459a7319

Branch: refs/heads/ISIS-1194
Commit: 459a7319bf1b4e002cb4c79d5ce719ff147ff4e5
Parents: 6b5264e
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Sep 10 09:39:28 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Sep 10 09:39:28 2015 +0100

----------------------------------------------------------------------
 .../runtime/system/persistence/ObjectStore.java | 68 +----------------
 .../system/persistence/PersistenceSession.java  | 77 ++++++++++++++++++--
 .../transaction/IsisTransactionManager.java     |  3 +-
 .../IsisConfigurationForJdoIntegTests.java      |  3 +-
 ...reTransactionManager_EndTransactionTest.java |  2 +-
 ...oreTransactionManager_InstantiationTest.java |  2 +-
 ...TransactionManager_StartTransactionTest.java |  2 +-
 .../persistence/PersistenceSessionTest.java     | 26 +++----
 8 files changed, 91 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/ObjectStore.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/ObjectStore.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/ObjectStore.java
index b9d1efb..48ba148 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/ObjectStore.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/ObjectStore.java
@@ -40,7 +40,7 @@ import static org.apache.isis.core.commons.ensure.Ensure.ensureThatState;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
 
-public class ObjectStore implements TransactionalResource, DebuggableWithTitle, SessionScopedComponent {
+public class ObjectStore implements DebuggableWithTitle, SessionScopedComponent {
 
     private static final Logger LOG = LoggerFactory.getLogger(ObjectStore.class);
 
@@ -57,11 +57,6 @@ public class ObjectStore implements TransactionalResource, DebuggableWithTitle,
      */
     public static final String DATANUCLEUS_PROPERTIES_ROOT = ROOT_KEY + "impl.";
 
-    /**
-     * @see #objectStoreIsFixturesInstalled()
-     */
-    public static final String INSTALL_FIXTURES_KEY = OptionHandlerFixtureAbstract.DATANUCLEUS_INSTALL_FIXTURES_KEY;
-    public static final boolean INSTALL_FIXTURES_DEFAULT = false;
 
 
     private final DataNucleusApplicationComponents applicationComponents;
@@ -121,67 +116,6 @@ public class ObjectStore implements TransactionalResource, DebuggableWithTitle,
     }
     //endregion
 
-    //region > isFixturesInstalled
-    /**
-     * Determine if the object store has been initialized with its set of start
-     * up objects.
-     *
-     * <p>
-     * This method is called only once after the session is opened called. If it returns <code>false</code> then the
-     * framework will run the fixtures to initialise the object store.
-     *
-     * <p>
-     * Implementation looks for the {@link #INSTALL_FIXTURES_KEY} in the
-     * {@link #getConfiguration() configuration}.
-     *
-     * <p>
-     * By default this is not expected to be there, but utilities can add in on
-     * the fly during bootstrapping if required.
-     */
-    public boolean objectStoreIsFixturesInstalled() {
-        final boolean installFixtures = getConfiguration().getBoolean(INSTALL_FIXTURES_KEY, INSTALL_FIXTURES_DEFAULT);
-        LOG.info("isFixturesInstalled: {} = {}", INSTALL_FIXTURES_KEY, installFixtures);
-        return !installFixtures;
-    }
-    //endregion
-
-    //region > transactions
-    public void startTransaction() {
-        beginJdoTransaction();
-    }
-
-    public void endTransaction() {
-        commitJdoTransaction();
-    }
-
-    public void abortTransaction() {
-        rollbackJdoTransaction();
-    }
-
-    private void beginJdoTransaction() {
-        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            throw new IllegalStateException("Transaction already active");
-        }
-        transaction.begin();
-    }
-
-    private void commitJdoTransaction() {
-        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.commit();
-        }
-    }
-
-    private void rollbackJdoTransaction() {
-        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
-        if (transaction.isActive()) {
-            transaction.rollback();
-        }
-    }
-    //endregion
-
-
     //region > helpers
 
     public void ensureOpened() {

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
index 9074213..84bebe2 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
@@ -70,8 +70,10 @@ import org.apache.isis.core.runtime.persistence.objectstore.algorithm.PersistAlg
 import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
 import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
 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.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.system.context.IsisContext;
 import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
 import org.apache.isis.core.runtime.system.transaction.TransactionalClosure;
@@ -90,10 +92,16 @@ import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.nullValue;
 
-public class PersistenceSession implements SessionScopedComponent, DebuggableWithTitle {
+public class PersistenceSession implements TransactionalResource, SessionScopedComponent, DebuggableWithTitle {
 
     private static final Logger LOG = LoggerFactory.getLogger(PersistenceSession.class);
 
+    /**
+     * @see #isFixturesInstalled()
+     */
+    public static final String INSTALL_FIXTURES_KEY = OptionHandlerFixtureAbstract.DATANUCLEUS_INSTALL_FIXTURES_KEY;
+    public static final boolean INSTALL_FIXTURES_DEFAULT = false;
+
     //region > constructor, fields
     private final ObjectFactory objectFactory;
 
@@ -167,7 +175,7 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
         this.objectAdapterFactory = new PojoAdapterFactory(adapterManager, specificationLoader, authenticationSession);
 
         this.persistenceQueryFactory = new PersistenceQueryFactory(getSpecificationLoader(), adapterManager);
-        this.transactionManager = new IsisTransactionManager(this, objectStore, servicesInjector);
+        this.transactionManager = new IsisTransactionManager(this, servicesInjector);
 
         setState(State.NOT_INITIALIZED);
 
@@ -515,7 +523,7 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
      * initialise the persistor.
      * 
      * <p>
-     * Returns the cached value of {@link ObjectStore#objectStoreIsFixturesInstalled()
+     * Returns the cached value of {@link #isFixturesInstalled()
      * whether fixtures are installed} from the
      * {@link PersistenceSessionFactory}.
      * <p>
@@ -527,11 +535,33 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
      */
     public boolean isFixturesInstalled() {
         if (persistenceSessionFactory.isFixturesInstalled() == null) {
-            persistenceSessionFactory.setFixturesInstalled(objectStore.objectStoreIsFixturesInstalled());
+            persistenceSessionFactory.setFixturesInstalled(objectStoreIsFixturesInstalled());
         }
         return persistenceSessionFactory.isFixturesInstalled();
     }
 
+
+    /**
+     * Determine if the object store has been initialized with its set of start
+     * up objects.
+     *
+     * <p>
+     * This method is called only once after the session is opened called. If it returns <code>false</code> then the
+     * framework will run the fixtures to initialise the object store.
+     *
+     * <p>
+     * Implementation looks for the {@link #INSTALL_FIXTURES_KEY} in the injected {@link #configuration configuration}.
+     *
+     * <p>
+     * By default this is not expected to be there, but utilities can add in on
+     * the fly during bootstrapping if required.
+     */
+    public boolean objectStoreIsFixturesInstalled() {
+        final boolean installFixtures = configuration.getBoolean(INSTALL_FIXTURES_KEY, INSTALL_FIXTURES_DEFAULT);
+        LOG.info("isFixturesInstalled: {} = {}", INSTALL_FIXTURES_KEY, installFixtures);
+        return !installFixtures;
+    }
+
     @Override
     protected void finalize() throws Throwable {
         super.finalize();
@@ -737,8 +767,6 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
     }
     //endregion
 
-
-
     //region > makePersistent
 
     /**
@@ -921,6 +949,43 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
 
     //endregion
 
+    //region > transactions
+    public void startTransaction() {
+        beginJdoTransaction();
+    }
+
+    public void endTransaction() {
+        commitJdoTransaction();
+    }
+
+    public void abortTransaction() {
+        rollbackJdoTransaction();
+    }
+
+    private void beginJdoTransaction() {
+        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            throw new IllegalStateException("Transaction already active");
+        }
+        transaction.begin();
+    }
+
+    private void commitJdoTransaction() {
+        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            transaction.commit();
+        }
+    }
+
+    private void rollbackJdoTransaction() {
+        final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
+        if (transaction.isActive()) {
+            transaction.rollback();
+        }
+    }
+    //endregion
+
+
     //region > Debugging
 
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
index 883f675..e130934 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
@@ -77,10 +77,9 @@ public class IsisTransactionManager implements SessionScopedComponent {
 
     public IsisTransactionManager(
             final PersistenceSession persistenceSession,
-            final TransactionalResource transactionalResource,
             final ServicesInjector servicesInjector) {
         this.persistenceSession = persistenceSession;
-        this.transactionalResource = transactionalResource;
+        this.transactionalResource = persistenceSession;
         this.servicesInjector = servicesInjector;
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/IsisConfigurationForJdoIntegTests.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/IsisConfigurationForJdoIntegTests.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/IsisConfigurationForJdoIntegTests.java
index 825567f..c8aef7f 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/IsisConfigurationForJdoIntegTests.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/IsisConfigurationForJdoIntegTests.java
@@ -29,6 +29,7 @@ import org.apache.isis.core.commons.config.IsisConfigurationDefault;
 import org.apache.isis.core.commons.resource.ResourceStreamSource;
 import org.apache.isis.core.runtime.persistence.PersistenceConstants;
 import org.apache.isis.core.runtime.system.persistence.ObjectStore;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
 import org.apache.isis.objectstore.jdo.service.RegisterEntities;
 
 public class IsisConfigurationForJdoIntegTests extends IsisConfigurationDefault {
@@ -80,7 +81,7 @@ public class IsisConfigurationForJdoIntegTests extends IsisConfigurationDefault
         addDataNucleusProperty("datanucleus.cache.level2.mode","ENABLE_SELECTIVE");
 
         // automatically install any fixtures that might have been registered
-        add(ObjectStore.INSTALL_FIXTURES_KEY , "true");
+        add(PersistenceSession.INSTALL_FIXTURES_KEY , "true");
 
         add(PersistenceConstants.ENFORCE_SAFE_SEMANTICS, ""+PersistenceConstants.ENFORCE_SAFE_SEMANTICS_DEFAULT);
 

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
index bd4241c..8f64054 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
@@ -70,7 +70,7 @@ public class ObjectStoreTransactionManager_EndTransactionTest {
             will(returnValue(mockMessageBroker));
         }});
 
-        transactionManager = new IsisTransactionManager(mockPersistenceSession, mockObjectStore, new ServicesInjectorDefault(Collections.emptyList())) {
+        transactionManager = new IsisTransactionManager(mockPersistenceSession, new ServicesInjectorDefault(Collections.emptyList())) {
             @Override
             public AuthenticationSession getAuthenticationSession() {
                 return mockAuthenticationSession;

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_InstantiationTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_InstantiationTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_InstantiationTest.java
index e917802..b55ff24 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_InstantiationTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_InstantiationTest.java
@@ -46,7 +46,7 @@ public class ObjectStoreTransactionManager_InstantiationTest {
 
     @Test
     public void canInstantiate() throws Exception {
-        transactionManager = new IsisTransactionManager(mockPersistenceSession, mockObjectStore, new ServicesInjectorDefault(Collections.emptyList()));
+        transactionManager = new IsisTransactionManager(mockPersistenceSession, new ServicesInjectorDefault(Collections.emptyList()));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_StartTransactionTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_StartTransactionTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_StartTransactionTest.java
index cb8fe52..17867c1 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_StartTransactionTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_StartTransactionTest.java
@@ -58,7 +58,7 @@ public class ObjectStoreTransactionManager_StartTransactionTest {
 
     @Before
     public void setUpTransactionManager() throws Exception {
-        transactionManager = new IsisTransactionManager(mockPersistenceSession, mockObjectStore, new ServicesInjectorDefault(Collections.emptyList())) {
+        transactionManager = new IsisTransactionManager(mockPersistenceSession, new ServicesInjectorDefault(Collections.emptyList())) {
             @Override
             protected AuthenticationSession getAuthenticationSession() {
                 return mockAuthenticationSession;

http://git-wip-us.apache.org/repos/asf/isis/blob/459a7319/core/runtime/src/test/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionTest.java
index ce387c9..e8144f2 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionTest.java
@@ -168,7 +168,7 @@ public class PersistenceSessionTest {
 
         
         transactionManager = persistenceSession.getTransactionManager();
-        new IsisTransactionManager(persistenceSession, mockObjectStore, servicesInjector) {
+        new IsisTransactionManager(persistenceSession, servicesInjector) {
             @Override
             public AuthenticationSession getAuthenticationSession() {
                 return mockAuthenticationSession;
@@ -188,14 +188,14 @@ public class PersistenceSessionTest {
         final Sequence tran = context.sequence("tran");
         context.checking(new Expectations() {
             {
-                one(mockObjectStore).startTransaction();
-                inSequence(tran);
+//                one(mockObjectStore).startTransaction();
+//                inSequence(tran);
 
 //                one(mockObjectStore).createDestroyObjectCommand(persistentAdapter);
 //                inSequence(tran);
 
-                one(mockObjectStore).abortTransaction();
-                inSequence(tran);
+//                one(mockObjectStore).abortTransaction();
+//                inSequence(tran);
             }
         });
         
@@ -211,8 +211,8 @@ public class PersistenceSessionTest {
         final Sequence tran = context.sequence("tran");
         context.checking(new Expectations() {
             {
-                oneOf(mockObjectStore).startTransaction();
-                inSequence(tran);
+//                oneOf(mockObjectStore).startTransaction();
+//                inSequence(tran);
 
 //                oneOf(mockObjectStore).createDestroyObjectCommand(persistentAdapter);
 //                inSequence(tran);
@@ -229,8 +229,8 @@ public class PersistenceSessionTest {
 //                oneOf(mockObjectStore).execute(with(equalTo(Collections.<PersistenceCommand>emptyList())));
 //                inSequence(tran);
 
-                oneOf(mockObjectStore).endTransaction();
-                inSequence(tran);
+//                oneOf(mockObjectStore).endTransaction();
+//                inSequence(tran);
             }
 
         });
@@ -247,8 +247,8 @@ public class PersistenceSessionTest {
         final Sequence tran = context.sequence("tran");
         context.checking(new Expectations() {
             {
-                oneOf(mockObjectStore).startTransaction();
-                inSequence(tran);
+//                oneOf(mockObjectStore).startTransaction();
+//                inSequence(tran);
 
 //                oneOf(mockObjectStore).execute(with(equalTo(Collections.<PersistenceCommand>emptyList())));
 //                inSequence(tran);
@@ -261,8 +261,8 @@ public class PersistenceSessionTest {
 //                oneOf(mockObjectStore).execute(with(equalTo(Collections.<PersistenceCommand>emptyList())));
 //                inSequence(tran);
 
-                oneOf(mockObjectStore).endTransaction();
-                inSequence(tran);
+//                oneOf(mockObjectStore).endTransaction();
+//                inSequence(tran);
             }
         });