mirror of
https://github.com/CarmJos/EasySQL.git
synced 2024-09-19 21:35:47 +00:00
[0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。
This commit is contained in:
parent
6ba58b540f
commit
fd0a4e48ef
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -4,7 +4,7 @@ import cc.carm.lib.easysql.api.SQLAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
||||
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Long>> {
|
||||
|
||||
/**
|
||||
* 设定多组SQL语句中所有 ? 对应的参数
|
||||
|
@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.action;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLAction;
|
||||
|
||||
public interface SQLUpdateAction extends SQLAction<Integer> {
|
||||
public interface SQLUpdateAction extends SQLAction<Long> {
|
||||
|
||||
/**
|
||||
* 设定自增主键的序列
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -17,7 +17,7 @@
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
|
||||
<modules>
|
||||
<module>api</module>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.3.10</version>
|
||||
<version>0.3.11</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
Loading…
Reference in New Issue
Block a user