Added test for obsolete bug and removed workaround in code.

This commit is contained in:
Evgeny Gerashchenko
2015-04-07 21:10:42 +03:00
parent 015da2f8ca
commit eeeb741d42
6 changed files with 71 additions and 8 deletions
@@ -37,7 +37,7 @@ fun <T> Connection.use(block : (Connection) -> T) : T {
fun <T> Connection.statement(block: (Statement) -> T): T {
val statement = createStatement()
if (statement != null) {
return statement.useSql(block)
return statement.use(block)
} else {
throw IllegalStateException("No Statement returned from $this")
}
@@ -7,7 +7,7 @@ import kotlin.template.StringTemplate
/**
* Processes a connection from the pool using the given function block
*/
fun <T> DataSource.useDataSource(block : (Connection) -> T): T { // TODO rename to "use" when KT-2493 is fixed
fun <T> DataSource.use(block : (Connection) -> T): T {
val connection = getConnection()
if (connection != null) {
try {
@@ -24,33 +24,33 @@ fun <T> DataSource.useDataSource(block : (Connection) -> T): T { // TODO rename
* Helper method to process a statement on this collection
*/
fun <T> DataSource.statement(block: (Statement) -> T): T {
return useDataSource{ it.statement(block) }
return use { it.statement(block) }
}
/**
* Perform an SQL update on the connection
*/
fun DataSource.update(sql: String): Int {
return useDataSource{ it.update(sql) }
return use { it.update(sql) }
}
/**
* Perform a query on the connection and processes the result set with a function
*/
fun <T> DataSource.query(sql: String, block: (ResultSet) -> T): T {
return useDataSource{ it.query(sql, block) }
return use { it.query(sql, block) }
}
/**
* Performs the update using the given SQL using a [[StringTemplate]]
*/
fun DataSource.update(template : StringTemplate) : Int {
return useDataSource{ it.update(template) }
return use { it.update(template) }
}
/**
* Perform a query on the connection using the SQL from the [[StringTemplate]] and processes the result set with a function
*/
fun <T> DataSource.query(template : StringTemplate, resultBlock : (ResultSet) -> T) : T {
return useDataSource{ it.query(template, resultBlock) }
return use { it.query(template, resultBlock) }
}
@@ -8,7 +8,7 @@ import java.sql.Statement
/**
* Uses the statement with the given block then closes the statement
*/
fun <T, S : Statement> S.useSql(block : (S) -> T) : T { // TODO rename to "use" when KT-2493 is fixed
fun <T, S : Statement> S.use(block : (S) -> T) : T {
try {
return block(this)
} finally {