Author: echatellier Date: 2012-04-17 17:37:23 +0200 (Tue, 17 Apr 2012) New Revision: 3371 Url: http://chorem.org/repositories/revision/lima/3371 Log: Add transaction support by container. Added: trunk/lima-business/src/main/java/org/chorem/lima/LimaThread.java trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java Removed: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountServiceLocal.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/resources/META-INF/ejb-jar.xml Added: trunk/lima-business/src/main/java/org/chorem/lima/LimaThread.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/LimaThread.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/LimaThread.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -0,0 +1,42 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima; + +import org.nuiton.topia.TopiaContext; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaThread { + + public static ThreadLocal<TopiaContext> threadLocal = new ThreadLocal<TopiaContext>(); +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/LimaThread.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -0,0 +1,153 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima; + +import javax.transaction.xa.XAException; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +/** + * Topia XA ressource containing TopiaContext to commit or rollback. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaXAResource implements XAResource { + + private static Log log = LogFactory.getLog(LimaXAResource.class); + + protected TopiaContext context; + + protected int timeout; + + public LimaXAResource(TopiaContext context) { + this.context = context; + } + + /* + * @see javax.transaction.xa.XAResource#commit(javax.transaction.xa.Xid, boolean) + */ + @Override + public void commit(Xid arg0, boolean arg1) throws XAException { + try { + context.commitTransaction(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error", ex); + } + throw new XAException(XAException.XA_HEURCOM); + } + } + + /* + * @see javax.transaction.xa.XAResource#end(javax.transaction.xa.Xid, int) + */ + @Override + public void end(Xid arg0, int arg1) throws XAException { + /*try { + context.closeContext(); + } catch (TopiaException ex) { + throw new XAException(XAException.XA_HEURCOM); + }*/ + } + + /* + * @see javax.transaction.xa.XAResource#forget(javax.transaction.xa.Xid) + */ + @Override + public void forget(Xid xid) throws XAException { + + } + + /* + * @see javax.transaction.xa.XAResource#getTransactionTimeout() + */ + @Override + public int getTransactionTimeout() throws XAException { + return timeout; + } + + /* + * @see javax.transaction.xa.XAResource#isSameRM(javax.transaction.xa.XAResource) + */ + @Override + public boolean isSameRM(XAResource xar) throws XAException { + return false; + } + + /* + * @see javax.transaction.xa.XAResource#prepare(javax.transaction.xa.Xid) + */ + @Override + public int prepare(Xid xid) throws XAException { + return XAResource.XA_OK; + } + + /* + * @see javax.transaction.xa.XAResource#recover(int) + */ + @Override + public Xid[] recover(int arg0) throws XAException { + return null; + } + + /* + * @see javax.transaction.xa.XAResource#rollback(javax.transaction.xa.Xid) + */ + @Override + public void rollback(Xid arg0) throws XAException { + try { + context.rollbackTransaction(); + } catch (TopiaException ex) { + throw new XAException(XAException.XA_HEURCOM); + } + } + + /* + * @see javax.transaction.xa.XAResource#setTransactionTimeout(int) + */ + @Override + public boolean setTransactionTimeout(int timeout) throws XAException { + this.timeout = timeout; + return true; + } + + /* + * @see javax.transaction.xa.XAResource#start(javax.transaction.xa.Xid, int) + */ + @Override + public void start(Xid arg0, int arg1) throws XAException { + + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -53,7 +53,7 @@ void updateAccountRules(Account account) throws LimaException; - void removeAccountRules(Account account, TopiaContext transaction) throws LimaException; + void removeAccountRules(Account account) throws LimaException; /** * Entrybook rules. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -0,0 +1,62 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +import org.chorem.lima.entity.AccountDAO; +import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +/** + * DOA helper based on EJB because of context using. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaDaoHelper { + + protected static TopiaContext getContextTransaction() { + TopiaContext result = (TopiaContext)LimaInterceptor.TOPIA_CONTEXT.get(); + + if (result == null) { + throw new IllegalStateException("No opened transaction found. Put @TransactionAttribute on method or class"); + } + + return result; + } + + public static AccountDAO getAccountDAO() throws TopiaException { + return LimaCallaoDAOHelper.getAccountDAO(getContextTransaction()); + } + + public static EntryDAO getEntryDAO() throws TopiaException { + return LimaCallaoDAOHelper.getEntryDAO(getContextTransaction()); + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -0,0 +1,122 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +import javax.annotation.Resource; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaXAResource; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; + +/** + * Interceptor for topia context transaction. + * + * http://stackoverflow.com/questions/8608349 + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Stateless +public class LimaInterceptor { + + private final Log log = LogFactory.getLog(LimaInterceptor.class); + + public static final ThreadLocal<TopiaContext> TOPIA_CONTEXT = new ThreadLocal<TopiaContext>(); + + @Resource + private TransactionManager transactionManager; + + protected TopiaContext rootContext; + + public LimaInterceptor() { + if (log.isInfoEnabled()) { + log.info("Init root context"); + } + + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getFlatOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init root context", ex); + } + } + } + + @AroundInvoke + public Object invoke(InvocationContext context) throws Exception { + + Object result; + + // only open transaction when incoming call just + // enter in service layer + // interceptor will be called before each internal + // ejb call, but opening a new transaction in not required + if (TOPIA_CONTEXT.get() == null) { + + // maybe take care of TransactionAttributeTypes ? + if (context.getTarget().getClass().getAnnotation(TransactionAttribute.class) != null || + context.getMethod().getAnnotation(TransactionAttribute.class) != null) { + if (log.isDebugEnabled()) { + log.debug("Init new topia transaction for method : " + + context.getTarget().getClass() + "#" + context.getMethod().getName()); + } + + TopiaContext tx = rootContext.beginTransaction(); + + TOPIA_CONTEXT.set(tx); + + Transaction tr = transactionManager.getTransaction(); + + // enlist topia xaresource, will will commited or rollback + // by container + tr.enlistResource(new LimaXAResource(tx)); + + result = context.proceed(); + TOPIA_CONTEXT.remove(); + } else { + result = context.proceed(); + } + + } else { + result = context.proceed(); + } + + return result; + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,11 +25,18 @@ package org.chorem.lima.business.accountingrules; +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaDaoHelper; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; @@ -48,12 +55,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - /** * Defaults rules, if no localized rules classes is instantiated * this default class contain the strict minimum rules to check the data integrity. @@ -67,6 +68,9 @@ protected static final Log log = LogFactory.getLog(DefaultAccountingRules.class); + /** DAO helper not injected by EJB. */ + protected LimaDaoHelper daoHelper = new LimaDaoHelper(); + /** * Rules to check before create accounts. */ @@ -111,16 +115,16 @@ * Recursive function */ @Override - public void removeAccountRules(Account account, TopiaContext transaction) throws LimaException { + public void removeAccountRules(Account account) throws LimaException { try { - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + EntryDAO entryDAO = daoHelper.getEntryDAO(); // Check if account have entries int nbentries = entryDAO.findAllByAccount(account).size(); if (nbentries != 0) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.deleteaccounterror")); } } catch (TopiaException ex) { - doCatch(transaction, ex, log); + throw new LimaException("Can't remvoe account", ex); } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,28 +25,26 @@ package org.chorem.lima.business.ejb; +import static org.nuiton.i18n.I18n._; + +import java.util.Collections; +import java.util.List; + +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaDaoHelper; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.AccountServiceLocal; import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - /** * Permet d'implémenter le Plan Comptable Général. * Un compte ne peut être supprimé si il contient des écritures comptables. @@ -57,40 +55,35 @@ */ @Stateless @Remote(AccountService.class) -@Local(AccountServiceLocal.class) -public class AccountServiceImpl extends AbstractLimaService implements AccountService, AccountServiceLocal { +@TransactionAttribute +public class AccountServiceImpl extends AbstractLimaService implements AccountService { - private TopiaContext rootContext; - - public AccountServiceImpl() { - rootContext = acquireRootContext(); - } - @Override public long getAccountCount() throws LimaException { long result = 0; - TopiaContext transaction = beginTransaction(rootContext); - try { - // check if the accountnumber already exist - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - + try { + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); result = accountDAO.count(); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + } catch (TopiaException ex) { + throw new LimaException("Can't count", ex); } return result; } /** - * Create new account with existing transaction. + * Permet de créer un nouveau compte dans le PCG de l'application. + * + * @param account account to create + * @throws LimaException */ @Override - public Account createAccountWithTransaction(Account account, - TopiaContext topiaContext) throws LimaException { + public Account createAccount(Account account) throws LimaException { + // check rules before create the account + AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); + accountingRules.createAccountRules(account); + Account result = null; try { @@ -98,8 +91,7 @@ account.setAccountNumber(account.getAccountNumber().toUpperCase()); // check if account number already exist - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); Account existAccount = accountDAO.findByAccountNumber(account.getAccountNumber()); @@ -111,63 +103,19 @@ //create it result = accountDAO.create(account); - - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create account", ex); } return result; } - - /** - * Permet de créer un nouveau compte dans le PCG de l'application. - * ATTENTION : le compte masterAccount, c'est à dire le compte père, doit - * exister, sinon le compte n'est pas créé. Si le compte n'a pas de père, alors - * mettre masterAccount à null. - * - * @param account account to create - * @throws LimaException - */ @Override - public Account createAccount(Account account) throws LimaException { - - // check rules before create the account - AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - accountingRules.createAccountRules(account); - - Account result = null; - TopiaContext transaction = beginTransaction(rootContext); - try { - - // check if the accountnumber already exist - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - Account existAccount = - accountDAO.findByAccountNumber(account.getAccountNumber()); - if (existAccount != null) { - throw new LimaBusinessException(_( - "lima-business.account.accountalreardyexist", - account.getAccountNumber())); - } - - result = createAccountWithTransaction(account, transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - return result; - } - - @Override public Account getMasterAccount(String accountNumber) throws LimaException { Account account = null; - TopiaContext transaction = beginTransaction(rootContext); try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); while (account == null && accountNumber.length() > 1) { @@ -175,10 +123,8 @@ account = accountDAO.findByAccountNumber(accountNumber); } - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + } catch (TopiaException ex) { + throw new LimaException("Can't get master account", ex); } return account; } @@ -188,16 +134,11 @@ public Account getAccountByNumber(String number) throws LimaException { Account account = null; - TopiaContext transaction = beginTransaction(rootContext); try { - - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); account = accountDAO.findByAccountNumber(number); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get master account", ex); } return account; @@ -208,18 +149,15 @@ @Override public List<Account> getAllAccounts() throws LimaException { - List<Account> accountsList = new ArrayList<Account>(); + List<Account> accountsList; - TopiaContext transaction = beginTransaction(rootContext); try { - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); accountsList = accountDAO.findAll(); Collections.sort(accountsList, new AccountComparator()); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get all accounts", ex); } return accountsList; @@ -232,15 +170,11 @@ List<Account> accountsList = null; - TopiaContext transaction = beginTransaction(rootContext); try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); accountsList = accountDAO.findAllLeafAccounts(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get all leaf accounts", ex); } return accountsList; @@ -258,10 +192,8 @@ List<Account> accountsList = null; - TopiaContext transaction = beginTransaction(rootContext); try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); //TopiaQuery query = accountDAO.createQuery(); //tchemit 2011-09-21 Only consider account childs from the master account @@ -294,9 +226,7 @@ accountsList = accountDAO.getSubAccounts(masterAccount); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get children accounts", ex); } return accountsList; @@ -320,24 +250,21 @@ */ @Override public void removeAccount(Account account) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); + AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { // Check rules for account if have entries - accountingRules.removeAccountRules(account, transaction); + accountingRules.removeAccountRules(account); // remove account - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); Account accountToDelete = accountDAO.findByTopiaId(account.getTopiaId()); accountDAO.delete(accountToDelete); - commitTransaction(transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + } catch (TopiaException ex) { + throw new LimaException("Can't remove account", ex); } } @@ -349,7 +276,6 @@ } } - /** * Permet de modifier un compte sur son label. * <p/> @@ -362,23 +288,19 @@ @Override public Account updateAccount(Account account) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); Account result = null; try { // DAO - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = LimaDaoHelper.getAccountDAO(); accountingRules.updateAccountRules(account); result = accountDAO.update(account); - commitTransaction(transaction); + } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't update account", ex); } - + return result; } } \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,6 +25,22 @@ package org.chorem.lima.business.ejb; +import static org.nuiton.i18n.I18n._; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import javax.ejb.EJB; +import javax.ejb.Local; +import javax.ejb.Remote; +import javax.ejb.Stateless; + import org.apache.commons.lang3.time.DateUtils; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.ReportsDatas; @@ -32,7 +48,7 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.api.AccountServiceLocal; +import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.EntryBookServiceLocal; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.FinancialTransactionServiceLocal; @@ -56,21 +72,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - /** * Gestion des exercices. * Un exercice ne peut être supprimée et débloquée après cloture. @@ -85,7 +86,7 @@ private TopiaContext rootContext; @EJB - protected AccountServiceLocal accountService; + protected AccountService accountService; @EJB protected FinancialPeriodServiceLocal financialPeriodService; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,9 +25,32 @@ package org.chorem.lima.business.ejb; -import au.com.bytecode.opencsv.CSVReader; -import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy; -import au.com.bytecode.opencsv.bean.CsvToBean; +import static org.nuiton.i18n.I18n._; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import javax.ejb.EJB; +import javax.ejb.Local; +import javax.ejb.Remote; +import javax.ejb.Stateless; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +77,7 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.api.AccountServiceLocal; +import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.EntryBookServiceLocal; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.FinancialStatementServiceLocal; @@ -100,31 +123,10 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import au.com.bytecode.opencsv.CSVReader; +import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy; +import au.com.bytecode.opencsv.bean.CsvToBean; -import static org.nuiton.i18n.I18n._; - /** * Import export service. * Currently import and export as CSV and EBP. @@ -139,7 +141,7 @@ private TopiaContext rootContext; @EJB - private AccountServiceLocal accountService; + private AccountService accountService; @EJB private FiscalPeriodServiceLocal fiscalPeriodService; @@ -365,7 +367,7 @@ .findByAccountNumber(masterAccountNumber); i++; } - accountService.createAccountWithTransaction(account, topiaContext); + accountService.createAccount(account); result.append(_("lima-business.import.accountadded", accountNumber, label)); } // else if account and exclude account start with 0 (fix from error on EBP) @@ -373,7 +375,7 @@ // if account is class account : 1, 2, 3, 4, 5, 6, 7,… int nbCharAccountNumber = accountNumber.length(); if (nbCharAccountNumber == 1) { - accountService.createAccountWithTransaction(account, topiaContext); + accountService.createAccount(account); result.append(_("lima-business.import.accountadded", accountNumber, label)); } else { Account masterAccount = null; @@ -385,7 +387,7 @@ .findByAccountNumber(masterAccountNumber); i++; } - accountService.createAccountWithTransaction(account, topiaContext); + accountService.createAccount(account); result.append(_("lima-business.import.accountadded", accountNumber, label)); } } @@ -1174,7 +1176,7 @@ account.setLabel(accountImport.getLabel()); account.setThirdParty(accountImport.getThirdParty()); - accountService.createAccountWithTransaction(account, topiaContext); + accountService.createAccount(account); result.append(_("lima-business.import.accountadded", accountImport.getAccountNumber(), Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,13 +25,23 @@ package org.chorem.lima.business.ejb; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.ejb.EJB; +import javax.ejb.Local; +import javax.ejb.Remote; +import javax.ejb.Stateless; + import org.apache.commons.lang3.StringUtils; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.BalanceTrialImpl; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.beans.ReportsDatasImpl; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.api.AccountServiceLocal; +import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.ReportService; import org.chorem.lima.business.api.ReportServiceLocal; @@ -48,15 +58,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - @Stateless @Remote(ReportService.class) @Local(ReportServiceLocal.class) @@ -68,7 +69,7 @@ protected FinancialPeriodServiceLocal financialPeriodService; @EJB - protected AccountServiceLocal accountService; + protected AccountService accountService; public ReportServiceImpl() { rootContext = acquireRootContext(); Modified: trunk/lima-business/src/main/resources/META-INF/ejb-jar.xml =================================================================== --- trunk/lima-business/src/main/resources/META-INF/ejb-jar.xml 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business/src/main/resources/META-INF/ejb-jar.xml 2012-04-17 15:37:23 UTC (rev 3371) @@ -25,5 +25,14 @@ <!-- Empty configuration file based on http://openejb.apache.org/application-discovery-via-the-classpath.html + + Interceptor based on : http://openejb.apache.org/examples-trunk/alternate-descriptors/ --> -<ejb-jar/> +<ejb-jar> + <assembly-descriptor> + <interceptor-binding> + <ejb-name>*</ejb-name> + <interceptor-class>org.chorem.lima.business.LimaInterceptor</interceptor-class> + </interceptor-binding> + </assembly-descriptor> +</ejb-jar> Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountServiceLocal.java 2012-04-13 16:06:28 UTC (rev 3370) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountServiceLocal.java 2012-04-17 15:37:23 UTC (rev 3371) @@ -1,45 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.api; - -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Account; -import org.nuiton.topia.TopiaContext; - -/** - * Account service. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -public interface AccountServiceLocal extends AccountService { - - Account createAccountWithTransaction(Account account, TopiaContext topiaContext) throws LimaException; - -} \ No newline at end of file