From b93f12d4138e81a69980a911e1c126a92d0782fe Mon Sep 17 00:00:00 2001 From: sollecitom Date: Wed, 28 Mar 2018 10:58:41 +0100 Subject: [PATCH] Finished porting change to make JPA entities non-final and serializable. --- .../persistence/entity/CertificateRevocationListEntity.kt | 3 ++- .../entity/CertificateRevocationRequestEntity.kt | 3 ++- .../persistence/entity/CertificateSigningRequestEntity.kt | 7 ++++--- .../common/persistence/entity/NetworkMapEntity.kt | 3 ++- .../common/persistence/entity/NetworkParametersEntity.kt | 8 +++++--- .../common/persistence/entity/NodeInfoEntity.kt | 5 +++-- .../common/persistence/entity/ParametersUpdateEntity.kt | 3 ++- .../net/corda/node/services/persistence/RunOnceService.kt | 3 ++- .../corda/node/services/schema/NodeSchemaServiceTest.kt | 2 +- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationListEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationListEntity.kt index ef84d3fcf7..7a184b3fdc 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationListEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationListEntity.kt @@ -1,6 +1,7 @@ package com.r3.corda.networkmanage.common.persistence.entity import com.r3.corda.networkmanage.common.persistence.CrlIssuer +import java.io.Serializable import java.security.cert.X509CRL import java.time.Instant import javax.persistence.* @@ -26,4 +27,4 @@ class CertificateRevocationListEntity( @Column(name = "modified_at", nullable = false) val modifiedAt: Instant = Instant.now() -) \ No newline at end of file +) : Serializable \ No newline at end of file diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationRequestEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationRequestEntity.kt index c28d10c767..410bde5a42 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationRequestEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateRevocationRequestEntity.kt @@ -3,6 +3,7 @@ package com.r3.corda.networkmanage.common.persistence.entity import com.r3.corda.networkmanage.common.persistence.RequestStatus import net.corda.core.identity.CordaX500Name import org.hibernate.envers.Audited +import java.io.Serializable import java.math.BigInteger import java.security.cert.CRLReason import java.time.Instant @@ -57,4 +58,4 @@ data class CertificateRevocationRequestEntity( @Audited @Column(name = "remark", length = 256) val remark: String? = null -) \ No newline at end of file +) : Serializable \ No newline at end of file diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateSigningRequestEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateSigningRequestEntity.kt index 7ba09df012..96661f4594 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateSigningRequestEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/CertificateSigningRequestEntity.kt @@ -19,6 +19,7 @@ import net.corda.core.identity.CordaX500Name import net.corda.nodeapi.internal.crypto.x509Certificates import org.bouncycastle.pkcs.PKCS10CertificationRequest import org.hibernate.envers.Audited +import java.io.Serializable import java.math.BigInteger import java.security.cert.CertPath import java.time.Instant @@ -69,7 +70,7 @@ data class CertificateSigningRequestEntity( @ManyToOne @JoinColumn(name = "private_network", foreignKey = ForeignKey(name = "FK__CSR__PN")) val privateNetwork: PrivateNetworkEntity? = null -) { +) : Serializable { fun toCertificateSigningRequest(): CertificateSigningRequest { return CertificateSigningRequest( requestId = requestId, @@ -108,7 +109,7 @@ data class CertificateDataEntity( @Column(name = "cert_serial_number", unique = true, nullable = false, columnDefinition = "NUMERIC(28)") val certificateSerialNumber: BigInteger -) { +) : Serializable { fun toCertificateData(): CertificateData = CertificateData(certificateStatus, certPath) val legalName: CordaX500Name get() { @@ -125,4 +126,4 @@ data class PrivateNetworkEntity( @Column(name = "name", length = 255, nullable = false) val networkName: String -) \ No newline at end of file +) : Serializable \ No newline at end of file diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkMapEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkMapEntity.kt index c080d33e69..86dd4b73de 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkMapEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkMapEntity.kt @@ -14,6 +14,7 @@ import net.corda.core.internal.DigitalSignatureWithCert import net.corda.core.serialization.serialize import net.corda.nodeapi.internal.network.NetworkMap import net.corda.nodeapi.internal.network.SignedNetworkMap +import java.io.Serializable import java.security.cert.X509Certificate import javax.persistence.* @@ -41,7 +42,7 @@ class NetworkMapEntity( @ManyToOne(optional = false, fetch = FetchType.EAGER) @JoinColumn(name = "network_parameters", nullable = false) val networkParameters: NetworkParametersEntity -) { +) : Serializable { fun toSignedNetworkMap(): SignedNetworkMap { return SignedNetworkMap(networkMap.serialize(), DigitalSignatureWithCert(certificate, signature)) } diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkParametersEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkParametersEntity.kt index 4fe42149c1..3c8424e95f 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkParametersEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NetworkParametersEntity.kt @@ -14,6 +14,7 @@ import net.corda.core.internal.DigitalSignatureWithCert import net.corda.core.node.NetworkParameters import net.corda.core.serialization.serialize import net.corda.nodeapi.internal.network.SignedNetworkParameters +import java.io.Serializable import java.security.cert.X509Certificate import java.time.Instant import javax.persistence.* @@ -43,12 +44,13 @@ class NetworkParametersEntity( @Column(name = "cert") @Convert(converter = X509CertificateConverter::class) val certificate: X509Certificate? -) { +) : Serializable { val isSigned: Boolean get() = certificate != null && signature != null fun toSignedNetworkParameters(): SignedNetworkParameters { - if (certificate == null || signature == null) throw IllegalStateException("Network parameters entity is not signed: $hash") - return SignedNetworkParameters(networkParameters.serialize(), DigitalSignatureWithCert(certificate, signature)) + val cert = certificate ?: throw IllegalStateException("Network parameters entity is not signed: $hash") + val sign = signature ?: throw IllegalStateException("Network parameters entity is not signed: $hash") + return SignedNetworkParameters(networkParameters.serialize(), DigitalSignatureWithCert(cert, sign)) } fun copy(parametersHash: String = this.hash, diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NodeInfoEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NodeInfoEntity.kt index ebea041651..b28f9eda00 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NodeInfoEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/NodeInfoEntity.kt @@ -11,6 +11,7 @@ package com.r3.corda.networkmanage.common.persistence.entity import net.corda.nodeapi.internal.SignedNodeInfo +import java.io.Serializable import java.time.Instant import javax.persistence.* @@ -40,7 +41,7 @@ data class NodeInfoEntity( @Column(name = "published_at", nullable = false) val publishedAt: Instant = Instant.now(), - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "accepted_params_update") val acceptedParametersUpdate: ParametersUpdateEntity? -) +) : Serializable diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/ParametersUpdateEntity.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/ParametersUpdateEntity.kt index 97e7c9385d..efdefe897b 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/ParametersUpdateEntity.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/common/persistence/entity/ParametersUpdateEntity.kt @@ -2,6 +2,7 @@ package com.r3.corda.networkmanage.common.persistence.entity import net.corda.core.crypto.SecureHash import net.corda.nodeapi.internal.network.ParametersUpdate +import java.io.Serializable import java.time.Instant import javax.persistence.* @@ -26,7 +27,7 @@ data class ParametersUpdateEntity( @Column(name = "status", length = 16, nullable = false, columnDefinition = "NVARCHAR(16)") @Enumerated(EnumType.STRING) val status: UpdateStatus = UpdateStatus.NEW -) { +) : Serializable { fun toParametersUpdate(): ParametersUpdate { return ParametersUpdate(SecureHash.parse(networkParameters.hash), description, updateDeadline) } diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/RunOnceService.kt b/node/src/main/kotlin/net/corda/node/services/persistence/RunOnceService.kt index 26d9b9e3fe..550d3701a0 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/RunOnceService.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/RunOnceService.kt @@ -16,6 +16,7 @@ import net.corda.node.utilities.AffinityExecutor import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import org.hibernate.Session +import java.io.Serializable import java.time.Duration import java.time.LocalDateTime import java.time.temporal.ChronoField @@ -57,7 +58,7 @@ class RunOnceService(private val database: CordaPersistence, private val machine @Entity @Table(name = TABLE) - class MutualExclusion(machineNameInit: String, pidInit: String, timeStampInit: LocalDateTime, versionInit: Long = 0) { + class MutualExclusion(machineNameInit: String, pidInit: String, timeStampInit: LocalDateTime, versionInit: Long = 0) : Serializable { @Column(name = ID, insertable = false, updatable = false) @Id val id: Char = 'X' diff --git a/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt index a7d3433f57..eea4fe8edc 100644 --- a/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt @@ -155,7 +155,7 @@ object TestSchema : MappedSchema(SchemaFamily::class.java, 1, setOf(Parent::clas @Suppress("unused") @Entity @Table(name = "children") - class Child { + class Child : Serializable { @Id @GeneratedValue @Column(name = "child_id", unique = true, nullable = false)