no message
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile QuickBaseTypeHandler.kt
|
||||
* LastUpdate 2026-01-08 07:59:47
|
||||
* LastUpdate 2026-01-28 10:01:35
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -53,7 +53,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
): T
|
||||
): T?
|
||||
|
||||
/**
|
||||
* 抽象方法,用于将 Java 类型 T 设置到 PreparedStatement 中。
|
||||
@@ -65,7 +65,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
abstract fun setValue(ps: PreparedStatement, index: Int, parameter: T, jdbcType: JdbcType?)
|
||||
abstract fun setValue(ps: PreparedStatement, index: Int, parameter: T?, jdbcType: JdbcType?)
|
||||
|
||||
/**
|
||||
* 实现 BaseTypeHandler 的 setNonNullParameter 方法,
|
||||
@@ -78,7 +78,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun setNonNullParameter(ps: PreparedStatement, i: Int, parameter: T, jdbcType: JdbcType?) {
|
||||
override fun setNonNullParameter(ps: PreparedStatement, i: Int, parameter: T?, jdbcType: JdbcType?) {
|
||||
setValue(ps, i, parameter, jdbcType)
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(rs: ResultSet, columnName: String): T {
|
||||
override fun getNullableResult(rs: ResultSet, columnName: String): T? {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_NAME, null, columnName)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(rs: ResultSet, columnIndex: Int): T {
|
||||
override fun getNullableResult(rs: ResultSet, columnIndex: Int): T? {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_INDEX, columnIndex, null)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(cs: CallableStatement, columnIndex: Int): T {
|
||||
override fun getNullableResult(cs: CallableStatement, columnIndex: Int): T? {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(cs, null), CallType.CALLABLE_STATEMENT_INDEX, columnIndex, null)
|
||||
}
|
||||
}
|
||||
|
||||
+17
-8
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile DateTimeTypeHandler.kt
|
||||
* LastUpdate 2026-01-07 19:23:12
|
||||
* LastUpdate 2026-02-05 11:20:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.apache.ibatis.type.JdbcType
|
||||
import org.apache.ibatis.type.MappedTypes
|
||||
import java.sql.PreparedStatement
|
||||
import java.sql.Timestamp
|
||||
import java.sql.Types.TIMESTAMP
|
||||
|
||||
/**
|
||||
* DateTime类型处理器,用于在数据库和Java对象之间转换DateTime类型
|
||||
@@ -42,22 +43,30 @@ class DateTimeTypeHandler : QuickBaseTypeHandler<DateTime>() {
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
): DateTime {
|
||||
): DateTime? {
|
||||
val data = (when (ct) {
|
||||
CallType.RESULTSET_INDEX -> vg.resultSet!!.getTimestamp(ci!!)
|
||||
CallType.RESULTSET_NAME -> vg.resultSet!!.getTimestamp(cn!!)
|
||||
CallType.CALLABLE_STATEMENT_INDEX -> vg.callableStatement!!.getTimestamp(ci!!)
|
||||
})
|
||||
if (data == null) {
|
||||
return null
|
||||
}
|
||||
return DateTime.of(
|
||||
(when (ct) {
|
||||
CallType.RESULTSET_INDEX -> vg.resultSet!!.getTimestamp(ci!!)
|
||||
CallType.RESULTSET_NAME -> vg.resultSet!!.getTimestamp(cn!!)
|
||||
CallType.CALLABLE_STATEMENT_INDEX -> vg.callableStatement!!.getTimestamp(ci!!)
|
||||
})
|
||||
data
|
||||
)
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement,
|
||||
index: Int,
|
||||
parameter: DateTime,
|
||||
parameter: DateTime?,
|
||||
jdbcType: JdbcType?
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, TIMESTAMP)
|
||||
return
|
||||
}
|
||||
ps.setTimestamp(index, Timestamp.valueOf(parameter.toLocalDateTime()))
|
||||
}
|
||||
}
|
||||
|
||||
+19
-9
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile MysqlUUIDBinaryTypeHandler.kt
|
||||
* LastUpdate 2026-01-07 19:30:31
|
||||
* LastUpdate 2026-01-28 10:08:46
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -59,19 +59,29 @@ class MysqlUUIDBinaryTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?
|
||||
): UUID {
|
||||
): UUID? {
|
||||
|
||||
val data: ByteArray? = when (ct) {
|
||||
CallType.RESULTSET_NAME -> vg.resultSet!!.getBytes(cn!!)
|
||||
CallType.RESULTSET_INDEX -> vg.resultSet!!.getBytes(ci!!)
|
||||
CallType.CALLABLE_STATEMENT_INDEX -> vg.resultSet!!.getBytes(ci!!)
|
||||
}
|
||||
if (data == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return toUUID(
|
||||
when (ct) {
|
||||
CallType.RESULTSET_NAME -> vg.resultSet!!.getBytes(cn!!)
|
||||
CallType.RESULTSET_INDEX -> vg.resultSet!!.getBytes(ci!!)
|
||||
CallType.CALLABLE_STATEMENT_INDEX -> vg.resultSet!!.getBytes(ci!!)
|
||||
}
|
||||
)!!
|
||||
data
|
||||
)
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement, index: Int, parameter: UUID, jdbcType: JdbcType?
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, java.sql.Types.BINARY)
|
||||
return
|
||||
}
|
||||
ps.setBytes(index, toByteArray(parameter))
|
||||
}
|
||||
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile PgsqlUUIDTypeHandler.kt
|
||||
* LastUpdate 2026-02-05 11:20:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis.typehandler.pgsql.uuid
|
||||
|
||||
import com.mingliqiye.utils.mybatis.CallType
|
||||
import com.mingliqiye.utils.mybatis.QuickBaseTypeHandler
|
||||
import com.mingliqiye.utils.mybatis.QuickBaseTypeHandlerValueGetter
|
||||
import com.mingliqiye.utils.uuid.UUID
|
||||
import org.apache.ibatis.type.JdbcType
|
||||
import org.apache.ibatis.type.MappedTypes
|
||||
import java.sql.PreparedStatement
|
||||
|
||||
@MappedTypes(UUID::class)
|
||||
class PgsqlUUIDTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?
|
||||
): UUID? {
|
||||
val data: String? = when (ct) {
|
||||
CallType.RESULTSET_INDEX ->
|
||||
vg.resultSet!!.getString(ci!!)
|
||||
|
||||
CallType.RESULTSET_NAME ->
|
||||
vg.resultSet!!.getString(cn)
|
||||
|
||||
CallType.CALLABLE_STATEMENT_INDEX ->
|
||||
vg.callableStatement!!.getString(cn)
|
||||
}
|
||||
if (data == null) {
|
||||
return null
|
||||
}
|
||||
return UUID.of(data)
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement, index: Int, parameter: UUID?, jdbcType: JdbcType?
|
||||
) {
|
||||
if (parameter == null) {
|
||||
ps.setNull(index, jdbcType?.TYPE_CODE ?: JdbcType.JAVA_OBJECT.TYPE_CODE)
|
||||
return
|
||||
}
|
||||
ps.setObject(index, parameter.getUuid())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user