ignite中的sql查詢


  ignite中進行sql查詢需要對要查詢的cache和字段進行配置,可以在xml中配置,也可以在代碼中配置或進行注解,我用的是xml配置:

<!-- 配置cache -->
        <property name="cacheConfiguration">
            <list>
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="task_template" />
                    <property name="cacheMode" value="PARTITIONED" />
                    <property name="atomicityMode" value="TRANSACTIONAL" />
                    <property name="backups" value="2" />
                    <property name="queryEntities">
                        <list>
                            <bean class="org.apache.ignite.cache.QueryEntity">
                                <property name="keyType" value="java.lang.Integer" />
                                <property name="valueType"
                                    value="com.domain.read.TaskTemplate" />
                                <property name="fields">
                                    <map>
                                        <entry key="taskTemplateId" value="java.lang.Integer" />
                                    </map>
                                </property>
                                <property name="indexes">
                                    <list>
                                        <bean class="org.apache.ignite.cache.QueryIndex">
                                            <constructor-arg value="taskTemplateId" />
                                        </bean>
                                    </list>
                                </property>
                            </bean>
                        </list>
                    </property>
                </bean>
            </list>
        </property>

  其中keyTpye和ValueType配置就是cache中儲存的k和v配置  

  dao查詢代碼:

public List<CacheEntryImpl> queryAll() {
        SqlQuery sql = new SqlQuery(TaskTemplate.class,
                "taskTemplateId <> -1");
        return cache().query(sql).getAll();
    }

  得到的CacheEntryImpl可以進行遍歷就得到了需要的東西.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM