3.2. 查询 ProtoStream 通用类型


对存储数据为 ProtoStream 通用类型的缓存执行 Ickle 查询,如 BigIntegerBigDecimal

流程

  1. 在类中添加索引注解,如下例所示:

    @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;
        }
    }
  2. dependentOn 属性设置为 CommonTypes.class,以指示生成的 Protobuf 模式可以引用和使用 CommonTypes 类型,如 BigIntegerBigDecimal

    @ProtoSchema(includeClasses = CalculusIndexed.class, dependsOn = CommonTypes.class,
         schemaFilePath = "/protostream", schemaFileName = "calculus-indexed.proto",
         schemaPackageName = "lab.indexed")
    public interface CalculusIndexedSchema extends GeneratedSchema {
    }
  3. 执行查询:

    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
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部