mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
5345e4cc61
commit
037d53794d
@ -66,7 +66,6 @@ public class AnsiSqlDialect implements Dialect {
|
||||
}
|
||||
// 批量,根据第一行数据结构生成SQL占位符
|
||||
final SqlBuilder insert = SqlBuilder.of(quoteWrapper).insert(entities[0], this.dialectName());
|
||||
final Set<String> fields = CollUtil.remove(entities[0].keySet(), StrUtil::isBlank);
|
||||
return StatementUtil.prepareStatementForBatch(conn, insert.build(), entities);
|
||||
}
|
||||
|
||||
@ -100,12 +99,12 @@ public class AnsiSqlDialect implements Dialect {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement psForFind(final Connection conn, final Query query) throws SQLException {
|
||||
public PreparedStatement psForFind(final Connection conn, final Query query) {
|
||||
return psForPage(conn, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement psForPage(final Connection conn, final Query query) throws SQLException {
|
||||
public PreparedStatement psForPage(final Connection conn, final Query query) {
|
||||
Assert.notNull(query, "query must be not null !");
|
||||
if (ArrayUtil.hasBlank(query.getTableNames())) {
|
||||
throw new DbRuntimeException("Table name must be not empty !");
|
||||
|
@ -29,6 +29,9 @@ import java.sql.SQLException;
|
||||
public class PhoenixDialect extends AnsiSqlDialect {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public PhoenixDialect() {
|
||||
// wrapper = new Wrapper('"');
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ import org.dromara.hutool.db.sql.QuoteWrapper;
|
||||
/**
|
||||
* SQLServer2012 方言
|
||||
*
|
||||
* @author loolly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class SqlServer2012Dialect extends AnsiSqlDialect {
|
||||
private static final long serialVersionUID = -37598166015777797L;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public SqlServer2012Dialect() {
|
||||
//双引号和中括号适用,双引号更广泛
|
||||
quoteWrapper = new QuoteWrapper('"');
|
||||
|
@ -17,12 +17,15 @@ import org.dromara.hutool.db.sql.QuoteWrapper;
|
||||
|
||||
/**
|
||||
* SqlLite3方言
|
||||
* @author loolly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class Sqlite3Dialect extends AnsiSqlDialect {
|
||||
private static final long serialVersionUID = -3527642408849291634L;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public Sqlite3Dialect() {
|
||||
quoteWrapper = new QuoteWrapper('[', ']');
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import org.dromara.hutool.core.collection.iter.ArrayIter;
|
||||
import org.dromara.hutool.core.convert.Convert;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.lang.builder.Builder;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.db.DbRuntimeException;
|
||||
import org.dromara.hutool.db.Entity;
|
||||
@ -27,6 +28,7 @@ import java.sql.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@link PreparedStatement}构建器,构建结果为{@link StatementWrapper}
|
||||
@ -137,6 +139,7 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
||||
try {
|
||||
ps = StatementWrapper.of(connection.prepareStatement(sql));
|
||||
final Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||
Set<String> keys = null;
|
||||
for (final Object params : paramsBatch) {
|
||||
if (null == params) {
|
||||
continue;
|
||||
@ -144,7 +147,14 @@ public class StatementBuilder implements Builder<StatementWrapper> {
|
||||
if (ArrayUtil.isArray(params)) {
|
||||
ps.fillParams(new ArrayIter<>(params), nullTypeMap);
|
||||
} else if (params instanceof Entity) {
|
||||
ps.fillParams(((Entity) params).values(), nullTypeMap);
|
||||
final Entity entity = (Entity) params;
|
||||
// 对于多Entity批量插入的情况,为防止数据不对齐,故按照首行提供键值对筛选。
|
||||
if(null == keys){
|
||||
keys = entity.keySet();
|
||||
ps.fillParams(entity.values(), nullTypeMap);
|
||||
} else{
|
||||
ps.fillParams(MapUtil.valuesOfKeys(entity, keys), nullTypeMap);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user