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 2016/02/26 15:53:04 UTC

[4/6] isis git commit: ISIS-993: fixes to prevent SpecificationCacheDefault from getting out-of-whack (by mapping ObjectSpecId to className, rather than spec; can then use the className to look up the spec in turn).

ISIS-993: fixes to prevent SpecificationCacheDefault from getting out-of-whack (by mapping ObjectSpecId to className, rather than spec; can then use the className to look up the spec in turn).

This stuff came about because reloading of grid after change was only working if invalidated the class spec (= refresh twice).


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

Branch: refs/heads/ISIS-993
Commit: 48fe231be5f2946d81eb2192ebfbdd958bbe21a6
Parents: 23f9233
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Feb 26 14:38:55 2016 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Feb 26 14:39:37 2016 +0000

----------------------------------------------------------------------
 .../specloader/ObjectReflectorDefault.java      |  2 +-
 .../specloader/SpecificationCacheDefault.java   | 23 +++++++++++++-------
 2 files changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/48fe231b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
index a48fab0..2957dd7 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
@@ -385,7 +385,7 @@ public final class ObjectReflectorDefault
             // don't have an ObjectSpecId; hence the guard.
             if(spec.containsDoOpFacet(ObjectSpecIdFacet.class)) {
                 ObjectSpecId specId = spec.getSpecId();
-                if (getCache().getByObjectType(specId) != spec) {
+                if (getCache().getByObjectType(specId) == null) {
                     getCache().recache(spec);
                 }
             }

http://git-wip-us.apache.org/repos/asf/isis/blob/48fe231b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationCacheDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationCacheDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationCacheDefault.java
index 1e4df63..4d2b476 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationCacheDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationCacheDefault.java
@@ -34,7 +34,7 @@ import org.apache.isis.core.metamodel.specloader.validator.ValidationFailures;
 class SpecificationCacheDefault {
     
     private final Map<String, ObjectSpecification> specByClassName = Maps.newHashMap();
-    private Map<ObjectSpecId, ObjectSpecification> specById;
+    private Map<ObjectSpecId, String> classNameBySpecId;
 
     public ObjectSpecification get(final String className) {
         return specByClassName.get(className);
@@ -58,16 +58,20 @@ class SpecificationCacheDefault {
         if (!isInitialized()) {
             throw new IllegalStateException("SpecificationCache by object type has not yet been initialized");
         }
-        return specById.get(objectSpecID);
+        final String className = classNameBySpecId.get(objectSpecID);
+        return className != null ? specByClassName.get(className) : null;
     }
 
     /**
      * Populated as a result of running {@link MetaModelValidator#validate(ValidationFailures)} validation} after
      * xxxallxxx most specs have been loaded.
      */
-    void setCacheBySpecId(Map<ObjectSpecId, ObjectSpecification> specById) {
-        this.specById = Maps.newHashMap();
-        this.specById.putAll(specById);
+    void setCacheBySpecId(final Map<ObjectSpecId, ObjectSpecification> specById) {
+        this.classNameBySpecId = Maps.newHashMap();
+        for (ObjectSpecId objectSpecId : specById.keySet()) {
+            final ObjectSpecification objectSpec = specById.get(objectSpecId);
+            this.classNameBySpecId.put(objectSpecId, objectSpec.getCorrespondingClass().getName());
+        }
     }
 
     public ObjectSpecification remove(String typeName) {
@@ -77,7 +81,7 @@ class SpecificationCacheDefault {
                 // umm.  It turns out that anonymous inner classes (eg org.estatio.dom.WithTitleGetter$ToString$1)
                 // don't have an ObjectSpecId; hence the guard.
                 ObjectSpecId specId = removed.getSpecId();
-                specById.remove(specId);
+                classNameBySpecId.remove(specId);
             }
         }
         return removed;
@@ -92,11 +96,14 @@ class SpecificationCacheDefault {
             // just ignore.
             return;
         }
-        specById.put(spec.getSpecId(), spec);
+        if(!spec.containsDoOpFacet(ObjectSpecIdFacet.class)) {
+            return;
+        }
+        classNameBySpecId.put(spec.getSpecId(), spec.getCorrespondingClass().getName());
     }
     
     boolean isInitialized() {
-        return specById != null;
+        return classNameBySpecId != null;
     }
 
 }