cleanup of code.
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CachedCommonServiceImpl.java -text
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmClientCacheException.java -text
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCacheKey.java -text
-eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCachingUtils.java -text
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelCacher.java -text
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelFieldPropertyFromClass.java -text
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmRemoteCacheManager.java -text
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
+import eu.etaxonomy.cdm.api.cache.CdmModelCacher;
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
configuration = (ICdmApplicationConfiguration)applicationContext.getBean("cdmApplicationRemoteConfiguration");
AbstractLazyInitializer.setConfiguration((CdmApplicationRemoteConfiguration)configuration);
AbstractPersistentCollection.setConfiguration((CdmApplicationRemoteConfiguration)configuration);
+
+ CdmModelCacher cmdmc = new CdmModelCacher();
+ cmdmc.cacheGetterFields();
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import eu.etaxonomy.cdm.api.cache.CdmEntityCachingUtils.CollectionType;
import eu.etaxonomy.cdm.api.service.ICommonService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
import eu.etaxonomy.taxeditor.remoting.session.CdmEntitySessionManager;
import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
+import eu.etaxonomy.cdm.api.cache.CdmTransientEntityCacher.CollectionType;;
/**
* @author cmathew
@Autowired
private CdmEntitySessionManager cdmEntitySessionManager;
- @Autowired
- private CdmEntityCachingUtils cdmEntityCachingUtils;
-
public static boolean isCacheEnabled() {
return cacheEnabled;
+++ /dev/null
-// $Id$
-/**
-* 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.api.cache;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import net.sf.ehcache.Cache;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.taxeditor.remoting.session.CdmEntitySessionManager;
-
-/**
- * @author cmathew
- * @date 15 Oct 2014
- *
- */
-@Component
-public class CdmEntityCachingUtils {
-
- @Autowired
- private CdmEntitySessionManager cdmEntityCacheManager;
-
-
-
- public static enum CollectionType {
- SET,
- LIST,
- MAP;
-
- @Override
- public String toString() {
- return this.name().toLowerCase();
- }
- }
-
- public void cachify(Map<Object,Object> map) {
- if(map == null || map.isEmpty()) {
- return;
- }
-
- int originalMapSize = map.size();
- Object[] result = new Object[ map.size() * 2 ];
- Iterator<Map.Entry<Object,Object>> iter = map.entrySet().iterator();
- int i=0;
- while ( iter.hasNext() ) {
- Map.Entry<Object,Object> e = (Map.Entry<Object,Object>) iter.next();
- result[i++] = e.getKey();
- result[i++] = e.getValue();
- }
-
- for(i=0; i<result.length;i++) {
- if(result[i] instanceof CdmBase) {
- CdmBase cdmBase = (CdmBase)result[i];
- CdmBase cachedCdmBase = cdmEntityCacheManager.getActiveCdmTransientEntityCacher().load(cdmBase, true);
- result[i] = cachedCdmBase;
- }
- }
- map.clear();
- for(i = 0; i < originalMapSize; i+=2 ) {
- map.put(
- result[i],
- result[i+1]
- );
- }
-
- }
-
- public void cachify(CdmBase cdmBase, boolean recursive) {
-
-
- }
-
-
-
-}
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml");
configuration.buildMappings();
- Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
+ Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
cache.removeAll();
public class CdmRemoteCacheManager {
private CacheManager cdmlibModelCacheManager;
- private CacheManager defaultCacheManager;
private static CdmRemoteCacheManager cdmRemoteCacheManager = null;
private CdmRemoteCacheManager() {
checkCacheProperties();
try {
+ // NOTE:Programmatically creating the cache manager may solve the problem of
+ // recreating data written to disk on startup
+ // see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
cdmlibModelCacheManager = new CacheManager(cacheFilePath);
@Autowired
ITermService termService;
-
+
+ @Override
+ protected void setup() {
+ CdmTransientEntityCacher.setDefaultCacher(this);
+ }
+
@Override
protected CdmBase findByUuid(UUID uuid) {
CdmBase term = termService.findWithoutFlush(uuid);
*/
package eu.etaxonomy.cdm.api.cache;
+import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
*
*/
-public class CdmTransientEntityCacher extends CdmServiceCacher {
+public class CdmTransientEntityCacher {
private static final Logger logger = Logger.getLogger(CdmTransientEntityCacher.class);
- @Autowired
- private CdmEntityCachingUtils cdmEntityCachingUtils;
+
+ private static CdmServiceCacher cdmServiceCacher;
@Autowired
private ICommonService commonService;
private static boolean isRecursiveEnabled = true;
+ public static enum CollectionType {
+ SET,
+ LIST,
+ MAP;
+ @Override
+ public String toString() {
+ return this.name().toLowerCase();
+ }
+ }
+
+ private CdmTransientEntityCacher() {
+
+ }
+
public CdmTransientEntityCacher(String cacheId) {
this.cacheId = cacheId;
cache = new Cache(getEntityCacheConfiguration(cacheId));
- getDefaultCacheManager().addCache(cache);
+ cdmServiceCacher.getDefaultCacheManager().addCache(cache);
cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
}
-
+ public static void setDefaultCacher(CdmServiceCacher css) {
+ cdmServiceCacher = css;
+ }
+
/**
* Returns the cache corresponding to the cache id
*
* @return
*/
private Cache getCache() {
- return getDefaultCacheManager().getCache(cacheId);
+ return cdmServiceCacher.getDefaultCacheManager().getCache(cacheId);
}
+ @SuppressWarnings("unchecked")
public <T extends Object> T load(T obj, boolean recursive) {
if(obj instanceof CdmBase) {
return load(obj, recursive);
} else if (obj instanceof Map) {
- return load(obj, recursive);
- }
+ return (T) load((Map<T,T>)obj, recursive);
+ } else if (obj instanceof Collection) {
+ return (T) load((Collection<T>)obj, recursive);
+ }
return obj;
}
@SuppressWarnings("unchecked")
private <T extends Object> T loadRecursive(T obj, Set<CdmBase> alreadyVisitedEntities) {
if(obj instanceof CdmBase) {
- return loadRecursive(obj, alreadyVisitedEntities);
+ return (T) loadRecursive((CdmBase)obj, alreadyVisitedEntities);
} else if (obj instanceof Map) {
return (T) load((Map<T,T>)obj, alreadyVisitedEntities);
- }
+ } else if (obj instanceof Collection) {
+ return (T) load((Collection<T>)obj, alreadyVisitedEntities);
+ }
+
logger.info("No caching yet for type " + obj.getClass().getName());
return obj;
public <T extends Object> Map<T,T> load(Map<T,T> map, boolean recursive){
if(isRecursiveEnabled && recursive) {
- logger.info("---- starting recursive load for map");
+ logger.info("---- starting recursive load for cdm entity map");
Set<CdmBase> alreadyVisitedEntities = new HashSet<CdmBase>();
Map<T,T> cachedMap = load(map, alreadyVisitedEntities);
alreadyVisitedEntities.clear();
return load(map, null);
}
}
+
private <T extends Object> Map<T,T> load(Map<T,T> map, Set<CdmBase> alreadyVisitedEntities){
if(map == null || map.isEmpty()) {
}
return map;
}
+
+ public <T extends Object> Collection<T> load(Collection<T> collection, boolean recursive){
+ if(isRecursiveEnabled && recursive) {
+ logger.info("---- starting recursive load for cdm entity collection");
+ Set<CdmBase> alreadyVisitedEntities = new HashSet<CdmBase>();
+ Collection<T> cachedList = load(collection, alreadyVisitedEntities);
+ alreadyVisitedEntities.clear();
+ logger.info("---- ending recursive load for cdm entity collection \n");
+ return cachedList;
+ } else {
+ return load(collection, null);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T extends Object> Collection<T> load(Collection<T> collection, Set<CdmBase> alreadyVisitedEntities){
+ int length = collection.size();
+ Object[] result = new Object[length];
+ Iterator<T> collectionItr = collection.iterator();
+ int count = 0;
+ while(collectionItr.hasNext()) {
+ if(alreadyVisitedEntities == null) {
+ result[count] = load(collectionItr.next(), false);
+ } else {
+ result[count] = loadRecursive(collectionItr.next(), alreadyVisitedEntities);
+ }
+ count++;
+ }
+
+ collection.clear();
+
+ for ( int i = 0; i < length; i++ ) {
+ collection.add((T)result[i]);
+ }
+
+ return collection;
+ }
+
+
/**
* Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
* in the cache corresponding to the given cache id
return load(cdmEntity);
}
- // split into two methods
- // - load(CdmBase cdmBase)
- // - recursiveLoad(CdmBase cdmbase, List<CdmBase> alreadyVisitedEntities)
- // : the entity to be visted should added before the recursive call
- // and deleted after the call to end finally with a list
- // of size zero at the end
- // : entity to recurse should be the original entity and
- // not the cached one
-
}
Element cachedCdmEntityElement = getCacheElement(id);
if(cachedCdmEntityElement == null) {
- cachedCdmEntityElement = getCacheElement(cdmEntity.getUuid());
+ cachedCdmEntityElement = cdmServiceCacher.getCacheElement(cdmEntity.getUuid());
if(cachedCdmEntityElement != null) {
logger.info("Cdm Entity with id : " + cdmEntity.getId() + " already exists in permanent cache. Ignoring put.");
return;
public CdmBase getFromCache(CdmBase cdmBase) {
CdmEntityCacheKey cacheId = generateKey(cdmBase);
-
CdmBase cachedCdmEntity = getFromCache(cacheId);
if(cachedCdmEntity == null) {
// ... then try the permanent (uuid-based) cache
- cachedCdmEntity = getFromCache(cdmBase.getUuid());
+ cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase.getUuid());
}
return cachedCdmEntity;
public CdmBase getFromCache(CdmBase cdmBase, Class<? extends CdmBase> clazz) {
- cdmBase = CdmBase.deproxy(cdmBase, clazz);
-
+ cdmBase = CdmBase.deproxy(cdmBase, clazz);
CdmEntityCacheKey cacheId = generateKey(cdmBase);
CdmBase cachedCdmEntity = getFromCache(cacheId);
if(cachedCdmEntity == null) {
// ... then try the permanent (uuid-based) cache
- cachedCdmEntity = getFromCache(cdmBase.getUuid());
+ cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase.getUuid());
}
return cachedCdmEntity;
return entities;
}
-
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.model.ICdmCacher#exists(java.util.UUID)
- */
- @Override
- public boolean exists(UUID uuid) {
- return (getCacheElement(uuid) != null || super.getCacheElement(uuid) != null);
- }
-
public boolean exists(CdmEntityCacheKey key) {
return (getCacheElement(key) != null);
}
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.model.ICdmCacher#existsAndIsNotNull(java.util.UUID)
- */
- @Override
- public boolean existsAndIsNotNull(UUID uuid) {
- return getFromCache(uuid) != null;
- }
-
public boolean existsAndIsNotNull(CdmEntityCacheKey id) {
return getFromCache(id) != null;
}
}
public CdmTransientEntityCacher getActiveCdmTransientEntityCacher() {
+ if(activeSession == null) {
+ throw new CdmClientSessionException("No active session has been bound");
+ }
return activeSession.getCdmTransientEntityCacher();
}
package eu.etaxonomy.cdm.api.cache;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import org.apache.log4j.Level;
import org.unitils.dbunit.annotation.DataSet;
import eu.etaxonomy.cdm.api.service.ICommonService;
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.model.common.CdmBase;
private static final Logger logger = Logger.getLogger(CdmClientCachingTest.class);
- UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
- UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
+ private UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
+ private UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
+ private UUID polytomousKeyNodeUuid1 = UUID.fromString("75e4c924-ff58-4ee7-a59d-fd9173517d08");
+ private UUID polytomousKeyNodeUuid2 = UUID.fromString("b775c027-13c0-4b87-8aa9-712faeaafbdc");
- IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
- ICommonService commonService = getRemoteApplicationController().getCommonService();
- ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
+ private IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
+ private IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
+ private ICommonService commonService = getRemoteApplicationController().getCommonService();
+ private ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
- CdmEntitySessionManager cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
+ private CdmEntitySessionManager cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
- CdmTransientEntityCacher cacher;
-
- Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
+
+ private CdmTransientEntityCacher cacher;
+ private ISessionEventListener sessionOwner;
private static final List<String> PKEY_DEPTH1_INIT_STRATEGY = Arrays.asList(new String[] {
});
private static final List<String> PKEY_DEPTH3_INIT_STRATEGY = Arrays.asList(new String[] {
"root.statement"});
- private ISessionEventListener sessionOwner;
+
@BeforeClass
public static void initializePolytomousKeyTest() {
logger.setLevel(Level.INFO);
- CDMServer.getInstance().setKeepServerRunning(true);
-
- CdmModelCacher cmdmc = new CdmModelCacher();
- cmdmc.cacheGetterFields();
-
+ CDMServer.getInstance().setKeepServerRunning(true);
//initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
}
}
-
+ /**
+ * when : loading objects from a collection
+ * then : the object stored in the cache should be the same
+ */
@Test
- public void savePolytomousKeyNodeDataWithSameSubKey() {
- //CachedCommonServiceImpl.setCacheEnabled(false);
- ISessionEventListener sessionOwner = new MockSessionOwner();
- cdmEntitySessionManager.bind(sessionOwner);
- PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
- PolytomousKeyNode pkeynode = pkey.getRoot();
-
- PolytomousKey subkey1 = pkeynode.getChildAt(0).getSubkey();
- String subkey1title = subkey1.getTitleCache();
- subkey1.setTitleCache(subkey1title + "test", true);
-
-
- PolytomousKey subkey2 = pkeynode.getChildAt(1).getChildAt(0).getSubkey();
- String subkey2title = subkey2.getTitleCache();
- subkey2.setTitleCache(subkey2title + "test", true);
-
- Assert.assertSame(subkey1, subkey2);
-
- polytomousKeyService.merge(pkey);
+ public void subGraphCollectionLoadTest() {
+
+ // this call will load into the session cache the graph and update the objects in the sub-graph for a
+ // polytomous key
+ // |- root : polytomous key node
+ // |- question : KeyStatement
+ // |- statement : KeyStatement
+
+ PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
+ PolytomousKeyNode childOfRootPKNode = pkey.getRoot().getChildAt(1);
+
+ Assert.assertSame(childOfRootPKNode, cacher.getFromCache(childOfRootPKNode));
+ Assert.assertSame(pkey.getRoot().getChildAt(1), childOfRootPKNode);
+
}
-
+
+ /**
+ * when : loading objects from a map
+ * then : the object stored in the cache should be the same
+ */
@Test
- public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
- CachedCommonServiceImpl.setCacheEnabled(false);
- PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
- PolytomousKeyNode pkeynode = pkey.getRoot();
-
- PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
- PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(children, 0);
- PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
- String subkey1title = subkey1.getTitleCache();
- subkey1.setTitleCache(subkey1title + "test", true);
-
- PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(children, 1);
- PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
- String subkey2title = subkey2.getTitleCache();
- subkey2.setTitleCache(subkey2title + "test", true);
+ public void subGraphMapLoadTest() {
+
+ Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
+ Language hindi = Language.getLanguageFromUuid(UUID.fromString("0a1d9d1d-135d-4575-b172-669b51673c39"));
+
+
+ // this call will load into the session cache the graph and update the objects in the sub-graph for a
+ // polytomous key
+ // |- root : polytomous key node
+ // |- question : KeyStatement
+ // |- statement : KeyStatement
+
+ PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
+ Map<Language, LanguageString> labelMap = pkey.getRoot().getStatement().getLabel();
+ Set<Language> languages = labelMap.keySet();
+ Iterator<Language> languagesItr = languages.iterator();
+ while(languagesItr.hasNext()) {
+ Language lang = languagesItr.next();
+ if(lang.equals(english)) {
+ Assert.assertSame(lang, english);
+ }
+ if(lang.equals(hindi)) {
+ Assert.assertSame(lang, hindi);
+ }
+ Assert.assertSame(lang, cacher.getFromCache(lang));
+ }
+ }
+
+ /**
+ * when : loading an object (first) and then (second) loading a graph the object is contained in, in the same session
+ * then : the object should be the same
+ */
+ @Test
+ public void subGraphObjectLoadTest1() {
- Assert.assertNotSame(subkey1, subkey2);
+ // this call will load into the session cache a polytomous key node object
+ PolytomousKeyNode rootPKNode = CdmBase.deproxy(polytomousKeyNodeService.find(polytomousKeyNodeUuid1),PolytomousKeyNode.class);
+ rootPKNode = cdmEntitySessionManager.add(sessionOwner, rootPKNode);
- polytomousKeyService.merge(pkey);
+ Assert.assertNotNull(rootPKNode);
+ Assert.assertSame(rootPKNode, cacher.getFromCache(rootPKNode));
+
+ PolytomousKeyNode childOfRootPKNode = CdmBase.deproxy(polytomousKeyNodeService.find(polytomousKeyNodeUuid2),PolytomousKeyNode.class);
+ childOfRootPKNode = cdmEntitySessionManager.add(sessionOwner, childOfRootPKNode);
+
+ Assert.assertNotNull(childOfRootPKNode);
+ Assert.assertSame(childOfRootPKNode, cacher.getFromCache(childOfRootPKNode));
+
+ // this call will load into the session cache the graph and update the objects in the sub-graph for a
+ // polytomous key
+ // |- root : polytomous key node
+ // |- question : KeyStatement
+ // |- statement : KeyStatement
+
+ PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
+ Assert.assertSame(childOfRootPKNode, cacher.getFromCache(childOfRootPKNode));
+ Assert.assertSame(pkey.getRoot().getChildAt(1), childOfRootPKNode);
}
-
+ /**
+ * when : loading a graph (first) and then (second) loading an object contained in in the graph, in the same session
+ * then : the object should be the same
+ */
@Test
- public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
- PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
- PolytomousKeyNode pkeynode = pkey.getRoot();
+ public void subGraphObjectLoadTest2() {
- Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel();
- label1.size();
- //Language lang1 = label1.get(english).getLanguage();
- //String title1 = lang1.getTitleCache();
+ // this call will load into the session cache the graph and update the objects in the sub-graph for a
+ // polytomous key
+ // |- root : polytomous key node
+ // |- question : KeyStatement
+ // |- statement : KeyStatement
+
+ PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
+ // this call will load into the session cache a polytomous key node object
+ PolytomousKeyNode rootPKNode = CdmBase.deproxy(polytomousKeyNodeService.find(polytomousKeyNodeUuid1),PolytomousKeyNode.class);
+ rootPKNode = cdmEntitySessionManager.add(sessionOwner, rootPKNode);
- Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel();
- label2.size();
- //Language lang2 = label2.get(english).getLanguage();
- //String title2 = lang2.getTitleCache();
+ Assert.assertNotNull(rootPKNode);
+ Assert.assertSame(rootPKNode, cacher.getFromCache(rootPKNode));
+
+ PolytomousKeyNode childOfRootPKNode = CdmBase.deproxy(polytomousKeyNodeService.find(polytomousKeyNodeUuid2),PolytomousKeyNode.class);
+ childOfRootPKNode = cdmEntitySessionManager.add(sessionOwner, childOfRootPKNode);
+
+ Assert.assertNotNull(childOfRootPKNode);
+ Assert.assertSame(childOfRootPKNode, cacher.getFromCache(childOfRootPKNode));
+
- polytomousKeyService.merge(pkey);
+
+ Assert.assertSame(childOfRootPKNode, cacher.getFromCache(childOfRootPKNode));
+ Assert.assertSame(pkey.getRoot().getChildAt(1), childOfRootPKNode);
}
+
}
@Test
public void savePolytomousKeyNodeDataWithSameSubKey() {
- //CachedCommonServiceImpl.setCacheEnabled(false);
+
ISessionEventListener sessionOwner = new MockSessionOwner();
cdmEntitySessionManager.bind(sessionOwner);
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
PolytomousKeyNode pkeynode = pkey.getRoot();
- PolytomousKey subkey1 = pkeynode.getChildAt(0).getSubkey();
+ PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class);
String subkey1title = subkey1.getTitleCache();
subkey1.setTitleCache(subkey1title + "test", true);
- PolytomousKey subkey2 = pkeynode.getChildAt(1).getChildAt(0).getSubkey();
+ PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class);
String subkey2title = subkey2.getTitleCache();
subkey2.setTitleCache(subkey2title + "test", true);
@Test
public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
- CachedCommonServiceImpl.setCacheEnabled(false);
+ ISessionEventListener sessionOwner = new MockSessionOwner();
+ cdmEntitySessionManager.bind(sessionOwner);
+
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+ pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+
PolytomousKeyNode pkeynode = pkey.getRoot();
PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
String subkey2title = subkey2.getTitleCache();
subkey2.setTitleCache(subkey2title + "test", true);
- Assert.assertNotSame(subkey1, subkey2);
+ Assert.assertNotSame(childNode0, childNode1);
+
+ Assert.assertSame(subkey1, subkey2);
polytomousKeyService.merge(pkey);
}
@BeforeClass
public static void initializeBaseRemotingTest() {
- //Logger.getRootLogger().setLevel(Level.INFO);
+ //NOTE: Run this the cdmTest H2 DB whenever it needs to be
+ // recreated e.g. after a model change
//DatabaseUnitils.disableConstraints();
try {
<PolytomousKeyNode_LanguageString PolytomousKeyNode_id="2759" modifyingtext_id="13793" modifyingtext_mapkey_id="124"/>
<LanguageString id="13780" created="2014-03-10 10:03:09.0" uuid="cceaa60b-61f4-4c8a-bb0e-d45f0fa3e2dc" text="Modifying Text 1a" language_id="124"/>
- <LanguageString id="13781" created="2014-03-10 10:03:17.0" uuid="01a0ace4-de49-4725-9909-e881fb13035d" text="" language_id="124"/>
+ <LanguageString id="13781" created="2014-03-10 10:03:17.0" uuid="01a0ace4-de49-4725-9909-e881fb13035d" text="Modifying Text 1b" language_id="124"/>
<LanguageString id="13782" created="2014-03-10 10:03:48.0" uuid="ec0fea40-69dd-4c3e-ab7a-34948037a069" updated="2014-03-10 10:06:32.0" text="Capitula with ligulate ray-florets; leaves pinnatisect" createdby_id="30" updatedby_id="30" language_id="124"/>
<LanguageString id="13783" created="2014-03-10 10:04:03.0" uuid="82f8a3a0-567f-4d89-ba10-3f3699111d55" updated="2014-03-10 10:06:32.0" text="Ray-florets yellow" createdby_id="30" updatedby_id="30" language_id="124"/>
<LanguageString id="13784" created="2014-03-10 10:04:21.0" uuid="4270501f-1efc-45c2-9e8f-c65f120e8f4c" updated="2014-03-10 10:06:32.0" text="Stem thinly pilose; leaves 10-15 mm wide, with spreading linear-subulate segments; perennial herb" createdby_id="30" updatedby_id="30" language_id="124"/>
<LanguageString id="13796" created="2014-03-10 10:03:25.0" uuid="69cffb28-8a85-478f-bcae-533e20938ccd" updated="2014-03-10 10:06:32.0" text="Capitula without ligulate ray-florets; leaves entire or subentire" createdby_id="30" updatedby_id="30" language_id="124"/>
<LanguageString id="14570" created="2014-10-09 15:42:33.0" uuid="84967760-6dbe-4af4-8e0c-309f1af6ce20" updated="2014-10-09 15:42:44.0" text="Question 1" createdby_id="10" updatedby_id="10" language_id="124"/>
<LanguageString id="14571" created="2014-10-09 15:42:55.0" uuid="d82f37b1-f51d-42c1-a291-0c7820db155e" updated="2014-10-09 15:43:03.0" text="Question 2" createdby_id="10" updatedby_id="10" language_id="124"/>
+ <LanguageString id="14572" created="2014-10-09 15:42:55.0" uuid="d82f37b1-f51d-42c1-a291-0c7820db155f" updated="2014-10-09 15:43:03.0" text="Koi Sach Ya Sawal" createdby_id="30" updatedby_id="30" language_id="125"/>
<TaxonBase DTYPE="Taxon" id="32" created="2011-03-01 20:11:26.0" uuid="8217ef77-2ab1-4318-bd67-ccd0cdef07c4" protectedtitlecache="false" titleCache="Achillea arabica Kotschy sec. Cyprus" doubtful="false" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="11" sec_id="10" publish="true"/>
<TaxonBase DTYPE="Taxon" id="35" created="2010-12-21 15:09:43.0" uuid="fade44fd-34b2-455f-861a-d1372b866f06" protectedtitlecache="false" titleCache="Achillea sec. Cyprus" doubtful="false" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="11" sec_id="10" publish="true"/>
<AgentBase DTYPE="Person" id="4809" created="2010-12-21 15:09:59.0" uuid="945d08f2-eb92-45b6-9252-6275ea6d338b" protectedtitlecache="false" titleCache="R. A. Graham" nomenclaturaltitle="R. A. Graham" createdby_id="11"/>
<DefinedTermBase DTYPE="Language" id="124" created="2010-12-21 15:09:09.0" uuid="e9f8cdb7-6819-44e8-95d3-e2d0690c3523" protectedtitlecache="false" titleCache="English" uri="" vocabulary_id="10" termType="LA" idInVocabulary="eng"/>
+ <DefinedTermBase DTYPE="Language" id="125" created="2010-12-21 15:09:09.0" uuid="0a1d9d1d-135d-4575-b172-669b51673c39" protectedtitlecache="false" titleCache="Hindi" uri="" vocabulary_id="10" termType="LA" idInVocabulary="hin"/>
<Extension id="10" created="2014-10-09 15:45:41.0" uuid="0d6f35d7-7e76-446a-a017-7e8355ee1b4c" updated="2014-10-09 15:48:01.0" extendedObj_type="eu.etaxonomy.cdm.model.description.PolytomousKey" extendedObj_id="1550" value="http://test.com" createdby_id="10" updatedby_id="10" type_id="2075"/>
<KeyStatement_LanguageString KeyStatement_id="2467" label_id="13796" label_mapkey_id="124"/>
<KeyStatement_LanguageString KeyStatement_id="2760" label_id="14570" label_mapkey_id="124"/>
<KeyStatement_LanguageString KeyStatement_id="2761" label_id="14571" label_mapkey_id="124"/>
+ <KeyStatement_LanguageString KeyStatement_id="2460" label_id="14572" label_mapkey_id="125"/>
<PolytomousKey id="751" created="2013-03-24 11:17:08.0" uuid="9d8bf4f6-a70a-4b80-8556-2ccfb436ff01" protectedtitlecache="true" titleCache="Asphodeline" createdby_id="30" startNumber="1"/>
<PolytomousKey id="1550" created="2014-03-10 10:02:35.0" uuid="0d53ba20-7de4-4baa-bd8a-401048447d66" updated="2014-03-10 10:02:42.0" protectedtitlecache="true" titleCache="Achillea" createdby_id="30" updatedby_id="30" root_id="2750" startNumber="1"/>