为Coherence缓存创建查询和过滤

时间:2014-10-13 20:50:34

标签: oracle-coherence

我有一个简单的POJO:

class Person {
  String name;
  int age;
}

我希望能够在缓存上创建一个索引,然后允许我执行以下伪查询:

find me all the people whose name is EQUAL to John and their age is GREATERTHAN 30

我尝试了MultiExtractor似乎创建了我想要的索引,但是当我使用Filter对象构建查询时,我似乎仍然最终得到了未经优化的查询。

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是添加属性访问器:

public class Person {
  public Person(String name, int age) {
    this.name = name;
    this.age = age;
  }

  public String getName() {
    return name;
  }

  public int getAge() {
    return age;
  }

  private String name;
  private int age;
}

现在您可以查询:

// find me all the people whose name is EQUAL to
// John and their age is GREATERTHAN 30
Filter filter = new AndFilter(
                    new EqualsFilter("getName", "John"),
                    new GreaterFilter("getAge", Integer.valueOf(30));
Set setKeys = cache.keySet(filter);

您还可以在SQL中对该过滤器进行编码。请参阅:https://community.oracle.com/message/11217211#11217211

其他资源: