CLOUDSTACK-8923: Create storage network IP range failed

transaction.getConnection() was wrapped in try-with-resource.
This caused transaction to get closed even before its committed.
This commit is contained in:
Rajani Karuturi 2015-10-15 15:03:31 +05:30
parent 2ce5a0c964
commit 79b7391c22
1 changed files with 12 additions and 13 deletions

View File

@ -104,20 +104,19 @@ public class StorageNetworkManagerImpl extends ManagerBase implements StorageNet
String insertSql =
"INSERT INTO `cloud`.`op_dc_storage_network_ip_address` (range_id, ip_address, mac_address, taken) VALUES (?, ?, (select mac_address from `cloud`.`data_center` where id=?), ?)";
String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
try (Connection conn = txn.getConnection();) {
while (startIPLong <= endIPLong) {
try (PreparedStatement stmt_insert = conn.prepareStatement(insertSql); ) {
stmt_insert.setLong(1, rangeId);
stmt_insert.setString(2, NetUtils.long2Ip(startIPLong++));
stmt_insert.setLong(3, zoneId);
stmt_insert.setNull(4, java.sql.Types.DATE);
stmt_insert.executeUpdate();
}
Connection conn = txn.getConnection();
while (startIPLong <= endIPLong) {
try (PreparedStatement stmt_insert = conn.prepareStatement(insertSql);) {
stmt_insert.setLong(1, rangeId);
stmt_insert.setString(2, NetUtils.long2Ip(startIPLong++));
stmt_insert.setLong(3, zoneId);
stmt_insert.setNull(4, java.sql.Types.DATE);
stmt_insert.executeUpdate();
}
try (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
stmt_update.setLong(1, zoneId);
stmt_update.executeUpdate();
}
try (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
stmt_update.setLong(1, zoneId);
stmt_update.executeUpdate();
}
}
}