3.5. 按键查询


您可以将缓存条目的键定义为 索引 类型,以索引键字段以及允许 Ickle 查询中使用的键的值字段。

要定义 Indexed 键,请指定 ProtocolBuffer 消息类型的完全限定名称,以用作 @Indexed 注释的 keyEntity 属性中的 key 类型。

注意

此功能仅适用于索引的远程查询。

指定索引实体的 keyEntity

import org.infinispan.api.annotations.indexing.Basic;
import org.infinispan.api.annotations.indexing.Indexed;
import org.infinispan.api.annotations.indexing.Text;
import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
import org.infinispan.protostream.annotations.ProtoSchema;

@Indexed(keyEntity = "model.StructureKey")
public class Structure {

   private final String code;
   private final String description;
   private final Integer value;

   @ProtoFactory
   public Structure(String code, String description, Integer value) {
      this.code = code;
      this.description = description;
      this.value = value;
   }

   @ProtoField(1)
   @Basic
   public String getCode() {
      return code;
   }

   @ProtoField(2)
   @Text
   public String getDescription() {
      return description;
   }

   @ProtoField(3)
   @Basic
   public Integer getValue() {
      return value;
   }

   @ProtoSchema(includeClasses = { Structure.class, StructureKey.class }, schemaPackageName = "model")
   public interface StructureSchema extends GeneratedSchema {
      StructureSchema INSTANCE = new StructureSchemaImpl();
   }
}
Copy to Clipboard Toggle word wrap

定义密钥实体及其索引字段

import org.infinispan.api.annotations.indexing.Basic;
import org.infinispan.api.annotations.indexing.Indexed;
import org.infinispan.api.annotations.indexing.Keyword;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;

@Indexed
public class StructureKey {

   private String zone;
   private Integer row;
   private Integer column;

   @ProtoFactory
   public StructureKey(String zone, Integer row, Integer column) {
      this.zone = zone;
      this.row = row;
      this.column = column;
   }

   @Keyword(projectable = true, sortable = true)
   @ProtoField(1)
   public String getZone() {
      return zone;
   }

   @Basic(projectable = true, sortable = true)
   @ProtoField(2)
   public Integer getRow() {
      return row;
   }

   @Basic(projectable = true, sortable = true)
   @ProtoField(3)
   public Integer getColumn() {
      return column;
   }
}
Copy to Clipboard Toggle word wrap

3.5.1. 键属性名称

默认情况下,使用名为 key 的属性将作为目标。

在 Ickle 查询中使用关键属性

select s.key.column from model.Structure s where s.key.zone = 'z7'
Copy to Clipboard Toggle word wrap

如果值已经具有名为 key 的属性,则密钥实体的定义可能会创建与属性的命名冲突。因此,通常也可以更改名称,将其分配为属性键的前缀,更改 @Indexed 注释的属性 keyPropertyName

3.5.2. 键包括深度

entity 键可以带有嵌入式实体。您可以通过更改属性 keyIncludeDepth (默认为 3 )来限制被索引的嵌入式实体字段的深度。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat