在Corda的H2数据库中,我们是否需要提供自己的索引?

时间:2018-08-08 11:07:13

标签: corda

我们正在使用默认的H2节点数据库。我们需要提供自己的数据库索引,还是由Corda本身创建?

1 个答案:

答案 0 :(得分:1)

使用H2时,将使用JPA批注自动配置索引。例如,Corda为vault_linear_states表创建一个索引,如图here所示:

@Entity
@Table(name = "vault_linear_states", indexes = arrayOf(
        Index(name = "external_id_index", columnList = "external_id"),
        Index(name = "uuid_index", columnList = "uuid")))
class VaultLinearStates(

定义自己的状态模式时,由您为它们提供索引。例如,我们可以在Example CorDapp的IOU表中添加索引,如下所示:

@Entity
@Table(name = "iou_states", indexes = [Index(name="lender_idx", columnList = "lender")])
class PersistentIOU(
        @Column(name = "lender")
        var lenderName: String,

        @Column(name = "borrower")
        var borrowerName: String,

        @Column(name = "value")
        var value: Int,

        @Column(name = "linear_id")
        var linearId: UUID
) : PersistentState()