From 8d557815077d251abec140ee821b1f4df40ffe9a Mon Sep 17 00:00:00 2001 From: Long Ma Date: Thu, 6 Jul 2023 09:48:55 -0600 Subject: [PATCH] mssql test fixes --- .../jpa/embedded/MsSqlEmbeddedDatabase.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/embedded/MsSqlEmbeddedDatabase.java b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/embedded/MsSqlEmbeddedDatabase.java index 5dbe58e1bd8c..a75b7fbbdb50 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/embedded/MsSqlEmbeddedDatabase.java +++ b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/embedded/MsSqlEmbeddedDatabase.java @@ -20,6 +20,8 @@ package ca.uhn.fhir.jpa.embedded; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.MSSQLServerContainer; import org.testcontainers.utility.DockerImageName; @@ -34,6 +36,7 @@ * @see MS SQL Server TestContainer */ public class MsSqlEmbeddedDatabase extends JpaEmbeddedDatabase { + private static final Logger ourLog = LoggerFactory.getLogger(MsSqlEmbeddedDatabase.class); private final MSSQLServerContainer myContainer; @@ -70,8 +73,18 @@ private void dropForeignKeys() { private void dropRemainingConstraints() { List> queryResults = getJdbcTemplate().queryForList("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS"); for(Map row : queryResults){ - String tableName = row.get("TABLE_NAME").toString(); - String constraintName = row.get("CONSTRAINT_NAME").toString(); + Object tableNameEntry = row.get("TABLE_NAME"); + if (tableNameEntry == null) { + ourLog.warn("Found a constraint with no table name: {}", row); + continue; + } + String tableName = tableNameEntry.toString(); + Object constraintNameEntry = row.get("CONSTRAINT_NAME"); + if (constraintNameEntry == null) { + ourLog.warn("Found a constraint with no constraint name: {}", row); + continue; + } + String constraintName = constraintNameEntry.toString(); getJdbcTemplate().execute(String.format("ALTER TABLE \"%s\" DROP CONSTRAINT \"%s\"", tableName, constraintName)); } }