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) {
|
if (inputStream != null) {
|
||||||
properties.load(new InputStreamReader(inputStream, encoding));
|
properties.load(new InputStreamReader(inputStream, encoding));
|
||||||
} else if (!fileName.contains("-")) {
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public final class FlexExceptions {
|
|||||||
* @return MybatisFlexException
|
* @return MybatisFlexException
|
||||||
*/
|
*/
|
||||||
public static MybatisFlexException wrap(Throwable throwable) {
|
public static MybatisFlexException wrap(Throwable throwable) {
|
||||||
if (throwable instanceof MybatisFlexException){
|
if (throwable instanceof MybatisFlexException) {
|
||||||
return (MybatisFlexException) throwable;
|
return (MybatisFlexException) throwable;
|
||||||
}
|
}
|
||||||
return new MybatisFlexException(throwable);
|
return new MybatisFlexException(throwable);
|
||||||
@ -63,15 +63,38 @@ public final class FlexExceptions {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 抛出一个新的 MybatisFlexException 异常
|
* 断言 condition 必须为 true
|
||||||
*
|
*
|
||||||
* @param condition 抛出条件
|
* @param condition 条件
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
* @param params 消息参数
|
* @param params 消息参数
|
||||||
*/
|
*/
|
||||||
public static void throwIf(boolean condition, String msg, Object... params) {
|
public static void assertTrue(boolean condition, String msg, Object... params) {
|
||||||
if (condition) {
|
if (!condition) {
|
||||||
throw wrap(msg, params);
|
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);
|
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
|
||||||
Object[] updateValues = tableInfo.obtainUpdateValues(entity, ignoreNulls, false);
|
Object[] updateValues = tableInfo.obtainUpdateValues(entity, ignoreNulls, false);
|
||||||
Object[] primaryValues = tableInfo.obtainPrimaryValues(entity);
|
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));
|
ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues));
|
||||||
|
|
||||||
return DialectFactory.getDialect().forUpdateEntity(tableInfo, entity, ignoreNulls);
|
return DialectFactory.getDialect().forUpdateEntity(tableInfo, entity, ignoreNulls);
|
||||||
|
|||||||
@ -88,12 +88,5 @@ public class ArrayUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 急速构建数组
|
|
||||||
*/
|
|
||||||
public static <T> T[] asArray(T... elements) {
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user