09052029:对这个资产展示使用线程池的方法去做,第五次优化代码
parent
230606de1d
commit
6c2130678c
|
@ -178,9 +178,12 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
|||
|
||||
private int getTotalRecords(MysqlPool mysqlPool, String tableName) throws SQLException {
|
||||
try (Connection conn = mysqlPool.getConn();
|
||||
Statement statement = conn.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM " + tableName)) {
|
||||
if (resultSet.next()) {
|
||||
Statement statement = conn != null ? conn.createStatement() : null;
|
||||
ResultSet resultSet = statement != null ? statement.executeQuery("SELECT COUNT(*) FROM " + tableName) : null) {
|
||||
if (conn == null) {
|
||||
throw new SQLException("Failed to get database connection");
|
||||
}
|
||||
if (resultSet != null && resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
} else {
|
||||
throw new SQLException("Failed to get total record count");
|
||||
|
@ -192,8 +195,11 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
|||
List<DataValue> batchResults = new ArrayList<>();
|
||||
String query = "SELECT * FROM " + tableName + " LIMIT ? OFFSET ?";
|
||||
|
||||
try (Connection conn = mysqlPool.getConn();
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
|
||||
try (Connection conn = mysqlPool.getConn()) {
|
||||
if (conn == null) {
|
||||
throw new SQLException("Failed to get database connection");
|
||||
}
|
||||
try (PreparedStatement preparedStatement = conn.prepareStatement(query)) {
|
||||
preparedStatement.setInt(1, BATCH_SIZE);
|
||||
preparedStatement.setInt(2, offset);
|
||||
|
||||
|
@ -222,6 +228,7 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue