📄 defaultcachecontroller.java
字号:
package com.ejsun.entapps.core.cache;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.ejsun.entapps.domain.Entity;
/**
* Default Cache Controller for Entity Cache;
* @author Quake Wang
* @since 2004-5-18
* @version $Revision: 1.1 $
*
**/
public class DefaultCacheController implements CacheController {
private Map cacheNames;
public String getCacheName(Method method) {
String invocationSignature =
method.getDeclaringClass().getName() + "." + method.getName();
String cacheName = (String) cacheNames.get(invocationSignature);
if (cacheName == null)
throw new CacheException(
"can not find the cache name with invocation: "
+ invocationSignature);
return cacheName;
}
public String getCacheKey(Method method, Object[] args) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Entity) {
result
.append("[")
.append(args[i].getClass().getName())
.append(":")
.append(((Entity) args[i]).getId())
.append("]");
} else {
result.append("[").append(args[i]).append("]");
}
}
return result.toString();
}
public List getRelativeCaches(Method method, Object[] args) {
List result = new ArrayList();
String invocationSignature =
method.getDeclaringClass().getName() + "." + method.getName();
String cacheName = (String) cacheNames.get(invocationSignature);
if (cacheName != null)
result.add(cacheName);
return result;
}
public void setCacheNames(Map map) {
cacheNames = map;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -