mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-28 00:59:14 +00:00
move quartz stuff out
This commit is contained in:
parent
91f4e62148
commit
83106c92c1
@ -32,17 +32,11 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
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 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;
|
||||||
|
|
||||||
@ -67,10 +61,10 @@ 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 = preProcessLines(sqlString);
|
String sqlStringNoComments = preProcessSqlString(theDriverType, sqlString);
|
||||||
String[] statements = sqlStringNoComments.split("\\;");
|
String[] statements = sqlStringNoComments.split("\\;");
|
||||||
for (String statement : statements) {
|
for (String statement : statements) {
|
||||||
String cleanedStatement = clean(statement);
|
String cleanedStatement = preProcessSqlStatement(theDriverType, statement);
|
||||||
if (!isBlank(cleanedStatement)) {
|
if (!isBlank(cleanedStatement)) {
|
||||||
retval.add(cleanedStatement);
|
retval.add(cleanedStatement);
|
||||||
}
|
}
|
||||||
@ -81,21 +75,12 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String preProcessLines(String theSqlString) {
|
protected String preProcessSqlString(DriverTypeEnum theDriverType, String sqlString) {
|
||||||
String pass1 = strip(ourSqlCommentPattern, theSqlString);
|
return sqlString;
|
||||||
String pass2 = strip(ourQuartzDeletePattern, pass1);
|
|
||||||
String pass3 = strip(ourQuartzDropPattern, pass2);
|
|
||||||
return pass3.replaceAll("\\n+", "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String strip(Pattern theStripPattern, String theSqlString) {
|
protected String preProcessSqlStatement(DriverTypeEnum theDriverType, String sqlStatement) {
|
||||||
return theStripPattern.matcher(theSqlString).replaceAll("");
|
return sqlStatement;
|
||||||
}
|
|
||||||
|
|
||||||
static String clean(String theStatement) {
|
|
||||||
// Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute...
|
|
||||||
Matcher matcher = ourTrailingCommaPattern.matcher(theStatement);
|
|
||||||
return matcher.replaceAll("$1\\)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package ca.uhn.fhir.jpa.migrate.tasks;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class SchemaInitializationProviderTest {
|
|
||||||
@Test
|
|
||||||
public void testClean() {
|
|
||||||
assertEquals("foo\n)", SchemaInitializationProvider.clean("foo,\n)"));
|
|
||||||
assertEquals("foo\n )", SchemaInitializationProvider.clean("foo,\n )"));
|
|
||||||
assertEquals("foo,bar\n )", SchemaInitializationProvider.clean("foo,bar\n )"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStripComments() {
|
|
||||||
String input = "no comment\n" +
|
|
||||||
" --spacecomment \n" +
|
|
||||||
"so like definitely no comment\n" +
|
|
||||||
"-- nospace comment\n";
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user