mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 15:28:20 +08:00
[0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。
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.3.10</version>
|
<version>0.3.11</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import cc.carm.lib.easysql.api.SQLAction;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Long>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定多组SQL语句中所有 ? 对应的参数
|
* 设定多组SQL语句中所有 ? 对应的参数
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.action;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
|
||||||
public interface SQLUpdateAction extends SQLAction<Integer> {
|
public interface SQLUpdateAction extends SQLAction<Long> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定自增主键的序列
|
* 设定自增主键的序列
|
||||||
|
|||||||
@@ -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.3.10</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
+1
-1
@@ -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.3.10</version>
|
<version>0.3.11</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PreparedSQLBatchUpdateActionImpl
|
public class PreparedSQLBatchUpdateActionImpl
|
||||||
extends AbstractSQLAction<List<Integer>>
|
extends AbstractSQLAction<List<Long>>
|
||||||
implements PreparedSQLUpdateBatchAction {
|
implements PreparedSQLUpdateBatchAction {
|
||||||
|
|
||||||
boolean returnKeys = false;
|
boolean returnKeys = false;
|
||||||
@@ -47,7 +47,7 @@ public class PreparedSQLBatchUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<Integer> execute() throws SQLException {
|
public @NotNull List<Long> execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
||||||
connection, getSQLContent(), allParams, returnKeys
|
connection, getSQLContent(), allParams, returnKeys
|
||||||
@@ -56,12 +56,13 @@ public class PreparedSQLBatchUpdateActionImpl
|
|||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
int[] executed = statement.executeBatch();
|
int[] executed = statement.executeBatch();
|
||||||
|
|
||||||
if (!returnKeys) return Arrays.stream(executed).boxed().collect(Collectors.toList());
|
if (!returnKeys) {
|
||||||
else {
|
return Arrays.stream(executed).mapToLong(Long::valueOf).boxed().collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||||
List<Integer> generatedKeys = new ArrayList<>();
|
List<Long> generatedKeys = new ArrayList<>();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
generatedKeys.add(resultSet.getInt(1));
|
generatedKeys.add(resultSet.getLong(1));
|
||||||
}
|
}
|
||||||
return generatedKeys;
|
return generatedKeys;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class PreparedSQLUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Integer execute() throws SQLException {
|
public @NotNull Long execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
|
|
||||||
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
|
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
|
||||||
@@ -62,10 +62,10 @@ public class PreparedSQLUpdateActionImpl
|
|||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
|
|
||||||
int changes = statement.executeUpdate();
|
int changes = statement.executeUpdate();
|
||||||
if (!returnGeneratedKeys) return changes;
|
if (!returnGeneratedKeys) return (long) changes;
|
||||||
else {
|
else {
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
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;
|
import java.sql.Statement;
|
||||||
|
|
||||||
public class SQLUpdateActionImpl
|
public class SQLUpdateActionImpl
|
||||||
extends AbstractSQLAction<Integer>
|
extends AbstractSQLAction<Long>
|
||||||
implements SQLUpdateAction {
|
implements SQLUpdateAction {
|
||||||
|
|
||||||
boolean returnGeneratedKeys = false;
|
boolean returnGeneratedKeys = false;
|
||||||
@@ -20,18 +20,18 @@ public class SQLUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Integer execute() throws SQLException {
|
public @NotNull Long execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = connection.createStatement()) {
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
|
|
||||||
if (!returnGeneratedKeys) {
|
if (!returnGeneratedKeys) {
|
||||||
return statement.executeUpdate(getSQLContent());
|
return (long) statement.executeUpdate(getSQLContent());
|
||||||
} else {
|
} else {
|
||||||
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||||
return resultSet.next() ? resultSet.getInt(1) : -1;
|
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,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.3.10</version>
|
<version>0.3.11</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>api</module>
|
<module>api</module>
|
||||||
|
|||||||
@@ -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.3.10</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</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.3.10</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
Reference in New Issue
Block a user