From 7314bddf3f0d0a58f2e6655784c144188a59654f Mon Sep 17 00:00:00 2001 From: "piotr.gawron" <piotr.gawron@uni-new> Date: Thu, 22 Sep 2016 14:06:26 +0200 Subject: [PATCH] test --- .../annotation/cache/GeneralCache.java | 289 +++++++++--------- 1 file changed, 145 insertions(+), 144 deletions(-) diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java index fef080dcec..2f3addc126 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java @@ -1,144 +1,145 @@ -package lcsb.mapviewer.annotation.cache; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.cache.CacheType; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; -import org.w3c.dom.Node; - -/** - * Cache used by the application. It contains two sub-classes responsible for - * application level cache (for single run of the application) and database - * level cache (for information that were gathere since the beginning). - * - * @author Piotr Gawron - * - */ -@Transactional(value = "txManager") -public class GeneralCache implements GeneralCacheInterface { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(GeneralCache.class); - - /** - * Application level cache. More information can be found - * {@link ApplicationLevelCache here}. - */ - private QueryCacheInterface cache1 = ApplicationLevelCache.getInstance(); - - /** - * Database level cache. More information can be found - * {@link PermanentDatabaseLevelCache here}. - */ - @Autowired - private QueryCacheInterface cache2; - - @Override - public void clearCache() { - if (cache1 != null) { - cache1.clearCache(); - } - if (cache2 != null) { - cache2.clearCache(); - } - } - - @Override - public Node getXmlNodeByQuery(String query, CacheType type) { - if (type == null) { - throw new InvalidArgumentException("Cache type cannot be null"); - } - - Node result = null; - if (cache1 != null) { - result = cache1.getXmlNodeByQuery(query, type); - } - if (result == null && cache2 != null) { - result = cache2.getXmlNodeByQuery(query, type); - if (result != null && cache1 != null) { - cache1.setCachedQuery(query, type, result); - } - } - return result; - } - - @Override - public String getStringByQuery(String query, CacheType type) { - if (type == null) { - throw new InvalidArgumentException("Cache type cannot be null"); - } - String result = null; - if (cache1 != null) { - result = cache1.getStringByQuery(query, type); - } - if (result == null && cache2 != null) { - result = cache2.getStringByQuery(query, type); - if (result != null && cache1 != null) { - cache1.setCachedQuery(query, type, result); - } - } - return result; - } - - @Override - public void setCachedQuery(String query, CacheType type, Object object) { - if (type == null) { - throw new InvalidArgumentException("Cache type cannot be null"); - } - if (cache1 != null) { - cache1.setCachedQuery(query, type, object); - } - if (cache2 != null) { - cache2.setCachedQuery(query, type, object); - } - } - - @Override - public void removeByQuery(String query, CacheType type) { - if (type == null) { - throw new InvalidArgumentException("Cache type cannot be null"); - } - if (cache1 != null) { - cache1.removeByQuery(query, type); - } - if (cache2 != null) { - cache2.removeByQuery(query, type); - } - } - - @Override - public void invalidateByQuery(String query, CacheType type) { - if (type == null) { - throw new InvalidArgumentException("Cache type cannot be null"); - } - if (cache1 != null) { - cache1.invalidateByQuery(query, type); - } - if (cache2 != null) { - cache2.invalidateByQuery(query, type); - } - - } - - /** - * @return the cache2 - * @see #cache2 - */ - public QueryCacheInterface getCache2() { - return cache2; - } - - /** - * @param cache2 - * the cache2 to set - * @see #cache2 - */ - public void setCache2(QueryCacheInterface cache2) { - this.cache2 = cache2; - } - -} +package lcsb.mapviewer.annotation.cache; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.cache.CacheType; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.w3c.dom.Node; + +/** + * Cache used by the application. It contains two sub-classes responsible for + * application level cache (for single run of the application) and database + * level cache (for information that were gathere since the beginning). + * + * @author Piotr Gawron + * + */ +@Transactional(value = "txManager") +public class GeneralCache implements GeneralCacheInterface { + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(GeneralCache.class); + + /** + * Application level cache. More information can be found + * {@link ApplicationLevelCache here}. + */ + private QueryCacheInterface cache1 = ApplicationLevelCache.getInstance(); + + /** + * Database level cache. More information can be found + * {@link PermanentDatabaseLevelCache here}. + */ + @Autowired + private QueryCacheInterface cache2; + + @Override + public void clearCache() { + if (cache1 != null) { + cache1.clearCache(); + } + if (cache2 != null) { + cache2.clearCache(); + } + } + + @Override + public Node getXmlNodeByQuery(String query, CacheType type) { + if (type == null) { + throw new InvalidArgumentException("Cache type cannot be null"); + } + + Node result = null; + if (cache1 != null) { + result = cache1.getXmlNodeByQuery(query, type); + } + if (result == null && cache2 != null) { + result = cache2.getXmlNodeByQuery(query, type); + if (result != null && cache1 != null) { + cache1.setCachedQuery(query, type, result); + } + } + return result; + } + + @Override + public String getStringByQuery(String query, CacheType type) { + if (type == null) { + throw new InvalidArgumentException("Cache type cannot be null"); + } + String result = null; + if (cache1 != null) { + result = cache1.getStringByQuery(query, type); + } + if (result == null && cache2 != null) { + result = cache2.getStringByQuery(query, type); + if (result != null && cache1 != null) { + cache1.setCachedQuery(query, type, result); + } + } + return result; + } + + @Override + public void setCachedQuery(String query, CacheType type, Object object) { + if (type == null) { + throw new InvalidArgumentException("Cache type cannot be null"); + } + if (cache1 != null) { + cache1.setCachedQuery(query, type, object); + } + if (cache2 != null) { + cache2.setCachedQuery(query, type, object); + } + } + + @Override + public void removeByQuery(String query, CacheType type) { + if (type == null) { + throw new InvalidArgumentException("Cache type cannot be null"); + } + if (cache1 != null) { + cache1.removeByQuery(query, type); + } + if (cache2 != null) { + cache2.removeByQuery(query, type); + } + } + + @Override + public void invalidateByQuery(String query, CacheType type) { + if (type == null) { + throw new InvalidArgumentException("Cache type cannot be null"); + } + if (cache1 != null) { + cache1.invalidateByQuery(query, type); + } + if (cache2 != null) { + cache2.invalidateByQuery(query, type); + } + + } + + /** + * @return the cache2 + * @see #cache2 + */ + public QueryCacheInterface getCache2() { + return cache2; + } + + /** + * @param cache2 + * the cache2 to set + * @see #cache2 + */ + public void setCache2(QueryCacheInterface cache2) { + this.cache2 = cache2; + } + +} -- GitLab