From 6012bc4c56b7fee73c41082634c4bbfb28f82bf4 Mon Sep 17 00:00:00 2001 From: Mike G Date: Thu, 3 Sep 2020 00:56:12 -0400 Subject: [PATCH 1/5] add getters and modify some setters to return a reference to itself --- .../ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java index e47787244a8..a9a4720d788 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java @@ -60,6 +60,14 @@ public abstract class BaseTask { mySchemaVersion = theSchemaVersion; } + public String getMyProductVersion() { + return myProductVersion; + } + + public String getMySchemaVersion() { + return mySchemaVersion; + } + public boolean isNoColumnShrink() { return myNoColumnShrink; } @@ -137,16 +145,18 @@ public abstract class BaseTask { return myConnectionProperties; } - public void setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) { + public BaseTask setConnectionProperties(DriverTypeEnum.ConnectionProperties theConnectionProperties) { myConnectionProperties = theConnectionProperties; + return this; } public DriverTypeEnum getDriverType() { return myDriverType; } - public void setDriverType(DriverTypeEnum theDriverType) { + public BaseTask setDriverType(DriverTypeEnum theDriverType) { myDriverType = theDriverType; + return this; } public abstract void validate(); From 60c03c429b9225bd1791bf4e1caf42d6c1bfa268 Mon Sep 17 00:00:00 2001 From: Mike G Date: Thu, 3 Sep 2020 00:57:32 -0400 Subject: [PATCH 2/5] add constraint dropping when dropping index in case of unique --- .../java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java index 2e04e4416a6..c04f6e22672 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java @@ -86,9 +86,13 @@ public class DropIndexTask extends BaseTableTask { @Language("SQL") String findConstraintSql = "SELECT DISTINCT constraint_name FROM user_cons_columns WHERE constraint_name = ? AND table_name = ?"; @Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?"; findAndDropConstraint(findConstraintSql, dropConstraintSql); - findConstraintSql = "SELECT DISTINCT constraint_name FROM all_constraints WHERE index_name = ? AND table_name = ?"; findAndDropConstraint(findConstraintSql, dropConstraintSql); + } else if (getDriverType() == DriverTypeEnum.MSSQL_2012) { + // Legacy deletion for SQL Server unique indexes + @Language("SQL") String findConstraintSql = "SELECT tc.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc WHERE tc.CONSTRAINT_NAME = ? AND tc.TABLE_NAME = ?"; + @Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?"; + findAndDropConstraint(findConstraintSql, dropConstraintSql); } Set indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName()); From faab5670956c5371d5abce2da53d05f8669d2b84 Mon Sep 17 00:00:00 2001 From: Mike G Date: Thu, 3 Sep 2020 00:58:49 -0400 Subject: [PATCH 3/5] replace fetching of query strings with running of tasks --- .../fhir/jpa/migrate/taskdef/DropTableTask.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java index 3d9eb3b4fcf..480a80cfda4 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java @@ -63,14 +63,15 @@ public class DropTableTask extends BaseTableTask { } } + DropIndexTask theIndexTask = new DropIndexTask(getMyProductVersion(), getMySchemaVersion()); + theIndexTask + .setTableName(getTableName()) + .setConnectionProperties(getConnectionProperties()) + .setDriverType(getDriverType()); for (String nextIndex : indexNames) { - List sqls = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType()); - if (!sqls.isEmpty()) { - logInfo(ourLog, "Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName()); - } - for (@Language("SQL") String sql : sqls) { - executeSql(getTableName(), sql); - } + theIndexTask + .setIndexName(nextIndex) + .execute(); } logInfo(ourLog, "Dropping table: {}", getTableName()); From 1de1ebb794b71408e1f126d4f3629f339316214d Mon Sep 17 00:00:00 2001 From: Mike G Date: Thu, 3 Sep 2020 10:15:07 -0400 Subject: [PATCH 4/5] rename getters --- .../main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java index a9a4720d788..d7d430f746c 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java @@ -60,11 +60,11 @@ public abstract class BaseTask { mySchemaVersion = theSchemaVersion; } - public String getMyProductVersion() { + public String getProductVersion() { return myProductVersion; } - public String getMySchemaVersion() { + public String getSchemaVersion() { return mySchemaVersion; } From 8167a0c509db43f4aa2074b7c6be4f6aea723b33 Mon Sep 17 00:00:00 2001 From: Mike G Date: Thu, 3 Sep 2020 10:15:55 -0400 Subject: [PATCH 5/5] use new getters --- .../java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java index 480a80cfda4..3f2bf48f0f2 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java @@ -63,7 +63,7 @@ public class DropTableTask extends BaseTableTask { } } - DropIndexTask theIndexTask = new DropIndexTask(getMyProductVersion(), getMySchemaVersion()); + DropIndexTask theIndexTask = new DropIndexTask(getProductVersion(), getSchemaVersion()); theIndexTask .setTableName(getTableName()) .setConnectionProperties(getConnectionProperties())