Skip to content

Commit

Permalink
Mapper fixes
Browse files Browse the repository at this point in the history
SingleConnection wrapper
publish non osgi jar
  • Loading branch information
laurentvdl committed Nov 27, 2015
1 parent 1b60933 commit b647f59
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ publishing {
}
}

jar {
/*jar {
from(configurations.embedded) {
into('lib')
}
Expand All @@ -81,7 +81,7 @@ jar {
instruction 'Import-Package', '!jet.*,!kotlin.*,*'
instruction 'Bundle-Classpath', ".,${configurations.embedded.files.collect({'lib/' + it.name}).join(',')}"
}
}
}*/

defaultTasks 'build'
sourceSets {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/sqlbuilder/impl/SelectImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class SelectImpl(val backend: Backend) : Select {
}
val con = backend.getSqlConnection()
try {
logger.info(sql)
logger.info("{} ({})", sql, whereParameters)

val sqlConverter = SqlConverter(backend.configuration)

Expand All @@ -265,7 +265,7 @@ class SelectImpl(val backend: Backend) : Select {
val parameterCount = ps.parameterMetaData.parameterCount
whereParameters.withIndex().forEach { pair ->
if (pair.index < parameterCount) {
sqlConverter.setParameter(ps, pair.value, pair.index + 1)
sqlConverter.setParameter(ps, pair.value, pair.index + 1, pair.value.javaClass)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/sqlbuilder/impl/mappers/BooleanMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public class BooleanMapper : BiMapper {
}

override fun handles(targetType: Class<*>): Boolean {
return Boolean::class.java == targetType
return Boolean::class.java == targetType || java.lang.Boolean::class.java == targetType
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/sqlbuilder/impl/mappers/CharMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class CharMapper : BiMapper {
}

override fun handles(targetType: Class<*>): Boolean {
return targetType == Char::class.java
return targetType == Char::class.java || java.lang.Character::class.java == targetType
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/sqlbuilder/impl/mappers/DateMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public class DateMapper : BiMapper {
}

override fun handles(targetType: Class<*>): Boolean {
return Boolean::class.java == targetType
return Date::class.java == targetType
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/sqlbuilder/impl/mappers/IntegerMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class IntegerMapper : BiMapper {
}

override fun handles(targetType: Class<*>): Boolean {
return Int::class.java == targetType
return Int::class.java == targetType || java.lang.Integer::class.java == targetType
}
}
52 changes: 52 additions & 0 deletions src/main/kotlin/sqlbuilder/pool/SingleConnectionDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package sqlbuilder.pool

import java.io.PrintWriter
import java.sql.Connection
import java.util.logging.Logger
import javax.sql.DataSource

/**
* Adapter to use SqlBuilder with an externally provided sql Connection.
* Will not close the target connection.
*/
public class SingleConnectionDataSource(val target: Connection) : DataSource {
override fun getConnection(): Connection? {
return NonClosingConnection(target)
}

override fun getConnection(username: String?, password: String?): Connection? {
return connection
}

override fun setLogWriter(out: PrintWriter?) {
throw UnsupportedOperationException()
}

override fun getLogWriter(): PrintWriter? {
throw UnsupportedOperationException()
}

override fun setLoginTimeout(seconds: Int) {
throw UnsupportedOperationException()
}

override fun getParentLogger(): Logger? {
throw UnsupportedOperationException()
}

override fun getLoginTimeout(): Int {
throw UnsupportedOperationException()
}

override fun isWrapperFor(iface: Class<*>?): Boolean {
throw UnsupportedOperationException()
}

override fun <T : Any?> unwrap(iface: Class<T>?): T {
throw UnsupportedOperationException()
}
}

private class NonClosingConnection(private val connection: Connection) : Connection by connection {
override fun close() {}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/sqlbuilder/pool/TransactionalConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TransactionalConnection(val target: Connection, val datasource: DataSource
override fun invoke(proxy: Any?, method: Method, args: Array<out Any>?): Any? {
return synchronized(datasource) {
lastModified = System.currentTimeMillis()
val methodName = method.getName()
val methodName = method.name
if ("close" == methodName) {
datasource.freeConnection(this)
} else {
Expand Down

0 comments on commit b647f59

Please sign in to comment.