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:
Armamem0t 2026-01-08 13:21:02 +08:00
parent 2db24530d6
commit 2063d86097
Signed by: minglipro
GPG Key ID: 5F355A77B22AA93B
13 changed files with 402 additions and 128 deletions

View File

@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils
* CurrentFile build.gradle.kts
* LastUpdate 2026-01-06 14:05:20
* LastUpdate 2026-01-08 11:10:03
* UpdateUser MingLiPro
*/
@ -76,7 +76,7 @@ dependencies {
compileOnly("com.google.code.gson:gson:2.13.1")
compileOnly("org.mybatis:mybatis:3.5.19")
compileOnly("com.alibaba.fastjson2:fastjson2:2.0.58")
compileOnly("io.netty:netty-all:4.2.9.Final")
compileOnly("io.netty:netty-all:4.1.130.Final")
compileOnly("com.baomidou:mybatis-plus-core:3.0.1")
compileOnly("net.java.dev.jna:jna:5.17.0")

View File

@ -16,13 +16,13 @@
# ProjectName mingli-utils
# ModuleName mingli-utils
# CurrentFile gradle.properties
# LastUpdate 2026-01-07 10:02:36
# LastUpdate 2026-01-08 13:20:25
# UpdateUser MingLiPro
#
JDKVERSIONS=1.8
GROUPSID=com.mingliqiye.utils
ARTIFACTID=mingli-utils
VERSIONS=4.2.7
VERSIONS=4.3.2
signing.keyId=B22AA93B
signing.password=
signing.secretKeyRingFile=secret.gpg

View File

@ -1,64 +0,0 @@
/*
* Copyright 2025 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.java
* LastUpdate 2025-09-21 21:07:10
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.mybatis;
import java.sql.CallableStatement;
import java.sql.ResultSet;
/**
* QuickBaseTypeHandlerValueGetter类用于封装CallableStatement和ResultSet对象的获取操作
* 该类提供了对存储过程调用结果和查询结果集的统一访问接口
*/
public class QuickBaseTypeHandlerValueGetter {
private final CallableStatement callableStatement;
private final ResultSet resultSet;
/**
* 构造函数初始化QuickBaseTypeHandlerValueGetter实例
*
* @param callableStatement 存储过程调用语句对象用于执行存储过程
* @param resultSet 查询结果集对象用于获取查询结果
*/
public QuickBaseTypeHandlerValueGetter(CallableStatement callableStatement, ResultSet resultSet) {
this.callableStatement = callableStatement;
this.resultSet = resultSet;
}
/**
* 获取结果集对象
*
* @return ResultSet 查询结果集对象
*/
public ResultSet getResultSet() {
return resultSet;
}
/**
* 获取存储过程调用语句对象
*
* @return CallableStatement 存储过程调用语句对象
*/
public CallableStatement getCallableStatement() {
return callableStatement;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* 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.
@ -15,18 +15,14 @@
*
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile CallType.java
* LastUpdate 2025-09-21 21:06:52
* CurrentFile CallType.kt
* LastUpdate 2026-01-07 19:06:59
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.mybatis;
package com.mingliqiye.utils.mybatis
/**
* CallType枚举类定义了不同的调用类型
* 用于标识数据库操作中结果集和可调用语句的访问方式
*/
public enum CallType {
enum class CallType {
/**
* 通过索引访问结果集
* 使用数字索引位置来获取结果集中的数据

View File

@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* 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.
@ -15,30 +15,28 @@
*
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile QuickBaseTypeHandler.java
* LastUpdate 2025-09-21 21:10:36
* CurrentFile QuickBaseTypeHandler.kt
* LastUpdate 2026-01-08 07:59:47
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.mybatis;
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;
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 类型
* @param T 要处理的 Java 类型
*/
public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
abstract class QuickBaseTypeHandler<T> : BaseTypeHandler<T>() {
/**
* 抽象方法用于从数据库结果中获取并转换为 Java 类型 T
*
@ -49,12 +47,13 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @return 转换后的 Java 类型 T 实例
* @throws SQLException SQL 执行异常时抛出
*/
public abstract T getValue(
QuickBaseTypeHandlerValueGetter vg,
CallType ct,
Integer ci,
String cn
) throws SQLException;
@Throws(SQLException::class)
abstract fun getValue(
vg: QuickBaseTypeHandlerValueGetter,
ct: CallType,
ci: Int?,
cn: String?
): T
/**
* 抽象方法用于将 Java 类型 T 设置到 PreparedStatement
@ -65,7 +64,8 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @param jdbcType JDBC 类型
* @throws SQLException SQL 执行异常时抛出
*/
public abstract void setValue(PreparedStatement ps, int index, T parameter, JdbcType jdbcType) throws SQLException;
@Throws(SQLException::class)
abstract fun setValue(ps: PreparedStatement, index: Int, parameter: T, jdbcType: JdbcType?)
/**
* 实现 BaseTypeHandler setNonNullParameter 方法
@ -77,9 +77,9 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @param jdbcType JDBC 类型
* @throws SQLException SQL 执行异常时抛出
*/
@Override
public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException {
setValue(ps, i, parameter, jdbcType);
@Throws(SQLException::class)
override fun setNonNullParameter(ps: PreparedStatement, i: Int, parameter: T, jdbcType: JdbcType?) {
setValue(ps, i, parameter, jdbcType)
}
/**
@ -91,9 +91,9 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @return 转换后的 Java 类型 T 实例可能为 null
* @throws SQLException SQL 执行异常时抛出
*/
@Override
public T getNullableResult(ResultSet rs, String columnName) throws SQLException {
return getValue(new QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_NAME, null, columnName);
@Throws(SQLException::class)
override fun getNullableResult(rs: ResultSet, columnName: String): T {
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_NAME, null, columnName)
}
/**
@ -105,9 +105,9 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @return 转换后的 Java 类型 T 实例可能为 null
* @throws SQLException SQL 执行异常时抛出
*/
@Override
public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
return getValue(new QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_NAME, columnIndex, null);
@Throws(SQLException::class)
override fun getNullableResult(rs: ResultSet, columnIndex: Int): T {
return getValue(QuickBaseTypeHandlerValueGetter(null, rs), CallType.RESULTSET_INDEX, columnIndex, null)
}
/**
@ -119,8 +119,8 @@ public abstract class QuickBaseTypeHandler<T> extends BaseTypeHandler<T> {
* @return 转换后的 Java 类型 T 实例可能为 null
* @throws SQLException SQL 执行异常时抛出
*/
@Override
public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
return getValue(new QuickBaseTypeHandlerValueGetter(cs, null), CallType.CALLABLE_STATEMENT_INDEX, columnIndex, null);
@Throws(SQLException::class)
override fun getNullableResult(cs: CallableStatement, columnIndex: Int): T {
return getValue(QuickBaseTypeHandlerValueGetter(cs, null), CallType.CALLABLE_STATEMENT_INDEX, columnIndex, null)
}
}

View File

@ -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?)

View File

@ -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()))
}
}

View File

@ -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))
}
}

View File

@ -0,0 +1,105 @@
/*
* 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 ClientScheduleReconnect.kt
* LastUpdate 2026-01-08 10:45:37
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.netty
import io.netty.bootstrap.Bootstrap
import io.netty.channel.Channel
import io.netty.channel.ChannelFuture
import io.netty.channel.ChannelFutureListener
import java.util.concurrent.TimeUnit
abstract class ClientScheduleReconnect(
protected val bootstrap: Bootstrap,
protected var delay: Long = 10L,
protected var timeUnit: TimeUnit = TimeUnit.SECONDS
) {
protected var isStop = false
protected var channel: Channel? = null
abstract fun onConnectedLog(channel: Channel)
abstract fun onConnectFailedLog(cause: Throwable?)
abstract fun onStoppedLog()
abstract fun doConnect(): ChannelFuture
open fun updateReconnectDelay(newDelay: Long, newTimeUnit: TimeUnit) {
require(newDelay > 0) { "Delay must be positive" }
this.delay = newDelay
this.timeUnit = newTimeUnit
}
open fun connect() {
doConnect().addListener(object : ChannelFutureListener {
override fun operationComplete(future: ChannelFuture) {
if (future.isSuccess) {
onConnected(future.channel())
} else {
onConnectFailed(future.cause())
}
}
})
}
open fun stop() {
isStop = true
disConnect()
}
open fun disConnect() {
channel?.close()
channel = null
}
open fun scheduleReconnect() {
if (isStop) {
onStoppedLog()
return
}
bootstrap.config().group().schedule({
if (isStop) {
onStoppedLog()
return@schedule
}
connect()
}, delay, timeUnit)
}
open fun onConnected(channel: Channel) {
this.channel = channel
onConnectedLog(channel)
channel.closeFuture().addListener { _ ->
scheduleReconnect()
}
}
open fun onConnectFailed(cause: Throwable?) {
onConnectFailedLog(cause)
scheduleReconnect()
}
open fun isConnected(): Boolean {
return channel?.isActive ?: false
}
}

View File

@ -0,0 +1,73 @@
/*
* 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 NamedThreadFactory.kt
* LastUpdate 2026-01-08 13:21:00
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.netty
import io.netty.util.concurrent.FastThreadLocalThread
import java.util.concurrent.ThreadFactory
import java.util.concurrent.atomic.AtomicInteger
open class NamedThreadFactory(private val getName: NamedThreadFactoryNameGetter) : ThreadFactory {
companion object {
@JvmStatic
private val allThreadPoolNumber = AtomicInteger(0)
@FunctionalInterface
fun interface NamedThreadFactoryNameGetter {
fun getName(clazz: Class<out NamedThreadFactory>, poolNumber: Int, threadNumber: Int): String
}
@JvmStatic
val defaultGetName =
NamedThreadFactoryNameGetter { clazz, poolNumber, threadNumber -> "${clazz.simpleName}-$poolNumber-$threadNumber" }
@JvmStatic
fun of(name: String): NamedThreadFactory {
return NamedThreadFactory { a, b, c ->
"$name-$c"
}
}
@JvmStatic
fun of(getter: NamedThreadFactoryNameGetter = defaultGetName): NamedThreadFactory {
return NamedThreadFactory(getter)
}
}
private val threadNumber = AtomicInteger(0)
private val threadPoolNumber = allThreadPoolNumber.addAndGet(1)
open fun getThreadName(clazz: Class<out NamedThreadFactory>, poolNumber: Int, threadNumber: Int) =
getName.getName(clazz, poolNumber, threadNumber)
override fun newThread(r: Runnable): Thread {
return FastThreadLocalThread(
null,
r,
getThreadName(this.javaClass, threadPoolNumber, threadNumber.addAndGet(1))
)
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* 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.
@ -15,20 +15,15 @@
*
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile StreamEmptyException.java
* LastUpdate 2025-09-20 13:24:07
* CurrentFile StreamEmptyException.kt
* LastUpdate 2026-01-07 19:13:29
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.stream;
package com.mingliqiye.utils.stream
public class StreamEmptyException extends java.lang.RuntimeException {
class StreamEmptyException : RuntimeException {
constructor(message: String) : super(message)
public StreamEmptyException(String message) {
super(message);
}
public StreamEmptyException(String message, Throwable cause) {
super(message, cause);
}
constructor(message: String, cause: Throwable) : super(message, cause)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* 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.
@ -16,10 +16,10 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile MysqlUUIDv1.kt
* LastUpdate 2025-09-15 22:32:50
* LastUpdate 2026-01-08 08:22:14
* UpdateUser MingLiPro
*/
@file:JvmName("MysqlUUIDv1")
@file:JvmName("MysqlUUIDConvertor")
package com.mingliqiye.utils.uuid

View File

@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile UUID.kt
* LastUpdate 2026-01-06 12:55:04
* LastUpdate 2026-01-08 13:21:00
* UpdateUser MingLiPro
*/
@ -537,7 +537,7 @@ class UUID : Serializable {
* @return MySQL 格式的 UUID 字节数组
*/
fun toMysql(): ByteArray {
return mysqlToUuid(this.data)
return uuidToMysql(this.data)
}
/**
@ -546,7 +546,7 @@ class UUID : Serializable {
* @return MySQL 格式的 UUID 实例
*/
fun toMysqlUUID(): UUID {
return of(mysqlToUuid(this.data))
return of(uuidToMysql(this.data))
}
/**