feat(core): 将项目从Java迁移到Kotlin并升级依赖
- 将多个Java文件转换为Kotlin文件,包括CallType、QuickBaseTypeHandler等 - 升级Netty版本从4.2.9.Final到4.130.Final - 添加新的Netty重连调度器ClientScheduleReconnect功能 - 新增DateTime和MySQL UUID类型处理器支持 - 创建命名线程工厂NamedThreadFactory用于线程池管理 - 修复UUID转换方法名称错误 - 更新项目版本号从4.2.7到4.3.2 - 移除Java版本的ValueGetter类,使用Kotlin数据类替代
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 CallType.kt
|
||||
* LastUpdate 2026-01-07 19:06:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis
|
||||
|
||||
enum class CallType {
|
||||
/**
|
||||
* 通过索引访问结果集
|
||||
* 使用数字索引位置来获取结果集中的数据
|
||||
*/
|
||||
RESULTSET_INDEX,
|
||||
|
||||
/**
|
||||
* 通过名称访问结果集
|
||||
* 使用列名来获取结果集中的数据
|
||||
*/
|
||||
RESULTSET_NAME,
|
||||
|
||||
/**
|
||||
* 通过索引访问可调用语句
|
||||
* 使用数字索引位置来获取可调用语句中的数据
|
||||
*/
|
||||
CALLABLE_STATEMENT_INDEX
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 QuickBaseTypeHandler.kt
|
||||
* LastUpdate 2026-01-08 07:59:47
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler
|
||||
import org.apache.ibatis.type.JdbcType
|
||||
import java.sql.CallableStatement
|
||||
import java.sql.PreparedStatement
|
||||
import java.sql.ResultSet
|
||||
import java.sql.SQLException
|
||||
|
||||
/**
|
||||
* 抽象类 QuickBaseTypeHandler 是 MyBatis 的 BaseTypeHandler 的扩展,
|
||||
* 提供了统一处理数据库字段与 Java 类型之间转换的抽象方法。
|
||||
* 子类需要实现 getValue 和 setValue 方法来完成具体的类型转换逻辑。
|
||||
*
|
||||
* @param T 要处理的 Java 类型
|
||||
*/
|
||||
abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
|
||||
/**
|
||||
* 抽象方法,用于从数据库结果中获取并转换为 Java 类型 T。
|
||||
*
|
||||
* @param vg 值获取器,封装了 ResultSet 或 CallableStatement
|
||||
* @param ct 调用类型,标识当前是从 ResultSet 还是 CallableStatement 获取数据
|
||||
* @param ci 列索引(可为 null)
|
||||
* @param cn 列名(可为 null)
|
||||
* @return 转换后的 Java 类型 T 实例
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
abstract fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter,
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
): T
|
||||
|
||||
/**
|
||||
* 抽象方法,用于将 Java 类型 T 设置到 PreparedStatement 中。
|
||||
*
|
||||
* @param ps PreparedStatement 对象
|
||||
* @param index 参数索引位置
|
||||
* @param parameter Java 类型 T 的实例
|
||||
* @param jdbcType JDBC 类型
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
abstract fun setValue(ps: PreparedStatement, index: Int, parameter: T, jdbcType: JdbcType?)
|
||||
|
||||
/**
|
||||
* 实现 BaseTypeHandler 的 setNonNullParameter 方法,
|
||||
* 将非空参数设置到 PreparedStatement 中。
|
||||
*
|
||||
* @param ps PreparedStatement 对象
|
||||
* @param i 参数索引位置
|
||||
* @param parameter Java 类型 T 的实例(非空)
|
||||
* @param jdbcType JDBC 类型
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun setNonNullParameter(ps: PreparedStatement, i: Int, parameter: T, jdbcType: JdbcType?) {
|
||||
setValue(ps, i, parameter, jdbcType)
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现 BaseTypeHandler 的 getNullableResult 方法,
|
||||
* 通过列名从 ResultSet 中获取可能为 null 的结果。
|
||||
*
|
||||
* @param rs ResultSet 对象
|
||||
* @param columnName 数据库列名
|
||||
* @return 转换后的 Java 类型 T 实例(可能为 null)
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(rs: ResultSet, columnName: String): T {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_NAME, null, columnName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现 BaseTypeHandler 的 getNullableResult 方法,
|
||||
* 通过列索引从 ResultSet 中获取可能为 null 的结果。
|
||||
*
|
||||
* @param rs ResultSet 对象
|
||||
* @param columnIndex 数据库列索引
|
||||
* @return 转换后的 Java 类型 T 实例(可能为 null)
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(rs: ResultSet, columnIndex: Int): T {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_INDEX, columnIndex, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现 BaseTypeHandler 的 getNullableResult 方法,
|
||||
* 通过列索引从 CallableStatement 中获取可能为 null 的结果。
|
||||
*
|
||||
* @param cs CallableStatement 对象
|
||||
* @param columnIndex 数据库列索引
|
||||
* @return 转换后的 Java 类型 T 实例(可能为 null)
|
||||
* @throws SQLException SQL 执行异常时抛出
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
override fun getNullableResult(cs: CallableStatement, columnIndex: Int): T {
|
||||
return getValue(QuickBaseTypeHandlerValueGetter(cs, null), CallType.CALLABLE_STATEMENT_INDEX, columnIndex, null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 QuickBaseTypeHandlerValueGetter.kt
|
||||
* LastUpdate 2026-01-07 19:10:44
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis
|
||||
|
||||
import java.sql.CallableStatement
|
||||
import java.sql.ResultSet
|
||||
|
||||
data class QuickBaseTypeHandlerValueGetter(var callableStatement: CallableStatement?, var resultSet: ResultSet?)
|
||||
+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 DateTimeTypeHandler.kt
|
||||
* LastUpdate 2026-01-07 19:23:12
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis.typehandler.datetime
|
||||
|
||||
import com.mingliqiye.utils.mybatis.CallType
|
||||
import com.mingliqiye.utils.mybatis.QuickBaseTypeHandler
|
||||
import com.mingliqiye.utils.mybatis.QuickBaseTypeHandlerValueGetter
|
||||
import com.mingliqiye.utils.time.DateTime
|
||||
import org.apache.ibatis.type.JdbcType
|
||||
import org.apache.ibatis.type.MappedTypes
|
||||
import java.sql.PreparedStatement
|
||||
import java.sql.Timestamp
|
||||
|
||||
/**
|
||||
* DateTime类型处理器,用于在数据库和Java对象之间转换DateTime类型
|
||||
*/
|
||||
@MappedTypes(DateTime::class)
|
||||
class DateTimeTypeHandler : QuickBaseTypeHandler<DateTime>() {
|
||||
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter,
|
||||
ct: CallType,
|
||||
ci: Int?,
|
||||
cn: String?
|
||||
): DateTime {
|
||||
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!!)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement,
|
||||
index: Int,
|
||||
parameter: DateTime,
|
||||
jdbcType: JdbcType?
|
||||
) {
|
||||
ps.setTimestamp(index, Timestamp.valueOf(parameter.toLocalDateTime()))
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 MysqlUUIDBinaryTypeHandler.kt
|
||||
* LastUpdate 2026-01-07 19:30:31
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.mybatis.typehandler.mysql.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 com.mingliqiye.utils.uuid.mysqlToUuid
|
||||
import com.mingliqiye.utils.uuid.uuidToMysql
|
||||
import org.apache.ibatis.type.JdbcType
|
||||
import org.apache.ibatis.type.MappedTypes
|
||||
import java.sql.PreparedStatement
|
||||
|
||||
@MappedTypes(UUID::class)
|
||||
class MysqlUUIDBinaryTypeHandler : QuickBaseTypeHandler<UUID>() {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* 将字节数组转换为UUID对象
|
||||
*
|
||||
* @param byteArray 字节数组
|
||||
* @return UUID对象,如果字节数组为null则返回null
|
||||
*/
|
||||
private fun toUUID(byteArray: ByteArray?): UUID? {
|
||||
return byteArray?.let { UUID.of(mysqlToUuid(it)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 将UUID对象转换为字节数组
|
||||
*
|
||||
* @param uuid UUID对象
|
||||
* @return 字节数组,如果UUID为null则返回null
|
||||
*/
|
||||
fun toByteArray(uuid: UUID?): ByteArray? {
|
||||
return uuid?.let { uuidToMysql(it.toBytes()) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getValue(
|
||||
vg: QuickBaseTypeHandlerValueGetter, ct: CallType, ci: Int?, cn: String?
|
||||
): UUID {
|
||||
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!!)
|
||||
}
|
||||
)!!
|
||||
}
|
||||
|
||||
override fun setValue(
|
||||
ps: PreparedStatement, index: Int, parameter: UUID, jdbcType: JdbcType?
|
||||
) {
|
||||
ps.setBytes(index, toByteArray(parameter))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user