diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/util/beans/DbUtils.java b/server/src/main/java/org/cloudfoundry/identity/uaa/util/beans/DbUtils.java index d19d144e516..2f825598983 100644 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/util/beans/DbUtils.java +++ b/server/src/main/java/org/cloudfoundry/identity/uaa/util/beans/DbUtils.java @@ -1,7 +1,6 @@ package org.cloudfoundry.identity.uaa.util.beans; import org.cloudfoundry.identity.uaa.error.UaaDBException; -import org.hsqldb.persist.HsqlDatabaseProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.JdbcTemplate; @@ -77,23 +76,19 @@ public synchronized String getQuotedIdentifier(String identifier, JdbcTemplate j } private QuoteCharacter computeQuoteCharacter(JdbcTemplate jdbcTemplate) throws SQLException { - DatabaseMetaData metaData; try { - metaData = metaDataExtractor.extractDatabaseMetaData( - jdbcTemplate.getDataSource() - ); + var metaData = metaDataExtractor.extractDatabaseMetaData(jdbcTemplate.getDataSource()); + if (metaData.getURL().startsWith("jdbc:hsqldb:")) { + // HSQL's databasemetadata's getIdentifierQuoteString returns double quotes, which is incorrect + // So we override with the value that actually works with HSQL db + return QuoteCharacter.NONE; + } + return QuoteCharacter.valueOf(getIdentifierQuoteChar(metaData)); } catch (MetaDataAccessException ex) { s_logger.error("Failed to extract DatabaseMetaData, aborting"); throw new UaaDBException("Failed to extract DatabaseMetaData", ex); } - if (HsqlDatabaseProperties.PRODUCT_NAME.equals(metaData.getDatabaseProductName())) { - // HSQL's databasemetadata's getIdentifierQuoteString returns double quotes, which is incorrect - // So we override with the value that actually works with HSQL db - return QuoteCharacter.NONE; - } else { - return QuoteCharacter.valueOf(getIdentifierQuoteChar(metaData)); - } } private static char getIdentifierQuoteChar(DatabaseMetaData metaData) throws SQLException { diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/util/beans/DbUtilsTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/util/beans/DbUtilsTest.java index 52db3a07c6d..25916594a3e 100644 --- a/server/src/test/java/org/cloudfoundry/identity/uaa/util/beans/DbUtilsTest.java +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/util/beans/DbUtilsTest.java @@ -1,6 +1,5 @@ package org.cloudfoundry.identity.uaa.util.beans; -import org.hsqldb.persist.HsqlDatabaseProperties; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; @@ -34,7 +33,7 @@ void setup() throws MetaDataAccessException { @Test void canQuoteHsqldbIdentifiers() throws SQLException { - when(databaseMetaData.getDatabaseProductName()).thenReturn(HsqlDatabaseProperties.PRODUCT_NAME); + when(databaseMetaData.getURL()).thenReturn("jdbc:hsqldb:mem:uaa"); String quotedIdentifier = dbUtils.getQuotedIdentifier(IDENTIFIER_NAME, jdbcTemplate); @@ -43,8 +42,8 @@ void canQuoteHsqldbIdentifiers() throws SQLException { @Test void canCacheForHsqldb() throws SQLException { - when(databaseMetaData.getDatabaseProductName()) - .thenReturn(HsqlDatabaseProperties.PRODUCT_NAME, "SHOULD NOT SEE THIS"); + when(databaseMetaData.getURL()) + .thenReturn("jdbc:hsqldb:mem:uaa", "SHOULD NOT SEE THIS"); dbUtils.getQuotedIdentifier(IDENTIFIER_NAME, jdbcTemplate); String subsequentQuotedIdentifier = dbUtils.getQuotedIdentifier(IDENTIFIER_NAME, jdbcTemplate); @@ -57,8 +56,8 @@ void canCacheForHsqldb() throws SQLException { class nonHsqldbTests { @BeforeEach void setup() throws SQLException { - when(databaseMetaData.getDatabaseProductName()) - .thenReturn("Anything but" + HsqlDatabaseProperties.PRODUCT_NAME); + when(databaseMetaData.getURL()) + .thenReturn("Anything but the h-s-q-l-d-b"); } @Test