feat: 添加 "未配置事务生成器" 时的异常信息国际化支持

This commit is contained in:
开源海哥 2023-08-03 10:43:24 +08:00
parent 599181b754
commit 5c95024062
3 changed files with 11 additions and 1 deletions

View File

@ -50,6 +50,8 @@ public enum LocalizedFormats implements Localizable {
ENTITY_VERSION_NULL("The version value of entity \"{0}\" must not be null."), ENTITY_VERSION_NULL("The version value of entity \"{0}\" must not be null."),
KEY_GENERATOR_BLANK("The name of key generator must not be null or blank."),
; ;
private final String sourceFormat; private final String sourceFormat;

View File

@ -15,9 +15,12 @@
*/ */
package com.mybatisflex.core.keygen; package com.mybatisflex.core.keygen;
import com.mybatisflex.core.exception.FlexExceptions;
import com.mybatisflex.core.exception.locale.LocalizedFormats;
import com.mybatisflex.core.keygen.impl.FlexIDKeyGenerator; import com.mybatisflex.core.keygen.impl.FlexIDKeyGenerator;
import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator; import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator;
import com.mybatisflex.core.keygen.impl.UUIDKeyGenerator; import com.mybatisflex.core.keygen.impl.UUIDKeyGenerator;
import com.mybatisflex.core.util.StringUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -43,9 +46,12 @@ public class KeyGeneratorFactory {
* 获取 主键生成器 * 获取 主键生成器
* *
* @param name * @param name
* @return * @return 主键生成器
*/ */
public static IKeyGenerator getKeyGenerator(String name) { public static IKeyGenerator getKeyGenerator(String name) {
if (StringUtil.isBlank(name)){
throw FlexExceptions.wrap(LocalizedFormats.KEY_GENERATOR_BLANK);
}
return KEY_GENERATOR_MAP.get(name.trim()); return KEY_GENERATOR_MAP.get(name.trim());
} }

View File

@ -12,3 +12,5 @@ UPDATE_ONLY_SUPPORT_1_TABLE=\"UpdateByQuery\" \u4ec5\u652f\u6301\u4f20\u5165 1 \
UPDATE_OR_DELETE_NOT_ALLOW=\u6267\u884c "update" \u6216\u8005 "delete" \u7684 SQL \u65f6\uff0c\u4e0d\u5141\u8bb8\u5168\u8868\u64cd\u4f5c\uff0c\u5fc5\u987b\u8981\u6709 where \u6761\u4ef6\u3002 UPDATE_OR_DELETE_NOT_ALLOW=\u6267\u884c "update" \u6216\u8005 "delete" \u7684 SQL \u65f6\uff0c\u4e0d\u5141\u8bb8\u5168\u8868\u64cd\u4f5c\uff0c\u5fc5\u987b\u8981\u6709 where \u6761\u4ef6\u3002
ENTITY_VERSION_NULL=\u4e50\u89c2\u9501\u5b9e\u4f53\u7c7b\u5fc5\u987b\u8bbe\u7f6e version \u7684\u503c\uff1a{0}\u3002 ENTITY_VERSION_NULL=\u4e50\u89c2\u9501\u5b9e\u4f53\u7c7b\u5fc5\u987b\u8bbe\u7f6e version \u7684\u503c\uff1a{0}\u3002
KEY_GENERATOR_BLANK=\u4e3b\u952e\u751f\u6210\u5668\u7684\u540d\u79f0\u4e0d\u80fd\u4e3a null \u6216\u8005\u7a7a\u5b57\u7b26\u4e32\u3002