mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Remove unused schema options (#5885)
This commit is contained in:
parent
b72f71e7ac
commit
1380779a9c
@ -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<MappedSchema>, metricRegistry: MetricRegistry? = null, cordappLoader: CordappLoader? = null, currentDir: Path? = null, ourName: CordaX500Name) {
|
||||
|
@ -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<MappedSchema, SchemaOptions>
|
||||
val schemas: Set<MappedSchema>
|
||||
|
||||
/**
|
||||
* Given a state, select schemas to map it to that are supported by [generateMappedObject] and that are configured
|
||||
|
@ -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<MappedSchema> = emptySet()
|
||||
}
|
||||
|
||||
// Required schemas are those used by internal Corda services
|
||||
private val requiredSchemas: Map<MappedSchema, SchemaService.SchemaOptions> =
|
||||
mapOf(Pair(CommonSchemaV1, SchemaOptions()),
|
||||
Pair(VaultSchemaV1, SchemaOptions()),
|
||||
Pair(NodeInfoSchemaV1, SchemaOptions()),
|
||||
Pair(NodeCoreV1, SchemaOptions()))
|
||||
private val requiredSchemas: Set<MappedSchema> =
|
||||
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<MappedSchema, SchemaService.SchemaOptions> = requiredSchemas + extraSchemas.associateBy({ it }, { SchemaOptions() })
|
||||
override val schemas: Set<MappedSchema> = requiredSchemas + extraSchemas
|
||||
|
||||
// Currently returns all schemas supported by the state, with no filtering or enrichment.
|
||||
override fun selectSchemas(state: ContractState): Iterable<MappedSchema> {
|
||||
@ -95,7 +95,7 @@ class NodeSchemaService(private val extraSchemas: Set<MappedSchema> = emptySet()
|
||||
|
||||
/** Returns list of [MappedSchemaValidator.SchemaCrossReferenceReport] violations. */
|
||||
fun mappedSchemasWarnings(): List<MappedSchemaValidator.SchemaCrossReferenceReport> =
|
||||
schemaOptions.keys.map { schema -> crossReferencesToOtherMappedSchema(schema) }.flatMap { it.toList() }
|
||||
schemas.map { schema -> crossReferencesToOtherMappedSchema(schema) }.flatMap { it.toList() }
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<String> {
|
||||
// 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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PersistentStateServiceTests {
|
||||
fun `test child objects are persisted`() {
|
||||
val testSchema = TestSchema
|
||||
val schemaService = object : SchemaService {
|
||||
override val schemaOptions: Map<MappedSchema, SchemaService.SchemaOptions> = mapOf(testSchema to SchemaService.SchemaOptions())
|
||||
override val schemas: Set<MappedSchema> = setOf(testSchema)
|
||||
|
||||
override fun selectSchemas(state: ContractState): Iterable<MappedSchema> = setOf(testSchema)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user