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 2017/09/19 22:06:44 UTC

[09/12] isis git commit: ISIS-1725: requires that an AppManifest is supplied (used to obtain list of entities).

ISIS-1725: requires that an AppManifest is supplied (used to obtain list of entities).


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

Branch: refs/heads/ISIS-1276-dn-5-1
Commit: 2f6ea98f2ba22146b006f525f5fc85f151cfcef0
Parents: 6e7d42e
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Sep 19 22:55:48 2017 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Sep 19 23:05:21 2017 +0100

----------------------------------------------------------------------
 .../persistence/PersistenceSessionFactory.java  |  2 +-
 .../jdo/service/RegisterEntities.java           | 96 ++------------------
 2 files changed, 9 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/2f6ea98f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
index 8a89c8a..4be046c 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
@@ -93,7 +93,7 @@ public class PersistenceSessionFactory implements ApplicationScopedComponent, Fi
             final Map<String, String> datanucleusProps = dataNucleusConfig.asMap();
             addDataNucleusPropertiesIfRequired(datanucleusProps);
 
-            final RegisterEntities registerEntities = new RegisterEntities(configuration.asMap(), specificationLoader);
+            final RegisterEntities registerEntities = new RegisterEntities(specificationLoader);
             final Set<String> classesToBePersisted = registerEntities.getEntityTypes();
 
             applicationComponents = new DataNucleusApplicationComponents(jdoObjectstoreConfig, specificationLoader,

http://git-wip-us.apache.org/repos/asf/isis/blob/2f6ea98f/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
index 538b5b1..a83b115 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
@@ -18,23 +18,13 @@
  */
 package org.apache.isis.objectstore.jdo.service;
 
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
-import javax.jdo.annotations.PersistenceCapable;
-
-import com.google.common.base.Function;
 import com.google.common.base.Joiner;
-import com.google.common.base.Predicate;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-import org.reflections.Reflections;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,7 +35,11 @@ public class RegisterEntities {
 
     @SuppressWarnings("unused")
     private final static Logger LOG = LoggerFactory.getLogger(RegisterEntities.class);
-    
+
+    /**
+     * @deprecated - no longer used; instead an AppManifest must be specified.
+     */
+    @Deprecated
     public final static String PACKAGE_PREFIX_KEY = "isis.persistor.datanucleus.RegisterEntities.packagePrefix";
 
     // //////////////////////////////////////
@@ -60,13 +54,13 @@ public class RegisterEntities {
     }
     //endregion
 
-    public RegisterEntities(final Map<String, String> configuration, final SpecificationLoader specificationLoader) {
+    public RegisterEntities(final SpecificationLoader specificationLoader) {
         this.specificationLoader = specificationLoader;
 
         Set<Class<?>> persistenceCapableTypes = AppManifest.Registry.instance().getPersistenceCapableTypes();
 
         if(persistenceCapableTypes == null) {
-            persistenceCapableTypes = searchForPersistenceCapables(configuration);
+            throw new IllegalStateException("AppManifest is required");
         }
 
         final List<String> classNamesNotEnhanced = Lists.newArrayList();
@@ -86,88 +80,14 @@ public class RegisterEntities {
         }
     }
 
-    /**
-     * only called if no appManifest
-     */
-    Set<Class<?>> searchForPersistenceCapables(final Map<String, String> configuration) {
-
-        final String packagePrefixes = lookupPackagePrefixes(configuration);
-
-        final Set<Class<?>> persistenceCapableTypes = Sets.newLinkedHashSet();
-        final List<String> domPackages = parseDomPackages(packagePrefixes);
-        for (final String packageName : domPackages) {
-            Reflections reflections = new Reflections(packageName);
-            final Set<Class<?>> entityTypesInPackage =
-                    reflections.getTypesAnnotatedWith(PersistenceCapable.class);
-
-            if(!entitiesIn(entityTypesInPackage)) {
-                throw new IllegalArgumentException(String.format(
-                        "Bad configuration.\n\nCould not locate any @PersistenceCapable entities in package '%s'\n" +
-                                "Check value of '%s' key in WEB-INF/*.properties\n",
-                        packageName,
-                        PACKAGE_PREFIX_KEY));
-            }
-            persistenceCapableTypes.addAll(entityTypesInPackage);
-        }
-        return persistenceCapableTypes;
-    }
-
-    private String lookupPackagePrefixes(final Map<String, String> configuration) {
-        final String packagePrefixes = configuration.get(PACKAGE_PREFIX_KEY);
-        if(Strings.isNullOrEmpty(packagePrefixes)) {
-            throw new IllegalArgumentException(String.format(
-                    "Could not locate '%s' key in property files - aborting",
-                    PACKAGE_PREFIX_KEY));
-        }
-        return packagePrefixes;
-    }
-
-    private static List<String> parseDomPackages(String packagePrefixes) {
-        return Collections.unmodifiableList(Lists.newArrayList(Iterables.transform(Splitter.on(",").split(packagePrefixes), trim())));
-    }
-
     private static boolean ignore(final Class<?> entityType) {
-        try {
-            if(entityType.isAnonymousClass() || entityType.isLocalClass() || entityType.isMemberClass()) {
-                return true;
-            }
-            final PersistenceCapable persistenceCapable = entityType.getAnnotation(PersistenceCapable.class);
-            return persistenceCapable == null; // ignore if doesn't have @PersistenceCapable
-        } catch (NoClassDefFoundError ex) {
-            return true;
-        }
-    }
-
-    private static Function<String,String> trim() {
-        return new Function<String,String>(){
-            @Override
-            public String apply(String input) {
-                return input.trim();
-            }
-        };
-    }
-
-    private static boolean entitiesIn(Set<Class<?>> entityTypes) {
-        return Iterables.filter(entityTypes, notNullClass()).iterator().hasNext();
+        return entityType.isAnonymousClass() || entityType.isLocalClass() || entityType.isMemberClass() || entityType.isAnnotation();
     }
 
-    /**
-     * {@link Reflections} seems to return a set with 1 null element if none can be found, so we ignore these.
-     */
-    private static <T> Predicate<T> notNullClass() {
-        return new Predicate<T>() {
-            @Override
-            public boolean apply(T input) {
-                return input != null;
-            }
-        };
-    }
 
-    // //////////////////////////////////////
 
     SpecificationLoader getSpecificationLoader() {
         return specificationLoader;
     }
 
-
 }