Commit 1f795342994796dc5a8cb56035823ec981f58e06
1 parent
8ec3ac75
Exists in
master
Remoção da dependência de escopos para o controle transacional
Showing
9 changed files
with
260 additions
and
50 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ApplicationLifecycleEvent.java
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 1 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 2 | 38 | ||
| 3 | -public interface ApplicationLifecycleEvent { | 39 | +interface ApplicationLifecycleEvent { |
| 4 | 40 | ||
| 5 | boolean removeProcessors(); | 41 | boolean removeProcessors(); |
| 6 | } | 42 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationFinalization.java
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 1 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 2 | 38 | ||
| 3 | public interface BeforeApplicationFinalization extends ApplicationLifecycleEvent { | 39 | public interface BeforeApplicationFinalization extends ApplicationLifecycleEvent { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/BeforeApplicationInitialization.java
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 1 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 2 | 38 | ||
| 3 | public interface BeforeApplicationInitialization extends ApplicationLifecycleEvent { | 39 | public interface BeforeApplicationInitialization extends ApplicationLifecycleEvent { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
| @@ -36,8 +36,6 @@ | @@ -36,8 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | ||
| 39 | -import java.util.Locale; | ||
| 40 | - | ||
| 41 | import javax.inject.Named; | 39 | import javax.inject.Named; |
| 42 | 40 | ||
| 43 | import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; | 41 | import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; |
| @@ -179,9 +177,7 @@ public class SecurityContextImpl implements SecurityContext { | @@ -179,9 +177,7 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 179 | 177 | ||
| 180 | private void checkLoggedIn() throws NotLoggedInException { | 178 | private void checkLoggedIn() throws NotLoggedInException { |
| 181 | if (!isLoggedIn()) { | 179 | if (!isLoggedIn()) { |
| 182 | - Locale locale = Beans.getReference(Locale.class); | ||
| 183 | - ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", locale); | ||
| 184 | - | 180 | + ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); |
| 185 | throw new NotLoggedInException(bundle.getString("user-not-authenticated")); | 181 | throw new NotLoggedInException(bundle.getString("user-not-authenticated")); |
| 186 | } | 182 | } |
| 187 | } | 183 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 1 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 2 | 38 | ||
| 3 | import java.io.FileNotFoundException; | 39 | import java.io.FileNotFoundException; |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TrancationContextImpl.java
| @@ -16,8 +16,9 @@ public class TrancationContextImpl implements TransactionContext { | @@ -16,8 +16,9 @@ public class TrancationContextImpl implements TransactionContext { | ||
| 16 | private static final long serialVersionUID = 1L; | 16 | private static final long serialVersionUID = 1L; |
| 17 | 17 | ||
| 18 | @Override | 18 | @Override |
| 19 | - public Transaction currentTransaction() { | ||
| 20 | - return StrategySelector.getReference("frameworkdemoiselle.transaction.class", Transaction.class, DefaultTransaction.class); | 19 | + public Transaction getCurrentTransaction() { |
| 20 | + return StrategySelector.getReference("frameworkdemoiselle.transaction.class", Transaction.class, | ||
| 21 | + DefaultTransaction.class); | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | } | 24 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionInfo.java
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 1 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 2 | 38 | ||
| 3 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 4 | 40 | ||
| 5 | import javax.enterprise.context.RequestScoped; | 41 | import javax.enterprise.context.RequestScoped; |
| 6 | 42 | ||
| 7 | -//TODO Inter [NQ]: considerar a necessidade da criação de um contexto de transação para manter a coerência com as demais funcionalidades que possuem um contexto. | ||
| 8 | -//Resposta: não foi feito porque só foi identificado uma funcionalidade (getCurrentTransaction). Aguardar novas ideias. | ||
| 9 | @RequestScoped | 43 | @RequestScoped |
| 10 | public class TransactionInfo implements Serializable { | 44 | public class TransactionInfo implements Serializable { |
| 11 | 45 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptor.java
| @@ -38,20 +38,20 @@ package br.gov.frameworkdemoiselle.internal.interceptor; | @@ -38,20 +38,20 @@ package br.gov.frameworkdemoiselle.internal.interceptor; | ||
| 38 | 38 | ||
| 39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 40 | 40 | ||
| 41 | -import javax.enterprise.inject.Instance; | ||
| 42 | -import javax.inject.Inject; | 41 | +import javax.enterprise.context.ContextNotActiveException; |
| 43 | import javax.interceptor.AroundInvoke; | 42 | import javax.interceptor.AroundInvoke; |
| 44 | import javax.interceptor.Interceptor; | 43 | import javax.interceptor.Interceptor; |
| 45 | import javax.interceptor.InvocationContext; | 44 | import javax.interceptor.InvocationContext; |
| 46 | 45 | ||
| 47 | import org.slf4j.Logger; | 46 | import org.slf4j.Logger; |
| 48 | 47 | ||
| 49 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 50 | import br.gov.frameworkdemoiselle.exception.ApplicationException; | 48 | import br.gov.frameworkdemoiselle.exception.ApplicationException; |
| 51 | import br.gov.frameworkdemoiselle.internal.implementation.TransactionInfo; | 49 | import br.gov.frameworkdemoiselle.internal.implementation.TransactionInfo; |
| 50 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 52 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 51 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 53 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; | 52 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
| 54 | import br.gov.frameworkdemoiselle.transaction.Transactional; | 53 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 54 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 55 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 55 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 56 | 56 | ||
| 57 | @Interceptor | 57 | @Interceptor |
| @@ -60,22 +60,41 @@ public class TransactionalInterceptor implements Serializable { | @@ -60,22 +60,41 @@ public class TransactionalInterceptor implements Serializable { | ||
| 60 | 60 | ||
| 61 | private static final long serialVersionUID = 1L; | 61 | private static final long serialVersionUID = 1L; |
| 62 | 62 | ||
| 63 | - private final Instance<TransactionContext> context; | 63 | + private TransactionContext transactionContext; |
| 64 | 64 | ||
| 65 | - private final Logger logger; | 65 | + private TransactionInfo transactionInfo; |
| 66 | 66 | ||
| 67 | - private final ResourceBundle bundle; | 67 | + private ResourceBundle bundle; |
| 68 | 68 | ||
| 69 | - private final Instance<TransactionInfo> info; | 69 | + private Logger logger; |
| 70 | 70 | ||
| 71 | - @Inject | ||
| 72 | - public TransactionalInterceptor(Instance<TransactionContext> context, Instance<TransactionInfo> info, | ||
| 73 | - Logger logger, @Name("demoiselle-core-bundle") ResourceBundle bundle) { | ||
| 74 | - this.context = context; | ||
| 75 | - this.info = info; | ||
| 76 | - this.logger = logger; | ||
| 77 | - this.bundle = bundle; | 71 | + private TransactionContext getTransactionContext() { |
| 72 | + if (this.transactionContext == null) { | ||
| 73 | + this.transactionContext = Beans.getReference(TransactionContext.class); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + return this.transactionContext; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + private TransactionInfo newTransactionInfo() { | ||
| 80 | + TransactionInfo instance; | ||
| 81 | + | ||
| 82 | + try { | ||
| 83 | + instance = Beans.getReference(TransactionInfo.class); | ||
| 84 | + | ||
| 85 | + } catch (ContextNotActiveException cause) { | ||
| 86 | + instance = new TransactionInfo(); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + return instance; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + private TransactionInfo getTransactionInfo() { | ||
| 93 | + if (this.transactionInfo == null) { | ||
| 94 | + this.transactionInfo = newTransactionInfo(); | ||
| 95 | + } | ||
| 78 | 96 | ||
| 97 | + return this.transactionInfo; | ||
| 79 | } | 98 | } |
| 80 | 99 | ||
| 81 | @AroundInvoke | 100 | @AroundInvoke |
| @@ -84,9 +103,7 @@ public class TransactionalInterceptor implements Serializable { | @@ -84,9 +103,7 @@ public class TransactionalInterceptor implements Serializable { | ||
| 84 | 103 | ||
| 85 | Object result = null; | 104 | Object result = null; |
| 86 | try { | 105 | try { |
| 87 | - this.logger.debug(bundle.getString("transactional-execution", ic.getMethod().toGenericString())); | ||
| 88 | - info.get().incrementCounter(); | ||
| 89 | - | 106 | + getLogger().debug(getBundle().getString("transactional-execution", ic.getMethod().toGenericString())); |
| 90 | result = ic.proceed(); | 107 | result = ic.proceed(); |
| 91 | 108 | ||
| 92 | } catch (Exception cause) { | 109 | } catch (Exception cause) { |
| @@ -94,7 +111,6 @@ public class TransactionalInterceptor implements Serializable { | @@ -94,7 +111,6 @@ public class TransactionalInterceptor implements Serializable { | ||
| 94 | throw cause; | 111 | throw cause; |
| 95 | 112 | ||
| 96 | } finally { | 113 | } finally { |
| 97 | - info.get().decrementCounter(); | ||
| 98 | complete(ic); | 114 | complete(ic); |
| 99 | } | 115 | } |
| 100 | 116 | ||
| @@ -102,20 +118,22 @@ public class TransactionalInterceptor implements Serializable { | @@ -102,20 +118,22 @@ public class TransactionalInterceptor implements Serializable { | ||
| 102 | } | 118 | } |
| 103 | 119 | ||
| 104 | private void initiate(final InvocationContext ic) { | 120 | private void initiate(final InvocationContext ic) { |
| 105 | - Transaction tx = this.context.get().currentTransaction(); | ||
| 106 | - TransactionInfo ctx = this.info.get(); | 121 | + Transaction transaction = getTransactionContext().getCurrentTransaction(); |
| 122 | + TransactionInfo transactionInfo = getTransactionInfo(); | ||
| 107 | 123 | ||
| 108 | - if (!tx.isActive()) { | ||
| 109 | - tx.begin(); | ||
| 110 | - ctx.markAsOwner(); | ||
| 111 | - this.logger.info(bundle.getString("begin-transaction")); | 124 | + if (!transaction.isActive()) { |
| 125 | + transaction.begin(); | ||
| 126 | + transactionInfo.markAsOwner(); | ||
| 127 | + getLogger().info(getBundle().getString("begin-transaction")); | ||
| 112 | } | 128 | } |
| 129 | + | ||
| 130 | + transactionInfo.incrementCounter(); | ||
| 113 | } | 131 | } |
| 114 | 132 | ||
| 115 | private void handleException(final Exception cause) { | 133 | private void handleException(final Exception cause) { |
| 116 | - Transaction tx = this.context.get().currentTransaction(); | 134 | + Transaction transaction = getTransactionContext().getCurrentTransaction(); |
| 117 | 135 | ||
| 118 | - if (!tx.isMarkedRollback()) { | 136 | + if (!transaction.isMarkedRollback()) { |
| 119 | boolean rollback = false; | 137 | boolean rollback = false; |
| 120 | ApplicationException annotation = cause.getClass().getAnnotation(ApplicationException.class); | 138 | ApplicationException annotation = cause.getClass().getAnnotation(ApplicationException.class); |
| 121 | 139 | ||
| @@ -124,30 +142,47 @@ public class TransactionalInterceptor implements Serializable { | @@ -124,30 +142,47 @@ public class TransactionalInterceptor implements Serializable { | ||
| 124 | } | 142 | } |
| 125 | 143 | ||
| 126 | if (rollback) { | 144 | if (rollback) { |
| 127 | - tx.setRollbackOnly(); | ||
| 128 | - this.logger.info(bundle.getString("transaction-marked-rollback", cause.getMessage())); | 145 | + transaction.setRollbackOnly(); |
| 146 | + getLogger().info(getBundle().getString("transaction-marked-rollback", cause.getMessage())); | ||
| 129 | } | 147 | } |
| 130 | } | 148 | } |
| 131 | } | 149 | } |
| 132 | 150 | ||
| 133 | private void complete(final InvocationContext ic) { | 151 | private void complete(final InvocationContext ic) { |
| 134 | - Transaction tx = this.context.get().currentTransaction(); | ||
| 135 | - TransactionInfo ctx = this.info.get(); | 152 | + Transaction transaction = getTransactionContext().getCurrentTransaction(); |
| 153 | + TransactionInfo transactionInfo = getTransactionInfo(); | ||
| 154 | + transactionInfo.decrementCounter(); | ||
| 136 | 155 | ||
| 137 | - if (ctx.getCounter() == 0 && tx.isActive()) { | 156 | + if (transactionInfo.getCounter() == 0 && transaction.isActive()) { |
| 138 | 157 | ||
| 139 | - if (ctx.isOwner()) { | ||
| 140 | - if (tx.isMarkedRollback()) { | ||
| 141 | - tx.rollback(); | ||
| 142 | - this.logger.info(bundle.getString("transaction-rolledback")); | 158 | + if (transactionInfo.isOwner()) { |
| 159 | + if (transaction.isMarkedRollback()) { | ||
| 160 | + transaction.rollback(); | ||
| 161 | + getLogger().info(getBundle().getString("transaction-rolledback")); | ||
| 143 | } else { | 162 | } else { |
| 144 | - tx.commit(); | ||
| 145 | - this.logger.info(bundle.getString("transaction-commited")); | 163 | + transaction.commit(); |
| 164 | + getLogger().info(getBundle().getString("transaction-commited")); | ||
| 146 | } | 165 | } |
| 147 | } | 166 | } |
| 148 | 167 | ||
| 149 | - } else if (ctx.getCounter() == 0 && !tx.isActive()) { | ||
| 150 | - this.logger.info(bundle.getString("transaction-already-finalized")); | 168 | + } else if (transactionInfo.getCounter() == 0 && !transaction.isActive()) { |
| 169 | + getLogger().info(getBundle().getString("transaction-already-finalized")); | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + private ResourceBundle getBundle() { | ||
| 174 | + if (this.bundle == null) { | ||
| 175 | + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
| 151 | } | 176 | } |
| 177 | + | ||
| 178 | + return this.bundle; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + private Logger getLogger() { | ||
| 182 | + if (this.logger == null) { | ||
| 183 | + this.logger = Beans.getReference(Logger.class); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + return this.logger; | ||
| 152 | } | 187 | } |
| 153 | } | 188 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionContext.java
| @@ -45,5 +45,5 @@ import java.io.Serializable; | @@ -45,5 +45,5 @@ import java.io.Serializable; | ||
| 45 | */ | 45 | */ |
| 46 | public interface TransactionContext extends Serializable { | 46 | public interface TransactionContext extends Serializable { |
| 47 | 47 | ||
| 48 | - Transaction currentTransaction(); | 48 | + Transaction getCurrentTransaction(); |
| 49 | } | 49 | } |