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 19:09:25 UTC

[3/3] isis git commit: ISIS-1194: inlining PersistAlgorithm to PersistenceSession

ISIS-1194: inlining PersistAlgorithm to PersistenceSession


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

Branch: refs/heads/ISIS-1194
Commit: 1cdbf74d704f0dcdc4ec61086d59308a7658ab5f
Parents: 97eed79
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Sep 10 18:09:05 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Sep 10 18:09:05 2015 +0100

----------------------------------------------------------------------
 .../objectstore/algorithm/PersistAlgorithm.java |  93 -------------
 .../objectstore/algorithm/package-info.java     |  39 ------
 .../system/persistence/PersistenceSession.java  |  37 +++++-
 .../adapterfactory/pojo/PojoAdapterTest.java    |   6 +-
 .../algorithm/PersistAlgorithmContractTest.java | 132 -------------------
 .../transaction/PojoAdapterBuilder.java         |  14 +-
 6 files changed, 42 insertions(+), 279 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
deleted file mode 100644
index a78dd7f..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
+++ /dev/null
@@ -1,93 +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.core.runtime.persistence.objectstore.algorithm;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.util.ToString;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-
-public class PersistAlgorithm {
-
-    private static final Logger LOG = LoggerFactory
-            .getLogger(PersistAlgorithm.class);
-
-
-    // ////////////////////////////////////////////////////////////////
-    // name
-    // ////////////////////////////////////////////////////////////////
-
-    public String name() {
-        return "PersistAlgorithm";
-    }
-
-
-    // ////////////////////////////////////////////////////////////////
-    // makePersistent
-    // ////////////////////////////////////////////////////////////////
-
-    public void makePersistent(final ObjectAdapter adapter,
-            final PersistenceSession persistenceSession) {
-        if (alreadyPersistedOrNotPersistable(adapter)) {
-            return;
-        }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("persist " + adapter);
-        }
-
-        // previously we called the PersistingCallback here.
-        // this is now done in the JDO framework synchronizer.
-        //
-        // the guard below used to be because (apparently)
-        // the callback might have caused the adapter to become persistent.
-        // leaving it in as think it does no harm...
-        if (alreadyPersistedOrNotPersistable(adapter)) {
-            return;
-        }
-        persistenceSession.addCreateObjectCommand(adapter);
-    }
-
-
-    private static boolean alreadyPersistedOrNotPersistable(final ObjectAdapter adapter) {
-        return adapter.representsPersistent() || objectSpecNotPersistable(adapter);
-    }
-
-
-    private static boolean objectSpecNotPersistable(final ObjectAdapter adapter) {
-        return !adapter.getSpecification().persistability().isPersistable() || adapter.isParentedCollection();
-    }
-
-
-
-    // ////////////////////////////////////////////////////////////////
-    // toString
-    // ////////////////////////////////////////////////////////////////
-
-    @Override
-    public String toString() {
-        final ToString toString = new ToString(this);
-        return toString.toString();
-    }
-
-
-
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/package-info.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/package-info.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/package-info.java
deleted file mode 100644
index 50837aa..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/package-info.java
+++ /dev/null
@@ -1,39 +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.
- */
-
-/**
- * This interface is used by the {@link org.apache.isis.core.runtime.system.persistence.PersistenceSession} and
- * is generally not intended to be implemented directly.  
- * 
- * <p>
- * The {@link PersistAlgorithm} defines how persistence-by-reachability is enacted.  This only
- * applies to the <tt>ObjectStorePersistor</tt> implementation, but has been brought up into
- * <tt>architecture</tt> module because it is very much a peer of the other helper objects
- * that influence the {@link org.apache.isis.core.runtime.system.persistence.PersistenceSession}'s behaviour, such
- * as {@link ClassSubstitutor} and {@link org.apache.isis.core.runtime.system.persistence.OidGenerator}. 
- * 
- * <p>
- * Since there is a close dependency between the {@link org.apache.isis.core.runtime.system.persistence.PersistenceSession}
- * and the {@link PersistAlgorithm} implementation, it is the job of the {@link org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller} to
- * ensure that the correct {@link PersistAlgorithm} is setup.
- * 
- * @see org.apache.isis.metamodel.specloader.classsubstitutor.classsubstitor.ClassSubstitutor.ClassStrategy
- * @see org.apache.isis.core.runtime.system.persistence.OidGenerator
- */
-package org.apache.isis.core.runtime.persistence.objectstore.algorithm;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/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 9afba03..8ab0e77 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
@@ -81,7 +81,6 @@ import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
 import org.apache.isis.core.runtime.persistence.PojoRefreshException;
 import org.apache.isis.core.runtime.persistence.UnsupportedFindException;
 import org.apache.isis.core.runtime.persistence.adaptermanager.AdapterManagerDefault;
