diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java index 4e313807..a329919a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java @@ -82,4 +82,18 @@ public final class FlexAssert { } } -} \ No newline at end of file + /** + * 断言传入的数组内容不能为 null 或者 空 + */ + public static void assertAreNotNull(T[] elements, String msg, Object params) { + if (elements == null || elements.length == 0) { + throw FlexExceptions.wrap(msg, params); + } + for (T element : elements) { + if (element == null) { + throw FlexExceptions.wrap(msg, params); + } + } + } + +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java index fb8dc5a9..4661d83f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/EntitySqlProvider.java @@ -18,7 +18,6 @@ package com.mybatisflex.core.provider; import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.dialect.DialectFactory; import com.mybatisflex.core.exception.FlexAssert; -import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryTable; import com.mybatisflex.core.query.QueryWrapper; @@ -240,7 +239,7 @@ public class EntitySqlProvider { Object[] primaryValues = tableInfo.buildPkSqlArgs(entity); Object[] tenantIdArgs = tableInfo.buildTenantIdArgs(); - FlexExceptions.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); + FlexAssert.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues, tenantIdArgs)); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java index 5f036516..21d7dba6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java @@ -18,7 +18,6 @@ package com.mybatisflex.core.provider; import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.dialect.DialectFactory; import com.mybatisflex.core.exception.FlexAssert; -import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Row; @@ -247,7 +246,7 @@ public class RowSqlProvider { Object[] primaryValues = tableInfo.buildPkSqlArgs(entity); Object[] tenantIdArgs = tableInfo.buildTenantIdArgs(); - FlexExceptions.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); + FlexAssert.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues, tenantIdArgs));