Handle errors while querying notes
This commit is contained in:
@@ -6,14 +6,15 @@ import java.sql.PreparedStatement
|
||||
import java.sql.ResultSet
|
||||
import java.sql.Types
|
||||
import java.util.*
|
||||
import java.util.UUID as JavaUUID
|
||||
|
||||
class UuidBinarySqlType : SqlType<java.util.UUID>(Types.BINARY, typeName = "uuidBinary") {
|
||||
override fun doGetResult(rs: ResultSet, index: Int): UUID? {
|
||||
class UuidBinarySqlType : SqlType<JavaUUID>(Types.BINARY, typeName = "uuidBinary") {
|
||||
override fun doGetResult(rs: ResultSet, index: Int): JavaUUID? {
|
||||
val value = rs.getBytes(index) ?: return null
|
||||
return ByteBuffer.wrap(value).let { b -> UUID(b.long, b.long) }
|
||||
return ByteBuffer.wrap(value).let { b -> JavaUUID(b.long, b.long) }
|
||||
}
|
||||
|
||||
override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: UUID) {
|
||||
override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: JavaUUID) {
|
||||
val bytes = ByteBuffer.allocate(16)
|
||||
.putLong(parameter.mostSignificantBits)
|
||||
.putLong(parameter.leastSignificantBits)
|
||||
@@ -22,6 +23,6 @@ class UuidBinarySqlType : SqlType<java.util.UUID>(Types.BINARY, typeName = "uuid
|
||||
}
|
||||
}
|
||||
|
||||
fun <E : Any> BaseTable<E>.uuidBinary(name: String): BaseTable<E>.ColumnRegistration<java.util.UUID> {
|
||||
fun <E : Any> BaseTable<E>.uuidBinary(name: String): BaseTable<E>.ColumnRegistration<JavaUUID> {
|
||||
return registerColumn(name, UuidBinarySqlType())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user