KEYCLOAK-18378 cannot configure Agroal ExceptionSorter correctly
This commit is contained in:
parent
c1cf306b92
commit
ead667aaac
3 changed files with 53 additions and 25 deletions
|
@ -47,6 +47,16 @@ public class Database {
|
|||
return DATABASES.containsKey(alias);
|
||||
}
|
||||
|
||||
static Optional<String> getDatabaseKind(String alias) {
|
||||
Vendor vendor = DATABASES.get(alias);
|
||||
|
||||
if (vendor == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(vendor.databaseKind);
|
||||
}
|
||||
|
||||
static Optional<String> getDefaultUrl(String alias) {
|
||||
Vendor vendor = DATABASES.get(alias);
|
||||
|
||||
|
@ -78,23 +88,27 @@ public class Database {
|
|||
}
|
||||
|
||||
private enum Vendor {
|
||||
H2("org.h2.jdbcx.JdbcDataSource", "io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect",
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String alias) {
|
||||
if ("h2-file".equalsIgnoreCase(alias)) {
|
||||
return "jdbc:h2:file:${kc.home.dir:${kc.db.url.path:~}}" + File.separator + "${kc.data.dir:data}" + File.separator + "keycloakdb${kc.db.url.properties:;;AUTO_SERVER=TRUE}";
|
||||
}
|
||||
return "jdbc:h2:mem:keycloakdb${kc.db.url.properties:}";
|
||||
H2("h2", "org.h2.jdbcx.JdbcDataSource", "io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect",
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String alias) {
|
||||
if ("h2-file".equalsIgnoreCase(alias)) {
|
||||
return "jdbc:h2:file:${kc.home.dir:${kc.db.url.path:~}}" + File.separator + "${kc.data.dir:data}"
|
||||
+ File.separator + "keycloakdb${kc.db.url.properties:;;AUTO_SERVER=TRUE}";
|
||||
}
|
||||
}, "h2-mem", "h2-file", H2Database.class.getName()),
|
||||
MYSQL("com.mysql.cj.jdbc.MysqlXADataSource", "org.hibernate.dialect.MySQL8Dialect",
|
||||
"jdbc:mysql://${kc.db.url.host:localhost}/${kc.db.url.database:keycloak}${kc.db.url.properties:}",
|
||||
UpdatedMySqlDatabase.class.getName()),
|
||||
MARIADB("org.mariadb.jdbc.MySQLDataSource", "org.hibernate.dialect.MariaDBDialect",
|
||||
"jdbc:mariadb://${kc.db.url.host:localhost}/${kc.db.url.database:keycloak}${kc.db.url.properties:}",
|
||||
UpdatedMariaDBDatabase.class.getName()),
|
||||
POSTGRES("org.postgresql.xa.PGXADataSource", new Function<String, String>() {
|
||||
return "jdbc:h2:mem:keycloakdb${kc.db.url.properties:}";
|
||||
}
|
||||
}, "h2-mem", "h2-file", H2Database.class
|
||||
.getName()),
|
||||
MYSQL("mysql", "com.mysql.cj.jdbc.MysqlXADataSource", "org.hibernate.dialect.MySQL8Dialect",
|
||||
"jdbc:mysql://${kc.db.url.host:localhost}/${kc.db.url.database:keycloak}${kc.db.url.properties:}",
|
||||
UpdatedMySqlDatabase.class
|
||||
.getName()),
|
||||
MARIADB("mariadb", "org.mariadb.jdbc.MySQLDataSource", "org.hibernate.dialect.MariaDBDialect",
|
||||
"jdbc:mariadb://${kc.db.url.host:localhost}/${kc.db.url.database:keycloak}${kc.db.url.properties:}",
|
||||
UpdatedMariaDBDatabase.class
|
||||
.getName()),
|
||||
POSTGRES("postgresql", "org.postgresql.xa.PGXADataSource", new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String alias) {
|
||||
if ("postgres-95".equalsIgnoreCase(alias)) {
|
||||
|
@ -103,26 +117,29 @@ public class Database {
|
|||
return "io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect";
|
||||
}
|
||||
}, "jdbc:postgresql://${kc.db.url.host:localhost}/${kc.db.url.database:keycloak}${kc.db.url.properties:}",
|
||||
"postgres-95", "postgres-10", PostgresDatabase.class.getName(), PostgresPlusDatabase.class.getName());
|
||||
"postgres-95", "postgres-10", PostgresDatabase.class.getName(), PostgresPlusDatabase.class.getName());
|
||||
|
||||
final String databaseKind;
|
||||
final String driver;
|
||||
final Function<String, String> dialect;
|
||||
final Function<String, String> defaultUrl;
|
||||
final String[] aliases;
|
||||
|
||||
Vendor(String driver, String dialect, String defaultUrl, String... aliases) {
|
||||
this(driver, (alias) -> dialect, (alias) -> defaultUrl, aliases);
|
||||
Vendor(String databaseKind, String driver, String dialect, String defaultUrl, String... aliases) {
|
||||
this(databaseKind, driver, (alias) -> dialect, (alias) -> defaultUrl, aliases);
|
||||
}
|
||||
|
||||
Vendor(String driver, String dialect, Function<String, String> defaultUrl, String... aliases) {
|
||||
this(driver, (alias) -> dialect, defaultUrl, aliases);
|
||||
Vendor(String databaseKind, String driver, String dialect, Function<String, String> defaultUrl, String... aliases) {
|
||||
this(databaseKind, driver, (alias) -> dialect, defaultUrl, aliases);
|
||||
}
|
||||
|
||||
Vendor(String driver, Function<String, String> dialect, String defaultUrl, String... aliases) {
|
||||
this(driver, dialect, (alias) -> defaultUrl, aliases);
|
||||
Vendor(String databaseKind, String driver, Function<String, String> dialect, String defaultUrl, String... aliases) {
|
||||
this(databaseKind, driver, dialect, (alias) -> defaultUrl, aliases);
|
||||
}
|
||||
|
||||
Vendor(String driver, Function<String, String> dialect, Function<String, String> defaultUrl, String... aliases) {
|
||||
Vendor(String databaseKind, String driver, Function<String, String> dialect, Function<String, String> defaultUrl,
|
||||
String... aliases) {
|
||||
this.databaseKind = databaseKind;
|
||||
this.driver = driver;
|
||||
this.dialect = dialect;
|
||||
this.defaultUrl = defaultUrl;
|
||||
|
|
|
@ -124,7 +124,7 @@ public final class PropertyMappers {
|
|||
create("db", "quarkus.datasource.jdbc.driver", (db, context) -> Database.getDriver(db).orElse(null), null);
|
||||
createBuildTimeProperty("db", "quarkus.datasource.db-kind", (db, context) -> {
|
||||
if (Database.isSupported(db)) {
|
||||
return db;
|
||||
return Database.getDatabaseKind(db).orElse(db);
|
||||
}
|
||||
addInitializationException(invalidDatabaseVendor(db, "h2-file", "h2-mem", "mariadb", "mysql", "postgres", "postgres-95", "postgres-10"));
|
||||
return "h2";
|
||||
|
|
|
@ -198,6 +198,17 @@ public class ConfigurationTest {
|
|||
config = createConfig();
|
||||
assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue());
|
||||
assertEquals("jdbc:h2:mem:keycloakdb", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
|
||||
assertEquals("h2", config.getConfigValue("quarkus.datasource.db-kind").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatabaseKindProperties() {
|
||||
System.setProperty("kc.config.args", "--db=postgres-10,--db-url=jdbc:postgresql://localhost/keycloak");
|
||||
SmallRyeConfig config = createConfig();
|
||||
assertEquals("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect",
|
||||
config.getConfigValue("quarkus.hibernate-orm.dialect").getValue());
|
||||
assertEquals("jdbc:postgresql://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
|
||||
assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue