Msg.code()

This commit is contained in:
Ken Stevens 2022-09-18 15:24:57 -04:00
parent 240a22ccd7
commit c6f89fdd05
2 changed files with 7 additions and 19 deletions

View File

@ -25,7 +25,7 @@ public final class Msg {
/**
* IMPORTANT: Please update the following comment after you add a new code
* Last used code value: 2140
* Last used code value: 2141
*/
private Msg() {}

View File

@ -1,7 +1,6 @@
package ca.uhn.fhir.jpa.migrate.dao;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.migrate.SchemaMigrator;
import ca.uhn.fhir.jpa.migrate.entity.HapiMigrationEntity;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.util.VersionEnum;
@ -17,9 +16,7 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
@ -76,7 +73,7 @@ public class HapiMigrationDao {
}
public void createMigrationTableIfRequired() {
if (getTableNames().contains(myMigrationTablename)) {
if (migrationTableExists()) {
return;
}
ourLog.info("Creating table {}", myMigrationTablename);
@ -85,33 +82,24 @@ public class HapiMigrationDao {
myJdbcTemplate.execute(createTableStatement);
}
private Set<String> getTableNames() {
private boolean migrationTableExists() {
try {
try (Connection connection = myDataSource.getConnection()) {
DatabaseMetaData metadata;
metadata = connection.getMetaData();
ResultSet tables = metadata.getTables(connection.getCatalog(), connection.getSchema(), null, null);
Set<String> columnNames = new HashSet<>();
while (tables.next()) {
String tableName = tables.getString("TABLE_NAME");
tableName = tableName.toUpperCase(Locale.US);
String tableType = tables.getString("TABLE_TYPE");
if ("SYSTEM TABLE".equalsIgnoreCase(tableType)) {
continue;
if (myMigrationTablename.equalsIgnoreCase(tableName)) {
return true;
}
if (SchemaMigrator.HAPI_FHIR_MIGRATION_TABLENAME.equalsIgnoreCase(tableName)) {
continue;
}
columnNames.add(tableName);
}
return columnNames;
return false;
}
} catch (SQLException e) {
throw new InternalErrorException(Msg.code(40) + e);
throw new InternalErrorException(Msg.code(2141) + e);
}
}
}