• ignite通过注解配置查询


    官方文档的叙述可能有些不清楚,我做了一个测试,并且可以成功运行,待会儿后面贴出小栗子.

      两步操作:

      第一步在属性值处贴上@QuerySqlField注解

      第二部设置key和value类型

    Person.java

    package test.ignite.client;
    
    import org.apache.ignite.cache.query.annotations.QuerySqlField;
    
    public class Person {
        
        @QuerySqlField
        private Integer id;
        
        @QuerySqlField
        private String name;
        
        @QuerySqlField
        private 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

    ...

  • 相关阅读:
    python学习笔记(一):基本概念
    selenuim webDriver API 16种定位方式
    css属性之display行内标签 块级标签 隐藏显示
    python------面向对象编程
    网络编程---发送http请求
    python----tcp/ip http
    python基础_md5加密与加盐
    python-----环境变量
    低代码工具-page-pipepline
    模块化的构建工具
  • 原文地址:https://www.cnblogs.com/garfieldcgf/p/5646374.html
Copyright © 2020-2023  润新知