Hi,

But what result do you observe in your experiment?

ср, 13 февр. 2019 г. в 05:16, chengpei <[email protected]>:
>
> 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/



-- 
Best regards,
Ivan Pavlukhin

Reply via email to