fun toXdHandlingAbstraction()

in dnq/src/main/kotlin/kotlinx/dnq/query/FakeTransientEntities.kt [288:317]


    fun <T : XdEntity> toXdHandlingAbstraction(): T {
        val node = XdModel.getOrThrow(type)
        val entityType = node.entityType
        if (entityType is XdNaturalWrapper) {
            @Suppress("UNCHECKED_CAST")
            return entityType.naturalWrap(this) as T
        }
        val entityConstructor = node.entityConstructor
        // this is abstract type. lets create fake implementation.
        if (entityConstructor == null) {
            val constructor = factoryCache.getOrPut(type) {
                val factory = ProxyFactory().apply {
                    superclass = node.entityType.enclosingEntityClass
                    setFilter({ method -> Modifier.isAbstract(method.modifiers) })
                }
                val c = factory.createClass()
                val cons = c.getConstructor(Entity::class.java)

                val ctor = { entity: Entity ->
                    cons.newInstance(entity)
                }
                ctor

            }
            @Suppress("UNCHECKED_CAST")
            return constructor(this) as T
        }
        @Suppress("UNCHECKED_CAST")
        return entityConstructor(this) as T
    }