mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
parent
06d1b4faab
commit
c19428aa81
@ -7,15 +7,24 @@ public class TransactionOptions {
|
||||
|
||||
public static final Option<Boolean> TRANSACTION_XA_ENABLED = new OptionBuilder<>("transaction-xa-enabled", Boolean.class)
|
||||
.category(OptionCategory.TRANSACTION)
|
||||
.description("Manually override the transaction type. Transaction type XA and the appropriate driver is used by default.")
|
||||
.description("If set to false, Keycloak uses a non-XA datasource in case the database does not support XA transactions.")
|
||||
.buildTime(true)
|
||||
.defaultValue(Boolean.TRUE)
|
||||
.expectedValues(Boolean.TRUE, Boolean.FALSE)
|
||||
.build();
|
||||
|
||||
public static final Option<Boolean> TRANSACTION_JTA_ENABLED = new OptionBuilder<>("transaction-jta-enabled", Boolean.class)
|
||||
.category(OptionCategory.TRANSACTION)
|
||||
.description("Set if distributed transactions are supported. If set to false, transactions are managed by the server and can not be joined if multiple data sources are used. By default, distributed transactions are enabled and only XA data sources can be used.")
|
||||
.buildTime(true)
|
||||
.hidden()
|
||||
.expectedValues(Boolean.TRUE, Boolean.FALSE)
|
||||
.build();
|
||||
|
||||
public static final List<Option<?>> ALL_OPTIONS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
ALL_OPTIONS.add(TRANSACTION_XA_ENABLED);
|
||||
ALL_OPTIONS.add(TRANSACTION_XA_ENABLED);
|
||||
ALL_OPTIONS.add(TRANSACTION_JTA_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,8 +100,14 @@ final class DatabasePropertyMappers {
|
||||
|
||||
private static Optional<String> getXaOrNonXaDriver(Optional<String> value, ConfigSourceInterceptorContext context) {
|
||||
ConfigValue xaEnabledConfigValue = context.proceed("kc.transaction-xa-enabled");
|
||||
ConfigValue jtaEnabledConfiguration = context.proceed("kc.transaction-jta-enabled");
|
||||
|
||||
boolean isXaEnabled = xaEnabledConfigValue == null || Boolean.parseBoolean(xaEnabledConfigValue.getValue());
|
||||
boolean isJtaEnabled = jtaEnabledConfiguration == null || Boolean.parseBoolean(jtaEnabledConfiguration.getValue());
|
||||
|
||||
if(!isJtaEnabled) {
|
||||
isXaEnabled = false;
|
||||
}
|
||||
|
||||
Optional<String> driver = Database.getDriver(value.get(), isXaEnabled);
|
||||
|
||||
|
||||
@ -161,7 +161,7 @@ public class PropertyMapper<T> {
|
||||
return this.option.getExpectedValues().stream().map(v -> v.toString()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Optional<T> getDefaultValue() {return this.option.getDefaultValue(); }
|
||||
public Optional<T> getDefaultValue() { return this.option.getDefaultValue(); }
|
||||
|
||||
public OptionCategory getCategory() {
|
||||
return this.option.getCategory();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package org.keycloak.quarkus.runtime.configuration.mappers;
|
||||
|
||||
import io.smallrye.config.ConfigSourceInterceptorContext;
|
||||
import io.smallrye.config.ConfigValue;
|
||||
import org.keycloak.config.TransactionOptions;
|
||||
|
||||
import static java.util.Optional.of;
|
||||
@ -10,12 +11,18 @@ import java.util.Optional;
|
||||
|
||||
public class TransactionPropertyMappers {
|
||||
|
||||
private static final String QUARKUS_TXPROP_TARGET = "quarkus.datasource.jdbc.transactions";
|
||||
|
||||
private TransactionPropertyMappers(){}
|
||||
|
||||
public static PropertyMapper[] getTransactionPropertyMappers() {
|
||||
return new PropertyMapper[] {
|
||||
fromOption(TransactionOptions.TRANSACTION_XA_ENABLED)
|
||||
.to("quarkus.datasource.jdbc.transactions")
|
||||
.to(QUARKUS_TXPROP_TARGET)
|
||||
.paramLabel(Boolean.TRUE + "|" + Boolean.FALSE)
|
||||
.transformer(TransactionPropertyMappers::getQuarkusTransactionsValue)
|
||||
.build(),
|
||||
fromOption(TransactionOptions.TRANSACTION_JTA_ENABLED)
|
||||
.paramLabel(Boolean.TRUE + "|" + Boolean.FALSE)
|
||||
.transformer(TransactionPropertyMappers::getQuarkusTransactionsValue)
|
||||
.build()
|
||||
@ -24,6 +31,11 @@ public class TransactionPropertyMappers {
|
||||
|
||||
private static Optional<String> getQuarkusTransactionsValue(Optional<String> txValue, ConfigSourceInterceptorContext context) {
|
||||
boolean isXaEnabled = Boolean.parseBoolean(txValue.get());
|
||||
boolean isJtaEnabled = getBooleanValue("kc.transaction-jta-enabled", context, true);
|
||||
|
||||
if (!isJtaEnabled) {
|
||||
return of("disabled");
|
||||
}
|
||||
|
||||
if (isXaEnabled) {
|
||||
return of("xa");
|
||||
@ -32,4 +44,13 @@ public class TransactionPropertyMappers {
|
||||
return of("enabled");
|
||||
}
|
||||
|
||||
private static boolean getBooleanValue(String key, ConfigSourceInterceptorContext context, boolean defaultValue) {
|
||||
boolean returnValue = defaultValue;
|
||||
ConfigValue configValue = context.proceed(key);
|
||||
|
||||
if (configValue != null) {
|
||||
returnValue = Boolean.parseBoolean(configValue.getValue());
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,13 +24,11 @@ import java.util.Optional;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import javax.persistence.FlushModeType;
|
||||
import javax.persistence.SynchronizationType;
|
||||
import org.hibernate.internal.SessionFactoryImpl;
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.connections.jpa.JpaConnectionProviderFactory;
|
||||
import org.keycloak.connections.jpa.JpaKeycloakTransaction;
|
||||
import org.keycloak.connections.jpa.PersistenceExceptionConverter;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
|
||||
@ -423,18 +423,25 @@ public class ConfigurationTest {
|
||||
System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-xa-enabled=false");
|
||||
assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql"));
|
||||
|
||||
SmallRyeConfig config = createConfig();
|
||||
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", config.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
|
||||
assertEquals("enabled", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
|
||||
SmallRyeConfig jtaEnabledConfig = createConfig();
|
||||
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", jtaEnabledConfig.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
|
||||
assertEquals("enabled", jtaEnabledConfig.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
|
||||
|
||||
System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-xa-enabled=true");
|
||||
assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql"));
|
||||
SmallRyeConfig config2 = createConfig();
|
||||
SmallRyeConfig xaConfig = createConfig();
|
||||
|
||||
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerXADataSource", config2.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
|
||||
assertEquals("xa", config2.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
|
||||
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerXADataSource", xaConfig.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
|
||||
assertEquals("xa", xaConfig.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
|
||||
|
||||
System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-jta-enabled=false");
|
||||
SmallRyeConfig jtaDisabledConfig = createConfig();
|
||||
|
||||
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", jtaDisabledConfig.getConfigValue("quarkus.datasource.jdbc.driver").getValue());
|
||||
assertEquals("disabled", jtaDisabledConfig.getConfigValue("quarkus.datasource.jdbc.transactions").getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolveHealthOption() {
|
||||
System.setProperty(CLI_ARGS, "--health-enabled=true");
|
||||
SmallRyeConfig config = createConfig();
|
||||
|
||||
@ -47,8 +47,8 @@ Database:
|
||||
Transaction:
|
||||
|
||||
--transaction-xa-enabled <true|false>
|
||||
Manually override the transaction type. Transaction type XA and the
|
||||
appropriate driver is used by default. Default: true.
|
||||
If set to false, Keycloak uses a non-XA datasource in case the database does
|
||||
not support XA transactions. Default: true.
|
||||
|
||||
Feature:
|
||||
|
||||
|
||||
@ -47,8 +47,8 @@ Database:
|
||||
Transaction:
|
||||
|
||||
--transaction-xa-enabled <true|false>
|
||||
Manually override the transaction type. Transaction type XA and the
|
||||
appropriate driver is used by default. Default: true.
|
||||
If set to false, Keycloak uses a non-XA datasource in case the database does
|
||||
not support XA transactions. Default: true.
|
||||
|
||||
Feature:
|
||||
|
||||
|
||||
@ -64,8 +64,8 @@ Database:
|
||||
Transaction:
|
||||
|
||||
--transaction-xa-enabled <true|false>
|
||||
Manually override the transaction type. Transaction type XA and the
|
||||
appropriate driver is used by default. Default: true.
|
||||
If set to false, Keycloak uses a non-XA datasource in case the database does
|
||||
not support XA transactions. Default: true.
|
||||
|
||||
Feature:
|
||||
|
||||
|
||||
@ -64,8 +64,8 @@ Database:
|
||||
Transaction:
|
||||
|
||||
--transaction-xa-enabled <true|false>
|
||||
Manually override the transaction type. Transaction type XA and the
|
||||
appropriate driver is used by default. Default: true.
|
||||
If set to false, Keycloak uses a non-XA datasource in case the database does
|
||||
not support XA transactions. Default: true.
|
||||
|
||||
Feature:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user