CdmCacher, CdmDaoCacher : split CdmCacher class to sub class which uses dao to access the data
MockCdmCacher : added mock cdm cacher for tests
TaxonNodeServiceImplTest, FeatureNodeServiceImplTest : removed duplicate @SpringApplicationContext annotation
IdentifiableServiceBaseTest, TaxonServiceSearchTest : reverted @Ignore on failing tests
TaxonServiceSearchTest : added mock cdm cacher
SecurityTest : removed duplicate PlatformTransactionManager autowiring
CdmCacherTest : extended test
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/MonitoredGenericApplicationContext.java -text
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/MonitoredListableBeanFactory.java -text
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/cache/CdmCacher.java -text
+cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/cache/CdmDaoCacher.java -text
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/conversation/ConversationHolder.java -text
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/conversation/ConversationHolderMock.java -text
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/conversation/IConversationEnabled.java -text
cdmlib-services/src/main/resources/wsdl/LSIDPortTypes.wsdl -text
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/application/FirstDataInserterTest.java -text
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/cache/CdmCacherTest.java -text
+cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/cache/MockCdmCacher.java -text
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeCacheStrategyTest.java -text
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeFieldUnitCacheStrategyTest.java -text
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeTest.java -text
import eu.etaxonomy.cdm.model.ICdmCacher;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
+import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmGenericDaoImpl;
/**
+ * CDM Entity Cacher class based on EhCache.
+ *
* @author cmathew
*
* @param <T>
*/
-@Component
-public class CdmCacher<T extends CdmBase> implements ICdmCacher<T> {
+
+public abstract class CdmCacher<T extends CdmBase> implements ICdmCacher<T> {
- @Autowired
- private ITermService termService;
-
- private static final String DEFAULT_CACHE_NAME = "defaultCache";
-
- private static final String DEFAULT_CACHE_MGR_NAME = "defaultCacheManager";
+ private static final String DEFAULT_CACHE_NAME = "defaultCache";
+
/**
* Constructor which initialises a singleton {@link net.sf.ehcache.CacheManager}
*
if (e == null) {
// nothing in the cache for "key" (or expired) ... re-load the entity
- cdmEntity = (T)termService.load(uuid);
+ cdmEntity = findByUuid(uuid);
put(uuid, cdmEntity);
} else {
// there is a valid element in the cache, however getObjectValue() may be null
return false;
}
+ /**
+ * Finds CDM Entity by uuid
+ *
+ * @param uuid
+ * @return
+ */
+ protected abstract T findByUuid(UUID uuid);
+
}
--- /dev/null
+package eu.etaxonomy.cdm.api.cache;
+
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmGenericDaoImpl;
+
+/**
+ * CDM Entity Cacher class which uses CDM DAOs to find cdm entities
+ *
+ * @author cmathew
+ *
+ * @param <T>
+ */
+@Component
+public class CdmDaoCacher<T extends CdmBase> extends CdmCacher<T> {
+
+ @Autowired
+ CdmGenericDaoImpl genericDao;
+
+ @Override
+ protected T findByUuid(UUID uuid) {
+ return (T)genericDao.findByUuidWithoutFlush(uuid);
+ }
+
+}
* @return an entity of type <T>, or null if the entity does not exist\r
*/\r
public T find(UUID uuid);\r
+ \r
+\r
+ public T findWithoutFlush(UUID uuid);\r
\r
/**\r
* Return a persisted entity that matches the database identifier\r
*/\r
public List<T> list(T example, Set<String> includeProperties, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
\r
+\r
}
\ No newline at end of file
public T find(UUID uuid) {\r
return dao.findByUuid(uuid);\r
}\r
+ \r
+ @Override\r
+ @Transactional(readOnly = true)\r
+ public T findWithoutFlush(UUID uuid) {\r
+ return dao.findByUuidWithoutFlush(uuid);\r
+ }\r
\r
@Override\r
@Transactional(readOnly = true)\r
import org.unitils.spring.annotation.SpringBeanByType;
import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.name.BotanicalName;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
import eu.etaxonomy.cdm.api.cache.CdmCacher;
+import eu.etaxonomy.cdm.api.service.IReferenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
public class CdmCacherTest extends CdmIntegrationTest {
@SuppressWarnings("unused")
@SpringBeanByType
private CdmCacher cdmCacher;
+ @SpringBeanByType
+ private IReferenceService referenceService;
+
+ @SpringBeanByType
+ private ITaxonService taxonService;
+
@Test
public void testLanguageCache() {
Language defaultLanguage = Language.getDefaultLanguage();
Language language = Language.getLanguageFromUuid(Language.uuidFrench);
Language languageInCache = (Language)cdmCacher.getFromCache(language.getUuid());
Assert.assertEquals("Loaded Language Term should match Language Term in Cache",language,languageInCache);
+
+ // Following test is just to make sure no exception is raised when saving a taxon corresponding
+ // to a taxon name with no name cache to begin with
+ Reference sec = ReferenceFactory.newDatabase();
+ referenceService.save(sec);
+ Taxon taxon = Taxon.NewInstance(NonViralName.NewInstance(Rank.SERIES()), sec);
+ taxon.setTitleCache("Tax" + "CdmCacher", true);
+ taxonService.save(taxon);
+ NonViralName nvn = (NonViralName)taxon.getName();
+ String nameCache = nvn.getNameCache();
+ logger.warn("name cache : " + nameCache);
}
}
--- /dev/null
+package eu.etaxonomy.cdm.api.cache;
+
+import java.util.UUID;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.PersistenceConfiguration;
+import net.sf.ehcache.config.PersistenceConfiguration.Strategy;
+import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
+
+import eu.etaxonomy.cdm.model.ICdmCacher;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Language;
+
+/**
+ * Since cdmlib-model cannot access CdmCacher we need to create a mock class
+ * for the tests
+ *
+ * @author cmathew
+ *
+ */
+public class MockCdmCacher implements ICdmCacher {
+
+ private static final String DEFAULT_CACHE_NAME = "defaultCache";
+
+ private static final String DEFAULT_CACHE_MGR_NAME = "defaultCacheManager";
+ /**
+ * Constructor which initialises a singleton {@link net.sf.ehcache.CacheManager}
+ *
+ */
+ public MockCdmCacher() {
+ init();
+ }
+
+ /**
+ * Initialises an empty singleton {@link net.sf.ehcache.CacheManager} and
+ * sets itself as the cacher object in specific CDM Entity objects.
+ *
+ */
+ private void init() {
+ // Remove all caches
+ getDefaultCacheManager().removalAll();
+ // Create default cache
+ getDefaultCacheManager().addCache(new Cache(getDefaultCacheConfiguration()));
+ put(Language.DEFAULT().getUuid(),Language.DEFAULT());
+ // We start first only with DefinedTermBase
+ DefinedTermBase.setCacher(this);
+
+ }
+
+ /**
+ * Returns the singleton default cache manager.
+ *
+ * @return
+ */
+ private static CacheManager getDefaultCacheManager() {
+ // this ensures a singleton cache manager
+ return CacheManager.create();
+ }
+
+ /**
+ * Returns the default cache configuration.
+ *
+ * @return
+ */
+ private CacheConfiguration getDefaultCacheConfiguration() {
+ return new CacheConfiguration(DEFAULT_CACHE_NAME, 50)
+ .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
+ .eternal(false)
+ // default ttl and tti set to 2 hours
+ .timeToLiveSeconds(60*60*2)
+ .timeToIdleSeconds(60*60*2)
+ .diskExpiryThreadIntervalSeconds(0)
+ .persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));
+ }
+
+ /**
+ * Returns the default cache
+ *
+ * @return
+ */
+ private static Cache getDefaultCache() {
+ return getDefaultCacheManager().getCache(DEFAULT_CACHE_NAME);
+ }
+
+ /**
+ * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
+ * in the cache
+ *
+ * @param uuid
+ * @param cdmEntity
+ */
+ public void put(UUID uuid, CdmBase cdmEntity) {
+ getDefaultCache().put(new Element(uuid, cdmEntity));
+ }
+
+ /**
+ * Gets the cache element corresponding to the given {@link java.util.UUID}
+ *
+ * @param uuid
+ * @return
+ */
+ private Element getCacheElement(UUID uuid) {
+ return getDefaultCache().get(uuid);
+ }
+
+ /**
+ * Get CDM Entity for given {@link java.util.UUID} from the cache
+ *
+ * @param uuid
+ * @return
+ */
+ private CdmBase getCdmEntity(UUID uuid) {
+ return (CdmBase)getDefaultCache().get(uuid).getObjectValue();
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.remote.cache.ICdmCacher#load(java.util.UUID)
+ */
+
+ public CdmBase load(UUID uuid) {
+ Element e = getCacheElement(uuid);
+ CdmBase cdmEntity;
+ if (e == null) {
+ return null;
+ } else {
+ return (CdmBase)e.getObjectValue();
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.ICdmCacher#getFromCache(java.util.UUID)
+ */
+ public CdmBase getFromCache(UUID uuid) {
+ Element e = getCacheElement(uuid);
+ CdmBase cdmEntity;
+ if (e == null) {
+ return null;
+ } else {
+ return(CdmBase)e.getObjectValue();
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.ICdmCacher#exists(java.util.UUID)
+ */
+ public boolean exists(UUID uuid) {
+ return getCacheElement(uuid) != null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.ICdmCacher#existsAndIsNotNull(java.util.UUID)
+ */
+ public boolean existsAndIsNotNull(UUID uuid) {
+ Element e = getCacheElement(uuid);
+ CdmBase cdmEntity;
+ if (e != null) {
+ return (CdmBase)e.getObjectValue() != null;
+ }
+ return false;
+ }
+
+}
* @author a.mueller
* @created 2013-09-28
*/
-@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
+//@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
public class FeatureNodeServiceImplTest extends CdmTransactionalIntegrationTest{
private static final String sep = ITreeNode.separator;
\r
@Test\r
@DataSet\r
- @ExpectedDataSet\r
- @Ignore\r
+ @ExpectedDataSet \r
public final void testUpdateTitleCache() {\r
Assert.assertEquals("There should be 5 TaxonNames in the data set", 5, nameService.count(TaxonNameBase.class));\r
Class clazz = TaxonNameBase.class;\r
\r
private static final Logger logger = Logger.getLogger(SecurityTest.class);\r
\r
- /**\r
- * The transaction manager to use\r
- */\r
- @SpringBeanByType\r
- PlatformTransactionManager transactionManager;\r
-\r
@SpringBeanByType\r
private ITaxonService taxonService;\r
\r
* @author n.hoffmann
* @created Dec 16, 2010
*/
-@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
+//@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
public class TaxonNodeServiceImplTest extends CdmTransactionalIntegrationTest{
import eu.etaxonomy.cdm.common.UTF8;\r
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;\r
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.api.cache.MockCdmCacher;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
france = Country.FRANCEFRENCHREPUBLIC();\r
russia = Country.RUSSIANFEDERATION();\r
canada = Country.CANADA();\r
+ \r
+ // Have to add a mock cdm cacher since the disabling of transactions\r
+ // results in the default CdmCacher object not working due to the fact that \r
+ // the current session for the CdmGenericDaoImpl.findByUuidWithoutFlush in\r
+ // the autowired CdmDaoCacher is null\r
+ // Comment out the line below to see the error.\r
+ MockCdmCacher cdmCacher = new MockCdmCacher();\r
\r
}\r
\r
*/\r
@SuppressWarnings("rawtypes")\r
@Test\r
- @DataSet\r
- @Ignore\r
+ @DataSet \r
public final void testFullText_Paging() throws CorruptIndexException, IOException, ParseException {\r
\r
Reference sec = ReferenceFactory.newDatabase();\r