-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ikasan 2370 add service to manage indoubt transactions v3 #1299
Merged
andrzej-majewski
merged 4 commits into
4.0.x
from
IKASAN-2370-add-service-to-manage-indoubt-transactions-v3
May 14, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c20f7d7
IKASAN-2370 adding in doubt transaction service. WIP
mick-stewart73 dc6a2a6
IKASAN-2370 adding service to manage in doubt transactions in the H2 …
mick-stewart73 a521df7
IKASAN-2370 fixing typo in docs.
mick-stewart73 1c896e3
IKASAN-2370 added feature to allow for all transactions to be committ…
mick-stewart73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
43 changes: 43 additions & 0 deletions
43
...persistence/src/main/java/org/ikasan/persistence/InDoubtTransactionAutoConfiguration.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 @@ | ||
package org.ikasan.persistence; | ||
|
||
import org.ikasan.persistence.dao.HibernateInDoubtTransactionDaoImpl; | ||
import org.ikasan.persistence.service.InDoubtTransactionServiceImpl; | ||
import org.ikasan.spec.persistence.dao.InDoubtTransactionDao; | ||
import org.ikasan.spec.persistence.service.InDoubtTransactionService; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
import org.springframework.orm.jpa.JpaVendorAdapter; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Properties; | ||
|
||
@Configuration | ||
@ImportResource("/persistence-transaction.xml") | ||
public class InDoubtTransactionAutoConfiguration { | ||
|
||
@Bean | ||
InDoubtTransactionService inDoubtTransactionService(InDoubtTransactionDao inDoubtTransactionDao) { | ||
return new InDoubtTransactionServiceImpl(inDoubtTransactionDao); | ||
} | ||
@Bean | ||
InDoubtTransactionDao inDoubtTransactionDao() { | ||
return new HibernateInDoubtTransactionDaoImpl(); | ||
} | ||
|
||
@Bean | ||
public LocalContainerEntityManagerFactoryBean persistenceEntityManager(@Qualifier("ikasan.ds")DataSource dataSource | ||
, JpaVendorAdapter jpaVendorAdapter, @Qualifier("platformJpaProperties") Properties platformJpaProperties) { | ||
LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean | ||
= new LocalContainerEntityManagerFactoryBean(); | ||
localContainerEntityManagerFactoryBean.setDataSource(dataSource); | ||
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter); | ||
localContainerEntityManagerFactoryBean.setJpaProperties(platformJpaProperties); | ||
localContainerEntityManagerFactoryBean.setPersistenceUnitName("persistence"); | ||
localContainerEntityManagerFactoryBean.setPersistenceXmlLocation("classpath:persistence-persistence.xml"); | ||
|
||
return localContainerEntityManagerFactoryBean; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...sistence/src/main/java/org/ikasan/persistence/dao/HibernateInDoubtTransactionDaoImpl.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,57 @@ | ||
package org.ikasan.persistence.dao; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import jakarta.persistence.TypedQuery; | ||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.CriteriaQuery; | ||
import jakarta.persistence.criteria.Root; | ||
import org.ikasan.persistence.model.InDoubtTransactionImpl; | ||
import org.ikasan.spec.persistence.dao.InDoubtTransactionDao; | ||
import org.ikasan.spec.persistence.model.InDoubtTransaction; | ||
|
||
import java.util.List; | ||
|
||
public class HibernateInDoubtTransactionDaoImpl implements InDoubtTransactionDao { | ||
|
||
@PersistenceContext(unitName = "persistence") | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public List<InDoubtTransaction> getInDoubtTransactions() { | ||
return entityManager.createNativeQuery( | ||
"SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT", InDoubtTransactionImpl.class) | ||
.getResultList(); | ||
} | ||
|
||
@Override | ||
public InDoubtTransaction getInDoubtTransaction(String transactionName) { | ||
List<InDoubtTransaction> inDoubtTransactions = this.getInDoubtTransactions(); | ||
|
||
for (InDoubtTransaction inDoubtTransaction: inDoubtTransactions) { | ||
if(inDoubtTransaction.getTransactionName().equalsIgnoreCase(transactionName)) { | ||
return inDoubtTransaction; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void commitInDoubtTransaction(String transactionName) { | ||
if(this.getInDoubtTransaction(transactionName) == null) { | ||
throw new RuntimeException(String.format("An in doubt transaction with name[%s] does not exist in the database!" + | ||
" Unable to commit the in doubt transaction!", transactionName)); | ||
} | ||
entityManager.createNativeQuery("COMMIT TRANSACTION " + transactionName).executeUpdate(); | ||
} | ||
|
||
@Override | ||
public void rollbackInDoubtTransaction(String transactionName) { | ||
if(this.getInDoubtTransaction(transactionName) == null) { | ||
throw new RuntimeException(String.format("An in doubt transaction with name[%s] does not exist in the database!" + | ||
" Unable to rollback the in doubt transaction!", transactionName)); | ||
} | ||
entityManager.createNativeQuery("ROLLBACK TRANSACTION " + transactionName).executeUpdate(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
ikasaneip/persistence/src/main/java/org/ikasan/persistence/model/InDoubtTransactionImpl.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,53 @@ | ||
package org.ikasan.persistence.model; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import org.ikasan.spec.persistence.model.InDoubtTransaction; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
@Table(name="IN_DOUBT") | ||
public class InDoubtTransactionImpl implements InDoubtTransaction { | ||
|
||
@Id | ||
@Column(name="TRANSACTION_NAME") | ||
private String transactionName; | ||
@Column(name="TRANSACTION_STATE") | ||
private String transactionState; | ||
|
||
@Override | ||
public String getTransactionName() { | ||
return transactionName; | ||
} | ||
|
||
@Override | ||
public void setTransactionName(String transactionName) { | ||
this.transactionName = transactionName; | ||
} | ||
|
||
@Override | ||
public String getTransactionState() { | ||
return transactionState; | ||
} | ||
|
||
@Override | ||
public void setTransactionState(String transactionState) { | ||
this.transactionState = transactionState; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof InDoubtTransactionImpl that)) return false; | ||
return Objects.equals(transactionName, that.transactionName) | ||
&& Objects.equals(transactionState, that.transactionState); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(transactionName, transactionState); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...rsistence/src/main/java/org/ikasan/persistence/service/InDoubtTransactionServiceImpl.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,63 @@ | ||
package org.ikasan.persistence.service; | ||
|
||
import org.ikasan.spec.persistence.dao.InDoubtTransactionDao; | ||
import org.ikasan.spec.persistence.model.InDoubtTransaction; | ||
import org.ikasan.spec.persistence.service.InDoubtTransactionService; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* The InDoubtTransactionServiceImpl class is an implementation of the InDoubtTransactionService interface. | ||
* It provides methods for retrieving, committing, and rolling back in-doubt transactions. | ||
*/ | ||
public class InDoubtTransactionServiceImpl implements InDoubtTransactionService { | ||
|
||
private InDoubtTransactionDao inDoubtTransactionDao; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* InDoubtTransactionServiceImpl class is an implementation of the InDoubtTransactionService interface. | ||
* | ||
* @param inDoubtTransactionDao the implementation of InDoubtTransactionDao used for data access | ||
*/ | ||
public InDoubtTransactionServiceImpl(InDoubtTransactionDao inDoubtTransactionDao) { | ||
this.inDoubtTransactionDao = inDoubtTransactionDao; | ||
if(this.inDoubtTransactionDao == null) { | ||
throw new IllegalArgumentException("inDoubtTransactionDao cannot be null!!"); | ||
} | ||
} | ||
|
||
@Override | ||
public List<InDoubtTransaction> getInDoubtTransactions() { | ||
return this.inDoubtTransactionDao.getInDoubtTransactions(); | ||
} | ||
|
||
@Override | ||
public InDoubtTransaction getInDoubtTransaction(String transactionName) { | ||
return this.inDoubtTransactionDao.getInDoubtTransaction(transactionName); | ||
} | ||
|
||
@Override | ||
public void commitInDoubtTransaction(String transactionName) { | ||
this.inDoubtTransactionDao.commitInDoubtTransaction(transactionName); | ||
} | ||
|
||
@Override | ||
public void rollbackInDoubtTransaction(String transactionName) { | ||
this.inDoubtTransactionDao.rollbackInDoubtTransaction(transactionName); | ||
} | ||
|
||
@Override | ||
public void commitAllInDoubtTransactions() { | ||
this.inDoubtTransactionDao.getInDoubtTransactions() | ||
.forEach(inDoubtTransaction -> this.commitInDoubtTransaction(inDoubtTransaction.getTransactionName())); | ||
} | ||
|
||
@Override | ||
public void rollbackAllInDoubtTransactions() { | ||
this.inDoubtTransactionDao.getInDoubtTransactions() | ||
.forEach(inDoubtTransaction -> this.rollbackInDoubtTransaction(inDoubtTransaction.getTransactionName())); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
ikasaneip/persistence/src/main/resources/META-INF/spring.factories
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.ikasan.persistence.PersistenceAutoConfiguration | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.ikasan.persistence.PersistenceAutoConfiguration\ | ||
,org.ikasan.persistence.InDoubtTransactionAutoConfiguration |
3 changes: 2 additions & 1 deletion
3
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
org.ikasan.persistence.PersistenceAutoConfiguration | ||
org.ikasan.persistence.PersistenceAutoConfiguration | ||
org.ikasan.persistence.InDoubtTransactionAutoConfiguration |
10 changes: 10 additions & 0 deletions
10
ikasaneip/persistence/src/main/resources/persistence-persistence.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,10 @@ | ||
<?xml version="1.0"?> | ||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | ||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" | ||
version="2.1"> | ||
<persistence-unit name="persistence" transaction-type="JTA"> | ||
<class>org.ikasan.persistence.model.InDoubtTransactionImpl</class> | ||
</persistence-unit> | ||
</persistence> |
64 changes: 64 additions & 0 deletions
64
ikasaneip/persistence/src/main/resources/persistence-transaction.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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
# // | ||
# // | ||
# // $Id$ | ||
# // $URL$ | ||
# // | ||
# // ==================================================================== | ||
# // Ikasan Enterprise Integration Platform | ||
# // | ||
# // Distributed under the Modified BSD License. | ||
# // Copyright notice: The copyright for this software and a full listing | ||
# // of individual contributors are as shown in the packaged copyright.txt | ||
# // file. | ||
# // | ||
# // All rights reserved. | ||
# // | ||
# // Redistribution and use in source and binary forms, with or without | ||
# // modification, are permitted provided that the following conditions are met: | ||
# // | ||
# // - Redistributions of source code must retain the above copyright notice, | ||
# // this list of conditions and the following disclaimer. | ||
# // | ||
# // - Redistributions in binary form must reproduce the above copyright notice, | ||
# // this list of conditions and the following disclaimer in the documentation | ||
# // and/or other materials provided with the distribution. | ||
# // | ||
# // - Neither the name of the ORGANIZATION nor the names of its contributors may | ||
# // be used to endorse or promote products derived from this software without | ||
# // specific prior written permission. | ||
# // | ||
# // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
# // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# // ==================================================================== | ||
# // | ||
# // Author: Ikasan Development Team | ||
# // | ||
--> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd | ||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> | ||
|
||
<aop:config> | ||
<aop:pointcut id="persistenceDaoInvocationCommit" | ||
expression="execution(* org.ikasan.spec.persistence.dao.InDoubtTransactionDao.commitInDoubtTransaction(..))"/> | ||
<aop:pointcut id="persistenceDaoInvocationRollback" | ||
expression="execution(* org.ikasan.spec.persistence.dao.InDoubtTransactionDao.rollbackInDoubtTransaction(..))"/> | ||
|
||
<aop:advisor advice-ref="requiresNew-TransactionAdvice" pointcut-ref="persistenceDaoInvocationCommit"/> | ||
<aop:advisor advice-ref="requiresNew-TransactionAdvice" pointcut-ref="persistenceDaoInvocationRollback"/> | ||
</aop:config> | ||
|
||
|
||
</beans> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add Service to CommitAll and RollBackAll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrzej-majewski I have added feature to commit and roll back all.