optimize Utils

This commit is contained in:
开源海哥 2023-03-09 11:50:46 +08:00
parent 814ea2fdc3
commit ec44b3ca27
4 changed files with 31 additions and 13 deletions

View File

@ -68,7 +68,6 @@ class MyBatisFlexProps {
if (inputStream != null) {
properties.load(new InputStreamReader(inputStream, encoding));
} else if (!fileName.contains("-")) {
}
} catch (Exception e) {
} finally {

View File

@ -63,15 +63,38 @@ public final class FlexExceptions {
/**
* 抛出一个新的 MybatisFlexException 异常
* 断言 condition 必须为 true
*
* @param condition 抛出条件
* @param condition 条件
* @param msg 消息
* @param params 消息参数
*/
public static void throwIf(boolean condition, String msg, Object... params) {
if (condition) {
public static void assertTrue(boolean condition, String msg, Object... params) {
if (!condition) {
throw wrap(msg, params);
}
}
/**
* 断言传入的内容不能为 null
*/
public static void assertNotNull(Object object, String msg, Object params) {
assertTrue(object != null, msg, params);
}
/**
* 断言传入的数组内容不能为 null 或者
*/
public static <T> void assertAreNotNull(T[] elements, String msg, Object params) {
if (elements == null || elements.length == 0) {
throw wrap(msg, params);
}
for (T element : elements) {
if (element == null) {
throw wrap(msg, params);
}
}
}
}

View File

@ -187,6 +187,9 @@ public class EntitySqlProvider {
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
Object[] updateValues = tableInfo.obtainUpdateValues(entity, ignoreNulls, false);
Object[] primaryValues = tableInfo.obtainPrimaryValues(entity);
FlexExceptions.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity);
ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues));
return DialectFactory.getDialect().forUpdateEntity(tableInfo, entity, ignoreNulls);

View File

@ -88,12 +88,5 @@ public class ArrayUtil {
return false;
}
/**
* 急速构建数组
*/
public static <T> T[] asArray(T... elements) {
return elements;
}
}