cleanup
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 26 Jun 2020 17:40:48 +0000 (19:40 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 26 Jun 2020 18:50:46 +0000 (20:50 +0200)
12 files changed:
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CacheLoader.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmClientCacheException.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmEntityCacheKey.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmModelCacher.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmModelCacherConnectionProvider.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmModelFieldPropertyFromClass.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmRemoteCacheManager.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmTransientEntityAndUuidCacher.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmTransientEntityCacher.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/EntityCacherDebugResult.java
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/ProxyUtils.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/utility/CdmUserHelper.java

index af5c06a15124d31d1f6ae44f2b147dcf29d08bc8..1fc905bb4e7e54ebcde8fab42d4c3a08a00969a9 100644 (file)
@@ -39,13 +39,11 @@ public class CacheLoader {
 
     private final Cache cdmlibModelCache;
 
-
     public CacheLoader(ICdmCacher cdmCacher) {
         this.cdmCacher = cdmCacher;
         this.cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
     }
 
-
     public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
         Element e = cdmlibModelCache.get(className);
         if (e == null) {
@@ -213,7 +211,7 @@ public class CacheLoader {
      * cache.
      * <p>
      * <b>WARNING: Recursive updating of the cached entity will not take place
-     * in case there is a cached entity which is the same object as
+     * in case there is a cached entity which is the same/identical object as
      * <code>cdmEntity</code>.</b>
      *
      * For in depth details on the mechanism see
@@ -284,6 +282,8 @@ public class CacheLoader {
      *            all fields of the cached entity will be overwritten by setting
      *            them to the value of the cdm entity being loaded
      * @return
+     *            The cached object which is identical with the input entity in case
+     *            the object did not yet exist in the cache
      */
     private <T extends CdmBase> T loadRecursive(T cdmEntity,  List<Object> alreadyVisitedEntities, boolean update) {
 
@@ -336,7 +336,7 @@ public class CacheLoader {
      * <code>cdmEntity</code>. In case the cached field value contains a proxy
      * object the value will always be overwritten (Q: This might only occur in
      * case of uninitialized proxies, since initialized proxies are expected to
-     * be replaces by the target entity.)
+     * be replaced by the target entity.)
      *
      * @param cdmEntity
      *            the entity to be loaded into the cache
@@ -405,7 +405,7 @@ public class CacheLoader {
                     if(cachedCdmEntityInSubGraph != null) {
                         if(cachedCdmEntityInSubGraph != cdmEntityInSubGraph) {
                             // exception : is the case where
-                            // the field has been already initialised, cached and
+                            // the field has been already initialized, cached and
                             // is not the same as the one in the cache, in which case we set the value
                             // of the field to the one found in the cache
                             logger.debug("setting cached + real value to '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
@@ -414,7 +414,7 @@ public class CacheLoader {
                         } else {
                             // since the field value object in cdmEntity
                             // is the same as the field value object in cachedCdmEntity
-                            // we are sure that the its subgraph is also correctly loaded,
+                            // we are sure that the subgraph is also correctly loaded,
                             // so we can exit the recursion
                             return null;
                         }
@@ -429,11 +429,7 @@ public class CacheLoader {
             // want to continue to recurse on the input cdm entity graph
             // and not the one in the cache
             return cdmEntityInSubGraph;
-        } catch (SecurityException e) {
-            throw new CdmClientCacheException(e);
-        } catch (IllegalArgumentException e) {
-            throw new CdmClientCacheException(e);
-        } catch (IllegalAccessException e) {
+        } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
             throw new CdmClientCacheException(e);
         }
     }
index 6d352ad5d73e43e411a7dc64f0a5aef33e50debf..f61051d037e2d1bd0762ac91b5c6ceeb6e4ceda9 100644 (file)
@@ -1,8 +1,18 @@
+/**
+ * Copyright (C) 2014 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 public class CdmClientCacheException extends RuntimeException {
-       
-       public CdmClientCacheException(String message) {
+
+    private static final long serialVersionUID = -7933042695466513846L;
+
+    public CdmClientCacheException(String message) {
                super(message);
        }
 
index 4025bbb2aaac30375650537764616f8185c04c19..dc42b2a908069b7d787be44958dd046428b7d8a2 100644 (file)
@@ -1,3 +1,11 @@
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -5,25 +13,18 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 public class CdmEntityCacheKey<T extends CdmBase> {
 
        private Class<T> persistenceClass;
-       private int persistenceId;
-
+       private int persistenceId;   //see #7709 for why we use id, not uuid
 
        public CdmEntityCacheKey(T cdmBase) {
                this.persistenceClass = (Class<T>)cdmBase.getClass();
                this.persistenceId = cdmBase.getId();
        }
 
-       /**
-        * @param clazz
-        * @param uuid
-        */
        public CdmEntityCacheKey(Class<T> clazz, int id) {
                this.persistenceClass = clazz;
                this.persistenceId = id;
        }
 
-
-
        public Class<? extends T> getPersistenceClass() {
                return persistenceClass;
        }
@@ -31,12 +32,12 @@ public class CdmEntityCacheKey<T extends CdmBase> {
        public int getPersistenceId() {
                return persistenceId;
        }
+
        @Override
        public boolean equals(Object obj) {
                if(obj == null || !(obj instanceof CdmEntityCacheKey)) {
                        return false;
                }
-
                if(this == obj) {
                        return true;
                }
@@ -45,7 +46,6 @@ public class CdmEntityCacheKey<T extends CdmBase> {
                        && this.persistenceId == that.persistenceId) {
                        return true;
                }
-
                return false;
        }
 
@@ -56,7 +56,7 @@ public class CdmEntityCacheKey<T extends CdmBase> {
 
        @Override
        public String toString() {
-               return this.persistenceClass.getName() + String.valueOf(this.persistenceId);
+               return this.persistenceClass.getName() +":" + String.valueOf(this.persistenceId);
        }
 
 }
index ceb32f32dc4d230bac60f1301f77103ace54be57..c62c838014d2a118df3d727b2e4abf8e9b4b1d38 100644 (file)
@@ -1,3 +1,11 @@
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 import java.io.File;
@@ -28,7 +36,6 @@ import org.hibernate.property.access.spi.Getter;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
-
 /**
  * This class is serializing and deserializing the CDM model for performance purposes.
  * To serialize see comments on {@link #main(String[])} and on
@@ -47,7 +54,6 @@ public class CdmModelCacher {
     public static final String CDM_MAP_SER_FOLDER = "/eu/etaxonomy/cdm/mappings/";
     public static final String CDM_MAP_SER_FILE_PATH = CDM_MAP_SER_FOLDER + CDM_MAP_SER_FILE;
 
-
     public void cacheGetterFields(Cache cache) throws IOException, ClassNotFoundException, URISyntaxException {
         Map<String, CdmModelFieldPropertyFromClass> modelClassMap = loadModelClassMap();
 
@@ -78,7 +84,6 @@ public class CdmModelCacher {
         return modelClassMap;
     }
 
-
     public Map<String, CdmModelFieldPropertyFromClass> generateModelClassMap() {
 
        // A SessionFactory is set up once for an application!
@@ -98,7 +103,6 @@ public class CdmModelCacher {
                Map<String, ClassMetadata> classMetaDataMap = sessionFactory.getAllClassMetadata();
 //             Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build();
 
-
             for(ClassMetadata classMetaData : classMetaDataMap.values()) {
                Class<?> mappedClass = classMetaData.getMappedClass();
 
@@ -117,12 +121,9 @@ public class CdmModelCacher {
                StandardServiceRegistryBuilder.destroy( registry );
                e.printStackTrace();
        }
-
-
         return modelClassMap;
     }
 
-
     public static Configuration buildConfiguration(String hibernateConfigFilePath) {
         Configuration configuration = new Configuration().configure(hibernateConfigFilePath);
         configuration.buildMappings();
@@ -148,8 +149,6 @@ public class CdmModelCacher {
         }
     }
 
-
-
     public static void main(String argv[]) {
 
         // To re-create the serialised cdm map run,
@@ -158,7 +157,6 @@ public class CdmModelCacher {
        // See also https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/TaxonomicEditorDevelopersGuide#Model-Change-Actions
        //Note AM: does not fully work for me, but running the main from the IDE works.
 
-
         CdmModelCacher cdmModelCacher = new CdmModelCacher();
         Map<String, CdmModelFieldPropertyFromClass> modelClassMap = cdmModelCacher.generateModelClassMap();
         try{
@@ -178,6 +176,5 @@ public class CdmModelCacher {
         }catch(Exception ex){
             ex.printStackTrace();
         }
-
     }
 }
index b5ece7835d8b5efb1d97c00a057b3a9992f6d4f9..eb98b704c2bd5a0a010c4c395c25f13c53ac050f 100644 (file)
@@ -1,3 +1,11 @@
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 import javax.sql.DataSource;
@@ -15,7 +23,6 @@ import eu.etaxonomy.cdm.database.CdmDataSource;
  * When changing this class please also adapt https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/TaxonomicEditorDevelopersGuide#Model-Change-Actions
  *
  * @author a.mueller
- *
  */
 public class CdmModelCacherConnectionProvider extends DatasourceConnectionProviderImpl{
        private static final long serialVersionUID = 454393966637126346L;
@@ -32,7 +39,4 @@ public class CdmModelCacherConnectionProvider extends DatasourceConnectionProvid
         CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path);
         return dataSource;
        }
-
-
-
 }
index 603069579dbf9162174672aad259b5c4380532fa..c2184f217ee94e71ded14cc058e425d3ad3f1aec 100644 (file)
@@ -1,3 +1,11 @@
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 import java.io.Serializable;
@@ -13,7 +21,6 @@ public class CdmModelFieldPropertyFromClass implements Serializable {
 
        private List<String> fields = new ArrayList<>();
 
-
        public CdmModelFieldPropertyFromClass(String className) {
                this.setClassName(className);
        }
@@ -21,7 +28,6 @@ public class CdmModelFieldPropertyFromClass implements Serializable {
        public String getParentClassName() {
                return parentClassName;
        }
-
        public void setParentClassName(String parentClassName) {
                this.parentClassName = parentClassName;
        }
@@ -29,7 +35,6 @@ public class CdmModelFieldPropertyFromClass implements Serializable {
        public List<String> getFields() {
                return fields;
        }
-
        public void setFields(List<String> fields) {
                this.fields = fields;
        }
@@ -41,7 +46,6 @@ public class CdmModelFieldPropertyFromClass implements Serializable {
        public String getClassName() {
                return className;
        }
-
        public void setClassName(String className) {
                this.className = className;
        }
index e4a8fb2e98ce3f7e1a9746ddc552ad078ff5b1ca..4014fb572cc6d6de8268593be8ae0998cf7917c9 100644 (file)
@@ -1,22 +1,30 @@
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.cache;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
 
+import org.apache.log4j.Logger;
+
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheException;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.config.CacheConfiguration;
 import net.sf.ehcache.config.SizeOfPolicyConfiguration;
 
-import org.apache.log4j.Logger;
-
 
 public class CdmRemoteCacheManager {
 
+    @SuppressWarnings("unused")
     private static final Logger logger = Logger.getLogger(CdmRemoteCacheManager.class);
 
-
     private Cache cdmlibModelCache;
 
     private static CdmRemoteCacheManager cdmRemoteCacheManager = null;
@@ -33,7 +41,6 @@ public class CdmRemoteCacheManager {
     }
 
     public static CdmRemoteCacheManager getInstance(){
-
         if(cdmRemoteCacheManager == null) {
             cdmRemoteCacheManager = new CdmRemoteCacheManager();
         }
@@ -41,7 +48,6 @@ public class CdmRemoteCacheManager {
     }
     private CdmRemoteCacheManager() {
 
-
         try {
             // NOTE:Programmatically creating the cache manager may solve the problem of
             //      recreating data written to disk on startup
@@ -54,10 +60,10 @@ public class CdmRemoteCacheManager {
             sizeOfConfig.setMaxDepthExceededBehavior("abort");
 
             CacheConfiguration modelcc = new CacheConfiguration(CDM_MODEL_CACHE_NAME, 0)
-            .eternal(true)
-            .statistics(true)
-            .sizeOfPolicy(sizeOfConfig)
-            .overflowToOffHeap(false);
+                    .eternal(true)
+                    .statistics(true)
+                    .sizeOfPolicy(sizeOfConfig)
+                    .overflowToOffHeap(false);
 
             cdmlibModelCache = new Cache(modelcc);
 
@@ -65,19 +71,11 @@ public class CdmRemoteCacheManager {
             CdmModelCacher cmdmc = new CdmModelCacher();
             cmdmc.cacheGetterFields(cdmlibModelCache);
 
-        } catch (CacheException e) {
-            throw new CdmClientCacheException(e);
-        } catch (ClassNotFoundException e) {
-            throw new CdmClientCacheException(e);
-        } catch (IOException e) {
-            throw new CdmClientCacheException(e);
-        } catch (URISyntaxException e) {
+        } catch (CacheException | ClassNotFoundException | IOException | URISyntaxException e) {
             throw new CdmClientCacheException(e);
         }
-
     }
 
-
     public Cache getCdmModelGetMethodsCache(){
         return cdmlibModelCache;
     }
index d96ac60699ae92b2f5183b5a4dead37662b69831..ae9af3b9409229f60ceaf7a90cdf63a29e2b9802 100644 (file)
@@ -24,22 +24,15 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
  *
  * @author a.kohlbecker
  * @since Oct 14, 2018
- *
  */
 public class CdmTransientEntityAndUuidCacher extends CdmTransientEntityCacher implements ICdmEntityUuidCacher {
 
     private Map<UUID, CdmEntityCacheKey<?>> uuidKeyMap = new HashMap<>();
 
-    /**
-     * @param cacheId
-     */
     public CdmTransientEntityAndUuidCacher(String cacheId) {
         super(cacheId);
     }
 
-    /**
-     * @param sessionOwner
-     */
     public CdmTransientEntityAndUuidCacher(Object sessionOwner) {
         super(sessionOwner);
     }
@@ -55,12 +48,9 @@ public class CdmTransientEntityAndUuidCacher extends CdmTransientEntityCacher im
         uuidKeyMap.put(cdmEntityToCache.getUuid(), key);
     }
 
-
     @Override
     public void dispose() {
         super.dispose();
         uuidKeyMap.clear();
     }
-
-
 }
index 0d0a90befeadbabba5b0a5de62ecacd42953e481..8cedd5aeb49aa24042b46adce5cd235058ee98ac 100644 (file)
@@ -48,7 +48,6 @@ import net.sf.ehcache.statistics.LiveCacheStatistics;
  *
  * @author cmathew
  * @since 14 Oct 2014
- *
  */
 public class CdmTransientEntityCacher implements ICdmCacher {
 
@@ -77,8 +76,8 @@ public class CdmTransientEntityCacher implements ICdmCacher {
 
         cache = new Cache(getEntityCacheConfiguration(cacheId));
 
-        createCacheManager().removeCache(cache.getName());
-        createCacheManager().addCache(cache);
+        getCacheManager().removeCache(cache.getName());
+        getCacheManager().addCache(cache);
 
         cacheLoader = new CacheLoader(this);
     }
@@ -87,16 +86,34 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         this(generateCacheId(sessionOwner));
     }
 
-    public static String generateCacheId(Object sessionOwner) {
+//****************************** STATIC METHODS *********************************/
+
+    /**
+     * Generates an id for this session.
+     * @param sessionOwner
+     * @return
+     */
+    private static String generateCacheId(Object sessionOwner) {
         return sessionOwner.getClass().getName() +  String.valueOf(sessionOwner.hashCode());
     }
 
+    public static <T extends CdmBase> CdmEntityCacheKey<T> generateKey(Class<T> clazz, int id) {
+        return new CdmEntityCacheKey<T>(clazz, id);
+    }
+
+    public static <T extends CdmBase> CdmEntityCacheKey<T> generateKey(T cdmBase) {
+        Class<T> entityClass = (Class<T>)cdmBase.getClass();
+        return new CdmEntityCacheKey<T>(entityClass, cdmBase.getId());
+    }
+
+    public static void setPermanentCacher(CdmCacher permanentCacher) {
+        permanentCache = permanentCacher;
+    }
+
 //****************************** METHODS *********************************/
 
     /**
      * Returns the default cache configuration.
-     *
-     * @return
      */
     private CacheConfiguration getEntityCacheConfiguration(String cacheId) {
         SizeOfPolicyConfiguration sizeOfConfig = new SizeOfPolicyConfiguration();
@@ -108,11 +125,6 @@ public class CdmTransientEntityCacher implements ICdmCacher {
             .statistics(true)
             .sizeOfPolicy(sizeOfConfig)
             .overflowToOffHeap(false);
-
-    }
-
-    public static void setPermanentCacher(CdmCacher permanentCacher) {
-        permanentCache = permanentCacher;
     }
 
     public LiveCacheStatistics getCacheStatistics() {
@@ -120,23 +132,19 @@ public class CdmTransientEntityCacher implements ICdmCacher {
             return cache.getLiveCacheStatistics();
         }
         return null;
-
     }
 
     /**
      * Returns the cache corresponding to the cache id
-     *
-     * @param cacheId
-     * @return
      */
     private Cache getCache() {
-        return  createCacheManager().getCache(cacheId);
+        return  getCacheManager().getCache(cacheId);
     }
 
     /**
-     * @return
+     * @return the singleton cacheManager
      */
-    protected CacheManager createCacheManager() {
+    protected CacheManager getCacheManager() {
 
         CacheManager cacheManager = CacheManager.create();
 
@@ -185,48 +193,6 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         return cacheLoader.load(cdmEntity, true, update);
     }
 
-
-    /* ################### to be implemented by subclass in taxeditor ########################
-    private CdmBase load(CdmEntityIdentifier cei, boolean update) {
-        return CdmApplicationState.getCommonService().findWithUpdate(cei.getCdmClass(), cei.getId());
-    }
-
-
-    public UpdateResult load(UpdateResult result, boolean update) {
-        // probably a good time to broadcast to other sessions
-
-        Set<CdmBase> updatedObjects = result.getUpdatedObjects();
-        Set<CdmBase> reloadedObjects = new HashSet<CdmBase>();
-        Set<CdmEntityIdentifier> updatedCdmIds = result.getUpdatedCdmIds();
-        boolean updatedCdmIdsIsEmpty = updatedCdmIds.isEmpty();
-
-        // if the cdm identifier set contains identifiers of objects already
-        // present in the updated objects set reomve them
-        for(CdmBase updatedObject : updatedObjects) {
-            if(updatedObject != null && exists(new CdmEntityCacheKey(updatedObject.getClass(), updatedObject.getId()))) {
-                CdmEntityIdentifier cdmEntityIdentifier = new CdmEntityIdentifier(updatedObject.getId(), updatedObject.getClass());
-                if(!updatedCdmIdsIsEmpty && updatedCdmIds.contains(cdmEntityIdentifier)) {
-                    updatedCdmIds.remove(cdmEntityIdentifier);
-                }
-                reloadedObjects.add(cacheLoader.load(updatedObject, true, update));
-            }
-        }
-
-        // remote load cdm identifiers of objects which already exist
-        // in the cache
-
-        for(CdmEntityIdentifier cei : updatedCdmIds) {
-            if(exists(new CdmEntityCacheKey(cei.getCdmClass(), cei.getId()))) {
-                reloadedObjects.add(load(cei, update));
-            }
-
-        }
-        updatedObjects.clear();
-        result.addUpdatedObjects(reloadedObjects);
-        return result;
-    }
-    */
-
     public MergeResult<CdmBase> load(MergeResult<CdmBase> mergeResult, boolean update) {
         return cacheLoader.load(mergeResult, true, update);
     }
@@ -235,7 +201,6 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         return cacheLoader.getFromCdmlibModelCache(className);
     }
 
-
     public void addNewEntity(CdmBase newEntity) {
         if(newEntity != null && newEntity.getId() == 0 && newEntity.getUuid() != null) {
             newEntitiesMap.put(newEntity.getUuid(), newEntity);
@@ -243,8 +208,8 @@ public class CdmTransientEntityCacher implements ICdmCacher {
     }
 
     /**
-     * Puts the passed <code>cdmEntity</code> into the cache as long it does
-     * not yet exist in the caches.
+     * Puts the passed <code>cdmEntity</code> into the according caches
+     * (cache, newEntitiesMap, permanentCache) as long it does not yet exist there.
      * <p>
      * The adjacent <b>ENTITY GRAPH WILL NOT BE LOADED RECURSIVELY</b>
      */
@@ -261,34 +226,29 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         cachedCdmEntity = getFromCache(key);
         if(cachedCdmEntity == null) {
             CdmBase cdmEntityToCache = cdmEntity;
-            CdmBase newEntity = newEntitiesMap.get(cdmEntity.getUuid());
-            if(newEntity != null) {
-                newEntity.setId(cdmEntity.getId());
-                cdmEntityToCache = newEntity;
+            CdmBase newInMapEntity = newEntitiesMap.get(cdmEntity.getUuid());
+            if(newInMapEntity != null) {
+                newInMapEntity.setId(cdmEntity.getId());
+                cdmEntityToCache = newInMapEntity;
             }
             putToCache(key, cdmEntityToCache);
             cdmEntityToCache.initListener();
             newEntitiesMap.remove(cdmEntity.getUuid());
             if (logger.isDebugEnabled()){logger.debug(" - object of type " + cdmEntityToCache.getClass().getName() + " with id " + cdmEntityToCache.getId() + " put in cache");}
             return;
+        }else{
+            logger.debug(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
         }
-        logger.debug(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
     }
 
-    /**
-     * @param key
-     * @param cdmEntityToCache
-     */
     protected void putToCache(CdmEntityCacheKey<?> key, CdmBase cdmEntityToCache) {
         getCache().put(new Element(key, cdmEntityToCache));
     }
 
-
     private Element getCacheElement(CdmEntityCacheKey<?> key) {
         return getCache().get(key);
     }
 
-
     public <T extends CdmBase> T getFromCache(CdmEntityCacheKey<T> id) {
         Element e = getCacheElement(id);
 
@@ -322,12 +282,6 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         return cachedCdmEntity;
     }
 
-    public CdmBase getFromCache(CdmBase cdmBase, Class<? extends CdmBase> clazz) {
-
-        cdmBase = CdmBase.deproxy(cdmBase, clazz);
-        return getFromCache(cdmBase);
-    }
-
     public List<CdmBase> getAllEntities() {
         List<CdmBase> entities = new ArrayList<>();
         Map<String, CdmBase> elementsMap = getCache().getAllWithLoader(getCache().getKeys(), null);
@@ -351,22 +305,11 @@ public class CdmTransientEntityCacher implements ICdmCacher {
 
     @Override
     public void dispose() {
-        createCacheManager().removeCache(cache.getName());
+        getCacheManager().removeCache(cache.getName());
         cache.dispose();
         newEntitiesMap.clear();
     }
 
-
-    public static <T extends CdmBase> CdmEntityCacheKey<T> generateKey(Class<T> clazz, int id) {
-        return new CdmEntityCacheKey<T>(clazz, id);
-    }
-
-
-    public static <T extends CdmBase> CdmEntityCacheKey<T> generateKey(T cdmBase) {
-        Class<T> entityClass = (Class<T>)cdmBase.getClass();
-        return new CdmEntityCacheKey<T>(entityClass, cdmBase.getId());
-    }
-
     @Override
     public <T extends CdmBase> T load(T cdmEntity) {
         return load(cdmEntity, true);
index 1efcc751db0962973740767f26f4a25ff2f53858..ad0f11792f2383bc712119d25759743b3b84ae13 100644 (file)
@@ -32,7 +32,6 @@ import net.sf.ehcache.Element;
 /**
  * @author cmathew
  * @since 9 Feb 2015
- *
  */
 public class EntityCacherDebugResult {
 
@@ -51,7 +50,6 @@ public class EntityCacherDebugResult {
     public EntityCacherDebugResult() {
     }
 
-
     public <T extends CdmBase> EntityCacherDebugResult(CdmTransientEntityCacher cacher, Collection<T> rootEntities) {
         this.cacher = cacher;
         init();
@@ -64,7 +62,6 @@ public class EntityCacherDebugResult {
                 debugOutput.append(out);
                 clear();
             }
-
         }
     }
 
@@ -97,7 +94,6 @@ public class EntityCacherDebugResult {
         System.out.println(toString(duplicateCdmEntityMap, notInCacheList, rootEntity));
     }
 
-
     @Override
     public String toString() {
         return debugOutput.toString();
@@ -107,7 +103,6 @@ public class EntityCacherDebugResult {
             List<CdmEntityInfo> notInCacheList,
             CdmBase rootEntity) {
 
-
         StringBuilder sb = new StringBuilder();
         sb.append(System.getProperty("line.separator"));
         sb.append("<<< Root Entity " + rootEntity.getUserFriendlyTypeName() + " with id " + rootEntity.getId() + " >>>");
@@ -231,7 +226,6 @@ public class EntityCacherDebugResult {
         return caches;
     }
 
-
     private void debug(CdmBase cdmEntity, boolean recursive) {
         if(cdmEntity == null) {
             return;
@@ -258,10 +252,7 @@ public class EntityCacherDebugResult {
         } else if (obj instanceof Collection) {
             debug((Collection<T>)obj, alreadyVisitedEntities, cei);
         }
-
         logger.info("No caching yet for type " + obj.getClass().getName());
-
-
     }
 
     private <T extends Object> void debug(Map<T,T> map,
@@ -306,21 +297,17 @@ public class EntityCacherDebugResult {
                 cei.addChild(childCei);
                 debugRecursive(obj, alreadyVisitedEntities, childCei);
             }
-
         }
-
     }
 
     private void debugRecursive(CdmBase cdmEntity,
             List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
 
-        CdmBase cachedCdmEntityInSubGraph = null;
-
         if(cei.getObject() instanceof CdmBase) {
            CdmBase cb =  (CdmBase)cei.getObject();
            cb = (CdmBase) ProxyUtils.deproxy(cb);
-           cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
+           CdmBase cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
            if(cachedCdmEntityInSubGraph != cb) {
                cei.setNotInCacheDetail(cachedCdmEntityInSubGraph == null ? NotInCacheDetail.NOT_FOUND : NotInCacheDetail.COPY_ENTITY);
                // found a cdm entity which is not in cache - need to record this
@@ -329,7 +316,6 @@ public class EntityCacherDebugResult {
            }
         }
 
-
         // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
         // since there could be new or deleted objects in the cdmEntity sub-graph
 
@@ -417,18 +403,12 @@ public class EntityCacherDebugResult {
             // we return the original cdm entity in the sub graph because we
             // want to continue to recurse on the input cdm entity graph
             // and not the one in the cache
-
             return childCei;
-        } catch (SecurityException e) {
-            throw new CdmClientCacheException(e);
-        } catch (IllegalArgumentException e) {
-            throw new CdmClientCacheException(e);
-        } catch (IllegalAccessException e) {
+        } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
             throw new CdmClientCacheException(e);
         }
     }
 
-
     private CdmEntityInfo getDuplicate(List<CdmEntityInfo> alreadyVisitedEntities, Object objectToCompare) {
         if(objectToCompare != null ) {
             for(CdmEntityInfo cei: alreadyVisitedEntities) {
@@ -474,7 +454,6 @@ public class EntityCacherDebugResult {
         public CdmEntityInfo getParent() {
             return parent;
         }
-
         public void setParent(CdmEntityInfo parent) {
             this.parent = parent;
         }
@@ -482,7 +461,6 @@ public class EntityCacherDebugResult {
         public List<CdmEntityInfo> getChildren() {
             return children;
         }
-
         public void setChildren(List<CdmEntityInfo> children) {
             this.children = children;
         }
@@ -495,12 +473,10 @@ public class EntityCacherDebugResult {
         public Field getField() {
             return field;
         }
-
         public void setField(Field field) {
             this.field = field;
         }
 
-
         public String getLabel() {
             String label;
             String fieldName = "";
@@ -568,20 +544,12 @@ public class EntityCacherDebugResult {
             this.isProxy = isProxy;
         }
 
-        /**
-         * @return the notInCacheDetail
-         */
         public NotInCacheDetail getNotInCacheDetail() {
             return notInCacheDetail;
         }
-
-        /**
-         * @param notInCacheDetail the notInCacheDetail to set
-         */
         public void setNotInCacheDetail(NotInCacheDetail notInCacheDetail) {
             this.notInCacheDetail = notInCacheDetail;
         }
-
     }
 
     enum NotInCacheDetail {
@@ -594,9 +562,6 @@ public class EntityCacherDebugResult {
             this.label = label;
         }
 
-        /**
-         * @return
-         */
         public Object getLabel() {
             return label;
         }
index a8a432a70c3aad53a3cbb0e3533101820a6f7866..67b51ef773e31fe887614b9cfe6b76fcb2ad4a30 100644 (file)
@@ -34,12 +34,9 @@ import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
 /**
  * @author cmathew
  * @since 17 Feb 2015
- *
  */
 public class ProxyUtils {
 
-
-
     public static enum CollectionType {
         SET,
         LIST,
@@ -142,7 +139,6 @@ public class ProxyUtils {
             LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
             if(!hli.isUninitialized()) {
                 return hli.getImplementation();
-
             }
         }
 
@@ -150,7 +146,6 @@ public class ProxyUtils {
             PersistentCollection pc = ((PersistentCollection)o);
             if(pc.wasInitialized()) {
                 return  ProxyUtils.getObject(pc);
-
             }
         }
         return o;
@@ -222,9 +217,6 @@ public class ProxyUtils {
     }
     ########################################### ########################################### */
 
-
-
-
     public static void setRoleValueInOwner(Object owner, String role, Object value) {
         if(role == null || role.isEmpty()) {
             throw new ProxyUtilsException("Role cannot be null or an empty string");
index 6cc88ba6857b86e5e1a6db7eb39d91e4354172a9..71536775001af3f5a4db11d8b58b48593ef8b596 100644 (file)
@@ -35,8 +35,8 @@ import eu.etaxonomy.cdm.database.PermissionDeniedException;
 import eu.etaxonomy.cdm.model.ICdmEntityUuidCacher;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.permission.CRUD;
-import eu.etaxonomy.cdm.model.permission.PermissionClass;
 import eu.etaxonomy.cdm.model.permission.GrantedAuthorityImpl;
+import eu.etaxonomy.cdm.model.permission.PermissionClass;
 import eu.etaxonomy.cdm.model.permission.User;
 import eu.etaxonomy.cdm.persistence.permission.CdmAuthority;
 import eu.etaxonomy.cdm.persistence.permission.CdmAuthorityParsingException;
@@ -46,7 +46,6 @@ import eu.etaxonomy.cdm.persistence.permission.Role;
 /**
  * @author a.kohlbecker
  * @since May 19, 2017
- *
  */
 public class CdmUserHelper implements UserHelper, Serializable {
 
@@ -62,7 +61,7 @@ public class CdmUserHelper implements UserHelper, Serializable {
     @Qualifier("cdmRepository")
     protected CdmRepository repo;
 
-    AuthenticationProvider runAsAuthenticationProvider;
+    private AuthenticationProvider runAsAuthenticationProvider;
 
     @Autowired(required=false)
     @Qualifier("runAsAuthenticationProvider")
@@ -79,16 +78,10 @@ public class CdmUserHelper implements UserHelper, Serializable {
         super();
     }
 
-    /**
-     * @return
-     */
     protected ICdmPermissionEvaluator permissionEvaluator() {
         return permissionEvaluator;
     }
 
-    /**
-     * @return
-     */
     protected CdmRepository repo() {
         return repo;
     }
@@ -102,7 +95,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return false;
     }
 
-
     @Override
     public boolean userIsAnnonymous() {
         Authentication authentication = getAuthentication();
@@ -140,9 +132,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public boolean userIs(RoleProbe roleProbe) {
         return roleProbe.checkForRole(getAuthentication());
@@ -188,11 +177,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return false;
     }
 
-    /**
-     * @param cdmType
-     * @param entitiyUuid
-     * @return
-     */
     protected CdmBase entity(Class<? extends CdmBase> cdmType, UUID entitiyUuid) {
         CdmBase entity = entityFromCache(cdmType, entitiyUuid);
         if(entity == null){
@@ -222,7 +206,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         SecurityContextHolder.clearContext();
     }
 
-
     private EnumSet<CRUD> crudSetFromArgs(Object[] args) {
         EnumSet<CRUD> crudSet = EnumSet.noneOf(CRUD.class);
         for(int i = 0; i < args.length; i++){
@@ -235,7 +218,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return crudSet;
     }
 
-
     private SecurityContext currentSecurityContext() {
         if(securityContextAccess != null){
             return securityContextAccess.currentSecurityContext();
@@ -243,18 +225,11 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return SecurityContextHolder.getContext();
     }
 
-    /**
-     * @return
-     */
     @Override
     public Authentication getAuthentication() {
         return currentSecurityContext().getAuthentication();
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     */
     @Override
     public CdmAuthority createAuthorityFor(String username, CdmBase cdmEntity, EnumSet<CRUD> crud, String property) {
 
@@ -314,13 +289,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return createAuthorityFor(username, cdmEntity, crud, property);
     }
 
-    /**
-     * @param username
-     * @param cdmType
-     * @param entitiyUuid
-     * @param crud
-     * @return
-     */
     @Override
     public CdmAuthority createAuthorityFor(String username, Class<? extends CdmBase> cdmType, UUID entitiyUuid, EnumSet<CRUD> crud, String property) {
 
@@ -328,49 +296,28 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return createAuthorityFor(username, cdmEntity, crud, property);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public CdmAuthority createAuthorityForCurrentUser(CdmBase cdmEntity, EnumSet<CRUD> crud, String property) {
         return createAuthorityFor(userName(), cdmEntity, crud, property);
 
     }
 
-    /**
-     * @param cdmType
-     * @param entitiyId
-     * @param crud
-     * @return
-     */
     @Override
     public CdmAuthority createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property) {
         return createAuthorityFor(userName(), cdmType, entitiyId, crud, property);
     }
 
-    /**
-     * @param cdmType
-     * @param entitiyUuid
-     * @param crud
-     * @return
-     */
     @Override
     public CdmAuthority createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, UUID entitiyUuid, EnumSet<CRUD> crud, String property) {
         return createAuthorityFor(userName(), cdmType, entitiyUuid, crud, property);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public void removeAuthorityForCurrentUser(CdmAuthority cdmAuthority) {
         removeAuthorityForCurrentUser(userName(), cdmAuthority);
 
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public void removeAuthorityForCurrentUser(String username, CdmAuthority cdmAuthority) {
 
@@ -394,9 +341,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         repo().commitTransaction(txStatus);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public Collection<CdmAuthority> findUserPermissions(CdmBase cdmEntity, EnumSet<CRUD> crud) {
         Set<CdmAuthority> matches = new HashSet<>();
@@ -421,7 +365,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return matches;
     }
 
-    // @Override
     @Override
     public <T extends CdmBase> Collection<CdmAuthority> findUserPermissions(Class<T> cdmType, EnumSet<CRUD> crud) {
         Set<CdmAuthority> matches = new HashSet<>();
@@ -442,17 +385,11 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return matches;
     }
 
-    /**
-     * @param securityContextAccess the securityContextAccess to set
-     */
     @Override
     public void setSecurityContextAccess(SecurityContextAccess securityContextAccess) {
         this.securityContextAccess = securityContextAccess;
     }
 
-    /**
-     * @return the runAsAutheticator
-     */
     public RunAsAuthenticator getRunAsAutheticator() {
         if(runAsAutheticator == null){
           throw new RuntimeException("RunAsAuthenticator is missing! The application needs to be configured with security context.");
@@ -460,18 +397,10 @@ public class CdmUserHelper implements UserHelper, Serializable {
         return runAsAutheticator;
     }
 
-    /**
-     * @return the cache
-     */
     public ICdmEntityUuidCacher getCache() {
         return null;
     }
 
-    /**
-     * @param cdmType
-     * @param entitiyUuid
-     * @return
-     */
     private CdmBase entityFromCache(Class<? extends CdmBase> cdmType, UUID entitiyUuid) {
         CdmBase entity = null;
         if(getCache() != null){
@@ -486,13 +415,11 @@ public class CdmUserHelper implements UserHelper, Serializable {
 
     @Override
     public CdmUserHelper withCache(ICdmEntityUuidCacher cache){
-
         return new CachingCdmUserHelper(cache);
     }
 
     class CachingCdmUserHelper extends CdmUserHelper{
 
-
         private static final long serialVersionUID = -5010082174809972831L;
 
         private ICdmEntityUuidCacher cache;
@@ -501,9 +428,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
             this.cache = cache;
         }
 
-        /**
-         * @return the cache
-         */
         @Override
         public ICdmEntityUuidCacher getCache() {
             return cache;
@@ -518,7 +442,6 @@ public class CdmUserHelper implements UserHelper, Serializable {
         protected ICdmPermissionEvaluator permissionEvaluator() {
             return CdmUserHelper.this.permissionEvaluator;
         }
-
     }
 
 }