3.2. 查询 ProtoStream 通用类型
对存储数据为 ProtoStream 通用类型的缓存执行 Ickle 查询,如 BigInteger 和 BigDecimal。
流程
在类中添加索引注解,如下例所示:
@Indexed public class CalculusIndexed { @Basic @ProtoField(value = 1) public BigInteger getPurchases() { return purchases; } @Decimal // the scale is 2 by default @ProtoField(value = 2) public BigDecimal getProspect() { return prospect; } }将
dependentOn属性设置为CommonTypes.class,以指示生成的 Protobuf 模式可以引用和使用CommonTypes类型,如BigInteger和BigDecimal:@ProtoSchema(includeClasses = CalculusIndexed.class, dependsOn = CommonTypes.class, schemaFilePath = "/protostream", schemaFileName = "calculus-indexed.proto", schemaPackageName = "lab.indexed") public interface CalculusIndexedSchema extends GeneratedSchema { }执行查询:
Query<Product> query = cache.query("from lab.indexed.CalculusIndexed c where c.purchases > 9"); QueryResult<Product> result = query.execute(); // play with the result query = cache.query("from lab.indexed.CalculusIndexed c where c.prospect = 2.2"); result = query.execute(); // play with the result