3.5. キーによるクエリー


キャッシュエントリーのキーを Indexed タイプとして定義して、キーフィールドと値フィールドをインデックス化し、キーを Ickle クエリーで使用できるようにします。

Indexed キーを定義するには、@Indexed アノテーションの keyEntity 属性でキータイプとして使用する ProtocolBuffer メッセージタイプの完全修飾名を指定します。

注記

この機能は、インデックス付きリモートクエリーでのみ使用できます。

インデックス化されたエンティティーの 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();
   }
}

キーエンティティーとそのインデックス化フィールドの定義

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;
   }
}

3.5.1. キープロパティー名

デフォルトでは、キーフィールドは key という名前のプロパティーを使用してターゲットになります。

Ickle クエリーでキープロパティーを使用する

select s.key.column from model.Structure s where s.key.zone = 'z7'

値に key という名前のプロパティーがすでに存在する場合、キーエンティティーの定義によってプロパティーとの名前の競合が発生する可能性があります。このため、また一般的には、@Indexed アノテーションの keyPropertyName 属性を変更することで、プロパティーキーの接頭辞として割り当てる名前を変更することも可能です。

3.5.2. キーには深さが含まれる

エンティティーキーには埋め込みエンティティーを含めることができます。属性 keyIncludeDepth を変更して、インデックス付けされる埋め込みエンティティーフィールドの深さを制限できます。この属性のデフォルトは 3 です。

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.