【发布时间】:2020-01-09 05:50:55
【问题描述】:
我正在使用以下代码进行缓存。
public class SuiteStandardQueryCache extends StandardQueryCache {
public SuiteStandardQueryCache(Settings settings, Properties props, UpdateTimestampsCache updateTimestampsCache, String regionName)
throws HibernateException {
super(settings, props, updateTimestampsCache, regionName);
}
public boolean put(QueryKey key, Type[] returnTypes, List result, boolean isNaturalKeyLookup, SessionImplementor session) throws HibernateException {
if (isNaturalKeyLookup && result.size() == 0) {
return false;
} else {
Long ts = new Long(session.getTimestamp());
List cacheable = new ArrayList(result.size() + 1);
cacheable.add(ts);
for (int i = 0; i < result.size(); i++) {
if (returnTypes.length == 1) {
// cacheable.add( returnTypes[0].disassemble( result.get( i
// ), session, null ) );
Object resultObj = result.get(i);
if (resultObj instanceof Object[]) {
resultObj = ((Object[]) result.get(i))[0];
}
cacheable.add(returnTypes[0].disassemble(resultObj, session, null));
} else {
cacheable.add(disassemble((Object[]) result.get(i), returnTypes, null, session, null));
}
}
getRegion().put(key, cacheable);
return true;
}
}
public static Serializable[] disassemble(final Object[] row,
return disassembled;
}
}
这段代码是 Hibernate 3 的休眠代码,我将把它升级到 Hibernate 5.4.4,其中没有这个类。
请帮助找出相同的替代方案。
【问题讨论】:
-
看起来这段代码是为了解决特定问题或错误而编写的,可能是在 Hibernate 的早期版本中。您首先需要找出为什么要写这个
-
@Guillaume 有可能,但我只是在寻找 StandardQueryCache 类,这个类的替代品是什么。