Oracle works yay!
This commit is contained in:
parent
7cc690ffd3
commit
91f4e62148
|
@ -39,6 +39,10 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
|
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
|
||||||
private static final Pattern ourSqlCommentPattern = Pattern.compile("(?m)^\\s*--.*$");
|
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 mySchemaFileClassPath;
|
||||||
private final String mySchemaExistsIndicatorTable;
|
private final String mySchemaExistsIndicatorTable;
|
||||||
|
|
||||||
|
@ -63,12 +67,12 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
|
||||||
}
|
}
|
||||||
// Assumes no escaped semicolons...
|
// Assumes no escaped semicolons...
|
||||||
String sqlString = IOUtils.toString(sqlFileInputStream, Charsets.UTF_8);
|
String sqlString = IOUtils.toString(sqlFileInputStream, Charsets.UTF_8);
|
||||||
String sqlStringNoComments = stripComments(sqlString);
|
String sqlStringNoComments = preProcessLines(sqlString);
|
||||||
String[] statements = sqlStringNoComments.split("\\;");
|
String[] statements = sqlStringNoComments.split("\\;");
|
||||||
for (String statement : statements) {
|
for (String statement : statements) {
|
||||||
String cleanedStatement = clean(statement);
|
String cleanedStatement = clean(statement);
|
||||||
if (!isBlank(cleanedStatement)) {
|
if (!isBlank(cleanedStatement)) {
|
||||||
retval.add(cleanedStatement + ";");
|
retval.add(cleanedStatement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -77,11 +81,16 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String stripComments(String theSqlString) {
|
static String preProcessLines(String theSqlString) {
|
||||||
return ourSqlCommentPattern.matcher(theSqlString).replaceAll("");
|
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) {
|
static String clean(String theStatement) {
|
||||||
// Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute...
|
// Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute...
|
||||||
|
|
|
@ -18,8 +18,24 @@ public class SchemaInitializationProviderTest {
|
||||||
" --spacecomment \n" +
|
" --spacecomment \n" +
|
||||||
"so like definitely no comment\n" +
|
"so like definitely no comment\n" +
|
||||||
"-- nospace comment\n";
|
"-- nospace comment\n";
|
||||||
String expectedOutput = "no comment\n\n" +
|
|
||||||
"so like definitely no comment\n\n";
|
String expectedOutput = "no comment\n" +
|
||||||
assertEquals(expectedOutput, SchemaInitializationProvider.stripComments(input));
|
"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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue