diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java index 09ac6fe554f..7226ca79ed4 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java @@ -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`";