
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可以进行遍历就得到了需要的东西.