mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 添加全表更新或全部删除时的异常信息国际化。
This commit is contained in:
parent
90a38bff7b
commit
b8b2d1bf21
@ -783,11 +783,7 @@ public class CommonsDialectImpl implements IDialect {
|
||||
Map<String, RawValue> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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."),
|
||||
;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user