From: Cherian Mathew Date: Thu, 23 Jul 2015 11:54:34 +0000 (+0200) Subject: #4932 Remove autowired members, Use serliaised cdm model map X-Git-Tag: remoting-3.9.0~79 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/5a49a28f486ef1ab21ae14661a4717efe14115e6 #4932 Remove autowired members, Use serliaised cdm model map --- diff --git a/eu.etaxonomy.taxeditor.cdmlib/.classpath b/eu.etaxonomy.taxeditor.cdmlib/.classpath index b149b77d4..76e36337a 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/.classpath +++ b/eu.etaxonomy.taxeditor.cdmlib/.classpath @@ -2,8 +2,9 @@ - - + + + @@ -197,5 +198,5 @@ - + diff --git a/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF index a7449bf40..4a39ebbc6 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF @@ -469,7 +469,8 @@ Bundle-Vendor: EDIT Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.eclipse.osgi, org.eclipse.equinox.common, - org.apache.commons.httpclient;bundle-version="3.1.0" + org.apache.commons.httpclient;bundle-version="3.1.0", + org.eclipse.core.runtime Bundle-ClassPath: ., lib/activation-1.1.1.jar, lib/antlr-2.7.7.jar, diff --git a/eu.etaxonomy.taxeditor.cdmlib/build.properties b/eu.etaxonomy.taxeditor.cdmlib/build.properties index 3e92568d4..89b98fae0 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/build.properties +++ b/eu.etaxonomy.taxeditor.cdmlib/build.properties @@ -193,7 +193,8 @@ bin.includes = META-INF/,\ lib/cdmlib-print-3.8.0-SNAPSHOT.jar,\ lib/cdmlib-remote-3.8.0-SNAPSHOT.jar,\ lib/cdmlib-services-3.8.0-SNAPSHOT.jar,\ - lib/apache-log4j-extras-1.2.17.jar + lib/apache-log4j-extras-1.2.17.jar,\ + cdm.map.ser jars.compile.order = . output.. = bin/ diff --git a/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser b/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser new file mode 100644 index 000000000..931f12eed Binary files /dev/null and b/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser differ diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java index 1d1e878ea..47af2ca42 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java @@ -147,14 +147,14 @@ public class CdmApplicationRemoteController extends CdmApplicationController { GenericApplicationContext applicationContext = new GenericApplicationContext(); - int nTasks = 2; + int nTasks = 3; progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks); - progressMonitor.subTask("Loading context beans ..."); - // initialising the cdm model cache + progressMonitor.subTask("Initialising CDM Model Cache ..."); CdmRemoteCacheManager.getInstance(); + progressMonitor.subTask("Loading context beans ..."); PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Properties properties = new Properties(); properties.setProperty("remoteServer", remoteSource.getServer()); diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java index 41f33d819..eb5eaa954 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java @@ -15,6 +15,7 @@ import java.lang.reflect.Type; import org.springframework.security.core.context.SecurityContext; +import eu.etaxonomy.cdm.api.cache.CdmServiceCacher; import eu.etaxonomy.cdm.api.service.ICommonService; import eu.etaxonomy.cdm.api.service.IService; import eu.etaxonomy.cdm.api.service.ITestService; @@ -39,6 +40,7 @@ public class CdmApplicationState { public static CdmApplicationState getInstance() { if(cdmApplicationState == null) { cdmApplicationState = new CdmApplicationState(); + new CdmServiceCacher(); } return cdmApplicationState; } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java index 475d586d2..288b20eb1 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java @@ -5,10 +5,9 @@ import java.util.UUID; import net.sf.ehcache.config.CacheConfiguration; import net.sf.ehcache.config.SizeOfPolicyConfiguration; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import eu.etaxonomy.cdm.api.service.ITermService; +import eu.etaxonomy.cdm.api.application.CdmApplicationState; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.common.DefinedTermBase; import eu.etaxonomy.taxeditor.remoting.cache.CacheLoader; @@ -34,8 +33,6 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver; @Component public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionManagerObserver { - @Autowired - ITermService termService; private ICdmEntitySessionManager cdmEntitySessionManager; @@ -49,6 +46,7 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMan DefinedTermBase.setCacher(this); CdmTransientEntityCacher.setDefaultCacher(this); TermServiceRequestExecutor.setDefaultCacher(this); + cacheLoader = new CacheLoader(this); } @@ -72,7 +70,7 @@ public class CdmServiceCacher extends CdmCacher implements ICdmEntitySessionMan @Override protected CdmBase findByUuid(UUID uuid) { - CdmBase term = termService.findWithoutFlush(uuid); + CdmBase term = CdmApplicationState.getCurrentAppConfig().getTermService().findWithoutFlush(uuid); return load(term); } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java index a0e095d91..45a3094e6 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java @@ -1,159 +1,137 @@ package eu.etaxonomy.taxeditor.remoting.cache; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.HashMap; import java.util.Iterator; -import java.util.List; +import java.util.Map; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; -import org.apache.log4j.Logger; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; import org.hibernate.cfg.Configuration; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.property.Getter; +import org.osgi.framework.Bundle; public class CdmModelCacher { - private static final Logger logger = Logger.getLogger(CdmModelCacher.class); - public static String HB_CONFIG_FILE_PATH= "/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"; - private final List cmgmfcList = new ArrayList(); + public static String HB_CONFIG_FILE_PATH= "/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"; + public static final String CDM_MAP_SER_FILE_PATH = "resources/cdm.map.ser"; - public static Configuration buildConfiguration() { - Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH); + + + + public void cacheGetterFields(Cache cache) throws IOException, ClassNotFoundException, URISyntaxException { + Map modelClassMap = loadModelClassMap(); + + cache.removeAll(); + + for(Map.Entry entry : modelClassMap.entrySet()) { + cache.put(new Element(entry.getKey(), entry.getValue())); + } + } + + public Map loadModelClassMap() throws URISyntaxException, IOException, ClassNotFoundException { + + Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib"); + + URL modelMapFileURL = bundle.getEntry(CDM_MAP_SER_FILE_PATH); + File modelMapFile = new File(FileLocator.resolve(modelMapFileURL).toURI()); + + FileInputStream fin = new FileInputStream(modelMapFile); + ObjectInputStream ois = new ObjectInputStream(fin); + Map modelClassMap = (Map) ois.readObject(); + ois.close(); + return modelClassMap; + } + + + public Map generateModelClassMap() { + + Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH); + Iterator classMappingIterator = configuration.getClassMappings(); + + Map modelClassMap = new HashMap(); + + while(classMappingIterator.hasNext()) { + PersistentClass persistentClass = classMappingIterator.next(); + Class mappedClass = persistentClass.getMappedClass(); + String mappedClassName = mappedClass.getName(); + + CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); + System.out.println("Adding class : " + mappedClassName + " to cache"); + addGetters(persistentClass, cmgmfc); + modelClassMap.put(mappedClassName, cmgmfc); + } + return modelClassMap; + } + + + public static Configuration buildConfiguration(String hibernateConfigFilePath) { + Configuration configuration = new Configuration().configure(hibernateConfigFilePath); configuration.buildMappings(); return configuration; - } - - public void cacheGetterFields(Cache cache) { - - Configuration configuration = buildConfiguration(); - Iterator classMappingIterator = configuration.getClassMappings(); - - cache.removeAll(); - - while(classMappingIterator.hasNext()) { - PersistentClass persistentClass = classMappingIterator.next(); - Class mappedClass = persistentClass.getMappedClass(); - String mappedClassName = mappedClass.getName(); - - CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); - //logger.info("Adding class : " + mappedClassName + " to cache"); - addGetters(persistentClass, cmgmfc); - cache.put(new Element(mappedClassName, cmgmfc)); - } - - } - - private void addGetters(PersistentClass persistentClass, CdmModelFieldPropertyFromClass cmgmfc) { - if (persistentClass != null) { - Iterator propertyIt = persistentClass.getPropertyIterator(); - - while(propertyIt.hasNext()) - { - Property property = (Property)propertyIt.next(); - Getter getter = property.getGetter(persistentClass.getMappedClass()); - if(getter != null && getter.getMember() != null) { - Field field = (Field)getter.getMember(); - - //logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'"); - cmgmfc.addGetMethods(field.getName()); - } - } - addGetters(persistentClass.getSuperclass(), cmgmfc); - } - } - - public void checkGetterMethods() { - - Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH); - configuration.buildMappings(); - Iterator classMappingIterator = configuration.getClassMappings(); - - Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache(); - cache.removeAll(); - - while(classMappingIterator.hasNext()) { - PersistentClass persistentClass = classMappingIterator.next(); - Class mappedClass = persistentClass.getMappedClass(); - String mappedClassName = mappedClass.getName(); - - Iterator propertyIt = persistentClass.getPropertyIterator(); - - Method[] methods = mappedClass.getMethods(); - - while(propertyIt.hasNext()) - { - Property property = (Property)propertyIt.next(); - Getter getter = property.getGetter(mappedClass); - if(getter != null && getter.getMember() != null) { - Field field = (Field)getter.getMember(); - String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName()); - - boolean foundMethod = false; - for(Method method : methods) { - if(method.getName().equals(getMethod)) { - foundMethod = true; - break; - } - } - if(!foundMethod) { - logger.info("Inferred method " + getMethod + " does not exist in class " + mappedClassName); - //throw new CdmClientCacheException("Inferred method " + getMethod + " does not exist in class " + mappedClassName); - } - } - } - - - } - - } - - public List getCdmModelGetMethodFromClassList() { - cmgmfcList.clear(); - Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH); - configuration.buildMappings(); - Iterator classMappingIterator = configuration.getClassMappings(); - - while(classMappingIterator.hasNext()) { - PersistentClass persistentClass = classMappingIterator.next(); - Class mappedClass = persistentClass.getMappedClass(); - String mappedClassName = mappedClass.getName(); - - CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); - Iterator propertyIt = persistentClass.getPropertyIterator(); - - while(propertyIt.hasNext()) - { - Property property = (Property)propertyIt.next(); - Getter getter = property.getGetter(mappedClass); - if(getter != null && getter.getMember() != null) { - Field field = (Field)getter.getMember(); - String getMethod = getMethodNameFromFieldName(getter.getMember().getName(),field.getType().getName()); - cmgmfc.addGetMethods(getMethod); - } - } - cmgmfcList.add(cmgmfc); - } - return cmgmfcList; - - } - - public static String getMethodNameFromFieldName(String fieldName, String type) { - String prefix = type != null && type.toLowerCase().endsWith("boolean") ? "is" : "get"; - String getMethod = prefix + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - return getMethod; - } + } + + private void addGetters(PersistentClass persistentClass, CdmModelFieldPropertyFromClass cmgmfc) { + if (persistentClass != null) { + Iterator propertyIt = persistentClass.getPropertyIterator(); + + while(propertyIt.hasNext()) + { + Property property = (Property)propertyIt.next(); + Getter getter = property.getGetter(persistentClass.getMappedClass()); + if(getter != null && getter.getMember() != null) { + Field field = (Field)getter.getMember(); + + //logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'"); + cmgmfc.addGetMethods(field.getName()); + } + } + addGetters(persistentClass.getSuperclass(), cmgmfc); + } + } + + + + public static void main(String argv[]) { + + // To re-create the serialised cdm map run, + // mvn exec:java -Dexec.mainClass="eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher" + // in the eu.etaxonomy.taxeditor.cdmlib project root dir + String CDM_MAP_SER_DIR = "resources/"; + + CdmModelCacher cdmModelCacher = new CdmModelCacher(); + Map modelClassMap = cdmModelCacher.generateModelClassMap(); + try{ + FileOutputStream fout = new FileOutputStream(CDM_MAP_SER_DIR + "cdm.map.ser"); + ObjectOutputStream oos = new ObjectOutputStream(fout); + oos.writeObject(modelClassMap); + oos.close(); + System.out.println("CDM Map serialized"); + }catch(Exception ex){ + ex.printStackTrace(); + } + } } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java index 84f88c24f..a2c4d1c66 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java @@ -1,5 +1,8 @@ package eu.etaxonomy.taxeditor.remoting.cache; +import java.io.IOException; +import java.net.URISyntaxException; + import net.sf.ehcache.Cache; import net.sf.ehcache.CacheException; import net.sf.ehcache.CacheManager; @@ -59,45 +62,23 @@ public class CdmRemoteCacheManager { cdmlibModelCache = new Cache(modelcc); CacheManager.create().addCache(cdmlibModelCache); - initCdmModelCache(cdmlibModelCache); + 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) { + throw new CdmClientCacheException(e); } } - private void initCdmModelCache(final Cache cache) { - - initThread = new Thread() { - @Override - public void run(){ - synchronized (cdmlibModelCache) { - CdmModelCacher cmdmc = new CdmModelCacher(); - cmdmc.cacheGetterFields(cache); - cacheInitialised = true; - logger.info("Initialisation of CDM getter fields complete"); - cdmlibModelCache.notify(); - } - } - - }; - initThread.start(); - } public Cache getCdmModelGetMethodsCache(){ - //Note : Even though we synchronize this method, the cache can be simply - // retrieved using CacheManager.create().getCache(CDM_MODEL_CACHE_NAME) - // in which case the cache may not be fully initialised - synchronized (cdmlibModelCache) { - while(!cacheInitialised) { - try { - logger.info("Waiting for initialisation of CDM getter fields to complete ..."); - cdmlibModelCache.wait(); - } catch (InterruptedException e) {} - } - } - logger.info("CDM getter fields cache initialised"); return cdmlibModelCache; } @@ -110,7 +91,4 @@ public class CdmRemoteCacheManager { } } } - - - } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java index e36138e69..0e5b8f9e6 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java @@ -12,16 +12,12 @@ 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; /** * @author cmathew @@ -32,15 +28,8 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager; public class CachedCommonServiceImpl implements ICachedCommonService { - @Autowired - private ICommonService commonService; - private static boolean cacheEnabled = true; - @Autowired - private ICdmEntitySessionManager cdmEntitySessionManager; - - public static boolean isCacheEnabled() { return cacheEnabled; } @@ -55,7 +44,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { @Override public CdmBase find(Class clazz, int id) { // if(cacheEnabled) { - CdmBase cdmEntity = commonService.find(clazz, id, getPropertyPaths(clazz)); + CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz)); if(cdmEntity == null) { throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id + " is null."); } @@ -77,19 +66,12 @@ public class CachedCommonServiceImpl implements ICachedCommonService { return propertyPaths; } - @Override - public void updatePersistentCollection(CollectionField colf) { - if(cacheEnabled) { - cdmEntitySessionManager.load(colf.getCollection(), false); - } - } - /* (non-Javadoc) * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String) */ @Override public Object initializeCollection(UUID ownerUuid, String fieldName) { - return commonService.initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName)); + return CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName)); } @@ -98,7 +80,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { */ @Override public boolean isEmpty(UUID ownerUuid, String fieldName) { - return commonService.isEmpty(ownerUuid, fieldName); + return CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName); } @@ -108,7 +90,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { */ @Override public int size(UUID ownerUuid, String fieldName) { - return commonService.size(ownerUuid, fieldName); + return CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName); } @@ -118,7 +100,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { */ @Override public boolean contains(UUID ownerUuid, String fieldName, Object element) { - return commonService.contains(ownerUuid, fieldName, element); + return CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element); } @@ -127,7 +109,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { */ @Override public boolean containsKey(UUID ownerUuid, String fieldName, Object key) { - return commonService.containsKey(ownerUuid, fieldName, key); + return CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key); } @@ -136,7 +118,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService { */ @Override public boolean containsValue(UUID ownerUuid, String fieldName, Object element) { - return commonService.containsValue(ownerUuid, fieldName, element); + return CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element); } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java index 0b7ca355d..8084eac89 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java @@ -4,12 +4,13 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration; import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationResult; 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.UpdateResult; import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager; @@ -18,13 +19,18 @@ public class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerReques private static final Logger logger = Logger.getLogger(CdmServiceRequestExecutor.class); - @Autowired - private ICdmEntitySessionManager cdmEntitySessionManager; + private ICdmEntitySessionManager cdmEntitySessionManager ; private RemoteInvocation currentRemoteInvocation; + + @Override protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException { + if(cdmEntitySessionManager == null) { + cdmEntitySessionManager = + ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager(); + } currentRemoteInvocation = invocation; super.writeRemoteInvocation(invocation, os); } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java index 3b85058ec..98c94d899 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java @@ -12,7 +12,6 @@ package eu.etaxonomy.taxeditor.service; import java.util.UUID; import eu.etaxonomy.cdm.model.common.CdmBase; -import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils.CollectionField; /** * @author cmathew @@ -23,7 +22,6 @@ public interface ICachedCommonService { public CdmBase find(Class clazz, int id); - public void updatePersistentCollection(CollectionField colf); /** * Initializes a collection or map. diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java deleted file mode 100644 index 04e998e31..000000000 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java +++ /dev/null @@ -1,72 +0,0 @@ -// $Id$ -/** -* 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.taxeditor.util; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; - -import org.apache.log4j.Logger; -import org.hibernate.cfg.Configuration; - -import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher; - -/** - * @author cmathew - * @date 27 May 2015 - * - */ -public class Serializer { - private static final Logger logger = Logger.getLogger(Serializer.class); - - - public static String HB_CONFIG_SER_FILE_NAME = "hibernate.cfg.ser"; - - public static boolean checkDir(String dirString) { - if(dirString == null || dirString.isEmpty()) { - logger.warn("Directory not set or set to empty string"); - return false; - } - - File dir = new File(dirString); - - if(!dir.exists()) { - logger.warn("Directory does not exist"); - return false; - } - - return true; - - } - public static void serializeHbConfig() { - - Configuration configuration = CdmModelCacher.buildConfiguration(); - String hbConfigDir = System.getProperty("hb.config.dir"); - if(checkDir(hbConfigDir)) { - try { - FileOutputStream fileOut = new FileOutputStream(hbConfigDir + File.separator + HB_CONFIG_SER_FILE_NAME); - ObjectOutputStream out = new ObjectOutputStream(fileOut); - out.writeObject(configuration); - out.close(); - fileOut.close(); - logger.info("Serialized configuration object"); - } catch(IOException i) { - i.printStackTrace(); - } - } - } - - public static void main(String[] args) { - serializeHbConfig(); - - } - -} diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml b/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml index adccb37c5..928decf93 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml @@ -6,8 +6,6 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> - - - - - - - @@ -81,9 +71,4 @@ - - - - diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java deleted file mode 100644 index 481dd1229..000000000 --- a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package eu.etaxonomy.cdm.api.cache; - -import java.util.List; - -import net.sf.ehcache.Cache; - -import org.apache.log4j.Logger; -import org.junit.Assert; -import org.junit.Test; - -import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher; -import eu.etaxonomy.taxeditor.remoting.cache.CdmModelFieldPropertyFromClass; -import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager; - - -public class CdmModelGetMethodCacherTest { - - private static final Logger logger = Logger.getLogger(CdmModelGetMethodCacherTest.class); - - - @Test - public void cacheGettersTest() { - - CdmModelCacher cmdmc = new CdmModelCacher(); - - Cache cdmlibCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache(); - List cmgmfcList = cmdmc.getCdmModelGetMethodFromClassList(); - - List keys = cdmlibCache.getKeys(); - Assert.assertEquals(cmgmfcList.size(), keys.size()); - - for(CdmModelFieldPropertyFromClass cmgmfc: cmgmfcList) { - String className = cmgmfc.getClassName(); - Assert.assertTrue(keys.contains(className)); - logger.info("Class Name : " + className + " has been cached"); - } - - //FIXME:Remoting do we need to test this ? - // this will cause the following tests to fail since all caches are shutdown - //cdmlibCache.removeAll(); - //CacheManager.create().shutdown(); - } - - - - -}