mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
增加达梦数据库方言
This commit is contained in:
parent
90ff9dc344
commit
5dd8d51f7a
@ -2,10 +2,11 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.27(2024-02-19)
|
||||
# 5.8.27(2024-02-22)
|
||||
|
||||
### 🐣新特性
|
||||
* 【extra 】 FreemarkerEngine修改默认版本参数
|
||||
* 【db 】 增加达梦数据库方言(pr#1178@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
|
@ -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<String> 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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user