mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
optimize Utils
This commit is contained in:
parent
814ea2fdc3
commit
ec44b3ca27
@ -68,7 +68,6 @@ class MyBatisFlexProps {
|
||||
|
||||
if (inputStream != null) {
|
||||
properties.load(new InputStreamReader(inputStream, encoding));
|
||||
} else if (!fileName.contains("-")) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -88,12 +88,5 @@ public class ArrayUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 急速构建数组
|
||||
*/
|
||||
public static <T> T[] asArray(T... elements) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user