Oracle works yay!

This commit is contained in:
Ken Stevens 2019-12-11 15:15:47 -05:00
parent 7cc690ffd3
commit 91f4e62148
2 changed files with 33 additions and 8 deletions

View File

@ -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...

View File

@ -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));
}
}