The filter would run on the server side, so yes, the model class would need to 
be deployed to there. Alternatively, you could use BinaryObject. Something like 
this should work:

QueryCursor<Cache.Entry<String, BinaryObject>> query = 
cache.withKeepBinary().query(new
        ScanQuery<String, BinaryObject>(new IgniteBiPredicate<String, 
BinaryObject>() {
    @Override
    public boolean apply(String s, BinaryObject person) {
        BinaryObjectBuilder p = person.toBuilder();
        System.out.println(s + " : " + person);
        return (int)p.getField("age") > 22;
    }
}));
(Not tested, but you get the idea.)

Regards,
Stephen

> On 13 Feb 2019, at 02:16, chengpei <chengpei...@gmail.com> wrote:
> 
> import org.apache.ignite.Ignite;
> import org.apache.ignite.IgniteCache;
> import org.apache.ignite.Ignition;
> import org.apache.ignite.cache.CacheAtomicityMode;
> import org.apache.ignite.cache.CacheMode;
> import org.apache.ignite.cache.CacheWriteSynchronizationMode;
> import org.apache.ignite.cache.query.QueryCursor;
> import org.apache.ignite.cache.query.ScanQuery;
> import org.apache.ignite.configuration.CacheConfiguration;
> import org.apache.ignite.configuration.IgniteConfiguration;
> import org.apache.ignite.lang.IgniteBiPredicate;
> 
> import javax.cache.Cache;
> 
> public class QueryTest {
> 
>    public static Ignite ignite;
> 
>    public static IgniteCache<String, Person> cache;
> 
>    public static void main(String[] args) {
>        try {
>            init();
> //            insertData();
>            queryData();
>        } catch (Exception e) {
>            throw e;
>        } finally {
>            ignite.close();
>        }
>    }
> 
>    private static void queryData() {
>        System.out.println("query data start");
>        QueryCursor<Cache.Entry&lt;String, Person>> query = cache.query(new
> ScanQuery<String, Person>(new IgniteBiPredicate<String, Person>() {
>            @Override
>            public boolean apply(String s, Person person) {
>                System.out.println(s + " : " + person);
>                return person.getAge() > 22;
>            }
>        }));
>        for (Cache.Entry<String, Person> entry : query) {
>            System.out.println("queryData() ====> key:" + entry.getKey() +
> ", value:" + entry.getValue());
>        }
>        System.out.println("query data end");
>    }
> 
>    private static void insertData() {
>        System.out.println("insert data start");
>        Person p1 = new Person("Jack", 20);
>        Person p2 = new Person("Tom", 21);
>        Person p3 = new Person("Mike", 22);
>        Person p4 = new Person("Luci", 23);
>        Person p5 = new Person("Debug", 24);
>        cache.put(p1.getName(), p1);
>        cache.put(p2.getName(), p2);
>        cache.put(p3.getName(), p3);
>        cache.put(p4.getName(), p4);
>        cache.put(p5.getName(), p5);
>        System.out.println("insert data end");
>    }
> 
>    private static void init() {
>        System.out.println("init ignite cache start");
>        IgniteConfiguration cfg = new IgniteConfiguration();
>        cfg.setClientMode(true);
>        cfg.setPeerClassLoadingEnabled(true);
> 
>        CacheConfiguration cardCacheCfg = new CacheConfiguration();
>        cardCacheCfg.setName("Person_Cache");
>        cardCacheCfg.setCacheMode(CacheMode.PARTITIONED);
> 
> cardCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
>        cardCacheCfg.setBackups(2);
>        cardCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
> 
>        cfg.setCacheConfiguration(cardCacheCfg);
>        ignite = Ignition.start(cfg);
>        cache =  ignite.getOrCreateCache("Person_Cache");
>        System.out.println("init ignite cache end");
>    }
> 
> }
> class Person {
> 
>    private String name;
> 
>    private int age;
> 
>    public String getName() {
>        return name;
>    }
> 
>    public void setName(String name) {
>        this.name = name;
>    }
> 
>    public int getAge() {
>        return age;
>    }
> 
>    public void setAge(int age) {
>        this.age = age;
>    }
> 
>    public Person(String name, int age) {
>        this.name = name;
>        this.age = age;
>    }
> 
>    @Override
>    public String toString() {
>        return "Person{" +
>                "name='" + name + '\'' +
>                ", age=" + age +
>                '}';
>    }
> }
> 
> <http://apache-ignite-users.70518.x6.nabble.com/file/t2304/1.png> 
> 
> I want the result to be
> key:Luci, value:Person{name='Luci', age=23}
> key:Debug, value:Person{name='Debug', age=24}
> 
> and Do I have to put lib in ignite lib folder ?
> Thanks
> 
> 
> 
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Reply via email to