override fun getValue()

in dnq/src/main/kotlin/kotlinx/dnq/XdEnumEntityType.kt [61:84]


                override fun getValue(thisRef: XdEntityType<XD>, property: KProperty<*>): XD {
                    val entityType = this@XdEnumEntityType
                    val transientEntityStore = entityType.entityStore
                    val entityTypeName = entityType.entityType
                    val enumFieldName = enumConst.enumFieldName
                    val result = transientEntityStore.getCachedEnumValue(entityTypeName, enumFieldName) ?: run {
                        val currentPersistentSession = transientEntityStore.persistentStore.currentTransaction
                                ?: throw IllegalStateException("EntityStore: current transaction is not set")

                        val it = currentPersistentSession.find(entityTypeName, XdEnumEntity.ENUM_CONST_NAME_FIELD, enumFieldName).iterator()
                        if (!it.hasNext()) {
                            throw IllegalStateException("Instance not created: $entityTypeName.$enumFieldName")
                        }
                        val result = it.next()
                        if (transientEntityStore is TransientEntityStoreImpl) {
                            transientEntityStore.setCachedEnumValue(entityTypeName, enumFieldName, result)
                        }
                        result
                    }

                    val threadSession = transientEntityStore.threadSession
                            ?: throw IllegalStateException("EntityStore: current transaction is not set")
                    return entityType.wrap(threadSession.newEntity(result))
                }