diff --git a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/MyBatisFlexProps.java b/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/MyBatisFlexProps.java index 7d430339..ffd4eed0 100644 --- a/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/MyBatisFlexProps.java +++ b/mybatis-flex-annotation/src/main/java/com/mybatisflex/processer/MyBatisFlexProps.java @@ -68,7 +68,6 @@ class MyBatisFlexProps { if (inputStream != null) { properties.load(new InputStreamReader(inputStream, encoding)); - } else if (!fileName.contains("-")) { } } catch (Exception e) { } finally { diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java index c509ecce..de415f7d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexExceptions.java @@ -31,7 +31,7 @@ public final class FlexExceptions { * @return MybatisFlexException */ public static MybatisFlexException wrap(Throwable throwable) { - if (throwable instanceof MybatisFlexException){ + if (throwable instanceof MybatisFlexException) { return (MybatisFlexException) throwable; } return new MybatisFlexException(throwable); @@ -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 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); + } + } + } } 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 0382a104..bf8633a0 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 @@ -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); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java index 5472c485..a4d6c87c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/ArrayUtil.java @@ -88,12 +88,5 @@ public class ArrayUtil { return false; } - /** - * 急速构建数组 - */ - public static T[] asArray(T... elements) { - return elements; - } - }