-import org.apache.isis.core.runtime.persistence.objectstore.algorithm.PersistAlgorithm;
 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;
@@ -134,8 +133,6 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
     private final OidGenerator oidGenerator;
     private final AdapterManagerDefault adapterManager;
 
-    private final PersistAlgorithm persistAlgorithm ;
-
     private final PersistenceQueryFactory persistenceQueryFactory;
     private final IsisConfiguration configuration;
     private final SpecificationLoaderSpi specificationLoader;
@@ -191,7 +188,6 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
 
         this.adapterManager = new AdapterManagerDefault(this, specificationLoader, oidMarshaller,
                 oidGenerator, authenticationSession, servicesInjector, configuration);
-        this.persistAlgorithm = new PersistAlgorithm();
 
         this.persistenceQueryFactory = new PersistenceQueryFactory(getSpecificationLoader(), adapterManager);
         this.transactionManager = new IsisTransactionManager(this, servicesInjector);
@@ -872,7 +868,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
 
             @Override
             public void execute() {
-                persistAlgorithm.makePersistent(adapter, PersistenceSession.this);
+                makePersistent(adapter);
 
                 // clear out the map of transient -> persistent
                 PersistenceSession.this.persistentByTransient.clear();
@@ -881,6 +877,37 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
         });
     }
 
+    private void makePersistent(final ObjectAdapter adapter) {
+        if (alreadyPersistedOrNotPersistable(adapter)) {
+            return;
+        }
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("persist " + adapter);
+        }
+
+        // previously we called the PersistingCallback here.
+        // this is now done in the JDO framework synchronizer.
+        //
+        // the guard below used to be because (apparently)
+        // the callback might have caused the adapter to become persistent.
+        // leaving it in as think it does no harm...
+        if (alreadyPersistedOrNotPersistable(adapter)) {
+            return;
+        }
+        addCreateObjectCommand(adapter);
+    }
+
+
+    private static boolean alreadyPersistedOrNotPersistable(final ObjectAdapter adapter) {
+        return adapter.representsPersistent() || objectSpecNotPersistable(adapter);
+    }
+
+
+    private static boolean objectSpecNotPersistable(final ObjectAdapter adapter) {
+        return !adapter.getSpecification().persistability().isPersistable() || adapter.isParentedCollection();
+    }
+
+
     //endregion
 
     //region > destroyObjectInTransaction

http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
index 04702b2..bbb3cb1 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
@@ -30,7 +30,6 @@ import org.junit.Test;
 import org.apache.isis.applib.profiles.Localization;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 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.RootOid;
 import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
 import org.apache.isis.core.metamodel.adapter.version.Version;
@@ -38,6 +37,7 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
 import org.apache.isis.core.runtime.persistence.adapter.PojoAdapter;
 import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
 
