Change default DB dialects

This commit is contained in:
Martin Bartoš 2023-03-14 18:51:35 +01:00 committed by Václav Muzikář
parent 8fb7fb0de9
commit 8584174099
7 changed files with 91 additions and 59 deletions

View file

@ -170,9 +170,9 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
String dataSource = config.get("dataSource"); String dataSource = config.get("dataSource");
if (dataSource != null) { if (dataSource != null) {
if (config.getBoolean("jta", jtaEnabled)) { if (config.getBoolean("jta", jtaEnabled)) {
properties.put(AvailableSettings.JPA_JTA_DATASOURCE, dataSource); properties.put(AvailableSettings.JAKARTA_JTA_DATASOURCE, dataSource);
} else { } else {
properties.put(AvailableSettings.JPA_NON_JTA_DATASOURCE, dataSource); properties.put(AvailableSettings.JAKARTA_NON_JTA_DATASOURCE, dataSource);
} }
} else { } else {
String url = config.get("url"); String url = config.get("url");
@ -180,16 +180,16 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
if (driver.equals("org.h2.Driver")) { if (driver.equals("org.h2.Driver")) {
url = addH2NonKeywords(url); url = addH2NonKeywords(url);
} }
properties.put(AvailableSettings.JPA_JDBC_URL, url); properties.put(AvailableSettings.JAKARTA_JDBC_URL, url);
properties.put(AvailableSettings.JPA_JDBC_DRIVER, driver); properties.put(AvailableSettings.JAKARTA_JDBC_DRIVER, driver);
String user = config.get("user"); String user = config.get("user");
if (user != null) { if (user != null) {
properties.put(AvailableSettings.JPA_JDBC_USER, user); properties.put(AvailableSettings.JAKARTA_JDBC_USER, user);
} }
String password = config.get("password"); String password = config.get("password");
if (password != null) { if (password != null) {
properties.put(AvailableSettings.JPA_JDBC_PASSWORD, password); properties.put(AvailableSettings.JAKARTA_JDBC_PASSWORD, password);
} }
} }

View file

