forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JBoss Narayana. Fixes spring-projectsgh-5552
- Loading branch information
Showing
35 changed files
with
2,186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]">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); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
spring-boot-samples/spring-boot-sample-jta-narayana/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>spring-boot-samples</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>1.4.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>spring-boot-sample-jta-narayana</artifactId> | ||
<name>Spring Boot Narayana JTA Sample</name> | ||
<description>Spring Boot Narayana JTA Sample</description> | ||
<url>http://projects.spring.io/spring-boot/</url> | ||
<properties> | ||
<main.basedir>${basedir}/../..</main.basedir> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jms</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jta-narayana</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-hornetq</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hornetq</groupId> | ||
<artifactId>hornetq-jms-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
...g-boot-samples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2012-2014 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 sample.narayana; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Account { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
private String username; | ||
|
||
Account() { | ||
} | ||
|
||
public Account(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getUsername() { | ||
return this.username; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ples/spring-boot-sample-jta-narayana/src/main/java/sample/narayana/AccountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2012-2014 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 sample.narayana; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AccountRepository extends JpaRepository<Account, Long> { | ||
|
||
} |
Oops, something went wrong.