mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
More migrator updates
This commit is contained in:
parent
e425d19cf6
commit
9906243d2d
@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
@ -18,7 +16,6 @@ import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@ -77,13 +74,17 @@ public enum DriverTypeEnum {
|
||||
throw new InternalErrorException("Unable to find driver class: " + myDriverClassName, e);
|
||||
}
|
||||
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
// dataSource.setAutoCommit(false);
|
||||
BasicDataSource dataSource = new BasicDataSource(){
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
ourLog.info("Creating new DB connection");
|
||||
return super.getConnection();
|
||||
}
|
||||
};
|
||||
dataSource.setDriverClassName(myDriverClassName);
|
||||
dataSource.setUrl(theUrl);
|
||||
dataSource.setUsername(theUsername);
|
||||
dataSource.setPassword(thePassword);
|
||||
// dataSource.setSuppressClose(true);
|
||||
|
||||
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
|
||||
transactionManager.setDataSource(dataSource);
|
||||
|
@ -45,7 +45,7 @@ public class JdbcUtils {
|
||||
public static Set<String> getIndexNames(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName) throws SQLException {
|
||||
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
try {
|
||||
@ -67,13 +67,13 @@ public class JdbcUtils {
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static boolean isIndexUnique(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName) throws SQLException {
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
try {
|
||||
@ -94,7 +94,7 @@ public class JdbcUtils {
|
||||
|
||||
throw new InternalErrorException("Can't find index: " + theIndexName + " on table " + theTableName);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +153,7 @@ public class JdbcUtils {
|
||||
*/
|
||||
public static Set<String> getForeignKeys(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theForeignTable) throws SQLException {
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
try {
|
||||
@ -182,13 +182,14 @@ public class JdbcUtils {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all index names
|
||||
*/
|
||||
public static Set<String> getColumnNames(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName) throws SQLException {
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
try {
|
||||
@ -212,12 +213,12 @@ public class JdbcUtils {
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getTableNames(DriverTypeEnum.ConnectionProperties theConnectionProperties) throws SQLException {
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
try {
|
||||
@ -243,10 +244,11 @@ public class JdbcUtils {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isColumnNullable(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theColumnName) throws SQLException {
|
||||
DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
|
||||
Connection connection = dataSource.getConnection();
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
//noinspection ConstantConditions
|
||||
return theConnectionProperties.getTxTemplate().execute(t -> {
|
||||
DatabaseMetaData metadata;
|
||||
@ -277,6 +279,6 @@ public class JdbcUtils {
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +277,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
||||
Builder.BuilderWithTableName spp = version.onTable("HFJ_RES_PARAM_PRESENT");
|
||||
version.startSectionWithMessage("Starting work on table: " + spp.getTableName());
|
||||
spp.dropIndex("IDX_RESPARMPRESENT_SPID_RESID");
|
||||
spp.dropColumn("SP_ID");
|
||||
spp
|
||||
.addColumn("HASH_PRESENCE")
|
||||
.nullable()
|
||||
@ -307,6 +306,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
||||
});
|
||||
version.addTask(consolidateSearchParamPresenceIndexesTask);
|
||||
|
||||
// SP_ID is no longer needed
|
||||
spp.dropColumn("SP_ID");
|
||||
|
||||
// Concept
|
||||
Builder.BuilderWithTableName trmConcept = version.onTable("TRM_CONCEPT");
|
||||
version.startSectionWithMessage("Starting work on table: " + trmConcept.getTableName());
|
||||
|
Loading…
x
Reference in New Issue
Block a user