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

org.komapper.r2dbc.dsl.runner.R2dbcRelationInsertValuesSupport.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
package org.komapper.r2dbc.dsl.runner

import org.komapper.core.dsl.context.RelationInsertValuesContext
import org.komapper.core.dsl.metamodel.EntityMetamodel
import org.komapper.core.dsl.metamodel.IdGenerator
import org.komapper.r2dbc.R2dbcDatabaseConfig

internal class R2dbcRelationInsertValuesSupport>(
    private val context: RelationInsertValuesContext,
) {

    suspend fun  handleIdGenerator(config: R2dbcDatabaseConfig, callback: Callback): R {
        return when (val idGenerator = context.target.idGenerator()) {
            is IdGenerator.AutoIncrement -> {
                callback.autoIncrement(idGenerator)
            }

            is IdGenerator.Sequence -> {
                if (context.target.disableSequenceAssignment() || context.options.disableSequenceAssignment) {
                    callback.other()
                } else {
                    val id = idGenerator.execute(config, context.options)
                    callback.sequence(idGenerator, id)
                }
            }

            else -> {
                callback.other()
            }
        }
    }

    internal interface Callback {
        suspend fun autoIncrement(idGenerator: IdGenerator.AutoIncrement): R
        suspend fun sequence(idGenerator: IdGenerator.Sequence, id: ID): R
        suspend fun other(): R
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy