All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.babyfish.jimmer.sql.kt.impl.KWildSubQueriesImpl.kt Maven / Gradle / Ivy

There is a newer version: 0.9.35
Show newest version
package org.babyfish.jimmer.sql.kt.impl

import org.babyfish.jimmer.kt.toImmutableProp
import org.babyfish.jimmer.meta.ImmutableProp
import org.babyfish.jimmer.meta.ImmutableType
import org.babyfish.jimmer.sql.association.Association
import org.babyfish.jimmer.sql.association.meta.AssociationType
import org.babyfish.jimmer.sql.ast.impl.AbstractMutableStatementImpl
import org.babyfish.jimmer.sql.ast.impl.query.MutableSubQueryImpl
import org.babyfish.jimmer.sql.kt.KWildSubQueries
import org.babyfish.jimmer.sql.kt.ast.query.KMutableSubQuery
import org.babyfish.jimmer.sql.kt.ast.query.impl.KMutableSubQueryImpl
import org.babyfish.jimmer.sql.kt.ast.table.KNonNullTableEx
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1

internal class KWildSubQueriesImpl(
    private val parent: AbstractMutableStatementImpl,
    private val parentTable: KNonNullTableEx

? = null ) : KWildSubQueries

{ override fun forEntity( entityType: KClass, block: KMutableSubQuery.() -> Unit ): KMutableSubQuery { val immutableType = ImmutableType.get(entityType.java) val subQuery = MutableSubQueryImpl(parent, immutableType) val wrappedQuery = KMutableSubQueryImpl(subQuery, parentTable) wrappedQuery.block() return wrappedQuery } override fun forReference( prop: KProperty1, block: KMutableSubQuery>.() -> Unit ): KMutableSubQuery> { return forAssociation(prop.toImmutableProp(), block) } override fun forList( prop: KProperty1>, block: KMutableSubQuery>.() -> Unit ): KMutableSubQuery> { return forAssociation(prop.toImmutableProp(), block) } private fun forAssociation( immutableProp: ImmutableProp, block: KMutableSubQuery>.() -> Unit ): KMutableSubQuery> { val associationType = AssociationType.of(immutableProp) val subQuery = MutableSubQueryImpl(parent, associationType) val wrappedQuery = KMutableSubQueryImpl>(subQuery, parentTable) wrappedQuery.block() return wrappedQuery } }