From 91f4e621481683b24bef031cc68a472ee9992274 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 11 Dec 2019 15:15:47 -0500 Subject: [PATCH] Oracle works yay! --- .../tasks/SchemaInitializationProvider.java | 19 +++++++++++----- .../SchemaInitializationProviderTest.java | 22 ++++++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java index 97a9efda396..4f481d20ae9 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java @@ -39,6 +39,10 @@ import static org.apache.commons.lang3.StringUtils.isBlank; public class SchemaInitializationProvider implements ISchemaInitializationProvider { private static final Pattern ourSqlCommentPattern = Pattern.compile("(?m)^\\s*--.*$"); + private static final Pattern ourQuartzDeletePattern = Pattern.compile("(?m)^delete from qrtz_\\w+;$"); + private static final Pattern ourQuartzDropPattern = Pattern.compile("(?m)^drop table qrtz_\\w+;$"); + + private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)"); private final String mySchemaFileClassPath; private final String mySchemaExistsIndicatorTable; @@ -63,12 +67,12 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid } // Assumes no escaped semicolons... String sqlString = IOUtils.toString(sqlFileInputStream, Charsets.UTF_8); - String sqlStringNoComments = stripComments(sqlString); + String sqlStringNoComments = preProcessLines(sqlString); String[] statements = sqlStringNoComments.split("\\;"); for (String statement : statements) { String cleanedStatement = clean(statement); if (!isBlank(cleanedStatement)) { - retval.add(cleanedStatement + ";"); + retval.add(cleanedStatement); } } } catch (IOException e) { @@ -77,11 +81,16 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid return retval; } - static String stripComments(String theSqlString) { - return ourSqlCommentPattern.matcher(theSqlString).replaceAll(""); + static String preProcessLines(String theSqlString) { + String pass1 = strip(ourSqlCommentPattern, theSqlString); + String pass2 = strip(ourQuartzDeletePattern, pass1); + String pass3 = strip(ourQuartzDropPattern, pass2); + return pass3.replaceAll("\\n+", "\n"); } - private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)"); + private static String strip(Pattern theStripPattern, String theSqlString) { + return theStripPattern.matcher(theSqlString).replaceAll(""); + } static String clean(String theStatement) { // Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute... diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProviderTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProviderTest.java index e143393e7c0..21b154183c4 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProviderTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProviderTest.java @@ -18,8 +18,24 @@ public class SchemaInitializationProviderTest { " --spacecomment \n" + "so like definitely no comment\n" + "-- nospace comment\n"; - String expectedOutput = "no comment\n\n" + - "so like definitely no comment\n\n"; - assertEquals(expectedOutput, SchemaInitializationProvider.stripComments(input)); + + String expectedOutput = "no comment\n" + + "so like definitely no comment\n"; + + assertEquals(expectedOutput, SchemaInitializationProvider.preProcessLines(input)); + } + + @Test + public void testStripQuartzDelete() { + String input = "delete from qrtz_paused_trigger_grps;\n" + + "delete from qrtz_locks;\n" + + "delete from qrtz_scheduler_state;\n" + + "\n" + + "drop table qrtz_calendars;\n" + + "drop table qrtz_fired_triggers;\n"; + + String expectedOutput = "\n"; + + assertEquals(expectedOutput, SchemaInitializationProvider.preProcessLines(input)); } }