Commit c3ddf67083b1c2c0d94d2babc0f289ad5dbc4a81
1 parent
35d2938b
Exists in
master
Alterada a forma de detecção se uma transação continua ativa, para levar
em conta os status adicionais de uma UserTransaction.
Showing
4 changed files
with
89 additions
and
1 deletions
Show diff stats
impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java
| @@ -38,12 +38,17 @@ package br.gov.frameworkdemoiselle.transaction; | @@ -38,12 +38,17 @@ package br.gov.frameworkdemoiselle.transaction; | ||
| 38 | 38 | ||
| 39 | import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.EXTENSIONS_L2_PRIORITY; | 39 | import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.EXTENSIONS_L2_PRIORITY; |
| 40 | 40 | ||
| 41 | +import javax.inject.Inject; | ||
| 41 | import javax.transaction.Status; | 42 | import javax.transaction.Status; |
| 42 | import javax.transaction.SystemException; | 43 | import javax.transaction.SystemException; |
| 43 | import javax.transaction.UserTransaction; | 44 | import javax.transaction.UserTransaction; |
| 44 | 45 | ||
| 46 | +import org.slf4j.Logger; | ||
| 47 | + | ||
| 48 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 49 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 46 | import br.gov.frameworkdemoiselle.util.Beans; | 50 | import br.gov.frameworkdemoiselle.util.Beans; |
| 51 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 47 | 52 | ||
| 48 | @Priority(EXTENSIONS_L2_PRIORITY) | 53 | @Priority(EXTENSIONS_L2_PRIORITY) |
| 49 | public class JTATransaction implements Transaction { | 54 | public class JTATransaction implements Transaction { |
| @@ -51,6 +56,13 @@ public class JTATransaction implements Transaction { | @@ -51,6 +56,13 @@ public class JTATransaction implements Transaction { | ||
| 51 | private static final long serialVersionUID = 1L; | 56 | private static final long serialVersionUID = 1L; |
| 52 | 57 | ||
| 53 | private UserTransaction delegate; | 58 | private UserTransaction delegate; |
| 59 | + | ||
| 60 | + @Inject | ||
| 61 | + private Logger logger; | ||
| 62 | + | ||
| 63 | + @Inject | ||
| 64 | + @Name("demoiselle-jta-bundle") | ||
| 65 | + private ResourceBundle bundle; | ||
| 54 | 66 | ||
| 55 | public UserTransaction getDelegate() { | 67 | public UserTransaction getDelegate() { |
| 56 | 68 | ||
| @@ -64,7 +76,27 @@ public class JTATransaction implements Transaction { | @@ -64,7 +76,27 @@ public class JTATransaction implements Transaction { | ||
| 64 | @Override | 76 | @Override |
| 65 | public boolean isActive() { | 77 | public boolean isActive() { |
| 66 | try { | 78 | try { |
| 67 | - return getDelegate().getStatus() == Status.STATUS_ACTIVE || isMarkedRollback(); | 79 | + final int delegateStatus = getDelegate().getStatus(); |
| 80 | + | ||
| 81 | + if (delegateStatus!=Status.STATUS_ACTIVE && delegateStatus!=Status.STATUS_NO_TRANSACTION){ | ||
| 82 | + //Os status mais comuns do UserTransaction são: explicitamente ativa (STATUS_ACTIVE) ou explicitamente | ||
| 83 | + //desativada (STATUS_NO_TRANSACTION). Qualquer outro status "intermediário" é registrado em log para análise posterior | ||
| 84 | + String status; | ||
| 85 | + switch(delegateStatus){ | ||
| 86 | + case Status.STATUS_COMMITTED: status="COMMITTED"; break; | ||
| 87 | + case Status.STATUS_COMMITTING: status="COMMITTING"; break; | ||
| 88 | + case Status.STATUS_MARKED_ROLLBACK: status="MARKED_ROLLBACK"; break; | ||
| 89 | + case Status.STATUS_PREPARED: status="PREPARED"; break; | ||
| 90 | + case Status.STATUS_PREPARING: status="PREPARING"; break; | ||
| 91 | + case Status.STATUS_ROLLEDBACK: status="ROLLEDBACK"; break; | ||
| 92 | + case Status.STATUS_ROLLING_BACK: status="ROLLING_BACK"; break; | ||
| 93 | + case Status.STATUS_UNKNOWN: status="UNKNOWN"; break; | ||
| 94 | + default: status="UNKNOWN"; | ||
| 95 | + } | ||
| 96 | + logger.debug(bundle.getString("usertransaction-abnormal-status",status)); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + return delegateStatus != Status.STATUS_NO_TRANSACTION; | ||
| 68 | 100 | ||
| 69 | } catch (SystemException cause) { | 101 | } catch (SystemException cause) { |
| 70 | throw new TransactionException(cause); | 102 | throw new TransactionException(cause); |
impl/extension/jta/src/main/resources/demoiselle-jta-bundle.properties
| @@ -32,3 +32,4 @@ | @@ -32,3 +32,4 @@ | ||
| 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | +usertransaction-abnormal-status=UserTransaction encontra-se em status anormal\: {0} | ||
| 35 | \ No newline at end of file | 36 | \ No newline at end of file |
impl/extension/jta/src/test/java/br/gov/frameworkdemoiselle/transaction/JTATransactionTest.java
| @@ -46,6 +46,8 @@ import static org.powermock.api.easymock.PowerMock.replayAll; | @@ -46,6 +46,8 @@ import static org.powermock.api.easymock.PowerMock.replayAll; | ||
| 46 | import static org.powermock.api.easymock.PowerMock.verify; | 46 | import static org.powermock.api.easymock.PowerMock.verify; |
| 47 | import static org.powermock.reflect.Whitebox.setInternalState; | 47 | import static org.powermock.reflect.Whitebox.setInternalState; |
| 48 | 48 | ||
| 49 | +import java.util.Locale; | ||
| 50 | + | ||
| 49 | import javax.transaction.HeuristicMixedException; | 51 | import javax.transaction.HeuristicMixedException; |
| 50 | import javax.transaction.HeuristicRollbackException; | 52 | import javax.transaction.HeuristicRollbackException; |
| 51 | import javax.transaction.NotSupportedException; | 53 | import javax.transaction.NotSupportedException; |
| @@ -60,8 +62,11 @@ import org.junit.Test; | @@ -60,8 +62,11 @@ import org.junit.Test; | ||
| 60 | import org.junit.runner.RunWith; | 62 | import org.junit.runner.RunWith; |
| 61 | import org.powermock.core.classloader.annotations.PrepareForTest; | 63 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 62 | import org.powermock.modules.junit4.PowerMockRunner; | 64 | import org.powermock.modules.junit4.PowerMockRunner; |
| 65 | +import org.slf4j.Logger; | ||
| 66 | +import org.slf4j.LoggerFactory; | ||
| 63 | 67 | ||
| 64 | import br.gov.frameworkdemoiselle.util.Beans; | 68 | import br.gov.frameworkdemoiselle.util.Beans; |
| 69 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 65 | 70 | ||
| 66 | @RunWith(PowerMockRunner.class) | 71 | @RunWith(PowerMockRunner.class) |
| 67 | @PrepareForTest({ Beans.class }) | 72 | @PrepareForTest({ Beans.class }) |
| @@ -70,14 +75,22 @@ public class JTATransactionTest { | @@ -70,14 +75,22 @@ public class JTATransactionTest { | ||
| 70 | private UserTransaction userTransaction; | 75 | private UserTransaction userTransaction; |
| 71 | 76 | ||
| 72 | private JTATransaction jtaTransaction; | 77 | private JTATransaction jtaTransaction; |
| 78 | + | ||
| 79 | + private Logger logger; | ||
| 80 | + | ||
| 81 | + private ResourceBundle bundle; | ||
| 73 | 82 | ||
| 74 | @Before | 83 | @Before |
| 75 | public void setUp() { | 84 | public void setUp() { |
| 76 | 85 | ||
| 77 | userTransaction = createMock(UserTransaction.class); | 86 | userTransaction = createMock(UserTransaction.class); |
| 78 | jtaTransaction = new JTATransaction(); | 87 | jtaTransaction = new JTATransaction(); |
| 88 | + logger = LoggerFactory.getLogger(JTATransaction.class); | ||
| 89 | + bundle = new ResourceBundle("demoiselle-jta-bundle",Locale.getDefault()); | ||
| 79 | 90 | ||
| 80 | setInternalState(jtaTransaction, UserTransaction.class, userTransaction); | 91 | setInternalState(jtaTransaction, UserTransaction.class, userTransaction); |
| 92 | + setInternalState(jtaTransaction, Logger.class, logger); | ||
| 93 | + setInternalState(jtaTransaction, ResourceBundle.class, bundle); | ||
| 81 | } | 94 | } |
| 82 | 95 | ||
| 83 | @Test | 96 | @Test |
| @@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
| 1 | +# Demoiselle Framework | ||
| 2 | +# Copyright (C) 2010 SERPRO | ||
| 3 | +# ---------------------------------------------------------------------------- | ||
| 4 | +# This file is part of Demoiselle Framework. | ||
| 5 | +# | ||
| 6 | +# Demoiselle Framework is free software; you can redistribute it and/or | ||
| 7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 8 | +# as published by the Free Software Foundation. | ||
| 9 | +# | ||
| 10 | +# This program is distributed in the hope that it will be useful, | ||
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | +# GNU General Public License for more details. | ||
| 14 | +# | ||
| 15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 19 | +# ---------------------------------------------------------------------------- | ||
| 20 | +# Este arquivo é parte do Framework Demoiselle. | ||
| 21 | +# | ||
| 22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 24 | +# do Software Livre (FSF). | ||
| 25 | +# | ||
| 26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 29 | +# para maiores detalhes. | ||
| 30 | +# | ||
| 31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 35 | + | ||
| 36 | +log4j.rootCategory=INFO, stdout | ||
| 37 | + | ||
| 38 | +log4j.logger.br.gov.frameworkdemoiselle=TRACE | ||
| 39 | + | ||
| 40 | +log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
| 41 | +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
| 42 | +log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{1}] %m%n |