mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 15:28:20 +08:00
[v0.2.2] 版本优化
- `[F]` 修复部分类的使用异常问题 - `[F]` 修复 SQLUpdateBatchAction 中 getSQLContent 方法返回内容不正确导致的其他方法一并出现异常的问题。 - `[U]` 修改 SQLUpdateBatchAction 的默认异常处理器。 - `[F]` 修复 PreparedSQLBatchUpdateActionImpl 异常继承导致的无法使用的问题。
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
+2
-2
@@ -12,10 +12,9 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl implements PreparedSQLUpdateBatchAction {
|
||||
public class PreparedSQLBatchUpdateActionImpl extends AbstractSQLAction<List<Integer>> implements PreparedSQLUpdateBatchAction {
|
||||
|
||||
int keyIndex = -1;
|
||||
List<Object[]> allParams;
|
||||
@@ -54,6 +53,7 @@ public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl i
|
||||
);
|
||||
outputDebugMessage();
|
||||
if (keyIndex > 0) {
|
||||
statement.executeBatch();
|
||||
List<Integer> generatedKeys = new ArrayList<>();
|
||||
ResultSet resultSet = statement.getGeneratedKeys();
|
||||
if (resultSet != null) {
|
||||
|
||||
+2
-1
@@ -59,13 +59,14 @@ public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements
|
||||
);
|
||||
outputDebugMessage();
|
||||
if (keyIndex > 0) {
|
||||
statement.executeUpdate();
|
||||
ResultSet resultSet = statement.getGeneratedKeys();
|
||||
if (resultSet != null) {
|
||||
if (resultSet.next()) value = resultSet.getInt(keyIndex);
|
||||
resultSet.close();
|
||||
}
|
||||
} else {
|
||||
value = statement.executeUpdate(getSQLContent());
|
||||
value = statement.executeUpdate();
|
||||
}
|
||||
|
||||
statement.close();
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SQLUpdateActionImpl extends AbstractSQLAction<Integer> implements SQLUpdateAction {
|
||||
|
||||
|
||||
@@ -23,9 +23,12 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
|
||||
|
||||
@Override
|
||||
public @NotNull String getSQLContent() {
|
||||
return this.sqlContents.stream()
|
||||
.map(content -> "[" + content + "]" + " ")
|
||||
.collect(Collectors.joining());
|
||||
return this.sqlContents.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> getSQLContents() {
|
||||
return this.sqlContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,5 +53,4 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
|
||||
|
||||
return returnedValues;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,9 +43,4 @@ public abstract class InsertBuilderImpl<T> extends AbstractSQLBuilder implements
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public InsertBuilderImpl<T> setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,4 @@ public abstract class ReplaceBuilderImpl<T> extends AbstractSQLBuilder implement
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public ReplaceBuilderImpl<T> setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -50,12 +50,6 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
||||
return new SQLUpdateActionImpl(getManager(), createSQL.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableCreateBuilder setTableName(@NotNull String tableName) {
|
||||
this.tableName = tableName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableCreateBuilder addColumn(@NotNull String column) {
|
||||
this.columns.add(column);
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ public class TableQueryBuilderImpl
|
||||
|
||||
@NotNull String tableName;
|
||||
|
||||
ArrayList<Object> params = new ArrayList<>();
|
||||
String[] columns;
|
||||
|
||||
@Nullable String orderBy;
|
||||
@@ -49,7 +48,7 @@ public class TableQueryBuilderImpl
|
||||
if (orderBy != null) sqlBuilder.append(orderBy);
|
||||
|
||||
return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
|
||||
.setParams(hasConditionParams() ? params : null);
|
||||
.setParams(hasConditionParams() ? getConditionParams() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package cc.carm.lib.easysql.util;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLAction;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.*;
|
||||
@@ -40,10 +38,9 @@ public class StatementUtil {
|
||||
) throws SQLException {
|
||||
sql = sql.trim();
|
||||
PreparedStatement statement = connection.prepareStatement(sql, returnGeneratedKey ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
|
||||
final Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||
if (params != null) {
|
||||
fillParams(statement, Arrays.asList(params), nullTypeMap);
|
||||
}
|
||||
Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||
if (params != null) fillParams(statement, Arrays.asList(params), nullTypeMap);
|
||||
statement.addBatch();
|
||||
return statement;
|
||||
}
|
||||
|
||||
@@ -76,7 +73,7 @@ public class StatementUtil {
|
||||
|
||||
sql = sql.trim();
|
||||
PreparedStatement statement = connection.prepareStatement(sql, returnGeneratedKey ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
|
||||
final Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||
Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||
for (Object[] params : paramsBatch) {
|
||||
fillParams(statement, Arrays.asList(params), nullTypeMap);
|
||||
statement.addBatch();
|
||||
|
||||
Reference in New Issue
Block a user