From 16989227d9e1ea57add8085cfaf535ad771a17c9 Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 7 Oct 2011 10:58:19 -0700 Subject: [PATCH] bug 11667: drop primary keys in cloud_usage.usage_load_balancer_policy and cloud_usage.usage_port_forwarding status 11667: resolved fixed --- .../com/cloud/upgrade/dao/DbUpgradeUtils.java | 19 +++++++++++++++++++ .../cloud/upgrade/dao/Upgrade2212to2213.java | 3 +++ .../com/cloud/user/AccountManagerImpl.java | 2 +- setup/db/create-schema-premium.sql | 6 ++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/DbUpgradeUtils.java b/server/src/com/cloud/upgrade/dao/DbUpgradeUtils.java index e61174a3ca0..e355f4ef696 100644 --- a/server/src/com/cloud/upgrade/dao/DbUpgradeUtils.java +++ b/server/src/com/cloud/upgrade/dao/DbUpgradeUtils.java @@ -39,6 +39,25 @@ public class DbUpgradeUtils { } + public static void dropPrimaryKeyIfExists(Connection conn, String tableName) { + PreparedStatement pstmt = null; + try { + pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " DROP PRIMARY KEY "); + pstmt.executeUpdate(); + s_logger.debug("Primary key is dropped successfully from the table " + tableName); + } catch (SQLException e) { + // do nothing here + } finally { + try { + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + + public static void dropTableColumnsIfExist(Connection conn, String tableName, List columns) { PreparedStatement pstmt = null; try { diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2212to2213.java b/server/src/com/cloud/upgrade/dao/Upgrade2212to2213.java index 3be561dbc68..e4200ba373a 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade2212to2213.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2212to2213.java @@ -89,5 +89,8 @@ public class Upgrade2212to2213 implements DbUpgrade { } + // drop primary keys + DbUpgradeUtils.dropPrimaryKeyIfExists(conn, "cloud_usage.usage_load_balancer_policy"); + DbUpgradeUtils.dropPrimaryKeyIfExists(conn, "cloud_usage.usage_port_forwarding"); } } diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index c5355701a40..5d88b4130da 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -489,7 +489,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag if (domainId != null) { sc.setParameters("domainId", domainId); - sc.setParameters("accountId", null); + sc.setParameters("accountId", (Object[])null); } if (resourceType != null) { diff --git a/setup/db/create-schema-premium.sql b/setup/db/create-schema-premium.sql index e663ed8844e..83aa7a45140 100644 --- a/setup/db/create-schema-premium.sql +++ b/setup/db/create-schema-premium.sql @@ -203,8 +203,7 @@ CREATE TABLE `cloud_usage`.`usage_load_balancer_policy` ( `account_id` bigint unsigned NOT NULL, `domain_id` bigint unsigned NOT NULL, `created` DATETIME NOT NULL, - `deleted` DATETIME NULL, - PRIMARY KEY (`id`) + `deleted` DATETIME NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `cloud_usage`.`usage_load_balancer_policy` ADD INDEX `i_usage_load_balancer_policy__account_id`(`account_id`); @@ -235,8 +234,7 @@ CREATE TABLE `cloud_usage`.`usage_port_forwarding` ( `account_id` bigint unsigned NOT NULL, `domain_id` bigint unsigned NOT NULL, `created` DATETIME NOT NULL, - `deleted` DATETIME NULL, - PRIMARY KEY (`id`) + `deleted` DATETIME NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `cloud_usage`.`usage_port_forwarding` ADD INDEX `i_usage_port_forwarding__account_id`(`account_id`);