add ClassUtil.isArray method

This commit is contained in:
开源海哥 2023-04-28 07:53:35 +08:00
parent d31d36887e
commit f636bb53d1
4 changed files with 17 additions and 20 deletions

View File

@ -16,6 +16,7 @@
package com.mybatisflex.core.audit; package com.mybatisflex.core.audit;
import com.mybatisflex.core.mybatis.TypeHandlerObject; import com.mybatisflex.core.mybatis.TypeHandlerObject;
import com.mybatisflex.core.util.ClassUtil;
import com.mybatisflex.core.util.DateUtil; import com.mybatisflex.core.util.DateUtil;
import java.io.Serializable; import java.io.Serializable;
@ -129,13 +130,7 @@ public class AuditMessage implements Serializable {
queryParams = new ArrayList<>(); queryParams = new ArrayList<>();
} }
for (Object object : objects) { for (Object object : objects) {
if (object != null && (object.getClass().isArray() if (object != null && ClassUtil.isArray(object.getClass())) {
|| object.getClass() == int[].class
|| object.getClass() == long[].class
|| object.getClass() == short[].class
|| object.getClass() == float[].class
|| object.getClass() == double[].class)
) {
for (int i = 0; i < Array.getLength(object); i++) { for (int i = 0; i < Array.getLength(object); i++) {
addParams(Array.get(object, i)); addParams(Array.get(object, i));
} }
@ -187,7 +182,7 @@ public class AuditMessage implements Serializable {
return (PreparedStatement) Proxy.newProxyInstance( return (PreparedStatement) Proxy.newProxyInstance(
AuditMessage.class.getClassLoader(), AuditMessage.class.getClassLoader(),
new Class[]{PreparedStatement.class}, (proxy, method, args) -> { new Class[]{PreparedStatement.class}, (proxy, method, args) -> {
if (args != null && args.length == 2){ if (args != null && args.length == 2) {
addParams(args[1]); addParams(args[1]);
} }
return null; return null;

View File

@ -17,6 +17,7 @@ package com.mybatisflex.core.query;
import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.util.ClassUtil;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -254,12 +255,7 @@ public class QueryCondition implements Serializable {
Object[] values = (Object[]) value; Object[] values = (Object[]) value;
int paramsCount = 0; int paramsCount = 0;
for (Object object : values) { for (Object object : values) {
if (object != null && (object.getClass().isArray() if (object != null && ClassUtil.isArray(object.getClass())) {
|| object.getClass() == int[].class
|| object.getClass() == long[].class
|| object.getClass() == short[].class
|| object.getClass() == float[].class
|| object.getClass() == double[].class)) {
paramsCount += Array.getLength(object); paramsCount += Array.getLength(object);
} else { } else {
paramsCount++; paramsCount++;

View File

@ -16,6 +16,7 @@
package com.mybatisflex.core.query; package com.mybatisflex.core.query;
import com.mybatisflex.core.util.ClassUtil;
import com.mybatisflex.core.util.CollectionUtil; import com.mybatisflex.core.util.CollectionUtil;
import com.mybatisflex.core.util.StringUtil; import com.mybatisflex.core.util.StringUtil;
@ -104,12 +105,7 @@ class WrapperUtil {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] values = (Object[]) value; Object[] values = (Object[]) value;
for (Object object : values) { for (Object object : values) {
if (object != null && (object.getClass().isArray() if (object != null && ClassUtil.isArray(object.getClass())) {
|| object.getClass() == int[].class
|| object.getClass() == long[].class
|| object.getClass() == short[].class
|| object.getClass() == float[].class
|| object.getClass() == double[].class)) {
for (int i = 0; i < Array.getLength(object); i++) { for (int i = 0; i < Array.getLength(object); i++) {
paras.add(Array.get(object, i)); paras.add(Array.get(object, i));
} }

View File

@ -95,6 +95,16 @@ public class ClassUtil {
} }
public static boolean isArray(Class<?> clazz) {
return clazz.isArray()
|| clazz == int[].class
|| clazz == long[].class
|| clazz == short[].class
|| clazz == float[].class
|| clazz == double[].class;
}
public static <T> T newInstance(Class<T> clazz) { public static <T> T newInstance(Class<T> clazz) {
try { try {
Constructor<?> defaultConstructor = null; Constructor<?> defaultConstructor = null;