org.babyfish.jimmer.sql.kt.impl.KSubQueriesImpl.kt Maven / Gradle / Ivy
Show all versions of jimmer-sql-kotlin Show documentation
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.KSubQueries
import org.babyfish.jimmer.sql.kt.ast.query.KConfigurableSubQuery
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 KSubQueriesImpl(
private val parent: AbstractMutableStatementImpl,
private val parentTable: KNonNullTableEx? = null
) : KSubQueries
{
override fun > forEntity(
entityType: KClass,
block: KMutableSubQuery.() -> SQ
): SQ {
val immutableType = ImmutableType.get(entityType.java)
val subQuery = MutableSubQueryImpl(parent, immutableType)
return KMutableSubQueryImpl
(subQuery, parentTable).block()
}
override fun > forReference(
prop: KProperty1,
block: KMutableSubQuery
>.() -> SQ
): SQ {
return forAssociation(prop.toImmutableProp(), block)
}
override fun > forList(
prop: KProperty1>,
block: KMutableSubQuery
>.() -> SQ
): SQ {
return forAssociation(prop.toImmutableProp(), block)
}
private fun > forAssociation(
immutableProp: ImmutableProp,
block: KMutableSubQuery
>.() -> SQ
): SQ {
val associationType = AssociationType.of(immutableProp)
val subQuery = MutableSubQueryImpl(parent, associationType)
return KMutableSubQueryImpl
>(subQuery, parentTable).block()
}
}