I'm trying to gain access to the current JDBI transaction handle
in my interface method, the purpose of this is to avoid passing the handle
as an argument to the interface's methods, thus keeping the interface free of any implementation details. The following example demonstrates what the intended use case is.
I have a UserApplicationService
managing the transaction being used
class UserApplicationService(val jdbi: Jdbi, val userRepository: UserRepository) {
fun changeUserName() {
jdbi.useTransaction<Exception> {
userRepository.updateName("peter pan")
}
}
}
I have a UserRepository
interface
interface UserRepository {
fun updateName(name: String)
}
I have a PostgresUserRepository
implementation of the interface
class PostgresUserRepository: UserRepository {
override fun updateName(name: String) {
val handle: Handle = getHandle() // some method to get the handle of the transaction, this is what I need help solving
handle.execute("...") // set new name of user using the handle
}
}
Any suggestions on how to solve this would be greatly appreciated.