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

com.firefly.kotlin.ext.db.AsyncTransactionalManager.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.kotlin.ext.db

import com.firefly.db.SQLConnection
import kotlinx.coroutines.experimental.future.await
import java.util.concurrent.TimeUnit

/**
 * @author Pengtao Qiu
 */
interface AsyncTransactionalManager {

    suspend fun getConnection(time: Long = 10000L, unit: TimeUnit = TimeUnit.MILLISECONDS): SQLConnection

    suspend fun getCurrentConnection(time: Long = 10000L, unit: TimeUnit = TimeUnit.MILLISECONDS): SQLConnection?

    suspend fun  execSQL(
        time: Long = 10000L,
        unit: TimeUnit = TimeUnit.MILLISECONDS,
        handler: suspend (conn: SQLConnection) -> T
                           ): T = getConnection().execSQL(time, unit, handler)

    suspend fun beginTransaction(): Boolean = getConnection().beginTransaction().await()

    suspend fun rollbackAndEndTransaction() {
        getConnection().rollbackAndEndTransaction().await()
    }

    suspend fun commitAndEndTransaction() {
        getConnection().commitAndEndTransaction().await()
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy