Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: remove code dependencies on hsqldb #3194

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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
Expand Down
Loading