generalize initialize schema interface
This commit is contained in:
parent
6ff1aaae61
commit
ea21b59fde
|
@ -31,8 +31,9 @@ public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
|
|||
DriverTypeEnum driverType = getDriverType();
|
||||
|
||||
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
|
||||
if (tableNames.contains("HFJ_RESOURCE")) {
|
||||
logInfo(ourLog, "The table HFJ_RESOURCE already exists. Skipping schema initialization for {}", driverType);
|
||||
String schemaExistsIndicatorTable = mySchemaInitializationProvider.getSchemaExistsIndicatorTable();
|
||||
if (tableNames.contains(schemaExistsIndicatorTable)) {
|
||||
logInfo(ourLog, "The table {} already exists. Skipping schema initialization for {}", schemaExistsIndicatorTable, driverType);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -867,7 +867,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
|||
private void init330() { // 20180114 - 20180329
|
||||
Builder version = forVersion(VersionEnum.V3_3_0);
|
||||
|
||||
version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database"));
|
||||
version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database", "HFJ_RESOURCE"));
|
||||
|
||||
Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE");
|
||||
version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName());
|
||||
|
|
|
@ -14,9 +14,16 @@ import java.util.List;
|
|||
|
||||
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
|
||||
private final String mySchemaFileClassPath;
|
||||
private final String mySchemaExistsIndicatorTable;
|
||||
|
||||
public SchemaInitializationProvider(String theSchemaFileClassPath) {
|
||||
/**
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public SchemaInitializationProvider(String theSchemaFileClassPath, String theSchemaExistsIndicatorTable) {
|
||||
mySchemaFileClassPath = theSchemaFileClassPath;
|
||||
mySchemaExistsIndicatorTable = theSchemaExistsIndicatorTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,4 +71,9 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
|
|||
.append(size())
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaExistsIndicatorTable() {
|
||||
return mySchemaExistsIndicatorTable;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ import java.util.List;
|
|||
|
||||
public interface ISchemaInitializationProvider {
|
||||
List<String> getSqlStatements(DriverTypeEnum theDriverType);
|
||||
|
||||
String getSchemaExistsIndicatorTable();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,11 @@ public class InitializeSchemaTaskTest extends BaseTest {
|
|||
return Collections.singletonList("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaExistsIndicatorTable() {
|
||||
return "DONT_MATCH_ME";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object theO) {
|
||||
if (this == theO) return true;
|
||||
|
|
Loading…
Reference in New Issue