fun initMetaData()

in dnq/src/main/kotlin/kotlinx/dnq/util/DNQMetaDataUtil.kt [37:99]


fun initMetaData(hierarchy: Map<String, XdHierarchyNode>, entityStore: TransientEntityStoreImpl) {
    val naturalNodes = hierarchy.filter {
        it.value.entityType is XdNaturalEntityType<*>
    }
    val modelMetaData = entityStore.modelMetaData as ModelMetaDataImpl

    naturalNodes.forEach {
        val (entityTypeName, node) = it
        entityStore.registerCustomTypes(node)
        modelMetaData.addEntityMetaData(entityTypeName, node)
    }

    naturalNodes.forEach {
        val (entityTypeName, node) = it
        node.linkProperties.values.forEach { sourceEnd ->
            modelMetaData.addLinkMetaData(hierarchy, entityTypeName, sourceEnd, node)
        }
    }
    val deprecatedNodes = hierarchy.filter {
        it.value.entityType !is XdNaturalEntityType<*>
    }
    XdModel.plugins.flatMap { it.typeExtensions }.forEach { extension ->
        deprecatedNodes.values.forEach { node ->
            node.linkProperties.forEach {
                if (it.value.property == extension) {
                    // will add all data to sub types automatically
                    modelMetaData.addLinkMetaData(hierarchy, node.entityType.entityType, it.value, node)
                }
            }
        }
    }
    entityStore.entityLifecycle = EntityLifecycleImpl()

    /**
     * This explicitly prepares all data structures within model metadata. If we don't invoke
     * preparation here, then it would be performed on demand and very likely simultaneously in two
     * threads: EventMultiplexer and the one executing App.init().
     */
    modelMetaData.prepare()

    // JT-57205: we should be able to start in read-only mode
    if (!entityStore.persistentStore.environment.environmentConfig.envIsReadonly) {
        entityStore.transactional { txn ->
            naturalNodes.values.asSequence().map {
                it.entityType
            }.filterIsInstance<XdEnumEntityType<*>>().forEach {
                it.initEnumValues(txn)
            }

            naturalNodes.values.asSequence().map {
                it.entityType
            }.filterIsInstance<XdNaturalEntityType<*>>().forEach {
                it.initEntityType()
            }

            naturalNodes.values.asSequence().map {
                it.entityType
            }.filterIsInstance<XdSingletonEntityType<*>>().forEach {
                it.get()
            }
        }
    }
}