编程语言
首页 > 编程语言> > java – Hazelcast查询可以使用对象方法吗?

java – Hazelcast查询可以使用对象方法吗?

作者:互联网

我在文档中找不到这个.

如果我在hazelcast缓存中有一个复杂的对象:

public class MyObj {
    private int something;
    private AnotherObject complexMember;
}

我可不可以做:

map.values(new SqlPredicate("something > 3 AND complexMember.someProperty > 3"));

我知道@Cachable注释使用SpEL这是可能的.有可能以某种方式以编程方式进行吗?

谢谢,

解决方法:

是的可能.试试以下;

public static void main(String[] args) throws Exception {
    final HazelcastInstance hz = Hazelcast.newHazelcastInstance(null);
    final IMap map = hz.getMap("test");
    map.put(1, new MyObj(1, new AnotherObject("value")));

    System.out.println(map.values(new SqlPredicate("something > 0 and complexMember.someString like 'val%'")));
}

static class MyObj implements Serializable {
    private int something;
    private AnotherObject complexMember;

    MyObj(final int something, final AnotherObject complexMember) {
        this.something = something;
        this.complexMember = complexMember;
    }
}

static class AnotherObject implements Serializable  {
    private String someString;

    AnotherObject(final String someString) {
        this.someString = someString;
    }
}

标签:java,spring,hazelcast,spring-el
来源: https://codeday.me/bug/20190902/1788138.html