refactor: 将 assertAreNotNull 从 FlexExceptions 移动到 FlexAssert 中。

This commit is contained in:
Suomm 2023-07-26 17:26:37 +08:00
parent e3325e5e4c
commit 5e73333682
3 changed files with 17 additions and 5 deletions

View File

@ -82,4 +82,18 @@ public final class FlexAssert {
}
}
}
/**
* 断言传入的数组内容不能为 null 或者
*/
public static <T> 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);
}
}
}
}

View File

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

View File

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