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

org.komapper.r2dbc.dsl.runner.R2dbcEntityDeleteBatchRunner.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.DatabaseConfig
import org.komapper.core.DryRunStatement
import org.komapper.core.dsl.context.EntityDeleteContext
import org.komapper.core.dsl.metamodel.EntityMetamodel
import org.komapper.core.dsl.runner.EntityDeleteBatchRunner
import org.komapper.r2dbc.R2dbcDatabaseConfig

internal class R2dbcEntityDeleteBatchRunner>(
    context: EntityDeleteContext,
    private val entities: List,
) :
    R2dbcRunner {
    private val runner: EntityDeleteBatchRunner =
        EntityDeleteBatchRunner(context, entities)

    private val support: R2dbcEntityDeleteRunnerSupport =
        R2dbcEntityDeleteRunnerSupport(context)

    override fun check(config: DatabaseConfig) {
        runner.check(config)
    }

    override suspend fun run(config: R2dbcDatabaseConfig) {
        if (entities.isEmpty()) return
        val batchResults = delete(config)
        postDelete(batchResults.map { it.first })
    }

    private suspend fun delete(config: R2dbcDatabaseConfig): List> {
        val statements = entities.map { runner.buildStatement(config, it) }
        return support.delete(config) { it.executeBatch(statements) }
    }

    private fun postDelete(counts: List) {
        runner.postDelete(counts)
    }

    override fun dryRun(config: DatabaseConfig): DryRunStatement {
        return runner.dryRun(config)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy