From 5e73333682bf358c36c0b49a2dd6860436cf2ec1 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:26:37 +0800 Subject: [PATCH 01/15] =?UTF-8?q?refactor:=20=E5=B0=86=20assertAreNotNull?= =?UTF-8?q?=20=E4=BB=8E=20FlexExceptions=20=E7=A7=BB=E5=8A=A8=E5=88=B0=20F?= =?UTF-8?q?lexAssert=20=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/exception/FlexAssert.java | 16 +++++++++++++++- .../core/provider/EntitySqlProvider.java | 3 +-- .../core/provider/RowSqlProvider.java | 3 +-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java index 4e313807..a329919a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/FlexAssert.java @@ -82,4 +82,18 @@ public final class FlexAssert { } } -} \ No newline at end of file + /** + * 断言传入的数组内容不能为 null 或者 空 + */ + public static void assertAreNotNull(T[] elements, String msg, Object params) { + if (elements == null || elements.length == 0) { + throw FlexExceptions.wrap(msg, params); + } + for (T element : elements) { + if (element == null) { + throw FlexExceptions.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 fb8dc5a9..4661d83f 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 @@ -18,7 +18,6 @@ package com.mybatisflex.core.provider; import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.dialect.DialectFactory; import com.mybatisflex.core.exception.FlexAssert; -import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryTable; import com.mybatisflex.core.query.QueryWrapper; @@ -240,7 +239,7 @@ public class EntitySqlProvider { Object[] primaryValues = tableInfo.buildPkSqlArgs(entity); Object[] tenantIdArgs = tableInfo.buildTenantIdArgs(); - FlexExceptions.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); + FlexAssert.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues, tenantIdArgs)); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java index 5f036516..21d7dba6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java @@ -18,7 +18,6 @@ package com.mybatisflex.core.provider; import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.dialect.DialectFactory; import com.mybatisflex.core.exception.FlexAssert; -import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Row; @@ -247,7 +246,7 @@ public class RowSqlProvider { Object[] primaryValues = tableInfo.buildPkSqlArgs(entity); Object[] tenantIdArgs = tableInfo.buildTenantIdArgs(); - FlexExceptions.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); + FlexAssert.assertAreNotNull(primaryValues, "The value of primary key must not be null, entity[%s]", entity); ProviderUtil.setSqlArgs(params, ArrayUtil.concat(updateValues, primaryValues, tenantIdArgs)); From 931b6cdd7492ca7c1263d1aaca385170ff0bc5a5 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:27:37 +0800 Subject: [PATCH 02/15] =?UTF-8?q?feat:=20=E5=9B=BD=E9=99=85=E5=8C=96?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/locale/Localizable.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/Localizable.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/Localizable.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/Localizable.java new file mode 100644 index 00000000..f26a4de7 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/Localizable.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.core.exception.locale; + +import java.io.Serializable; +import java.util.Locale; + +/** + * 可本地化字符串接口。 + * + * @author 王帅 + * @since 2023-07-26 + */ +public interface Localizable extends Serializable { + + /** + * 获取源(非本地化)字符串。 + * + * @return 源字符串 + */ + String getSourceString(); + + /** + * 获取本地化字符串。 + * + * @param locale 要获取字符串的区域 + * @return 本地化字符串或源字符串(如果没有可用的本地化版本) + */ + String getLocalizedString(Locale locale); + +} From d7b2aa210e5979290db8809d20cd22c913550215 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:27:59 +0800 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=E5=BC=82=E5=B8=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=9B=BD=E9=99=85=E5=8C=96=E6=B6=88=E6=81=AF=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/locale/LocalizedFormats.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java new file mode 100644 index 00000000..031c9442 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.core.exception.locale; + +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * 异常消息中使用的本地化消息格式的枚举。 + * + * @author 王帅 + * @since 2023-07-26 + */ +public enum LocalizedFormats implements Localizable { + + OBJECT_NULL("{0} can not be null."); + + private final String sourceFormat; + + LocalizedFormats(String sourceFormat) { + this.sourceFormat = sourceFormat; + } + + @Override + public String getSourceString() { + return this.sourceFormat; + } + + @Override + public String getLocalizedString(final Locale locale) { + try { + // 本地化消息路径 + String path = LocalizedFormats.class.getName().replace(".", "/"); + // 获取多语言本地化消息信息文件 + ResourceBundle bundle = ResourceBundle.getBundle("assets/" + path, locale); + // 获取当前语言的消息格式 + if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) { + return bundle.getString(toString()); + } + } catch (MissingResourceException mre) { + mre.printStackTrace(); + // do nothing here. + } + // 如果没有该语言的本地化消息,则返回源消息字符串 + return sourceFormat; + } + +} From 0ff13a49b7d5d36d88d9ebbffe8c76d8ce5a536e Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:28:26 +0800 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BF=A1=E6=81=AF=E5=9B=BD=E9=99=85=E5=8C=96=E5=A4=84?= =?UTF-8?q?=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/locale/package-info.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/package-info.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/package-info.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/package-info.java new file mode 100644 index 00000000..4d0366c3 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * 异常信息国际化。 + */ +package com.mybatisflex.core.exception.locale; From f65779cfdc471f169e9c158e9b5be645ad146d28 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:28:56 +0800 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=E6=A0=B9=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BD=E9=99=85=E5=8C=96=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/MybatisFlexException.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java index a18b3f13..bc26fa69 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/MybatisFlexException.java @@ -15,10 +15,23 @@ */ package com.mybatisflex.core.exception; +import com.mybatisflex.core.exception.locale.Localizable; + +import java.text.MessageFormat; +import java.util.Locale; + public class MybatisFlexException extends RuntimeException { private static final long serialVersionUID = 1L; + private Localizable pattern; + private Object[] arguments; + + public MybatisFlexException(Localizable pattern, Object... arguments) { + this.pattern = pattern; + this.arguments = arguments; + } + public MybatisFlexException(String message) { super(message); } @@ -31,5 +44,19 @@ public class MybatisFlexException extends RuntimeException { super(cause); } + @Override + public String getMessage() { + return getMessage(Locale.CHINESE); + } + + @Override + public String getLocalizedMessage() { + return getMessage(Locale.getDefault()); + } + + private String getMessage(Locale locale) { + String localizedString = pattern.getLocalizedString(locale); + return MessageFormat.format(localizedString, arguments); + } } From 51de0101e714decfe3a3ed9020a8dd705ad94d60 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:29:20 +0800 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20=E6=8F=90=E4=BE=9B=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E6=B6=88=E6=81=AF=E5=B0=81=E8=A3=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/FlexExceptions.java | 39 ++----------------- 1 file changed, 4 insertions(+), 35 deletions(-) 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 cf335bf2..2d196564 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 @@ -15,6 +15,8 @@ */ package com.mybatisflex.core.exception; +import com.mybatisflex.core.exception.locale.Localizable; + /** * MybatisFlexException 异常封装类 */ @@ -61,41 +63,8 @@ public final class FlexExceptions { return new MybatisFlexException(String.format(msg, params)); } - - /** - * 断言 condition 必须为 true - * - * @param condition 条件 - * @param msg 消息 - * @param params 消息参数 - */ - 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); - } - } + public static MybatisFlexException wrap(Localizable pattern, Object... args) { + return new MybatisFlexException(pattern, args); } } From 96441e484068e0b4b17b6991afe8b8ff6185497f Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:29:40 +0800 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20=E5=9B=BD=E9=99=85=E5=8C=96?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=A8=A1=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/locale/LocalizedFormats_en.properties | 1 + .../core/exception/locale/LocalizedFormats_zh.properties | 1 + 2 files changed, 2 insertions(+) create mode 100644 mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_en.properties create mode 100644 mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties diff --git a/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_en.properties b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_en.properties new file mode 100644 index 00000000..e6ad24ae --- /dev/null +++ b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_en.properties @@ -0,0 +1 @@ +OBJECT_NULL={0} can not be null. diff --git a/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties new file mode 100644 index 00000000..f910a9bb --- /dev/null +++ b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties @@ -0,0 +1 @@ +OBJECT_NULL={0} \u4E0D\u80FD\u4E3A null \u503C\u3002 From 6b18032106a848e8f8bb4c374b98fc13d1d32bb9 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:30:01 +0800 Subject: [PATCH 08/15] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=B6=88=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coretest/LocaleFormatTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LocaleFormatTest.java diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LocaleFormatTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LocaleFormatTest.java new file mode 100644 index 00000000..11ef72c4 --- /dev/null +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LocaleFormatTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.coretest; + +import com.mybatisflex.core.exception.FlexExceptions; +import com.mybatisflex.core.exception.locale.LocalizedFormats; +import org.junit.Test; + +/** + * @author 王帅 + * @since 2023-07-26 + */ +public class LocaleFormatTest { + + @Test + public void test() { + throw FlexExceptions.wrap(LocalizedFormats.OBJECT_NULL, "primaryValues"); + } + +} From 5a75b31c796a6166aa6242bccf3c7c6670625b34 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:30:30 +0800 Subject: [PATCH 09/15] =?UTF-8?q?build:=20=E5=B0=86=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=E6=B6=88=E6=81=AF=E9=85=8D=E7=BD=AE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=B0=E6=89=93=E5=8C=85=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index 3a363d93..f4f42959 100644 --- a/pom.xml +++ b/pom.xml @@ -198,11 +198,6 @@ **/* - - - *.properties - - From 7c24bd2638ba2945db193741177da05491fd636e Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 17:54:35 +0800 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E9=9B=86=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/processor/config/ConfigurationKey.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/config/ConfigurationKey.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/config/ConfigurationKey.java index ae76ebd9..40f4488f 100644 --- a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/config/ConfigurationKey.java +++ b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/config/ConfigurationKey.java @@ -29,6 +29,11 @@ public enum ConfigurationKey { */ ENABLE("processor.enable", ""), + /** + * 生成文件的字符集。 + */ + CHARSET("processor.charset", "UTF-8"), + /** * APT 代码生成路径。 */ From d44a6c85dde3f69b1b502eaf184a4987e21c6cc2 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:06:05 +0800 Subject: [PATCH 11/15] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=B8=BA?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=87=E4=BB=B6=E6=8C=87=E5=AE=9A=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E9=9B=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/processor/MybatisFlexProcessor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MybatisFlexProcessor.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MybatisFlexProcessor.java index 780b20dc..9a6e39bc 100644 --- a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MybatisFlexProcessor.java +++ b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/MybatisFlexProcessor.java @@ -45,7 +45,6 @@ import java.io.PrintWriter; import java.io.Writer; import java.math.BigDecimal; import java.math.BigInteger; -import java.nio.file.Files; import java.sql.Time; import java.sql.Timestamp; import java.time.*; @@ -383,7 +382,7 @@ public class MybatisFlexProcessor extends AbstractProcessor { return; } - writer = new PrintWriter(Files.newOutputStream(genJavaFile.toPath())); + writer = new PrintWriter(genJavaFile, configuration.get(ConfigurationKey.CHARSET)); writer.write(genContent); writer.flush(); } catch (IOException e) { From a6ce1f3eafa1e49766173be5e0dc2f951acc4613 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:06:13 +0800 Subject: [PATCH 12/15] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E6=96=87=E6=A1=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/others/apt.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/zh/others/apt.md b/docs/zh/others/apt.md index 61e12eba..db3bcaf7 100644 --- a/docs/zh/others/apt.md +++ b/docs/zh/others/apt.md @@ -18,6 +18,7 @@ MyBatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编 | processor.enable | 全局启用apt开关 | true/false | true | | processor.stopBubbling | 是否停止向上级合并配 | true/false | false | | processor.genPath | APT 代码生成路径 | 合法的绝对或相对路径 | target/generated-sources/annotations | +| processor.charset | APT 代码生成文件字符集 | UTF-8 | target/generated-sources/annotations | | processor.allInTables.enable | 是否所有的类都生成在 Tables 类里 | true/false | false | | processor.allInTables.package | Tables 类名 | 合法的包名 | ${entityPackage}.table | | processor.allInTables.className | Tables 类名 | 合法的类名 | Tables | From e88817fbe903d42e85c04949371c23ec8a5e782d Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:32:49 +0800 Subject: [PATCH 13/15] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logicdelete/AbstractLogicDeleteProcessor.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java index cc55732a..486d6ab5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java @@ -47,20 +47,6 @@ public abstract class AbstractLogicDeleteProcessor implements LogicDeleteProcess , getLogicNormalValue())); } - /** - * 获取逻辑删除列未删除标记值。 - * - * @return 未删除标记值 - */ - public abstract Object getLogicNormalValue(); - - /** - * 获取逻辑删除列删除时标记值。 - * - * @return 删除时标记值 - */ - public abstract Object getLogicDeletedValue(); - } From 998b6b7426014010f4421f4b58cb74d1315879c6 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:33:10 +0800 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=99=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PrimaryKeyLogicDeleteProcessor.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java new file mode 100644 index 00000000..40f041fa --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mybatisflex.core.logicdelete.impl; + +import com.mybatisflex.core.FlexGlobalConfig; +import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexAssert; +import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor; +import com.mybatisflex.core.table.IdInfo; +import com.mybatisflex.core.table.TableInfo; + +import java.util.List; + +import static com.mybatisflex.core.constant.SqlConsts.EQUALS; + +/** + * 主键逻辑删除处理器。 + * + * @author 王帅 + * @see I7O1VV + * @since 2023-07-26 + */ +public class PrimaryKeyLogicDeleteProcessor extends AbstractLogicDeleteProcessor { + + @Override + public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) { + List primaryKeyList = tableInfo.getPrimaryKeyList(); + FlexAssert.notEmpty(primaryKeyList, "Must have one primary key."); + String column = primaryKeyList.get(0).getColumn(); + return dialect.wrap(logicColumn) + EQUALS + dialect.wrap(column); + } + + /** + * 正常未删除的值为 0 (或者可配置为其他值)。 + */ + @Override + public Object getLogicNormalValue() { + Object normalValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete(); + if (normalValueOfLogicDelete instanceof Number) { + return normalValueOfLogicDelete; + } + return 0; + } + + /** + * 逻辑删除后,则更新逻辑删除字段值为主键的值。 + */ + @Override + public Object getLogicDeletedValue() { + return null; + } + +} From dd709597b0608d89ba7359f545a45bfac50ef8be Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:33:20 +0800 Subject: [PATCH 15/15] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=99=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/coretest/LogicDeleteTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java index 888719aa..80d56ffa 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java @@ -20,6 +20,8 @@ import com.mybatisflex.core.dialect.DialectFactory; import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.logicdelete.LogicDeleteProcessor; import com.mybatisflex.core.logicdelete.impl.*; +import com.mybatisflex.core.table.TableInfo; +import com.mybatisflex.core.table.TableInfoFactory; import org.junit.Test; /** @@ -41,12 +43,14 @@ public class LogicDeleteTest { print("IntegerLogicDeleteProcessor", new IntegerLogicDeleteProcessor()); print("DateTimeLogicDeleteProcessor", new DateTimeLogicDeleteProcessor()); print("TimeStampLogicDeleteProcessor", new TimeStampLogicDeleteProcessor()); + print("PrimaryKeyLogicDeleteProcessor", new PrimaryKeyLogicDeleteProcessor()); } public void print(String type, LogicDeleteProcessor processor) { System.out.println("===== " + type + " ====="); - System.out.println(processor.buildLogicDeletedSet(logicColumn, null, dialect)); - System.out.println(processor.buildLogicNormalCondition(logicColumn, null, dialect)); + TableInfo tableInfo = TableInfoFactory.ofEntityClass(Account.class); + System.out.println(processor.buildLogicDeletedSet(logicColumn, tableInfo, dialect)); + System.out.println(processor.buildLogicNormalCondition(logicColumn, tableInfo, dialect)); } -} \ No newline at end of file +}