mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 07:18:23 +08:00
[0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PreparedSQLBatchUpdateActionImpl
|
||||
extends AbstractSQLAction<List<Integer>>
|
||||
extends AbstractSQLAction<List<Long>>
|
||||
implements PreparedSQLUpdateBatchAction {
|
||||
|
||||
boolean returnKeys = false;
|
||||
@@ -47,7 +47,7 @@ public class PreparedSQLBatchUpdateActionImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<Integer> execute() throws SQLException {
|
||||
public @NotNull List<Long> execute() throws SQLException {
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
||||
connection, getSQLContent(), allParams, returnKeys
|
||||
@@ -56,12 +56,13 @@ public class PreparedSQLBatchUpdateActionImpl
|
||||
outputDebugMessage();
|
||||
int[] executed = statement.executeBatch();
|
||||
|
||||
if (!returnKeys) return Arrays.stream(executed).boxed().collect(Collectors.toList());
|
||||
else {
|
||||
if (!returnKeys) {
|
||||
return Arrays.stream(executed).mapToLong(Long::valueOf).boxed().collect(Collectors.toList());
|
||||
} else {
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
List<Integer> generatedKeys = new ArrayList<>();
|
||||
List<Long> generatedKeys = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
generatedKeys.add(resultSet.getInt(1));
|
||||
generatedKeys.add(resultSet.getLong(1));
|
||||
}
|
||||
return generatedKeys;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PreparedSQLUpdateActionImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Integer execute() throws SQLException {
|
||||
public @NotNull Long execute() throws SQLException {
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
|
||||
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
|
||||
@@ -62,10 +62,10 @@ public class PreparedSQLUpdateActionImpl
|
||||
outputDebugMessage();
|
||||
|
||||
int changes = statement.executeUpdate();
|
||||
if (!returnGeneratedKeys) return changes;
|
||||
if (!returnGeneratedKeys) return (long) changes;
|
||||
else {
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
return resultSet.next() ? resultSet.getInt(1) : -1;
|
||||
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class SQLUpdateActionImpl
|
||||
extends AbstractSQLAction<Integer>
|
||||
extends AbstractSQLAction<Long>
|
||||
implements SQLUpdateAction {
|
||||
|
||||
boolean returnGeneratedKeys = false;
|
||||
@@ -20,18 +20,18 @@ public class SQLUpdateActionImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Integer execute() throws SQLException {
|
||||
public @NotNull Long execute() throws SQLException {
|
||||
try (Connection connection = getManager().getConnection()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
outputDebugMessage();
|
||||
|
||||
if (!returnGeneratedKeys) {
|
||||
return statement.executeUpdate(getSQLContent());
|
||||
return (long) statement.executeUpdate(getSQLContent());
|
||||
} else {
|
||||
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
return resultSet.next() ? resultSet.getInt(1) : -1;
|
||||
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user