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