This commit is contained in:
Looly 2024-09-06 11:40:17 +08:00
parent 21c759ae4f
commit 262c3b7e11
2 changed files with 26 additions and 24 deletions

View File

@ -37,6 +37,14 @@ import java.sql.PreparedStatement;
*/
public interface Dialect extends Serializable {
/**
* 方言名
*
* @return 方言名
* @since 5.5.3
*/
String dialectName();
/**
* @return 包装器
*/
@ -99,6 +107,19 @@ public interface Dialect extends Serializable {
*/
PreparedStatement psForUpdate(Connection conn, Entity entity, Query query) throws DbException;
/**
* 构建用于upsert的{@link PreparedStatement}<br>
* 方言实现需实现此默认方法如果没有实现抛出{@link DbException}
*
* @param conn 数据库连接对象
* @param entity 数据实体类包含表名
* @param keys 查找字段某些数据库此字段必须如H2某些数据库无需此字段如MySQL通过主键
* @return PreparedStatement
* @throws DbException SQL执行异常或方言数据不支持此操作
* @since 5.7.20
*/
PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws DbException;
// -------------------------------------------- Query
/**
@ -173,28 +194,4 @@ public interface Dialect extends Serializable {
.append(") hutool_alias_count_");
return psForPage(conn, sqlBuilder, null);
}
/**
* 构建用于upsert的{@link PreparedStatement}<br>
* 方言实现需实现此默认方法如果没有实现抛出{@link DbException}
*
* @param conn 数据库连接对象
* @param entity 数据实体类包含表名
* @param keys 查找字段某些数据库此字段必须如H2某些数据库无需此字段如MySQL通过主键
* @return PreparedStatement
* @throws DbException SQL执行异常或方言数据不支持此操作
* @since 5.7.20
*/
default PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws DbException {
throw new DbException("Unsupported upsert operation of " + dialectName());
}
/**
* 方言名
*
* @return 方言名
* @since 5.5.3
*/
String dialectName();
}

View File

@ -108,6 +108,11 @@ public class AnsiSqlDialect implements Dialect {
return StatementUtil.prepareStatement(false, this.dbConfig, conn, update.build(), update.getParamValueArray());
}
@Override
public PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws DbException {
throw new DbException("Unsupported upsert operation of " + dialectName());
}
@Override
public PreparedStatement psForFind(final Connection conn, final Query query) {
return psForPage(conn, query);