@@ -61,7 +61,7 @@ public class PojoAdapterTest {
     @Mock
     private AuthenticationSession mockAuthenticationSession;
     @Mock
-    private AdapterManager mockObjectAdapterLookup;
+    private PersistenceSession mockPersistenceSession;
     @Mock
     private Localization mockLocalization;
     
@@ -70,7 +70,7 @@ public class PojoAdapterTest {
         domainObject = new RuntimeTestPojo();
         
         adapter = new PojoAdapter(domainObject, RootOid.create(ObjectSpecId.of("CUS"), "1"), mockAuthenticationSession,
-                mockLocalization, mockSpecificationLoader, persistenceSession);
+                mockLocalization, mockSpecificationLoader, mockPersistenceSession);
         adapter.setVersion(mockVersion);
         
         allowUnimportantMethodCallsOn(mockVersion);

http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
deleted file mode 100644
index ece097c..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
+++ /dev/null
@@ -1,132 +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.core.runtime.persistence.objectstore.algorithm;
-
-import org.jmock.Expectations;
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.Persistability;
-import org.apache.isis.core.runtime.persistence.NotPersistableException;
-import org.apache.isis.core.runtime.persistence.adapter.PojoAdapter;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Persistence;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Type;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-
-public abstract class PersistAlgorithmContractTest {
-
-    @Rule
-    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
-    @Mock
-    private PersistenceSession mockAdder;
-
-    @Mock
-    private ObjectSpecification objectSpec;
-
-    @Mock
-    private AdapterManager mockObjectAdapterLookup;
-    
-    private PersistAlgorithm persistAlgorithm;
-
-    
-
-    @Before
-    public void setUp() throws Exception {
-        persistAlgorithm = createPersistAlgorithm();
-    }
-
-    /**
-     * Hook for any implementation to implement.
-     * 
-     * @return
-     */
-    protected abstract PersistAlgorithm createPersistAlgorithm();
-
-    @Test
-    public void makePersistent_skipsValueObjects() {
-        
-        context.checking(new Expectations() {
-            {
-                allowing(objectSpec).isParentedOrFreeCollection();
-                will(returnValue(false));
-
-                allowing(objectSpec).persistability();
-                will(returnValue(Persistability.USER_PERSISTABLE));
-                
-                never(mockAdder);
-            }
-        });
-
-        final PojoAdapter valueAdapter = PojoAdapterBuilder.create().with(Type.VALUE).with(objectSpec).build();
-        persistAlgorithm.makePersistent(valueAdapter, mockAdder);
-    }
-
-
-    @Test(expected=NotPersistableException.class)
-    public void makePersistent_failsIfObjectAlreadyPersistent() {
-        context.checking(new Expectations() {
-            {
-                allowing(objectSpec).isService();
-                will(returnValue(false));
-
-                allowing(objectSpec).isParentedOrFreeCollection();
-                will(returnValue(false));
-
-                allowing(objectSpec).persistability();
-                will(returnValue(Persistability.PROGRAM_PERSISTABLE));
-                
-                never(mockAdder);
-            }
-        });
-        
-        final PojoAdapter rootAdapter = PojoAdapterBuilder.create().with(Type.ROOT).with(Persistence.PERSISTENT).with(objectSpec).build();
-        persistAlgorithm.makePersistent(rootAdapter, mockAdder);
-    }
-    
-    
-    @Test(expected=NotPersistableException.class)
-    public void makePersistent_failsIfObjectMustBeTransient() {
-        context.checking(new Expectations() {
-            {
-                allowing(objectSpec).isService();
-                will(returnValue(false));
-
-                allowing(objectSpec).isParentedOrFreeCollection();
-                will(returnValue(false));
-
-                allowing(objectSpec).persistability();
-                will(returnValue(Persistability.TRANSIENT));
-                
-                never(mockAdder);
-            }
-        });
-        
-        final PojoAdapter rootAdapter = PojoAdapterBuilder.create().with(Type.ROOT).with(Persistence.TRANSIENT).with(objectSpec).build();
-        persistAlgorithm.makePersistent(rootAdapter, mockAdder);
-    }
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/1cdbf74d/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
index 68c5ec5..e496be2 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
@@ -25,18 +25,20 @@ import com.google.common.base.Splitter;
 
 import org.apache.isis.applib.profiles.Localization;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
-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.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.ParentedCollectionOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.adapter.version.Version;
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 import org.apache.isis.core.runtime.persistence.adapter.PojoAdapter;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
 
 public class PojoAdapterBuilder {
 
+    private PersistenceSession persistenceSession;
+
     private PojoAdapterBuilder(){
     }
     
@@ -47,8 +49,6 @@ public class PojoAdapterBuilder {
     
     private SpecificationLoader specificationLoader;
     
-    private AdapterManager objectAdapterLookup;
-    
     private ObjectSpecId objectSpecId = ObjectSpecId.of("CUS");
     private String identifier = "1";
     // only used if type is AGGREGATED
@@ -166,11 +166,11 @@ public class PojoAdapterBuilder {
         return this;
     }
 
-    public PojoAdapterBuilder with(AdapterManager objectAdapterLookup) {
-        this.objectAdapterLookup = objectAdapterLookup;
+    public PojoAdapterBuilder with(PersistenceSession persistenceSession) {
+        this.persistenceSession = persistenceSession;
         return this;
     }
-    
+
     public PojoAdapterBuilder with(SpecificationLoader specificationLoader) {
         this.specificationLoader = specificationLoader;
         return this;