cleanup
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / cache / CdmServiceCacher.java
index 559039dd10cacf14011aaaafbdbc856821904ef8..c8538625bc41f1ed46117e2bf68aad3f87c172ac 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.api.cache;
 
 import java.io.File;
@@ -14,6 +22,7 @@ import eu.etaxonomy.cdm.cache.CdmTransientEntityCacher;
 import eu.etaxonomy.cdm.config.ConfigFileUtil;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.model.term.Representation;
 import eu.etaxonomy.cdm.model.term.TermBase;
 import eu.etaxonomy.taxeditor.service.RemoteInvocationTermCacher;
 import eu.etaxonomy.taxeditor.session.CdmEntitySession;
@@ -33,9 +42,7 @@ import net.sf.ehcache.config.SizeOfPolicyConfiguration;
  *
  * @author cmathew
  */
-@Component //FIXME This indicates that the CdmServiceCacher is initialized as Spring Component but it seems only to be instantiated directly
-public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionManagerObserver {
-
+public class CdmServiceCacher extends CdmCacherBase implements ICdmEntitySessionManagerObserver {
 
     private ICdmEntitySessionManager cdmEntitySessionManager;
 
@@ -44,7 +51,7 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
     private CacheLoader cacheLoader;
 
     @Autowired
-    ConfigFileUtil configFileUtil = null;
+    private ConfigFileUtil configFileUtil = null;
 
     @Override
     protected void setup() {
@@ -83,10 +90,8 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
 
         cacheConfig.setDiskStoreConfiguration(diskStoreConfiguration);
         addCacheManager(cacheConfig.cacheManager());
-
     }
 
-
     @Override
     protected CacheConfiguration getDefaultCacheConfiguration() {
         // For a better understanding on how to size caches, refer to
@@ -101,7 +106,6 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
                .statistics(true)
                .sizeOfPolicy(sizeOfConfig)
                .overflowToOffHeap(false);
-
     }
 
     @Override
@@ -112,14 +116,15 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
 
     @Override
     public boolean isCachable(CdmBase cdmEntity) {
-     //   if(cdmEntity != null && cdmEntity instanceof DefinedTermBase) {
-          if(cdmEntity != null && cdmEntity instanceof TermBase) {
+       if(cdmEntity == null){
+           return false;
+       }else if (cdmEntity instanceof TermBase || cdmEntity instanceof Representation){
             return true;
+        }else{
+            return false;
         }
-        return false;
     }
 
-
     public void setCdmEntitySessionManager(ICdmEntitySessionManager cdmEntitySessionManager) {
         this.cdmEntitySessionManager = cdmEntitySessionManager;
         if(cdmEntitySessionManager != null) {
@@ -127,7 +132,6 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
         }
     }
 
-
     public CdmTransientEntityCacher getCurrentCacher() {
         ICdmEntitySession cdmEntitySession = cdmEntitySessionManager.getActiveSession();
         if(cdmEntitySession != null && cdmEntitySession instanceof CdmEntitySession) {
@@ -142,12 +146,11 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMana
         // first we check in the active session cache if the
         // entity has been loaded there
         // FIXME:Remoting do we really need the cdmTransientEntityCacher
-        // here. Is it not guarenteed that all every entity which 'isCachable'
+        // here. Is it not guaranteed that all every entity which 'isCachable'
         // by this cacher is cached only in this cacher ?
         if(!isCachable(cdmBase) && cdmTransientEntityCacher != null) {
             CdmEntityCacheKey<T> key = CdmTransientEntityCacher.generateKey(cdmBase);
             cachedCdmEntity = cdmTransientEntityCacher.getFromCache(key);
-
         }
         if(cachedCdmEntity == null) {
             cachedCdmEntity = super.getFromCache(cdmBase);