From b8b2d1bf21c378efc84134bef83e88ba5167075f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Sun, 30 Jul 2023 11:13:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E8=A1=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=88=96=E5=85=A8=E9=83=A8=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/dialect/impl/CommonsDialectImpl.java | 14 +++++--------- .../core/exception/locale/LocalizedFormats.java | 1 + .../locale/LocalizedFormats_zh.properties | 1 + .../java/com/mybatisflex/test/MainSqlTest.java | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java index 2d7864ec..4e5a28a6 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java @@ -783,11 +783,7 @@ public class CommonsDialectImpl implements IDialect { Map rawValueMap = tableInfo.obtainUpdateRawValueMap(entity); sql.append(UPDATE).append(forHint(CPI.getHint(queryWrapper))); - if (StringUtil.isNotBlank(tableInfo.getSchema())) { - sql.append(wrap(getRealSchema(tableInfo.getSchema()))).append(REFERENCE); - } - - sql.append(wrap(getRealTable(tableInfo.getTableName()))).append(SET); + sql.append(tableInfo.getWrapSchemaAndTableName(this)).append(SET); StringJoiner stringJoiner = new StringJoiner(DELIMITER); @@ -818,7 +814,7 @@ public class CommonsDialectImpl implements IDialect { //不允许全量更新 if (StringUtil.isBlank(whereConditionSql)) { - throw new IllegalArgumentException("Not allowed UPDATE a table without where condition."); + throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW); } sql.append(WHERE).append(whereConditionSql); @@ -848,7 +844,7 @@ public class CommonsDialectImpl implements IDialect { //不允许全量更新 if (StringUtil.isBlank(whereConditionSql)) { - throw new IllegalArgumentException("Not allowed UPDATE a table without where condition."); + throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW); } sql.append(WHERE).append(whereConditionSql); @@ -997,12 +993,12 @@ public class CommonsDialectImpl implements IDialect { if (StringUtil.isNotBlank(whereSql)) { sqlBuilder.append(WHERE).append(whereSql); } else if (!allowNoCondition) { - throw new IllegalArgumentException("Not allowed DELETE or UPDATE a table without where condition."); + throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW); } } else { // whereQueryCondition == null if (!allowNoCondition) { - throw new IllegalArgumentException("Not allowed DELETE or UPDATE a table without where condition."); + throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW); } } } 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 index f8e1d059..21a175fb 100644 --- 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 @@ -43,6 +43,7 @@ public enum LocalizedFormats implements Localizable { UPDATE_ONLY_SUPPORT_1_TABLE("\"UpdateByQuery\" only support 1 table."), + UPDATE_OR_DELETE_NOT_ALLOW("Not allowed \"UPDATE\" or \"DELETE\" a table without where condition."), ENTITY_VERSION_NULL("The version value of entity[{0}] must 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 index ee1b038b..c6aee994 100644 --- 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 @@ -4,4 +4,5 @@ DATASOURCE_TYPE_NOT_FIND=\u65e0\u6cd5\u627e\u5230\u6570\u636e\u6e90\u7c7b\u578b\ DATASOURCE_CAN_NOT_INSTANCE=\u65e0\u6cd5\u6839\u636e\u7c7b\uff1a {0} \u521b\u5efa\u6570\u636e\u6e90\u3002 DATASOURCE_JDBC_URL=\u65e0\u6cd5\u83b7\u53d6\u6570\u636e\u6e90\u7c7b\u7684 jdbcUrl \u914d\u7f6e\u3002 UPDATE_ONLY_SUPPORT_1_TABLE=\"UpdateByQuery\" \u4ec5\u652f\u6301\u4f20\u5165 1 \u5f20\u8868\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 diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MainSqlTest.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MainSqlTest.java index 7760bb1f..528d4fb6 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MainSqlTest.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MainSqlTest.java @@ -53,7 +53,7 @@ public class MainSqlTest { String sql2 = UpdateChain.of(Article.class) .set("xxxx", "xxxx") - .where(Article::getId).ge(100) +// .where(Article::getId).ge(100) .toSQL(); System.out.println(sql2);