name schema initializer to distinguish between different schemas

This commit is contained in:
Ken Stevens 2019-11-28 12:10:34 -05:00
parent bf003f0d16
commit a58da3b535
5 changed files with 21 additions and 6 deletions

View File

@ -39,7 +39,7 @@ public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
public InitializeSchemaTask(String theProductVersion, String theSchemaVersion, ISchemaInitializationProvider theSchemaInitializationProvider) { public InitializeSchemaTask(String theProductVersion, String theSchemaVersion, ISchemaInitializationProvider theSchemaInitializationProvider) {
super(theProductVersion, theSchemaVersion); super(theProductVersion, theSchemaVersion);
mySchemaInitializationProvider = theSchemaInitializationProvider; mySchemaInitializationProvider = theSchemaInitializationProvider;
setDescription("Initialize schema"); setDescription("Initialize schema for " + theSchemaInitializationProvider.getDescription());
} }
@Override @Override

View File

@ -875,7 +875,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
private void init330() { // 20180114 - 20180329 private void init330() { // 20180114 - 20180329
Builder version = forVersion(VersionEnum.V3_3_0); Builder version = forVersion(VersionEnum.V3_3_0);
version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database", "HFJ_RESOURCE")); version.initializeSchema("20180115.0", new SchemaInitializationProvider("HAPI-FHIR", "/ca/uhn/hapi/fhir/jpa/docs/database", "HFJ_RESOURCE"));
Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE"); Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE");
version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName()); version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName());

View File

@ -38,15 +38,17 @@ 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 ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)"); private final String mySchemaDescription;
private final String mySchemaFileClassPath; private final String mySchemaFileClassPath;
private final String mySchemaExistsIndicatorTable; private final String mySchemaExistsIndicatorTable;
/** /**
* @param theSchemaDescription description of the schema being updated (for logging)
* @param theSchemaFileClassPath pathname to script used to initialize schema * @param theSchemaFileClassPath pathname to script used to initialize schema
* @param theSchemaExistsIndicatorTable a table name we can use to determine if this schema has already been initialized * @param theSchemaExistsIndicatorTable a table name we can use to determine if this schema has already been initialized
*/ */
public SchemaInitializationProvider(String theSchemaFileClassPath, String theSchemaExistsIndicatorTable) { public SchemaInitializationProvider(String theSchemaDescription, String theSchemaFileClassPath, String theSchemaExistsIndicatorTable) {
mySchemaDescription = theSchemaDescription;
mySchemaFileClassPath = theSchemaFileClassPath; mySchemaFileClassPath = theSchemaFileClassPath;
mySchemaExistsIndicatorTable = theSchemaExistsIndicatorTable; mySchemaExistsIndicatorTable = theSchemaExistsIndicatorTable;
} }
@ -75,13 +77,19 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
return retval; return retval;
} }
private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)");
static String clean(String theStatement) { static String clean(String theStatement) {
// Remove commas before brackets. Some databases don't like this and // Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute...
// some schemas shipped with Quartz include them
Matcher matcher = ourTrailingCommaPattern.matcher(theStatement); Matcher matcher = ourTrailingCommaPattern.matcher(theStatement);
return matcher.replaceAll("$1\\)"); return matcher.replaceAll("$1\\)");
} }
@Override
public String getDescription() {
return mySchemaDescription;
}
@Nonnull @Nonnull
protected String getInitScript(DriverTypeEnum theDriverType) { protected String getInitScript(DriverTypeEnum theDriverType) {
return theDriverType.getSchemaFilename(); return theDriverType.getSchemaFilename();

View File

@ -28,4 +28,6 @@ public interface ISchemaInitializationProvider {
List<String> getSqlStatements(DriverTypeEnum theDriverType); List<String> getSqlStatements(DriverTypeEnum theDriverType);
String getSchemaExistsIndicatorTable(); String getSchemaExistsIndicatorTable();
String getDescription();
} }

View File

@ -40,6 +40,11 @@ public class InitializeSchemaTaskTest extends BaseTest {
return "DONT_MATCH_ME"; return "DONT_MATCH_ME";
} }
@Override
public String getDescription() {
return "test";
}
@Override @Override
public boolean equals(Object theO) { public boolean equals(Object theO) {
if (this == theO) return true; if (this == theO) return true;