我有一个System.Linq.Expression对象,其值为: ((FieldA ==“Value1”)&&(FieldB ==“ValueB”))
我需要将此表达式应用于coherence缓存对象的顶部,并将过滤后的对象返回给调用方法。
public object MyMethod(Expression expression)
{
IQueryable<T> myCoherenceCacheObject;
var filteredCacheObject = //Filter logic here;
return filteredCacheObject;
}
我该怎么做?
感谢您的帮助。
答案 0 :(得分:0)
您可能希望使用AndFilter
撰写两个EaqualFilters
。
以下是代码段,假设您的对象以POF
格式缓存:
private YourPofObject yourPofObject() {
ValueExtractor extractorA = new PofExtractor(String.class, 0); // 0 - is index for fieldA property of your POF object
ValueExtractor extractorB = new PofExtractor(String.class, 1); // 1 - is index for fieldB property of your POF object
Filter filterAB = new AndFilter(new EqualsFilter(extractorA, "Value1"),
new EqualsFilter(extractorB, "ValueB"));
Set extractedEntries = namedCache.entrySet(filterAB);
for (Object extractedEntry : extractedEntries) {
Map.Entry<String, YourPofObject> entry = (Map.Entry<String, YourPofObject>) extractedEntry;
return entry.getValue();
}
return null;
}
确保您的缓存有indexes个POF对象的fieldA
和fieldB
,否则提取操作可能会非常慢。