Database schema changes. (#2389)

Changes compatible with R3.Corda (ENT-794):
1) Added Hibernate corda-wrapper-binary two to to columns.
2) Shorten names of tables in dummy schemas used in tests.
3) Undo removal of compound index of VaultTxnNote (b423fea).
4) Assertions for 2 vault tests don't rely on order of rows.
This commit is contained in:
szymonsztuka 2018-01-19 17:09:02 +00:00 committed by GitHub
parent ac7637e2b4
commit f59560bb06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 27 deletions

View File

@ -33,6 +33,7 @@ object CommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSche
var issuancePartyHash: String, var issuancePartyHash: String,
@Column(name = "issuance_ref") @Column(name = "issuance_ref")
@Type(type = "corda-wrapper-binary")
var issuanceRef: ByteArray, var issuanceRef: ByteArray,
@Column(name = "owner_key_hash", length = MAX_HASH_HEX_SIZE) @Column(name = "owner_key_hash", length = MAX_HASH_HEX_SIZE)

View File

@ -31,6 +31,7 @@ object SampleCommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPap
var issuancePartyHash: String, var issuancePartyHash: String,
@Column(name = "issuance_ref") @Column(name = "issuance_ref")
@Type(type = "corda-wrapper-binary")
var issuanceRef: ByteArray, var issuanceRef: ByteArray,
@Column(name = "owner_key_hash", length = MAX_HASH_HEX_SIZE) @Column(name = "owner_key_hash", length = MAX_HASH_HEX_SIZE)

View File

@ -13,6 +13,7 @@ import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.node.utilities.AppendOnlyPersistentMap import net.corda.node.utilities.AppendOnlyPersistentMap
import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX
import org.hibernate.annotations.Type
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*
import javax.annotation.concurrent.ThreadSafe import javax.annotation.concurrent.ThreadSafe
@ -43,6 +44,7 @@ class PersistentUniquenessProvider : UniquenessProvider, SingletonSerializeAsTok
var name: String = "", var name: String = "",
@Column(name = "requesting_party_key", length = 255) @Column(name = "requesting_party_key", length = 255)
@Type(type = "corda-wrapper-binary")
var owningKey: ByteArray = ByteArray(0) var owningKey: ByteArray = ByteArray(0)
) : Serializable ) : Serializable

View File

