Skip to content
Snippets Groups Projects
Commit 7314bddf authored by piotr.gawron's avatar piotr.gawron
Browse files

test

parent 63926f60
No related branches found
No related tags found
1 merge request!1Issue 37
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment