|
@@ -1,12 +1,28 @@
|
|
|
package com.chelvc.framework.database.context;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.Reader;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.Modifier;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.Month;
|
|
|
+import java.time.OffsetDateTime;
|
|
|
+import java.time.OffsetTime;
|
|
|
+import java.time.Year;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.time.chrono.JapaneseDate;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -29,8 +45,12 @@ import com.chelvc.framework.base.util.SpringUtils;
|
|
|
import com.chelvc.framework.common.function.Executor;
|
|
|
import com.chelvc.framework.common.function.Handler;
|
|
|
import com.chelvc.framework.common.function.Provider;
|
|
|
+import com.chelvc.framework.common.model.File;
|
|
|
+import com.chelvc.framework.common.model.Modification;
|
|
|
import com.chelvc.framework.common.model.Pagination;
|
|
|
import com.chelvc.framework.common.model.Paging;
|
|
|
+import com.chelvc.framework.common.model.Period;
|
|
|
+import com.chelvc.framework.common.model.Region;
|
|
|
import com.chelvc.framework.common.util.AssertUtils;
|
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
@@ -39,7 +59,9 @@ import com.chelvc.framework.database.entity.Entity;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import lombok.NonNull;
|
|
|
import org.apache.ibatis.reflection.property.PropertyNamer;
|
|
|
+import org.apache.ibatis.session.Configuration;
|
|
|
import org.apache.ibatis.type.TypeHandler;
|
|
|
+import org.apache.ibatis.type.UnknownTypeHandler;
|
|
|
import org.mybatis.spring.SqlSessionTemplate;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
@@ -87,6 +109,10 @@ public final class DatabaseContextHolder {
|
|
|
*/
|
|
|
private static volatile DatabaseCryptoContext CRYPTO_CONTEXT;
|
|
|
|
|
|
+ /**
|
|
|
+ * 未知类型处理器实例
|
|
|
+ */
|
|
|
+ private static volatile UnknownTypeHandler UNKNOWN_TYPE_HANDLER;
|
|
|
|
|
|
private DatabaseContextHolder() {
|
|
|
}
|
|
@@ -428,6 +454,28 @@ public final class DatabaseContextHolder {
|
|
|
return column.getColumn();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断对象类型处理器是否已注册
|
|
|
+ *
|
|
|
+ * @param type 对象类型
|
|
|
+ * @return true/false
|
|
|
+ */
|
|
|
+ public static boolean isTypeHandlerRegistered(Class<?> type) {
|
|
|
+ return type == byte.class || type == Byte.class || type == byte[].class || type == Byte[].class
|
|
|
+ || type == char.class || type == Character.class || type == short.class || type == Short.class
|
|
|
+ || type == int.class || type == Integer.class || type == long.class || type == Long.class
|
|
|
+ || type == float.class || type == Float.class || type == double.class || type == Double.class
|
|
|
+ || type == boolean.class || type == Boolean.class || type == String.class || type == Object.class
|
|
|
+ || type == BigInteger.class || type == BigDecimal.class || type == Reader.class
|
|
|
+ || type == InputStream.class || type == Date.class || type == java.sql.Date.class
|
|
|
+ || type == java.sql.Time.class || type == java.sql.Timestamp.class || type == Instant.class
|
|
|
+ || type == LocalDate.class || type == LocalTime.class || type == LocalDateTime.class
|
|
|
+ || type == OffsetTime.class || type == OffsetDateTime.class || type == ZonedDateTime.class
|
|
|
+ || type == Year.class || type == Month.class || type == YearMonth.class || type == JapaneseDate.class
|
|
|
+ || (type != null && Enum.class.isAssignableFrom(type)) || type == File.class || type == Period.class
|
|
|
+ || type == Region.class || type == Modification.class;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化TypeHandler实例
|
|
|
*
|
|
@@ -446,6 +494,23 @@ public final class DatabaseContextHolder {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取未知类型处理器实例
|
|
|
+ *
|
|
|
+ * @param configuration MyBatis配置信息
|
|
|
+ * @return 未知类型处理器实例
|
|
|
+ */
|
|
|
+ public static UnknownTypeHandler getUnknownTypeHandler(@NonNull Configuration configuration) {
|
|
|
+ if (UNKNOWN_TYPE_HANDLER == null) {
|
|
|
+ synchronized (DatabaseContextHolder.class) {
|
|
|
+ if (UNKNOWN_TYPE_HANDLER == null) {
|
|
|
+ UNKNOWN_TYPE_HANDLER = new UnknownTypeHandler(configuration);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return UNKNOWN_TYPE_HANDLER;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据包名查找数据模型对象
|
|
|
*
|