From e1ad8c6ff629903e0ae3a4c6e5959922c540b5da Mon Sep 17 00:00:00 2001 From: vince Date: Sun, 19 Jan 2025 23:18:50 +0800 Subject: [PATCH] fix warning --- .../kotlin/org/ktorm/database/CachedRowSet.kt | 22 ++++++++++--------- .../org/ktorm/support/sqlite/QueryTest.kt | 1 - 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ktorm-core/src/main/kotlin/org/ktorm/database/CachedRowSet.kt b/ktorm-core/src/main/kotlin/org/ktorm/database/CachedRowSet.kt index 781c8748..6992c585 100644 --- a/ktorm-core/src/main/kotlin/org/ktorm/database/CachedRowSet.kt +++ b/ktorm-core/src/main/kotlin/org/ktorm/database/CachedRowSet.kt @@ -23,11 +23,13 @@ import java.math.BigInteger import java.net.URI import java.net.URL import java.sql.* +import java.sql.Array as SQLArray import java.sql.Date import java.sql.ResultSet.* import java.time.* import java.util.* import javax.sql.rowset.serial.* +import kotlin.use /** * Special implementation of [ResultSet], used to hold the query results for Ktorm. @@ -245,7 +247,7 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { is SQLData -> SerialStruct(obj, _typeMap) is Blob -> try { MemoryBlob(obj) } finally { obj.free() } is Clob -> try { MemoryClob(obj) } finally { obj.free() } - is java.sql.Array -> try { MemoryArray(obj, _typeMap) } finally { obj.free() } + is SQLArray -> try { MemoryArray(obj, _typeMap) } finally { obj.free() } else -> obj } } @@ -276,9 +278,9 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { } private class MemoryArray( - array: java.sql.Array, + array: SQLArray, typeMap: Map>? - ) : java.sql.Array by if (typeMap != null) SerialArray(array, typeMap) else SerialArray(array) { + ) : SQLArray by if (typeMap != null) SerialArray(array, typeMap) else SerialArray(array) { override fun free() { // no-op @@ -396,7 +398,7 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { override fun getBytes(columnIndex: Int): ByteArray? { return when (val value = getColumnValue(columnIndex)) { null -> null - is ByteArray -> Arrays.copyOf(value, value.size) + is ByteArray -> value.copyOf() is Blob -> value.binaryStream.use { it.readBytes() } else -> throw SQLException("Cannot convert ${value.javaClass.name} value to byte[].") } @@ -1076,10 +1078,10 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { } } - override fun getArray(columnIndex: Int): java.sql.Array? { + override fun getArray(columnIndex: Int): SQLArray? { return when (val value = getColumnValue(columnIndex)) { null -> null - is java.sql.Array -> value + is SQLArray -> value else -> throw SQLException("Cannot convert ${value.javaClass.name} value to Array.") } } @@ -1100,7 +1102,7 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { return getClob(findColumn(columnLabel)) } - override fun getArray(columnLabel: String): java.sql.Array? { + override fun getArray(columnLabel: String): SQLArray? { return getArray(findColumn(columnLabel)) } @@ -1195,12 +1197,12 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { } @Deprecated("The result set is not updatable.", level = DeprecationLevel.ERROR) - override fun updateArray(columnIndex: Int, x: java.sql.Array?): Nothing { + override fun updateArray(columnIndex: Int, x: SQLArray?): Nothing { throw SQLFeatureNotSupportedException("The result set is not updatable.") } @Deprecated("The result set is not updatable.", level = DeprecationLevel.ERROR) - override fun updateArray(columnLabel: String?, x: java.sql.Array?): Nothing { + override fun updateArray(columnLabel: String?, x: SQLArray?): Nothing { throw SQLFeatureNotSupportedException("The result set is not updatable.") } @@ -1460,7 +1462,7 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet { Instant::class -> getInstant(columnIndex) Blob::class -> getBlob(columnIndex) Clob::class -> getClob(columnIndex) - java.sql.Array::class -> getArray(columnIndex) + SQLArray::class -> getArray(columnIndex) Ref::class -> getRef(columnIndex) URL::class -> getURL(columnIndex) else -> getObject(columnIndex) diff --git a/ktorm-support-sqlite/src/test/kotlin/org/ktorm/support/sqlite/QueryTest.kt b/ktorm-support-sqlite/src/test/kotlin/org/ktorm/support/sqlite/QueryTest.kt index 66b9fee8..e613e1bc 100644 --- a/ktorm-support-sqlite/src/test/kotlin/org/ktorm/support/sqlite/QueryTest.kt +++ b/ktorm-support-sqlite/src/test/kotlin/org/ktorm/support/sqlite/QueryTest.kt @@ -1,7 +1,6 @@ package org.ktorm.support.sqlite import org.junit.Test -import org.ktorm.database.use import org.ktorm.dsl.* import org.ktorm.schema.TextSqlType import java.sql.Clob