Add method to sessionOwner objects to fine tune performance using property paths
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / service / CachedCommonServiceImpl.java
index 4b2503f199874e642802509f6f3824a1e85ac5e9..3b302659c707ad45ef973ae6442197a95bd1a35a 100644 (file)
@@ -9,14 +9,18 @@
 */
 package eu.etaxonomy.taxeditor.service;
 
+import java.util.List;
 import java.util.UUID;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils.CollectionField;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 /**
@@ -51,7 +55,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
     @Override
     public CdmBase find(Class<? extends CdmBase> clazz, int id) {
         if(cacheEnabled) {
-            CdmBase cdmEntity = CdmBase.deproxy(commonService.find(clazz, id),clazz);
+            CdmBase cdmEntity = CdmBase.deproxy(commonService.find(clazz, id, getPropertyPaths(clazz)),clazz);
             if(cdmEntity == null) {
                 throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
             }
@@ -62,6 +66,16 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
     }
 
 
+    private List<String> getPropertyPaths(Object obj) {
+        List<String> propertyPaths = null;
+        ICdmEntitySession cdmEntitySession =
+                ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
+        if(cdmEntitySession != null) {
+            propertyPaths = cdmEntitySession.getPropertyPaths(obj);
+        }
+        return propertyPaths;
+    }
+
     @Override
     public void updatePersistentCollection(CollectionField colf) {
         if(cacheEnabled) {
@@ -74,7 +88,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public Object initializeCollection(UUID ownerUuid, String fieldName) {
-        return commonService.initializeCollection(ownerUuid, fieldName);
+        return commonService.initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
     }