From 5dd8d51f7af1d76df97a6b812e9ac7a7d0e22898 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 22 Feb 2024 12:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BE=BE=E6=A2=A6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=96=B9=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +- .../cn/hutool/db/dialect/impl/DmDialect.java | 38 ++++++++----------- .../src/test/java/cn/hutool/db/DmTest.java | 2 + 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbdf9a98..353f16247 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.27(2024-02-19) +# 5.8.27(2024-02-22) ### 🐣新特性 * 【extra 】 FreemarkerEngine修改默认版本参数 +* 【db 】 增加达梦数据库方言(pr#1178@Gitee) ### 🐞Bug修复 diff --git a/hutool-db/src/main/java/cn/hutool/db/dialect/impl/DmDialect.java b/hutool-db/src/main/java/cn/hutool/db/dialect/impl/DmDialect.java index 5239dbd41..111d0682a 100644 --- a/hutool-db/src/main/java/cn/hutool/db/dialect/impl/DmDialect.java +++ b/hutool-db/src/main/java/cn/hutool/db/dialect/impl/DmDialect.java @@ -30,12 +30,6 @@ public class DmDialect extends AnsiSqlDialect { return DialectName.DM.name(); } - @Override - protected SqlBuilder wrapPageSql(SqlBuilder find, Page page) { - // limit A , B 表示:A就是查询的起点位置,B就是你需要多少行。 - return find.append(" limit ").append(page.getStartPosition()).append(" , ").append(page.getPageSize()); - } - @Override public PreparedStatement psForUpsert(Connection conn, Entity entity, String... keys) throws SQLException { Assert.notEmpty(keys, "Keys must be not empty for DM MERGE SQL."); @@ -43,42 +37,42 @@ public class DmDialect extends AnsiSqlDialect { final SqlBuilder builder = SqlBuilder.create(wrapper); List keyList = Arrays.asList(keys); - final StringBuilder keyfieldsPart = new StringBuilder(); - final StringBuilder updatefieldsPart = new StringBuilder(); - final StringBuilder insertfieldsPart = new StringBuilder(); - final StringBuilder insertplaceHolder = new StringBuilder(); + final StringBuilder keyFieldsPart = new StringBuilder(); + final StringBuilder updateFieldsPart = new StringBuilder(); + final StringBuilder insertFieldsPart = new StringBuilder(); + final StringBuilder insertPlaceHolder = new StringBuilder(); // 构建字段部分和参数占位符部分 entity.forEach((field, value) -> { if (StrUtil.isNotBlank(field) && keyList.contains(field)) { - if (keyfieldsPart.length() > 0) { - keyfieldsPart.append(" and "); + if (keyFieldsPart.length() > 0) { + keyFieldsPart.append(" and "); } - keyfieldsPart.append(field + "= ?"); + keyFieldsPart.append(field + "= ?"); builder.addParams(value); } }); entity.forEach((field, value) -> { if (StrUtil.isNotBlank(field) && !keyList.contains(field)) { - if (updatefieldsPart.length() > 0) { + if (updateFieldsPart.length() > 0) { // 非第一个参数,追加逗号 - updatefieldsPart.append(", "); + updateFieldsPart.append(", "); } - updatefieldsPart.append(field + "= ?"); + updateFieldsPart.append(field).append("= ?"); builder.addParams(value); } }); entity.forEach((field, value) -> { if (StrUtil.isNotBlank(field)) { - if (insertfieldsPart.length() > 0) { + if (insertFieldsPart.length() > 0) { // 非第一个参数,追加逗号 - insertfieldsPart.append(", "); - insertplaceHolder.append(", "); + insertFieldsPart.append(", "); + insertPlaceHolder.append(", "); } - insertfieldsPart.append((null != wrapper) ? wrapper.wrap(field) : field); - insertplaceHolder.append("?"); + insertFieldsPart.append((null != wrapper) ? wrapper.wrap(field) : field); + insertPlaceHolder.append("?"); builder.addParams(value); } }); @@ -88,7 +82,7 @@ public class DmDialect extends AnsiSqlDialect { tableName = this.wrapper.wrap(tableName); } - builder.append("MERGE INTO ").append(tableName).append(" USING DUAL ON ").append(keyfieldsPart).append(" WHEN MATCHED THEN UPDATE SET ").append(updatefieldsPart).append(" WHEN NOT MATCHED THEN INSERT (").append(insertfieldsPart).append(") VALUES (").append(insertplaceHolder).append(")"); + builder.append("MERGE INTO ").append(tableName).append(" USING DUAL ON ").append(keyFieldsPart).append(" WHEN MATCHED THEN UPDATE SET ").append(updateFieldsPart).append(" WHEN NOT MATCHED THEN INSERT (").append(insertFieldsPart).append(") VALUES (").append(insertPlaceHolder).append(")"); return StatementUtil.prepareStatement(conn, builder); } diff --git a/hutool-db/src/test/java/cn/hutool/db/DmTest.java b/hutool-db/src/test/java/cn/hutool/db/DmTest.java index 8b59ac8a9..521a588a9 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DmTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DmTest.java @@ -2,6 +2,7 @@ package cn.hutool.db; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import java.sql.SQLException; @@ -27,6 +28,7 @@ public class DmTest { } @Test + @Ignore public void upsertTest() throws SQLException { Db db = Db.use(DS_GROUP_NAME); db.upsert(Entity.create("test").set("a", 1).set("b", 111), "a");