ignite通过注解配置查询
生活随笔
收集整理的這篇文章主要介紹了
ignite通过注解配置查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
官方文檔的敘述可能有些不清楚,我做了一個測試,并且可以成功運行,待會兒后面貼出小栗子.
兩步操作:
第一步在屬性值處貼上@QuerySqlField注解
第二部設置key和value類型
Person.java
package test.ignite.client;import org.apache.ignite.cache.query.annotations.QuerySqlField;public class Person {@QuerySqlFieldprivate Integer id;@QuerySqlFieldprivate String name;@QuerySqlFieldprivate String age;public String getName() {return name;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}}測試類:
package test.ignite.client;import java.util.List;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.query.SqlQuery; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.cache.CacheEntryImpl;public class MMM {public static void main(String[] args) {System.out.println("======================================================");Ignite ignite = Ignition.start("ignite.xml");CacheConfiguration<Integer, Person> cfg = new CacheConfiguration<Integer, Person>();cfg.setName("Person");cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);cfg.setIndexedTypes(Integer.class, Person.class);ignite.getOrCreateCache(cfg);IgniteCache<Integer, Person> cache = ignite.cache("Person");Person a = new Person();a.setId(1);a.setAge("12");a.setName("32323");cache.put(1, a);SqlQuery sql = new SqlQuery(Person.class,"id <> -1");List<CacheEntryImpl> lists = ignite.cache("Person").query(sql).getAll();for (CacheEntryImpl cacheEntryImpl : lists) {Person aa = (Person)cacheEntryImpl.getValue();System.out.println(aa.getAge());}}}輸出結果:
[11:36:39] Ignite node started OK (id=ce3e8b48) [11:36:39] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, heap=1.8GB] 12...
轉載于:https://www.cnblogs.com/garfieldcgf/p/5646374.html
總結
以上是生活随笔為你收集整理的ignite通过注解配置查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51Nod 1079 中国剩余定理 La
- 下一篇: 移动APP接口遇到的一些小问题