Basically what I am looking for is a convenient way to wrap a function call given some annotations on the function.
A good starting point:
typealias ExecutionContext = MutableMap<String, Any?>
interface ExecutionTransformer {
@Throws(CommandException::class)
fun transform(src: CommandSource, context: ExecutionContext, next: () -> Unit)
}
My primary usecase: wrapping function calls in Exposed transaction blocks, to reduce redundancy.
import org.jetbrains.exposed.sql.transactions.transaction
annotation class Transactional
object TransactionExecutionTransformer : ExecutionTransformer {
override fun transform(src: CommandSource, context: ExecutionContext, next: () -> Unit) {
transaction {
next()
}
}
}
@Transactional
@Command("mycmd")
fun mycmd(@Source src: CommandSource) {
// we can do things with a table since we're in a transaction
}
Basically what I am looking for is a convenient way to wrap a function call given some annotations on the function.
A good starting point:
My primary usecase: wrapping function calls in Exposed transaction blocks, to reduce redundancy.