modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/ResourceAncestryUpgradeTask.java
| 25 ++++++++--
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
| 20 ++++----
2 files changed, 32 insertions(+), 13 deletions(-)
New commits:
commit aef7d20d1095ebcb89e1a9f3d6b3ab8293e1936a
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri Apr 29 16:47:21 2011 -0400
[BZ 700868 - RHQ3 ---> RHQ4 Upgrade error with Oracle]
More upgrade fixes, oracle-specific but postgres should retested now.
diff --git
a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/ResourceAncestryUpgradeTask.java
b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/ResourceAncestryUpgradeTask.java
index d07e09b..60727eb 100644
---
a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/ResourceAncestryUpgradeTask.java
+++
b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/ResourceAncestryUpgradeTask.java
@@ -18,6 +18,7 @@
*/
package org.rhq.core.db.upgrade;
+import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
@@ -50,8 +51,16 @@ public class ResourceAncestryUpgradeTask implements DatabaseUpgradeTask
{
+ " res.RESOURCE_TYPE_ID=rt.ID and
rt.CATEGORY='PLATFORM'";
List<Object[]> rs = databaseType.executeSelectSql(connection, sql);
for (Object[] result : rs) {
- int rtId = (Integer) result[0];
- int resId = (Integer) result[1];
+ int rtId;
+ int resId;
+
+ if (result[0] instanceof BigDecimal) {
+ rtId = ((BigDecimal) result[0]).intValue();
+ resId = ((BigDecimal) result[1]).intValue();
+ } else {
+ rtId = (Integer) result[0];
+ resId = (Integer) result[1];
+ }
String resName = (String) result[2];
handleChildren(rtId, resId, resName, null);
@@ -66,8 +75,16 @@ public class ResourceAncestryUpgradeTask implements DatabaseUpgradeTask
{
+ " res.RESOURCE_TYPE_ID=rt.ID and res.PARENT_RESOURCE_ID=" +
parentResId;
List<Object[]> rs = databaseType.executeSelectSql(connection, sql);
for (Object[] result : rs) {
- int rtId = (Integer) result[0];
- int resId = (Integer) result[1];
+ int rtId;
+ int resId;
+
+ if (result[0] instanceof BigDecimal) {
+ rtId = ((BigDecimal) result[0]).intValue();
+ resId = ((BigDecimal) result[1]).intValue();
+ } else {
+ rtId = (Integer) result[0];
+ resId = (Integer) result[1];
+ }
String resName = (String) result[2];
String ancestry = getAncestry(parentRtId, parentResId, parentResName,
parentAncestry);
String updateSql = "update RHQ_RESOURCE set ANCESTRY='" +
ancestry + "' where ID=" + resId;
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 57f82f0..a82c9bf 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -3288,10 +3288,14 @@
<!-- Finally, make ID the primary key, rather than (JOB_NAME,
JOB_GROUP), and make
(JOB_NAME, JOB_GROUP) a unique index instead. -->
<schema-directSQL>
- <statement desc="Changing primary key of
RHQ_OPERATION_SCHEDULE to ID...">
- ALTER TABLE RHQ_OPERATION_SCHEDULE DROP CONSTRAINT
RHQ_OPERATION_SCHEDULE_KEY;
- ALTER TABLE RHQ_OPERATION_SCHEDULE ADD PRIMARY KEY (ID);
- CREATE UNIQUE INDEX RHQ_OPERATION_SCHEDULE_KEY_IDX ON
RHQ_OPERATION_SCHEDULE (JOB_NAME, JOB_GROUP);
+ <statement desc="Changing primary key of
RHQ_OPERATION_SCHEDULE to ID. Step1/3...">
+ ALTER TABLE RHQ_OPERATION_SCHEDULE DROP CONSTRAINT
RHQ_OPERATION_SCHEDULE_KEY
+ </statement>
+ <statement desc="Changing primary key of
RHQ_OPERATION_SCHEDULE to ID. Step2/3...">
+ ALTER TABLE RHQ_OPERATION_SCHEDULE ADD PRIMARY KEY (ID)
+ </statement>
+ <statement desc="Changing primary key of
RHQ_OPERATION_SCHEDULE to ID. Step3/3...">
+ CREATE UNIQUE INDEX RHQ_OPERATION_SCHEDULE_KEY_IDX ON
RHQ_OPERATION_SCHEDULE (JOB_NAME, JOB_GROUP)
</statement>
</schema-directSQL>
</schemaSpec>
@@ -3350,15 +3354,13 @@
<schema-addColumn table="RHQ_REPO"
column="IS_PRIVATE" columnType="BOOLEAN" />
<schema-directSQL>
<statement targetDBVendor="postgresql" desc="Set
is_private flag for existing repos to false">
- UPDATE RHQ_REPO
- SET IS_PRIVATE = false
+ UPDATE RHQ_REPO SET IS_PRIVATE = false
</statement>
<statement targetDBVendor="oracle" desc="Set
is_private flag for existing repos to false">
- UPDATE RHQ_REPO
- SET IS_PRIVATE = 0
+ UPDATE RHQ_REPO SET IS_PRIVATE = 0
</statement>
</schema-directSQL>
- <schema-alterColumn table="RHQ_REPO"
column="IS_PRIVATE" nullable="FALSE" default="TRUE"/>
+ <schema-alterColumn table="RHQ_REPO"
column="IS_PRIVATE" nullable="FALSE"/>
<schema-directSQL>
<statement desc="Creating OWNER_ID foreign key relation on
RHQ_REPO">
ALTER TABLE RHQ_REPO