Skip to content
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

PAYARA-510 fixes 505 ensures resources are enlisted into the transaction #524

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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