2017-10-05 65 views
2

我正在关注Ignite高速缓存中正在运行的SQL查询的代码,但能够完全实现CacheConfiguration.setIndexedTypes API的使用。如何将CacheConfiguration.setIndexedTypes用于Ignite高速缓存

我追随着我在点火网站找到的唯一帮助。

文档here说,使用 CacheConfiguration.setIndexedTypes(MyKey.class,MyValue.class)。

现在,让我们在Person类

@QuerySqlField(index = true) 
private long id; 

@QuerySqlField 
private String firstName; 

它们是我的参数应该是传入setIndexedType方法说呢?

回答

0

你的情况,这将是

cacheConfig.setIndexedTypes(KeyType.class, Person.class) 

其中的KeyType是你同时呼吁cache.put(key, person)insert into Person(_key, ...) ...
请参考this documentation section

0

setIndexedTypes需要偶数个参数用于键的类型。每个奇数参数对应一个键类型,并且每个偶数对应一个值类型。在你的情况下,你应该使用id参数作为关键字,所以你应该这样称呼它:

cacheConfig.setIndexedTypes(Long.class,Person.class);

的Javadoc setIndexedTypes方法中包含这种方法的一个很好的解释:https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/configuration/CacheConfiguration.html#setIndexedTypes(java.lang.Class...)

UPD:

有将登记表中的SQL每一对您提供给setIndexedTypes方法参数。

您的SQL实体将映射到缓存记录,除了您配置为QuerySqlField-s之外,它们还将有_key_val列。因此,您应该为每个表指定将在缓存中使用的键和值的类型。

您可以参考此页面了解更多信息:https://apacheignite.readme.io/docs/dml#basic-configuration

+0

所以在情况下,可以说我对类人 @QuerySqlField(指数=真) 私人长期ID两个指标; @QuerySqlField(index = true) private String orgId; 我的索引类型应该是 - cacheConfig.setIndexedTypes(Long.class,Person.class,String.class,Person.class); 这是正确的吗? – frewper

+0

@frewper不,实际上键类型不依赖索引。即使您将其他字段编入索引,setIndexedTypes调用也将保持不变。我添加了一些关于它的信息给我的答案。 – Denis