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可以進行遍歷就得到了需要的東西.