如何在corda的默认构造函数中设置日期和金额(货币)的值

时间:2018-06-05 09:00:52

标签: corda

如何在corda程序中设置日期和金额(货币)字段默认构造函数(在模式中)的值。我尝试评论构造函数,但在API中遇到错误。

1 个答案:

答案 0 :(得分:0)

以下是其中一个字段value

的默认值的架构
object IOUSchemaV1 : MappedSchema(
        schemaFamily = IOUSchema.javaClass,
        version = 1,
        mappedTypes = listOf(PersistentIOU::class.java)) {
    @Entity
    @Table(name = "iou_states")
    class PersistentIOU(
            @Column(name = "lender")
            var lenderName: String,

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

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

            @Column(name = "value")
            var value: Int = 93
    ) : PersistentState() {
        // Default constructor required by hibernate.
        constructor(): this("", "", UUID.randomUUID(), 0)
    }
}

如果您没有为此字段提供值,则会使用默认值93。例如:

override fun generateMappedObject(schema: MappedSchema): PersistentState {
    return when (schema) {
        is IOUSchemaV1 -> IOUSchemaV1.PersistentIOU(
                this.lender.name.toString(),
                this.borrower.name.toString(),
                this.linearId.id
        )
        else -> throw IllegalArgumentException("Unrecognised schema $schema")
    }
}