try-with-resource to prevent resource leaks

(cherry picked from commit 39f775c381)
(cherry picked from commit fc52e641d8)

Conflicts:
	engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java
This commit is contained in:
Daan Hoogland 2014-06-06 17:28:07 +02:00
parent 91489501f5
commit 3dc0a64b3e
1 changed files with 13 additions and 17 deletions

View File

@ -68,28 +68,25 @@ public class Upgrade430to440 implements DbUpgrade {
private void addExtractTemplateAndVolumeColumns(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
try (PreparedStatement selectTemplateInfostmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'template_store_ref' AND COLUMN_NAME = 'download_url_created'");
ResultSet templateInfoResults = selectTemplateInfostmt.executeQuery();
PreparedStatement addDownloadUrlCreatedToTemplateStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url_created` datetime");
PreparedStatement addDownloadUrlToTemplateStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url` varchar(255)");
PreparedStatement selectVolumeInfostmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'volume_store_ref' AND COLUMN_NAME = 'download_url_created'");
ResultSet volumeInfoResults = selectVolumeInfostmt.executeQuery();
PreparedStatement addDownloadUrlCreatedToVolumeStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`volume_store_ref` ADD COLUMN `download_url_created` datetime");
) {
// Add download_url_created, download_url to template_store_ref
pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'template_store_ref' AND COLUMN_NAME = 'download_url_created'");
rs = pstmt.executeQuery();
if (!rs.next()) {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url_created` datetime");
pstmt.executeUpdate();
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url` varchar(255)");
pstmt.executeUpdate();
if (!templateInfoResults.next()) {
addDownloadUrlCreatedToTemplateStorerefstatement.executeUpdate();
addDownloadUrlToTemplateStorerefstatement.executeUpdate();
}
// Add download_url_created to volume_store_ref - note download_url already exists
pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'volume_store_ref' AND COLUMN_NAME = 'download_url_created'");
rs = pstmt.executeQuery();
if (!rs.next()) {
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`volume_store_ref` ADD COLUMN `download_url_created` datetime");
pstmt.executeUpdate();
if (!volumeInfoResults.next()) {
addDownloadUrlCreatedToVolumeStorerefstatement.executeUpdate();
}
} catch (SQLException e) {
@ -97,7 +94,6 @@ public class Upgrade430to440 implements DbUpgrade {
}
}
private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn) {
String secondIpsSql = "SELECT id, vmId, network_id, account_id, domain_id, ip4_address FROM `cloud`.`nic_secondary_ips`";