Add Narayana JTA support
Add support for JBoss Narayana. Fixes gh-5552
This commit is contained in:
committed by
Phillip Webb
parent
1b146f89f0
commit
a2adc5a130
@@ -40,7 +40,7 @@ import org.springframework.context.annotation.Import;
|
||||
ActiveMQAutoConfiguration.class, HornetQAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class })
|
||||
@Import({ JndiJtaConfiguration.class, BitronixJtaConfiguration.class,
|
||||
AtomikosJtaConfiguration.class })
|
||||
AtomikosJtaConfiguration.class, NarayanaJtaConfiguration.class })
|
||||
@EnableConfigurationProperties(JtaProperties.class)
|
||||
public class JtaAutoConfiguration {
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||
|
||||
import javax.jms.Message;
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.jta.XAConnectionFactoryWrapper;
|
||||
import org.springframework.boot.jta.XADataSourceWrapper;
|
||||
import org.springframework.boot.jta.narayana.NarayanaBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.jta.narayana.NarayanaConfigurationBean;
|
||||
import org.springframework.boot.jta.narayana.NarayanaProperties;
|
||||
import org.springframework.boot.jta.narayana.NarayanaRecoveryManagerBean;
|
||||
import org.springframework.boot.jta.narayana.NarayanaXAConnectionFactoryWrapper;
|
||||
import org.springframework.boot.jta.narayana.NarayanaXADataSourceWrapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
|
||||
/**
|
||||
* JTA Configuration for <a href="http://narayana.io/">Narayana</a>.
|
||||
*
|
||||
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ JtaTransactionManager.class, com.arjuna.ats.jta.UserTransaction.class })
|
||||
@ConditionalOnMissingBean(PlatformTransactionManager.class)
|
||||
public class NarayanaJtaConfiguration {
|
||||
|
||||
@Autowired
|
||||
private JtaProperties jtaProperties;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public NarayanaProperties narayanaProperties() {
|
||||
return new NarayanaProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public NarayanaConfigurationBean narayanaConfigurationBean(NarayanaProperties narayanaProperties) {
|
||||
if (this.jtaProperties.getLogDir() != null) {
|
||||
narayanaProperties.setLogDir(this.jtaProperties.getLogDir());
|
||||
}
|
||||
|
||||
if (this.jtaProperties.getTransactionManagerId() != null) {
|
||||
narayanaProperties.setTransactionManagerId(this.jtaProperties.getTransactionManagerId());
|
||||
}
|
||||
|
||||
return new NarayanaConfigurationBean(narayanaProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("narayanaConfigurationBean")
|
||||
@ConditionalOnMissingBean
|
||||
public UserTransaction narayanaUserTransaction() {
|
||||
return com.arjuna.ats.jta.UserTransaction.userTransaction();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("narayanaConfigurationBean")
|
||||
@ConditionalOnMissingBean
|
||||
public TransactionManager narayanaTransactionManager() {
|
||||
return com.arjuna.ats.jta.TransactionManager.transactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("narayanaConfigurationBean")
|
||||
public RecoveryManagerService narayanaRecoveryManagerService() {
|
||||
return new RecoveryManagerService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NarayanaRecoveryManagerBean narayanaRecoveryManagerBean(RecoveryManagerService recoveryManagerService) {
|
||||
return new NarayanaRecoveryManagerBean(recoveryManagerService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JtaTransactionManager transactionManager(UserTransaction userTransaction, TransactionManager transactionManager) {
|
||||
return new JtaTransactionManager(userTransaction, transactionManager);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(XADataSourceWrapper.class)
|
||||
public XADataSourceWrapper xaDataSourceWrapper(NarayanaRecoveryManagerBean narayanaRecoveryManagerBean,
|
||||
NarayanaProperties narayanaProperties) {
|
||||
return new NarayanaXADataSourceWrapper(narayanaRecoveryManagerBean, narayanaProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public static NarayanaBeanFactoryPostProcessor narayanaBeanFactoryPostProcessor() {
|
||||
return new NarayanaBeanFactoryPostProcessor();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Message.class)
|
||||
static class NarayanaJtaJmsConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(XAConnectionFactoryWrapper.class)
|
||||
public NarayanaXAConnectionFactoryWrapper xaConnectionFactoryWrapper(TransactionManager transactionManager,
|
||||
NarayanaRecoveryManagerBean narayanaRecoveryManagerBean, NarayanaProperties narayanaProperties) {
|
||||
return new NarayanaXAConnectionFactoryWrapper(transactionManager, narayanaRecoveryManagerBean, narayanaProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user