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:
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ public interface SQLAction<T> {
|
|||||||
return (exception, action) -> {
|
return (exception, action) -> {
|
||||||
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
|
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
|
||||||
getManager().getLogger().severe(exception.getLocalizedMessage());
|
getManager().getLogger().severe(exception.getLocalizedMessage());
|
||||||
|
exception.printStackTrace();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package cc.carm.lib.easysql.api.action;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public interface SQLUpdateAction extends SQLAction<Integer> {
|
public interface SQLUpdateAction extends SQLAction<Integer> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,4 +27,6 @@ public interface SQLUpdateAction extends SQLAction<Integer> {
|
|||||||
return setKeyIndex(-1); // will return changed lines number
|
return setKeyIndex(-1); // will return changed lines number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package cc.carm.lib.easysql.api.action;
|
|||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
||||||
|
|
||||||
@@ -15,4 +17,20 @@ public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
|||||||
*/
|
*/
|
||||||
SQLUpdateBatchAction addBatch(@NotNull String sql);
|
SQLUpdateBatchAction addBatch(@NotNull String sql);
|
||||||
|
|
||||||
|
List<String> getSQLContents();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default BiConsumer<SQLException, SQLAction<List<Integer>>> defaultExceptionHandler() {
|
||||||
|
return (exception, action) -> {
|
||||||
|
getManager().getLogger().severe("Error when execute SQLs : ");
|
||||||
|
int i = 1;
|
||||||
|
for (String content : getSQLContents()) {
|
||||||
|
getManager().getLogger().severe("#" + i + " [" + content + "]");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
getManager().getLogger().severe(exception.getLocalizedMessage());
|
||||||
|
exception.printStackTrace();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public interface ConditionalBuilder<T> extends SQLBuilder {
|
|||||||
ConditionalBuilder<T> addCondition(@NotNull String[] queryNames, @Nullable Object[] queryValues);
|
ConditionalBuilder<T> addCondition(@NotNull String[] queryNames, @Nullable Object[] queryValues);
|
||||||
|
|
||||||
ConditionalBuilder<T> addNotNullCondition(@NotNull String queryName);
|
ConditionalBuilder<T> addNotNullCondition(@NotNull String queryName);
|
||||||
|
|
||||||
default ConditionalBuilder<T> addTimeCondition(@NotNull String queryName, long startMillis, long endMillis) {
|
default ConditionalBuilder<T> addTimeCondition(@NotNull String queryName, long startMillis, long endMillis) {
|
||||||
return addTimeCondition(queryName,
|
return addTimeCondition(queryName,
|
||||||
startMillis > 0 ? new Date(startMillis) : null,
|
startMillis > 0 ? new Date(startMillis) : null,
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ public interface InsertBuilder<T> {
|
|||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
InsertBuilder<T> setTableName(String tableName);
|
|
||||||
|
|
||||||
T setColumnNames(List<String> columnNames);
|
T setColumnNames(List<String> columnNames);
|
||||||
|
|
||||||
default T setColumnNames(String... columnNames) {
|
default T setColumnNames(String... columnNames) {
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ public interface ReplaceBuilder<T> {
|
|||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
ReplaceBuilder<T> setTableName(String tableName);
|
|
||||||
|
|
||||||
T setColumnNames(List<String> columnNames);
|
T setColumnNames(List<String> columnNames);
|
||||||
|
|
||||||
default T setColumnNames(String... columnNames) {
|
default T setColumnNames(String... columnNames) {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ public interface TableCreateBuilder extends SQLBuilder {
|
|||||||
|
|
||||||
@NotNull String getTableName();
|
@NotNull String getTableName();
|
||||||
|
|
||||||
TableCreateBuilder setTableName(@NotNull String tableName);
|
|
||||||
|
|
||||||
@NotNull String getTableSettings();
|
@NotNull String getTableSettings();
|
||||||
|
|
||||||
TableCreateBuilder setTableSettings(@NotNull String settings);
|
TableCreateBuilder setTableSettings(@NotNull String settings);
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
package cc.carm.lib.easysql.api.builder;
|
package cc.carm.lib.easysql.api.builder;
|
||||||
|
|
||||||
public interface UpsertBuilder {
|
public interface UpsertBuilder {
|
||||||
|
|
||||||
|
String getTableName();
|
||||||
|
|
||||||
|
UpsertBuilder setColumnNames(String[] columnNames, String updateColumn);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<!--项目地址 https://github.com/brettwooldridge/HikariCP/ -->
|
<!--项目地址 https://github.com/brettwooldridge/HikariCP/ -->
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>4.0.3</version>
|
<version>5.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -12,10 +12,9 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl implements PreparedSQLUpdateBatchAction {
|
public class PreparedSQLBatchUpdateActionImpl extends AbstractSQLAction<List<Integer>> implements PreparedSQLUpdateBatchAction {
|
||||||
|
|
||||||
int keyIndex = -1;
|
int keyIndex = -1;
|
||||||
List<Object[]> allParams;
|
List<Object[]> allParams;
|
||||||
@@ -54,6 +53,7 @@ public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl i
|
|||||||
);
|
);
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
if (keyIndex > 0) {
|
if (keyIndex > 0) {
|
||||||
|
statement.executeBatch();
|
||||||
List<Integer> generatedKeys = new ArrayList<>();
|
List<Integer> generatedKeys = new ArrayList<>();
|
||||||
ResultSet resultSet = statement.getGeneratedKeys();
|
ResultSet resultSet = statement.getGeneratedKeys();
|
||||||
if (resultSet != null) {
|
if (resultSet != null) {
|
||||||
|
|||||||
+2
-1
@@ -59,13 +59,14 @@ public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements
|
|||||||
);
|
);
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
if (keyIndex > 0) {
|
if (keyIndex > 0) {
|
||||||
|
statement.executeUpdate();
|
||||||
ResultSet resultSet = statement.getGeneratedKeys();
|
ResultSet resultSet = statement.getGeneratedKeys();
|
||||||
if (resultSet != null) {
|
if (resultSet != null) {
|
||||||
if (resultSet.next()) value = resultSet.getInt(keyIndex);
|
if (resultSet.next()) value = resultSet.getInt(keyIndex);
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = statement.executeUpdate(getSQLContent());
|
value = statement.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.sql.Connection;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class SQLUpdateActionImpl extends AbstractSQLAction<Integer> implements SQLUpdateAction {
|
public class SQLUpdateActionImpl extends AbstractSQLAction<Integer> implements SQLUpdateAction {
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,12 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getSQLContent() {
|
public @NotNull String getSQLContent() {
|
||||||
return this.sqlContents.stream()
|
return this.sqlContents.get(0);
|
||||||
.map(content -> "[" + content + "]" + " ")
|
}
|
||||||
.collect(Collectors.joining());
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> getSQLContents() {
|
||||||
|
return this.sqlContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,5 +53,4 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
|
|||||||
|
|
||||||
return returnedValues;
|
return returnedValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,4 @@ public abstract class InsertBuilderImpl<T> extends AbstractSQLBuilder implements
|
|||||||
public String getTableName() {
|
public String getTableName() {
|
||||||
return tableName;
|
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() {
|
public String getTableName() {
|
||||||
return tableName;
|
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());
|
return new SQLUpdateActionImpl(getManager(), createSQL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableCreateBuilder setTableName(@NotNull String tableName) {
|
|
||||||
this.tableName = tableName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableCreateBuilder addColumn(@NotNull String column) {
|
public TableCreateBuilder addColumn(@NotNull String column) {
|
||||||
this.columns.add(column);
|
this.columns.add(column);
|
||||||
|
|||||||
+1
-2
@@ -15,7 +15,6 @@ public class TableQueryBuilderImpl
|
|||||||
|
|
||||||
@NotNull String tableName;
|
@NotNull String tableName;
|
||||||
|
|
||||||
ArrayList<Object> params = new ArrayList<>();
|
|
||||||
String[] columns;
|
String[] columns;
|
||||||
|
|
||||||
@Nullable String orderBy;
|
@Nullable String orderBy;
|
||||||
@@ -49,7 +48,7 @@ public class TableQueryBuilderImpl
|
|||||||
if (orderBy != null) sqlBuilder.append(orderBy);
|
if (orderBy != null) sqlBuilder.append(orderBy);
|
||||||
|
|
||||||
return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
|
return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
|
||||||
.setParams(hasConditionParams() ? params : null);
|
.setParams(hasConditionParams() ? getConditionParams() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package cc.carm.lib.easysql.util;
|
package cc.carm.lib.easysql.util;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
@@ -40,10 +38,9 @@ public class StatementUtil {
|
|||||||
) throws SQLException {
|
) throws SQLException {
|
||||||
sql = sql.trim();
|
sql = sql.trim();
|
||||||
PreparedStatement statement = connection.prepareStatement(sql, returnGeneratedKey ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
|
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<>();
|
||||||
if (params != null) {
|
if (params != null) fillParams(statement, Arrays.asList(params), nullTypeMap);
|
||||||
fillParams(statement, Arrays.asList(params), nullTypeMap);
|
statement.addBatch();
|
||||||
}
|
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +73,7 @@ public class StatementUtil {
|
|||||||
|
|
||||||
sql = sql.trim();
|
sql = sql.trim();
|
||||||
PreparedStatement statement = connection.prepareStatement(sql, returnGeneratedKey ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
|
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) {
|
for (Object[] params : paramsBatch) {
|
||||||
fillParams(statement, Arrays.asList(params), nullTypeMap);
|
fillParams(statement, Arrays.asList(params), nullTypeMap);
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2-SNAPSHOT</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>easysql-api</module>
|
<module>easysql-api</module>
|
||||||
@@ -126,20 +126,20 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
|
||||||
<version>1.5</version>
|
<!-- <version>1.5</version>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<id>sign-artifacts</id>
|
<!-- <id>sign-artifacts</id>-->
|
||||||
<phase>verify</phase>
|
<!-- <phase>verify</phase>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>sign</goal>
|
<!-- <goal>sign</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
|||||||
Reference in New Issue
Block a user