@ -123,7 +123,7 @@ public final class Database {
Enabled.LEGACY_ONLY, Enabled.LEGACY_ONLY,
"org.h2.jdbcx.JdbcDataSource", "org.h2.jdbcx.JdbcDataSource",
"org.h2.Driver", "org.h2.Driver",
"io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect", "org.hibernate.dialect.H2Dialect",
new Function<String, String>() { new Function<String, String>() {
@Override @Override
public String apply(String alias) { public String apply(String alias) {
@ -170,7 +170,7 @@ public final class Database {
Enabled.LEGACY_ONLY, Enabled.LEGACY_ONLY,
"com.mysql.cj.jdbc.MysqlXADataSource", "com.mysql.cj.jdbc.MysqlXADataSource",
"com.mysql.cj.jdbc.Driver", "com.mysql.cj.jdbc.Driver",
"org.hibernate.dialect.MySQL8Dialect", "org.hibernate.dialect.MySQLDialect",
"jdbc:mysql://${kc.db-url-host:localhost}:${kc.db-url-port:3306}/${kc.db-url-database:keycloak}${kc.db-url-properties:}", "jdbc:mysql://${kc.db-url-host:localhost}:${kc.db-url-port:3306}/${kc.db-url-database:keycloak}${kc.db-url-properties:}",
asList("org.keycloak.connections.jpa.updater.liquibase.UpdatedMySqlDatabase") asList("org.keycloak.connections.jpa.updater.liquibase.UpdatedMySqlDatabase")
), ),
@ -186,7 +186,7 @@ public final class Database {
Enabled.ENABLED, Enabled.ENABLED,
"org.postgresql.xa.PGXADataSource", "org.postgresql.xa.PGXADataSource",
"org.postgresql.Driver", "org.postgresql.Driver",
"io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect", "org.hibernate.dialect.PostgreSQLDialect",
"jdbc:postgresql://${kc.db-url-host:localhost}:${kc.db-url-port:5432}/${kc.db-url-database:keycloak}${kc.db-url-properties:}", "jdbc:postgresql://${kc.db-url-host:localhost}:${kc.db-url-port:5432}/${kc.db-url-database:keycloak}${kc.db-url-properties:}",
asList("liquibase.database.core.PostgresDatabase", "org.keycloak.connections.jpa.updater.liquibase.PostgresPlusDatabase"), asList("liquibase.database.core.PostgresDatabase", "org.keycloak.connections.jpa.updater.liquibase.PostgresPlusDatabase"),
"postgres" "postgres"
@ -204,7 +204,7 @@ public final class Database {
Enabled.LEGACY_ONLY, Enabled.LEGACY_ONLY,
"com.microsoft.sqlserver.jdbc.SQLServerXADataSource", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource",
"com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"org.hibernate.dialect.SQLServer2016Dialect", "org.hibernate.dialect.SQLServerDialect",
"jdbc:sqlserver://${kc.db-url-host:localhost}:${kc.db-url-port:1433};databaseName=${kc.db-url-database:keycloak}${kc.db-url-properties:}", "jdbc:sqlserver://${kc.db-url-host:localhost}:${kc.db-url-port:1433};databaseName=${kc.db-url-database:keycloak}${kc.db-url-properties:}",
asList("org.keycloak.quarkus.runtime.storage.database.liquibase.database.CustomMSSQLDatabase"), asList("org.keycloak.quarkus.runtime.storage.database.liquibase.database.CustomMSSQLDatabase"),
"mssql" "mssql"
@ -213,7 +213,7 @@ public final class Database {
Enabled.LEGACY_ONLY, Enabled.LEGACY_ONLY,
"oracle.jdbc.xa.client.OracleXADataSource", "oracle.jdbc.xa.client.OracleXADataSource",
"oracle.jdbc.driver.OracleDriver", "oracle.jdbc.driver.OracleDriver",
"org.hibernate.dialect.Oracle12cDialect", "org.hibernate.dialect.OracleDialect",
"jdbc:oracle:thin:@//${kc.db-url-host:localhost}:${kc.db-url-port:1521}/${kc.db-url-database:keycloak}", "jdbc:oracle:thin:@//${kc.db-url-host:localhost}:${kc.db-url-port:1521}/${kc.db-url-database:keycloak}",
asList("liquibase.database.core.OracleDatabase") asList("liquibase.database.core.OracleDatabase")
); );

View file

@ -63,8 +63,10 @@ import org.keycloak.authorization.policy.provider.js.DeployedScriptPolicyFactory
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.common.crypto.FipsMode; import org.keycloak.common.crypto.FipsMode;
import org.keycloak.common.util.StreamUtil; import org.keycloak.common.util.StreamUtil;
import org.keycloak.config.DatabaseOptions;
import org.keycloak.config.SecurityOptions; import org.keycloak.config.SecurityOptions;
import org.keycloak.config.StorageOptions; import org.keycloak.config.StorageOptions;
import org.keycloak.config.TransactionOptions;
import org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory; import org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory;
import org.keycloak.connections.jpa.JpaConnectionProvider; import org.keycloak.connections.jpa.JpaConnectionProvider;
import org.keycloak.connections.jpa.JpaConnectionSpi; import org.keycloak.connections.jpa.JpaConnectionSpi;
@ -142,7 +144,10 @@ import static org.keycloak.quarkus.runtime.Environment.getProviderFiles;
import static org.keycloak.quarkus.runtime.KeycloakRecorder.DEFAULT_HEALTH_ENDPOINT; import static org.keycloak.quarkus.runtime.KeycloakRecorder.DEFAULT_HEALTH_ENDPOINT;
import static org.keycloak.quarkus.runtime.KeycloakRecorder.DEFAULT_METRICS_ENDPOINT; import static org.keycloak.quarkus.runtime.KeycloakRecorder.DEFAULT_METRICS_ENDPOINT;
import static org.keycloak.quarkus.runtime.Providers.getProviderManager; import static org.keycloak.quarkus.runtime.Providers.getProviderManager;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getConfig; import static org.keycloak.quarkus.runtime.configuration.Configuration.getKcConfigValue;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getOptionalKcBooleanValue;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getOptionalKcValue;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getOptionalValue;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getPropertyNames; import static org.keycloak.quarkus.runtime.configuration.Configuration.getPropertyNames;
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX; import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_QUARKUS; import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_QUARKUS;
@ -302,20 +307,24 @@ class KeycloakProcessor {
Properties unitProperties = descriptor.getProperties(); Properties unitProperties = descriptor.getProperties();
unitProperties.setProperty(AvailableSettings.DIALECT, config.defaultPersistenceUnit.dialect.dialect.orElse(null)); final Optional<String> dialect = getOptionalKcValue(DatabaseOptions.DB_DIALECT.getKey());
if (Objects.equals(getConfig().getConfigValue("kc.transaction-jta-enabled").getValue(), "disabled")) { dialect.ifPresent(d -> unitProperties.setProperty(AvailableSettings.DIALECT, d));
unitProperties.setProperty(AvailableSettings.JPA_TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());
final Optional<String> defaultSchema = getOptionalKcValue(DatabaseOptions.DB_SCHEMA.getKey());
defaultSchema.ifPresent(ds -> unitProperties.setProperty(AvailableSettings.DEFAULT_SCHEMA, ds));
final Optional<Boolean> transactionJtaEnabled = getOptionalKcBooleanValue(TransactionOptions.TRANSACTION_JTA_ENABLED.getKey());
if (transactionJtaEnabled.isPresent() && !transactionJtaEnabled.get()) {
unitProperties.setProperty(AvailableSettings.JAKARTA_TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());
} else { } else {
// will happen for both "enabled" and "xa" // will happen for both "enabled" and "xa"
unitProperties.setProperty(AvailableSettings.JPA_TRANSACTION_TYPE, PersistenceUnitTransactionType.JTA.name()); unitProperties.setProperty(AvailableSettings.JAKARTA_TRANSACTION_TYPE, PersistenceUnitTransactionType.JTA.name());
} }
ConfigValue lockTimeoutConfigValue = getConfig().getConfigValue("kc.spi-map-storage-jpa-lock-timeout"); final Optional<String> lockTimeoutConfigValue = getOptionalValue("spi-map-storage-jpa-lock-timeout");
if (lockTimeoutConfigValue != null && lockTimeoutConfigValue.getValue() != null) { lockTimeoutConfigValue.ifPresent(v -> unitProperties.setProperty(AvailableSettings.JAKARTA_LOCK_TIMEOUT, v));
unitProperties.setProperty(AvailableSettings.JPA_LOCK_TIMEOUT, lockTimeoutConfigValue.getValue());
}
ConfigValue storage = getConfig().getConfigValue(NS_KEYCLOAK_PREFIX.concat(StorageOptions.STORAGE.getKey())); final ConfigValue storage = getKcConfigValue(StorageOptions.STORAGE.getKey());
if (storage != null && Objects.equals(storage.getValue(), StorageOptions.StorageType.jpa.name())) { if (storage != null && Objects.equals(storage.getValue(), StorageOptions.StorageType.jpa.name())) {
// if JPA map storage is enabled, pass on the property to 'EventListenerIntegrator' to activate the necessary event listeners for JPA map storage // if JPA map storage is enabled, pass on the property to 'EventListenerIntegrator' to activate the necessary event listeners for JPA map storage
unitProperties.setProperty(EventListenerIntegrator.JPA_MAP_STORAGE_ENABLED, Boolean.TRUE.toString()); unitProperties.setProperty(EventListenerIntegrator.JPA_MAP_STORAGE_ENABLED, Boolean.TRUE.toString());
@ -571,13 +580,13 @@ class KeycloakProcessor {
if (isHealthEnabled()) { if (isHealthEnabled()) {
ignoredPaths.add(nonApplicationRootPathBuildItem. ignoredPaths.add(nonApplicationRootPathBuildItem.
resolvePath(Configuration.getOptionalValue(QUARKUS_HEALTH_ROOT_PROPERTY) resolvePath(getOptionalValue(QUARKUS_HEALTH_ROOT_PROPERTY)
.orElse(QUARKUS_DEFAULT_HEALTH_PATH))); .orElse(QUARKUS_DEFAULT_HEALTH_PATH)));
} }
if (isMetricsEnabled()) { if (isMetricsEnabled()) {
ignoredPaths.add(nonApplicationRootPathBuildItem. ignoredPaths.add(nonApplicationRootPathBuildItem.
resolvePath(Configuration.getOptionalValue(QUARKUS_METRICS_PATH_PROPERTY) resolvePath(getOptionalValue(QUARKUS_METRICS_PATH_PROPERTY)
.orElse(QUARKUS_DEFAULT_METRICS_PATH))); .orElse(QUARKUS_DEFAULT_METRICS_PATH)));
} }
@ -629,7 +638,7 @@ class KeycloakProcessor {
@BuildStep @BuildStep
@Record(ExecutionTime.STATIC_INIT) @Record(ExecutionTime.STATIC_INIT)
void setCryptoProvider(KeycloakRecorder recorder) { void setCryptoProvider(KeycloakRecorder recorder) {
FipsMode fipsMode = Configuration.getOptionalValue(NS_KEYCLOAK_PREFIX + SecurityOptions.FIPS_MODE.getKey()) FipsMode fipsMode = getOptionalValue(NS_KEYCLOAK_PREFIX + SecurityOptions.FIPS_MODE.getKey())
.map(FipsMode::valueOfOption) .map(FipsMode::valueOfOption)
.orElse(FipsMode.DISABLED); .orElse(FipsMode.DISABLED);
if (Profile.isFeatureEnabled(Profile.Feature.FIPS) && !fipsMode.isFipsEnabled()) { if (Profile.isFeatureEnabled(Profile.Feature.FIPS) && !fipsMode.isFipsEnabled()) {

View file

@ -21,7 +21,6 @@ import static org.keycloak.quarkus.runtime.Environment.getProfileOrDefault;
import static org.keycloak.quarkus.runtime.cli.Picocli.ARG_PREFIX; import static org.keycloak.quarkus.runtime.cli.Picocli.ARG_PREFIX;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function;
import io.smallrye.config.ConfigValue; import io.smallrye.config.ConfigValue;
import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfig;
@ -32,6 +31,8 @@ import org.keycloak.quarkus.runtime.Environment;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper; import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers; import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers;
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;
/** /**
* The entry point for accessing the server configuration * The entry point for accessing the server configuration
*/ */
@ -73,7 +74,13 @@ public final class Configuration {
} }
public static String getRawValue(String propertyName) { public static String getRawValue(String propertyName) {
return getConfig().getRawValue(propertyName); try {
return getConfig().getRawValue(propertyName);
} catch (NullPointerException ignore) {
// Tracker issue: https://github.com/keycloak/keycloak/issues/19084
// Try-catch block can be removed once https://github.com/smallrye/smallrye-config/issues/906 is resolved
return null;
}
} }
public static Iterable<String> getPropertyNames() { public static Iterable<String> getPropertyNames() {
@ -81,20 +88,39 @@ public final class Configuration {
} }
public static ConfigValue getConfigValue(String propertyName) { public static ConfigValue getConfigValue(String propertyName) {
return getConfig().getConfigValue(propertyName); try {
return getConfig().getConfigValue(propertyName);
} catch (NullPointerException ignore) {
// Tracker issue: https://github.com/keycloak/keycloak/issues/19084
// Try-catch block can be removed once https://github.com/smallrye/smallrye-config/issues/906 is resolved
return null;
}
}
public static ConfigValue getKcConfigValue(String propertyName) {
return getConfigValue(NS_KEYCLOAK_PREFIX.concat(propertyName));
} }
public static Optional<String> getOptionalValue(String name) { public static Optional<String> getOptionalValue(String name) {
return getConfig().getOptionalValue(name, String.class); try {
return getConfig().getOptionalValue(name, String.class);
} catch (NullPointerException ignore) {
// Tracker issue: https://github.com/keycloak/keycloak/issues/19084
// Try-catch block can be removed once https://github.com/smallrye/smallrye-config/issues/906 is resolved
return Optional.empty();
}
}
public static Optional<String> getOptionalKcValue(String propertyName) {
return getOptionalValue(NS_KEYCLOAK_PREFIX.concat(propertyName));
} }
public static Optional<Boolean> getOptionalBooleanValue(String name) { public static Optional<Boolean> getOptionalBooleanValue(String name) {
return getConfig().getOptionalValue(name, String.class).map(new Function<String, Boolean>() { return getOptionalValue(name).map(Boolean::parseBoolean);
@Override }
public Boolean apply(String s) {
return Boolean.parseBoolean(s); public static Optional<Boolean> getOptionalKcBooleanValue(String name) {
} return getOptionalBooleanValue(NS_KEYCLOAK_PREFIX.concat(name));
});
} }
public static String getMappedPropertyName(String key) { public static String getMappedPropertyName(String key) {

View file

@ -27,7 +27,6 @@ final class DatabasePropertyMappers {
return new PropertyMapper[] { return new PropertyMapper[] {
fromOption(DatabaseOptions.DB_DIALECT) fromOption(DatabaseOptions.DB_DIALECT)
.mapFrom("db") .mapFrom("db")
.to("quarkus.hibernate-orm.dialect")
.transformer(DatabasePropertyMappers::transformDialect) .transformer(DatabasePropertyMappers::transformDialect)
.build(), .build(),
fromOption(DatabaseOptions.DB_DRIVER) fromOption(DatabaseOptions.DB_DRIVER)
@ -78,7 +77,6 @@ final class DatabasePropertyMappers {
.isMasked(true) .isMasked(true)
.build(), .build(),
fromOption(DatabaseOptions.DB_SCHEMA) fromOption(DatabaseOptions.DB_SCHEMA)
.to("quarkus.hibernate-orm.database.default-schema")
.paramLabel("schema") .paramLabel("schema")
.build(), .build(),
fromOption(DatabaseOptions.DB_POOL_INITIAL_SIZE) fromOption(DatabaseOptions.DB_POOL_INITIAL_SIZE)

View file

@ -28,8 +28,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect; import org.hibernate.dialect.H2Dialect;
import io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect; import org.hibernate.dialect.PostgreSQLDialect;
import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.LaunchMode;
import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfig;
import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.ConfigProvider;
@ -49,7 +49,6 @@ import org.keycloak.quarkus.runtime.Environment;
import org.keycloak.quarkus.runtime.vault.FilesPlainTextVaultProviderFactory; import org.keycloak.quarkus.runtime.vault.FilesPlainTextVaultProviderFactory;
import org.mariadb.jdbc.MariaDbDataSource; import org.mariadb.jdbc.MariaDbDataSource;
import org.postgresql.xa.PGXADataSource; import org.postgresql.xa.PGXADataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
public class ConfigurationTest { public class ConfigurationTest {
@ -235,7 +234,7 @@ public class ConfigurationTest {
public void testPropertyMapping() { public void testPropertyMapping() {
System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak"); System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
} }
@ -243,7 +242,7 @@ public class ConfigurationTest {
public void testDatabaseUrlProperties() { public void testDatabaseUrlProperties() {
System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb:aurora://foo/bar?a=1&b=2"); System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb:aurora://foo/bar?a=1&b=2");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:mariadb:aurora://foo/bar?a=1&b=2", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:mariadb:aurora://foo/bar?a=1&b=2", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
} }
@ -251,12 +250,12 @@ public class ConfigurationTest {
public void testDatabaseDefaults() { public void testDatabaseDefaults() {
System.setProperty(CLI_ARGS, "--db=dev-file"); System.setProperty(CLI_ARGS, "--db=dev-file");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:h2:file:" + System.getProperty("user.home") + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;AUTO_SERVER=TRUE;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:h2:file:" + System.getProperty("user.home") + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;AUTO_SERVER=TRUE;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
System.setProperty(CLI_ARGS, "--db=dev-mem"); System.setProperty(CLI_ARGS, "--db=dev-mem");
config = createConfig(); config = createConfig();
assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:h2:mem:keycloakdb;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:h2:mem:keycloakdb;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("h2", config.getConfigValue("quarkus.datasource.db-kind").getValue()); assertEquals("h2", config.getConfigValue("quarkus.datasource.db-kind").getValue());
@ -277,8 +276,8 @@ public class ConfigurationTest {
public void testDatabaseKindProperties() { public void testDatabaseKindProperties() {
System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url=jdbc:postgresql://localhost/keycloak"); System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url=jdbc:postgresql://localhost/keycloak");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect", assertEquals("org.hibernate.dialect.PostgreSQLDialect",
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:postgresql://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:postgresql://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue()); assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue());
} }
@ -287,8 +286,8 @@ public class ConfigurationTest {
public void testDefaultDbPropertiesGetApplied() { public void testDefaultDbPropertiesGetApplied() {
System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-properties=?foo=bar"); System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-properties=?foo=bar");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect", assertEquals("org.hibernate.dialect.PostgreSQLDialect",
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:postgresql://myhost:5432/kcdb?foo=bar", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:postgresql://myhost:5432/kcdb?foo=bar", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue()); assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue());
} }
@ -297,8 +296,8 @@ public class ConfigurationTest {
public void testRemoveSpaceFromValue() { public void testRemoveSpaceFromValue() {
System.setProperty(CLI_ARGS, "--db=postgres "); System.setProperty(CLI_ARGS, "--db=postgres ");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect", assertEquals("org.hibernate.dialect.PostgreSQLDialect",
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); config.getConfigValue("kc.db-dialect").getValue());
assertEquals("postgres", config.getConfigValue("quarkus.datasource.db-kind").getRawValue()); assertEquals("postgres", config.getConfigValue("quarkus.datasource.db-kind").getRawValue());
} }
@ -306,8 +305,8 @@ public class ConfigurationTest {
public void testDefaultDbPortGetApplied() { public void testDefaultDbPortGetApplied() {
System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-port=1234" + ARG_SEPARATOR + "--db-url-properties=?foo=bar"); System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-port=1234" + ARG_SEPARATOR + "--db-url-properties=?foo=bar");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals("org.hibernate.dialect.SQLServer2016Dialect", assertEquals("org.hibernate.dialect.SQLServerDialect",
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:sqlserver://myhost:1234;databaseName=kcdb?foo=bar", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:sqlserver://myhost:1234;databaseName=kcdb?foo=bar", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("mssql", config.getConfigValue("quarkus.datasource.db-kind").getValue()); assertEquals("mssql", config.getConfigValue("quarkus.datasource.db-kind").getValue());
} }
@ -317,7 +316,7 @@ public class ConfigurationTest {
System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak"); System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals("org.hibernate.dialect.MariaDBDialect", assertEquals("org.hibernate.dialect.MariaDBDialect",
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("mariadb", config.getConfigValue("quarkus.datasource.db-kind").getValue()); assertEquals("mariadb", config.getConfigValue("quarkus.datasource.db-kind").getValue());
} }
@ -328,32 +327,32 @@ public class ConfigurationTest {
System.setProperty("kc.db-url-path", "test-dir"); System.setProperty("kc.db-url-path", "test-dir");
System.setProperty(CLI_ARGS, "--db=dev-file"); System.setProperty(CLI_ARGS, "--db=dev-file");
SmallRyeConfig config = createConfig(); SmallRyeConfig config = createConfig();
assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals("xa", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue()); assertEquals("xa", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
System.setProperty(CLI_ARGS, ""); System.setProperty(CLI_ARGS, "");
config = createConfig(); config = createConfig();
assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
System.setProperty("kc.db-url-properties", "?test=test&test1=test1"); System.setProperty("kc.db-url-properties", "?test=test&test1=test1");
System.setProperty(CLI_ARGS, "--db=mariadb"); System.setProperty(CLI_ARGS, "--db=mariadb");
config = createConfig(); config = createConfig();
assertEquals("jdbc:mariadb://localhost:3306/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:mariadb://localhost:3306/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals(MariaDbDataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue()); assertEquals(MariaDbDataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
System.setProperty(CLI_ARGS, "--db=postgres"); System.setProperty(CLI_ARGS, "--db=postgres");
config = createConfig(); config = createConfig();
assertEquals("jdbc:postgresql://localhost:5432/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("jdbc:postgresql://localhost:5432/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
assertEquals(QuarkusPostgreSQL10Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); assertEquals(PostgreSQLDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals(PGXADataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue()); assertEquals(PGXADataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
System.setProperty(CLI_ARGS, "--db-schema=test-schema"); System.setProperty(CLI_ARGS, "--db-schema=test-schema");
config = createConfig(); config = createConfig();
assertEquals("test-schema", config.getConfigValue("kc.db-schema").getValue()); assertEquals("test-schema", config.getConfigValue("kc.db-schema").getValue());
assertEquals("test-schema", config.getConfigValue("quarkus.hibernate-orm.database.default-schema").getValue()); assertEquals("test-schema", config.getConfigValue("kc.db-schema").getValue());
} }
// KEYCLOAK-15632 // KEYCLOAK-15632
@ -426,7 +425,7 @@ public class ConfigurationTest {
@Test @Test
public void testDatabaseDialectSetExplicitly() { public void testDatabaseDialectSetExplicitly() {
System.setProperty(CLI_ARGS, "--db-dialect=user-defined"); System.setProperty(CLI_ARGS, "--db-dialect=user-defined");
assertEquals("user-defined", createConfig().getRawValue("quarkus.hibernate-orm.dialect")); assertEquals("user-defined", createConfig().getRawValue("kc.db-dialect"));
} }
@Test @Test

View file

@ -23,7 +23,7 @@
<persistence-unit name="user-store" transaction-type="JTA"> <persistence-unit name="user-store" transaction-type="JTA">
<class>com.acme.provider.legacy.jpa.entity.Realm</class> <class>com.acme.provider.legacy.jpa.entity.Realm</class>
<properties> <properties>
<property name="hibernate.dialect" value="io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect" /> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<!-- Sets the name of the datasource to be the same as the datasource name in quarkus.properties--> <!-- Sets the name of the datasource to be the same as the datasource name in quarkus.properties-->
<property name="hibernate.connection.datasource" value="user-store" /> <property name="hibernate.connection.datasource" value="user-store" />
<property name="jakarta.persistence.transactionType" value="JTA" /> <property name="jakarta.persistence.transactionType" value="JTA" />