mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
add PhoenixDialect
This commit is contained in:
parent
e8ecadd9a3
commit
41757b1e36
@ -13,6 +13,7 @@
|
||||
* 【core 】 IterUtil增加getFirstNonNull方法
|
||||
* 【core 】 NumberUtil判空改为isBlank(issue#1664@Github)
|
||||
* 【jwt 】 增加JWTValidator、RegisteredPayload
|
||||
* 【db 】 增加Phoenix方言(issue#1656@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【db 】 修复Oracle下别名错误造成的SQL语法啊错误(issue#I3VTQW@Gitee)
|
||||
|
@ -7,6 +7,7 @@ import cn.hutool.db.dialect.impl.AnsiSqlDialect;
|
||||
import cn.hutool.db.dialect.impl.H2Dialect;
|
||||
import cn.hutool.db.dialect.impl.MysqlDialect;
|
||||
import cn.hutool.db.dialect.impl.OracleDialect;
|
||||
import cn.hutool.db.dialect.impl.PhoenixDialect;
|
||||
import cn.hutool.db.dialect.impl.PostgresqlDialect;
|
||||
import cn.hutool.db.dialect.impl.SqlServer2012Dialect;
|
||||
import cn.hutool.db.dialect.impl.Sqlite3Dialect;
|
||||
@ -64,6 +65,8 @@ public class DialectFactory implements DriverNamePool{
|
||||
return new H2Dialect();
|
||||
} else if (DRIVER_SQLSERVER.equalsIgnoreCase(driverName)) {
|
||||
return new SqlServer2012Dialect();
|
||||
} else if (DRIVER_PHOENIX.equalsIgnoreCase(driverName)) {
|
||||
return new PhoenixDialect();
|
||||
}
|
||||
}
|
||||
// 无法识别可支持的数据库类型默认使用ANSI方言,可兼容大部分SQL语句
|
||||
|
@ -1,12 +1,24 @@
|
||||
package cn.hutool.db.dialect;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 方言名<br>
|
||||
* 方言枚举列出了Hutool支持的所有数据库方言
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public enum DialectName {
|
||||
ANSI, MYSQL, ORACLE, POSTGREESQL, SQLITE3, H2, SQLSERVER, SQLSERVER2012
|
||||
ANSI, MYSQL, ORACLE, POSTGREESQL, SQLITE3, H2, SQLSERVER, SQLSERVER2012, PHOENIX;
|
||||
|
||||
/**
|
||||
* 是否为指定数据库方言,检查时不分区大小写
|
||||
*
|
||||
* @param dialectName 方言名
|
||||
* @return 是否时Oracle数据库
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public boolean match(String dialectName) {
|
||||
return StrUtil.equalsIgnoreCase(dialectName, name());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package cn.hutool.db.dialect.impl;
|
||||
|
||||
import cn.hutool.db.Entity;
|
||||
import cn.hutool.db.dialect.DialectName;
|
||||
import cn.hutool.db.sql.Query;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Phoenix数据库方言
|
||||
*
|
||||
* @author loolly
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public class PhoenixDialect extends AnsiSqlDialect {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PhoenixDialect() {
|
||||
// wrapper = new Wrapper('"');
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement psForUpdate(Connection conn, Entity entity, Query query) throws SQLException {
|
||||
// Phoenix的插入、更新语句是统一的,统一使用upsert into关键字
|
||||
return super.psForInsert(conn, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dialectName() {
|
||||
return DialectName.PHOENIX.name();
|
||||
}
|
||||
}
|
@ -151,7 +151,7 @@ public class SqlBuilder implements Builder<String> {
|
||||
entity.setTableName(wrapper.wrap(entity.getTableName()));
|
||||
}
|
||||
|
||||
final boolean isOracle = StrUtil.equalsAnyIgnoreCase(dialectName, DialectName.ORACLE.name());// 对Oracle的特殊处理
|
||||
final boolean isOracle = DialectName.ORACLE.match(dialectName);// 对Oracle的特殊处理
|
||||
final StringBuilder fieldsPart = new StringBuilder();
|
||||
final StringBuilder placeHolder = new StringBuilder();
|
||||
|
||||
@ -181,8 +181,16 @@ public class SqlBuilder implements Builder<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
sql.append("INSERT INTO ")//
|
||||
.append(entity.getTableName()).append(" (").append(fieldsPart).append(") VALUES (")//
|
||||
|
||||
// issue#1656@Github Phoenix兼容
|
||||
if (DialectName.PHOENIX.match(dialectName)) {
|
||||
sql.append("UPSERT INTO ");
|
||||
} else {
|
||||
sql.append("INSERT INTO ");
|
||||
}
|
||||
|
||||
sql.append(entity.getTableName())
|
||||
.append(" (").append(fieldsPart).append(") VALUES (")//
|
||||
.append(placeHolder).append(")");
|
||||
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user