diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index d8f25c1340..84530a3c15 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -1248,13 +1248,13 @@ fun createCordaPersistence(databaseConfig: DatabaseConfig, val jdbcUrl = hikariProperties.getProperty("dataSource.url", "") return CordaPersistence( databaseConfig, - schemaService.schemaOptions.keys, + schemaService.schemas, jdbcUrl, cacheFactory, attributeConverters, customClassLoader, errorHandler = { t -> FlowStateMachineImpl.currentStateMachine()?.scheduleEvent(Event.Error(t)) - }) + }) } fun CordaPersistence.startHikariPool(hikariProperties: Properties, databaseConfig: DatabaseConfig, schemas: Set, metricRegistry: MetricRegistry? = null, cordappLoader: CordappLoader? = null, currentDir: Path? = null, ourName: CordaX500Name) { diff --git a/node/src/main/kotlin/net/corda/node/services/api/SchemaService.kt b/node/src/main/kotlin/net/corda/node/services/api/SchemaService.kt index 4a4d815708..a33ec7bad6 100644 --- a/node/src/main/kotlin/net/corda/node/services/api/SchemaService.kt +++ b/node/src/main/kotlin/net/corda/node/services/api/SchemaService.kt @@ -10,14 +10,9 @@ import net.corda.core.schemas.PersistentState */ interface SchemaService { /** - * Represents any options configured on the node for a schema. + * All available schemas in this node */ - data class SchemaOptions(val databaseSchema: String? = null, val tablePrefix: String? = null) - - /** - * Options configured for this node's schemas. A missing entry for a schema implies all properties are null. - */ - val schemaOptions: Map + val schemas: Set /** * Given a state, select schemas to map it to that are supported by [generateMappedObject] and that are configured diff --git a/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt b/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt index 34343e8680..a834dbb3ab 100644 --- a/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt +++ b/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt @@ -10,7 +10,6 @@ import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.node.internal.DBNetworkParametersStorage import net.corda.node.internal.schemas.NodeInfoSchemaV1 import net.corda.node.services.api.SchemaService -import net.corda.node.services.api.SchemaService.SchemaOptions import net.corda.node.services.events.NodeSchedulerService import net.corda.node.services.identity.PersistentIdentityService import net.corda.node.services.keys.BasicHSMKeyManagementService @@ -52,20 +51,21 @@ class NodeSchemaService(private val extraSchemas: Set = emptySet() } // Required schemas are those used by internal Corda services - private val requiredSchemas: Map = - mapOf(Pair(CommonSchemaV1, SchemaOptions()), - Pair(VaultSchemaV1, SchemaOptions()), - Pair(NodeInfoSchemaV1, SchemaOptions()), - Pair(NodeCoreV1, SchemaOptions())) + private val requiredSchemas: Set = + setOf(CommonSchemaV1, + VaultSchemaV1, + NodeInfoSchemaV1, + NodeCoreV1) - fun internalSchemas() = requiredSchemas.keys + extraSchemas.filter { schema -> // when mapped schemas from the finance module are present, they are considered as internal ones + fun internalSchemas() = requiredSchemas + extraSchemas.filter { schema -> + // when mapped schemas from the finance module are present, they are considered as internal ones schema::class.qualifiedName == "net.corda.finance.schemas.CashSchemaV1" || schema::class.qualifiedName == "net.corda.finance.schemas.CommercialPaperSchemaV1" || schema::class.qualifiedName == "net.corda.node.services.transactions.NodeNotarySchemaV1" || schema::class.qualifiedName?.startsWith("net.corda.notary.") ?: false } - override val schemaOptions: Map = requiredSchemas + extraSchemas.associateBy({ it }, { SchemaOptions() }) + override val schemas: Set = requiredSchemas + extraSchemas // Currently returns all schemas supported by the state, with no filtering or enrichment. override fun selectSchemas(state: ContractState): Iterable { @@ -95,7 +95,7 @@ class NodeSchemaService(private val extraSchemas: Set = emptySet() /** Returns list of [MappedSchemaValidator.SchemaCrossReferenceReport] violations. */ fun mappedSchemasWarnings(): List = - schemaOptions.keys.map { schema -> crossReferencesToOtherMappedSchema(schema) }.flatMap { it.toList() } + schemas.map { schema -> crossReferencesToOtherMappedSchema(schema) }.flatMap { it.toList() } } diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DbMapDeadlockTest.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DbMapDeadlockTest.kt index dc0fc48fef..cf10667496 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DbMapDeadlockTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DbMapDeadlockTest.kt @@ -94,7 +94,7 @@ class DbMapDeadlockTest { val dbConfig = DatabaseConfig(initialiseSchema = true, transactionIsolationLevel = TransactionIsolationLevel.READ_COMMITTED) val schemaService = NodeSchemaService(extraSchemas = setOf(LockDbSchemaV2)) createCordaPersistence(dbConfig, { null }, { null }, schemaService, hikariProperties, cacheFactory, null).apply { - startHikariPool(hikariProperties, dbConfig, schemaService.schemaOptions.keys, ourName = TestIdentity(ALICE_NAME, 70).name) + startHikariPool(hikariProperties, dbConfig, schemaService.schemas, ourName = TestIdentity(ALICE_NAME, 70).name) }.use { persistence -> // First clean up any remains from previous test runs 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 d8b24e6a60..fece373e9e 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 @@ -34,7 +34,7 @@ class NodeSchemaServiceTest { val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(DummyLinearStateSchemaV1::class.packageName)) val mockNode = mockNet.createNode() val schemaService = mockNode.services.schemaService - assertTrue(schemaService.schemaOptions.containsKey(DummyLinearStateSchemaV1)) + assertTrue(schemaService.schemas.contains(DummyLinearStateSchemaV1)) mockNet.stopNodes() } @@ -45,7 +45,7 @@ class NodeSchemaServiceTest { val schemaService = mockNode.services.schemaService // check against NodeCore schemas - assertTrue(schemaService.schemaOptions.containsKey(NodeCoreV1)) + assertTrue(schemaService.schemas.contains(NodeCoreV1)) mockNet.stopNodes() } @@ -56,7 +56,7 @@ class NodeSchemaServiceTest { val schemaService = mockNotaryNode.services.schemaService // check against NodeCore Schema - assertTrue(schemaService.schemaOptions.containsKey(NodeCoreV1)) + assertTrue(schemaService.schemas.contains(NodeCoreV1)) mockNet.stopNodes() } @@ -112,7 +112,7 @@ class NodeSchemaServiceTest { @Suspendable override fun call(): List { // returning MappedSchema's as String'ified family names to avoid whitelist serialization errors - return (this.serviceHub as ServiceHubInternal).schemaService.schemaOptions.keys.map { it.name } + return (this.serviceHub as ServiceHubInternal).schemaService.schemas.map { it.name } } } diff --git a/node/src/test/kotlin/net/corda/node/services/schema/PersistentStateServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/schema/PersistentStateServiceTests.kt index d2b13e2a75..a77c9ca8ed 100644 --- a/node/src/test/kotlin/net/corda/node/services/schema/PersistentStateServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/schema/PersistentStateServiceTests.kt @@ -50,7 +50,7 @@ class PersistentStateServiceTests { fun `test child objects are persisted`() { val testSchema = TestSchema val schemaService = object : SchemaService { - override val schemaOptions: Map = mapOf(testSchema to SchemaService.SchemaOptions()) + override val schemas: Set = setOf(testSchema) override fun selectSchemas(state: ContractState): Iterable = setOf(testSchema)