Capacity to change hibernate dialect

Closes #10749
This commit is contained in:
Pedro Igor 2022-03-18 11:58:06 -03:00
parent 441ba8d2c8
commit 183ad30755
2 changed files with 17 additions and 2 deletions

View file

@ -5,7 +5,6 @@ import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigValue;
import org.keycloak.quarkus.runtime.storage.database.Database;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
@ -23,7 +22,7 @@ final class DatabasePropertyMappers {
.mapFrom("db")
.to("quarkus.hibernate-orm.dialect")
.isBuildTimeProperty(true)
.transformer((db, context) -> Database.getDialect(db).orElse(Database.getDialect("dev-file").get()))
.transformer(DatabasePropertyMappers::transformDialect)
.hidden(true)
.build(),
builder().from("db-driver")
@ -149,4 +148,14 @@ final class DatabasePropertyMappers {
String db = context.proceed("kc.db").getValue();
return Database.getDatabaseKind(db).get().equals(DatabaseKind.H2);
}
private static String transformDialect(String db, ConfigSourceInterceptorContext context) {
Optional<String> databaseKind = Database.getDatabaseKind(db);
if (databaseKind.isEmpty()) {
return db;
}
return Database.getDialect(db).orElse(Database.getDialect("dev-file").get());
}
}

View file

@ -389,6 +389,12 @@ public class ConfigurationTest {
assertEquals("enabled", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
}
@Test
public void testDatabaseDialectSetExplicitly() {
System.setProperty(CLI_ARGS, "--db-dialect=user-defined");
assertEquals("user-defined", createConfig().getRawValue("quarkus.hibernate-orm.dialect"));
}
@Test
public void testTransactionTypeChangesDriver() {
System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-xa-enabled=false");