Skip to content

Commit

Permalink
Merge pull request #524 from smillidge/PAYARA-510
Browse files Browse the repository at this point in the history
PAYARA-510 fixes 505 ensures resources are enlisted into the transaction
  • Loading branch information
Pandrex247 committed Nov 30, 2015
2 parents f6b17b5 + 9e094fb commit 805649f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions appserver/web/weld-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,11 @@
<artifactId>logging-annotation-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.glassfish.main.transaction</groupId>
<artifactId>jta</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2015] [C2B2 Consulting Limited]

package org.glassfish.cdi.transaction;

import org.glassfish.logging.annotation.LoggerInfo;

import com.sun.enterprise.transaction.TransactionManagerHelper;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.transaction.Status;
import javax.transaction.TransactionalException;
import java.util.logging.Logger;
import javax.transaction.TransactionManager;

/**
* Transactional annotation Interceptor class for Required transaction type,
Expand Down Expand Up @@ -78,6 +80,11 @@ public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(java.util.logging.Level.INFO, CDI_JTA_MBREQUIRED);
try {
getTransactionManager().begin();
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper)tm).preInvokeTx(true);
}

} catch (Exception exception) {
String messageString =
"Managed bean with Transactional annotation and TxType of REQUIRED " +
Expand All @@ -95,6 +102,10 @@ public Object transactional(InvocationContext ctx) throws Exception {
} finally {
if (isTransactionStarted) {
try {
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper)tm).postInvokeTx(false,true);
}
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
if(getTransactionManager().getTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK) {
getTransactionManager().rollback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2015] [C2B2 Consulting Limited]

package org.glassfish.cdi.transaction;

import org.glassfish.logging.annotation.LoggerInfo;
import com.sun.enterprise.transaction.TransactionManagerHelper;

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
Expand All @@ -49,6 +50,7 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionalException;
import java.util.logging.Logger;
import javax.transaction.TransactionManager;

/**
* Transactional annotation Interceptor class for RequiresNew transaction type,
Expand Down Expand Up @@ -83,6 +85,10 @@ public Object transactional(InvocationContext ctx) throws Exception {
//todo catch, wrap in new transactional exception and throw
}
try {
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper)tm).preInvokeTx(true);
}
getTransactionManager().begin();
} catch (Exception exception) {
String messageString =
Expand All @@ -97,6 +103,10 @@ public Object transactional(InvocationContext ctx) throws Exception {
proceed = proceed(ctx);
} finally {
try {
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper)tm).postInvokeTx(false,true);
}
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
if(getTransactionManager().getTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK) {
getTransactionManager().rollback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2015] [C2B2 Consulting Limited]

package org.glassfish.cdi.transaction;

import java.util.concurrent.ConcurrentHashMap;
import org.junit.Test;

import javax.enterprise.context.spi.Contextual;
Expand All @@ -61,6 +63,7 @@ public void testAllMethods() {
Contextual<LocalBean> contextual = (Contextual<LocalBean>) mockSupport.createMock(Contextual.class);
CreationalContext<LocalBean> creationalContext = (CreationalContext<LocalBean>) mockSupport.createMock(CreationalContext.class);
TransactionScopedContextImpl transactionScopedContext = mockSupport.createMock(TransactionScopedContextImpl.class);
transactionScopedContext.beansPerTransaction = new ConcurrentHashMap<>();

// test getContextualInstance
TransactionScopedBean<LocalBean> transactionScopedBean = getTransactionScopedBean(mockSupport,
Expand Down

0 comments on commit 805649f

Please sign in to comment.