@ -151,7 +151,8 @@ object VaultSchemaV1 : MappedSchema(schemaFamily = VaultSchema.javaClass, versio
@Entity @Entity
@Table(name = "vault_transaction_notes", @Table(name = "vault_transaction_notes",
indexes = arrayOf(Index(name = "transaction_id_index", columnList = "transaction_id"))) indexes = arrayOf(Index(name = "seq_no_index", columnList = "seq_no"),
Index(name = "transaction_id_index", columnList = "transaction_id")))
class VaultTxnNote( class VaultTxnNote(
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -745,24 +745,18 @@ class VaultQueryTests {
// DOCEND VaultQueryExample22 // DOCEND VaultQueryExample22
assertThat(results.otherResults).hasSize(15) assertThat(results.otherResults).hasSize(15)
/** CHF */ // the order of rows not guaranteed, a row has format 'NUM, NUM, NUM, CURRENCY_CODE'
assertThat(results.otherResults[0]).isEqualTo(50000L) val actualRows = mapOf(results.otherResults[4] as String to results.otherResults.subList(0,4),
assertThat(results.otherResults[1]).isEqualTo(10274L) results.otherResults[9] as String to results.otherResults.subList(5,9),
assertThat(results.otherResults[2]).isEqualTo(9481L) results.otherResults[14] as String to results.otherResults.subList(10,14))
assertThat(results.otherResults[3]).isEqualTo(10000.0)
assertThat(results.otherResults[4]).isEqualTo("CHF") val expectedRows = mapOf("CHF" to listOf(50000L, 10274L, 9481L, 10000.0),
/** GBP */ "GBP" to listOf(40000L, 10343L, 9351L, 10000.0),
assertThat(results.otherResults[5]).isEqualTo(40000L) "USD" to listOf(60000L, 11298L, 8702L, 10000.0))
assertThat(results.otherResults[6]).isEqualTo(10343L)
assertThat(results.otherResults[7]).isEqualTo(9351L) assertThat(expectedRows["CHF"]).isEqualTo(actualRows["CHF"])
assertThat(results.otherResults[8]).isEqualTo(10000.0) assertThat(expectedRows["GBP"]).isEqualTo(actualRows["GBP"])
assertThat(results.otherResults[9]).isEqualTo("GBP") assertThat(expectedRows["USD"]).isEqualTo(actualRows["USD"])
/** USD */
assertThat(results.otherResults[10]).isEqualTo(60000L)
assertThat(results.otherResults[11]).isEqualTo(11298L)
assertThat(results.otherResults[12]).isEqualTo(8702L)
assertThat(results.otherResults[13]).isEqualTo(10000.0)
assertThat(results.otherResults[14]).isEqualTo("USD")
} }
} }
@ -1454,12 +1448,14 @@ class VaultQueryTests {
val results = vaultService.queryBy<FungibleAsset<*>>(criteria) val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
assertThat(results.otherResults).hasSize(6) assertThat(results.otherResults).hasSize(6)
assertThat(results.otherResults[0]).isEqualTo(110000L) // the order of rows not guaranteed
assertThat(results.otherResults[1]).isEqualTo("CHF") val actualTotals = mapOf(results.otherResults[1] as String to results.otherResults[0] as Long,
assertThat(results.otherResults[2]).isEqualTo(70000L) results.otherResults[3] as String to results.otherResults[2] as Long,
assertThat(results.otherResults[3]).isEqualTo("GBP") results.otherResults[5] as String to results.otherResults[4] as Long)
assertThat(results.otherResults[4]).isEqualTo(30000L) val expectedTotals = mapOf("CHF" to 110000L, "GBP" to 70000L, "USD" to 30000L)
assertThat(results.otherResults[5]).isEqualTo("USD") assertThat(expectedTotals["CHF"]).isEqualTo(actualTotals["CHF"])
assertThat(expectedTotals["GBP"]).isEqualTo(actualTotals["GBP"])
assertThat(expectedTotals["USD"]).isEqualTo(actualTotals["USD"])
} }
} }

View File

@ -22,7 +22,7 @@ object DummyDealStateSchemaV1 : MappedSchema(schemaFamily = DummyDealStateSchema
/** parent attributes */ /** parent attributes */
@ElementCollection @ElementCollection
@Column(name = "participants") @Column(name = "participants")
@CollectionTable(name = "dummy_deal_states_participants", joinColumns = arrayOf( @CollectionTable(name = "dummy_deal_states_parts", joinColumns = arrayOf(
JoinColumn(name = "output_index", referencedColumnName = "output_index"), JoinColumn(name = "output_index", referencedColumnName = "output_index"),
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"))) JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
override var participants: MutableSet<AbstractParty>? = null, override var participants: MutableSet<AbstractParty>? = null,

View File

@ -18,7 +18,7 @@ object DummyLinearStateSchemaV2 : MappedSchema(schemaFamily = DummyLinearStateSc
@ElementCollection @ElementCollection
@Column(name = "participants") @Column(name = "participants")
@CollectionTable(name = "dummy_linear_states_v2_participants", joinColumns = arrayOf( @CollectionTable(name = "dummy_linear_states_v2_parts", joinColumns = arrayOf(
JoinColumn(name = "output_index", referencedColumnName = "output_index"), JoinColumn(name = "output_index", referencedColumnName = "output_index"),
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"))) JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
override var participants: MutableSet<AbstractParty>? = null, override var participants: MutableSet<AbstractParty>? = null,