org.babyfish.jimmer.sql.kt.impl.KQueriesImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql-kotlin Show documentation
Show all versions of jimmer-sql-kotlin Show documentation
A revolutionary ORM framework for both java and kotlin
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.query.FilterLevel
import org.babyfish.jimmer.sql.ast.impl.query.MutableRootQueryImpl
import org.babyfish.jimmer.sql.ast.table.AssociationTable
import org.babyfish.jimmer.sql.ast.table.Table
import org.babyfish.jimmer.sql.kt.KQueries
import org.babyfish.jimmer.sql.kt.ast.query.KConfigurableRootQuery
import org.babyfish.jimmer.sql.kt.ast.query.KMutableRootQuery
import org.babyfish.jimmer.sql.kt.ast.query.impl.KMutableRootQueryImpl
import org.babyfish.jimmer.sql.runtime.ExecutionPurpose
import org.babyfish.jimmer.sql.runtime.JSqlClientImplementor
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
internal class KQueriesImpl(
private val sqlClient: JSqlClientImplementor
) : KQueries {
@Suppress("UNCHECKED_CAST")
override fun forEntity(
entityType: KClass,
block: KMutableRootQuery.() -> KConfigurableRootQuery
): KConfigurableRootQuery {
val query = MutableRootQueryImpl>(
sqlClient,
ImmutableType.get(entityType.java),
ExecutionPurpose.QUERY,
FilterLevel.DEFAULT
)
return KMutableRootQueryImpl(
query as MutableRootQueryImpl>
).block()
}
override fun forReference(
prop: KProperty1,
block: KMutableRootQuery>.() -> KConfigurableRootQuery, R>
): KConfigurableRootQuery, R> {
return forAssociation(prop.toImmutableProp(), block)
}
override fun forList(
prop: KProperty1>,
block: KMutableRootQuery>.() -> KConfigurableRootQuery, R>
): KConfigurableRootQuery, R> {
return forAssociation(prop.toImmutableProp(), block)
}
@Suppress("UNCHECKED_CAST")
private fun forAssociation(
immutableProp: ImmutableProp,
block: KMutableRootQuery>.() -> KConfigurableRootQuery, R>
): KConfigurableRootQuery, R> {
val associationType = AssociationType.of(immutableProp)
val query: MutableRootQueryImpl, T, Table>> =
MutableRootQueryImpl(
sqlClient,
associationType,
ExecutionPurpose.QUERY,
FilterLevel.DEFAULT
)
return KMutableRootQueryImpl(
query as MutableRootQueryImpl>>
).block()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy