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 です。