1 min readJun 11, 2020
I Kotlin you'd write some inline function that encapsulated your domain specific cach/wrap logic. Let's call it "sqlContext". You'll use it in your SQL methods like this:
fun querySomething(param: String) =
sqlContext(param) {
// the actual query
}
This way you avoid writing try/catch in general code, remove boilerplate and implement centralized handling for SQL errors. You can also easily incorporate a context that would close all open results sets, thus avoiding try-with-resource boilerplate on each SQL operation, too.