r2914 - trunk/lima-business/src/main/java/org/chorem/lima/business/ejb
Author: jpepin Date: 2010-05-27 17:06:34 +0200 (Thu, 27 May 2010) New Revision: 2914 Url: http://chorem.org/repositories/revision/lima/2914 Log: Move begin transaction & commit in methods 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/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.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/ReportServiceImpl.java 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 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -95,9 +95,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // check if account number already exist AccountDAO accountDAO = @@ -119,8 +117,7 @@ accountDAO.update(masterAccount); } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -142,9 +139,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // check if the accountnumber already exist AccountDAO accountDAO = @@ -165,8 +160,7 @@ accountDAO.update(masterAccount); } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -191,7 +185,7 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); @@ -218,7 +212,7 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); @@ -256,7 +250,7 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); @@ -299,7 +293,7 @@ public void removeAccount(Account account) throws LimaException { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // Check rules accountingRules.removeAccountRules(account, transaction); @@ -313,8 +307,7 @@ AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); accountDAO.delete(account); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } } catch (TopiaException ex) { @@ -333,7 +326,7 @@ public void removeAccountwithSubAccounts(Account account) throws LimaException{ TopiaContext transaction = null; try{ - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); List<Account> existingSubAccounts = getChildrenAccounts(account); @@ -344,8 +337,7 @@ } // remove account accountDAO.delete(account); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -372,13 +364,12 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // update account AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); accountDAO.update(account); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { if (log.isErrorEnabled()) { @@ -387,4 +378,22 @@ throw new LimaException("Can't update account", ex); } } + + protected void commitTransaction(TopiaContext transaction) throws TopiaException { + try { + transaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } + + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext transaction; + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + return transaction; + } } \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -89,9 +89,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // check if entrybook with is name already exist EntryBookDAO entryBookDAO = @@ -123,8 +121,7 @@ closedPeriodicEntryBookDAO.create(closedPeriodicEntryBook); } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -142,9 +139,7 @@ List<EntryBook> EntryBooksList = new ArrayList<EntryBook>(); TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); // check if entrybook with is name already exist EntryBookDAO EntryBookDAO = @@ -152,8 +147,7 @@ List<EntryBook> EntryBooks = EntryBookDAO.findAll(); EntryBooksList.addAll(EntryBooks); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -174,9 +168,7 @@ public void updateEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); @@ -184,8 +176,7 @@ // creation du EntryBook entryBookDAO.update(entryBook); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -208,9 +199,7 @@ TopiaContext topiaTransaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); //check accountingRules.removeEntryBookRules(entryBook, topiaTransaction); @@ -220,8 +209,7 @@ LimaCallaoDAOHelper.getEntryBookDAO(topiaTransaction); EntryBookDAO.delete(entryBook); - // commit - topiaTransaction.commitTransaction(); + commitTransaction(topiaTransaction); } catch (TopiaException ex) { doCatch(topiaTransaction, ex, log); @@ -230,4 +218,22 @@ doFinally(topiaTransaction, log); } } + + protected void commitTransaction(TopiaContext transaction) throws TopiaException { + try { + transaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } + + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext transaction; + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + return transaction; + } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -89,9 +89,7 @@ TopiaContext topiaTransaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); createFinancialPeriodWithTransaction(financialPeriod, topiaTransaction); } @@ -110,9 +108,7 @@ public void createFinancialPeriodWithTransaction(FinancialPeriod financialPeriod, TopiaContext topiaContext) throws LimaException { try { - // basic check done, make check in database - // TODO move it into JTA - + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); @@ -135,8 +131,7 @@ //create financial period financialPeriodDAO.create(financialPeriod); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -153,16 +148,13 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. getFinancialPeriodDAO(transaction); result = financialPeriodDAO.findAll(); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -184,16 +176,13 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. getFinancialPeriodDAO(transaction); result = financialPeriodDAO.findAllByLocked(false); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -212,7 +201,7 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); @@ -235,11 +224,12 @@ @Override public ClosedPeriodicEntryBook getClosedPeriodicEntryBook(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException { - ClosedPeriodicEntryBook closedPeriodicEntryBook = new ClosedPeriodicEntryBookImpl(); + ClosedPeriodicEntryBook closedPeriodicEntryBook = + new ClosedPeriodicEntryBookImpl(); TopiaContext topiaContext = null; try { - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); @@ -269,7 +259,7 @@ TopiaContext topiaContext = null; try { - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); //check rules before create the account accountingRules.blockClosedPeriodicEntryBookRules(closedPeriodicEntryBook, topiaContext); @@ -283,8 +273,7 @@ closedPeriodicEntryBook2.setLocked(true); closedPeriodicEntryBookDAO.update(closedPeriodicEntryBook2); - //commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -302,9 +291,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); @@ -318,17 +305,20 @@ .addOrder(FiscalPeriod.FINANCIAL_PERIOD, FinancialPeriod.BEGIN_DATE); //IMPORTANT : LOADING ClosedPeriodicEntryBook AND IS COLUMN FOR NO LAZY EXCEPTION - String loadEntryBookProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.ENTRY_BOOK, EntryBook.LABEL); + String loadEntryBookProperty = + TopiaQuery.getProperty(ClosedPeriodicEntryBook.ENTRY_BOOK, + EntryBook.LABEL); query.addLoad(loadEntryBookProperty); - String loadFinancialPeriodProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, FinancialPeriod.BEGIN_DATE); + String loadFinancialPeriodProperty = + TopiaQuery.getProperty(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, + FinancialPeriod.BEGIN_DATE); query.addLoad(loadFinancialPeriodProperty); //call query result = closedPeriodicEntryBookDAO.findAllByQuery(query); log.debug(result); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -346,9 +336,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); @@ -358,8 +346,7 @@ closedPeriodicEntryBook.getEntryBook().getLabel(); closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(); } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -369,7 +356,23 @@ } return result; } + + protected void commitTransaction(TopiaContext transaction) throws TopiaException { + try { + transaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext topiaTransaction; + // basic check done, make check in database + // TODO move it into JTA + topiaTransaction = rootContext.beginTransaction(); + return topiaTransaction; + } - } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -90,9 +90,7 @@ TopiaContext topiaContext = null; try { - // basic check done, make check in database - // TODO move it into JTA - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( @@ -103,8 +101,7 @@ financialtransactionDAO.create(financialtransaction); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -190,7 +187,6 @@ @Override public List<FinancialTransaction> getAllFinancialTransactionsForFinancialPeriod( FinancialPeriod period) throws LimaException { - // TODO Auto-generated method stub return getAllFinancialTransactionsForEntryBookAndFinancialPeriod(null, period); } @@ -203,7 +199,7 @@ List<FinancialTransaction> financialTransactions = null; TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); @@ -246,17 +242,17 @@ TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction, topiaTransaction); + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( + financialtransaction, topiaTransaction); FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); transactionDAO.update(financialtransaction); - // commit - topiaTransaction.commitTransaction(); + commitTransaction(topiaTransaction); } catch (TopiaException ex) { doCatch(topiaTransaction, ex, log); @@ -272,18 +268,18 @@ TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction, topiaTransaction); + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( + financialtransaction, topiaTransaction); FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); FinancialTransaction financialTransaction2 = transactionDAO.findByTopiaId(financialtransaction.getTopiaId()); transactionDAO.delete(financialTransaction2); - // commit - topiaTransaction.commitTransaction(); + commitTransaction(topiaTransaction); } catch (TopiaException ex) { doCatch(topiaTransaction, ex, log); @@ -301,18 +297,16 @@ TopiaContext topiaContext = null; try { - // basic check done, make check in database - // TODO move it into JTA - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(entry.getFinancialTransaction(), topiaContext); + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( + entry.getFinancialTransaction(), topiaContext); EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); //delete entryDAO.delete(entry); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -327,8 +321,7 @@ TopiaContext topiaContext = null; try { - // TODO move it into JTA - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); @@ -349,8 +342,7 @@ entryOld.setLettering(entry.getLettering()); //update entryDAO.update(entryOld); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -372,19 +364,17 @@ TopiaContext topiaContext = null; try { - // basic check done, make check in database - // TODO move it into JTA - topiaContext = rootContext.beginTransaction(); + topiaContext = beginTransaction(); //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(entry.getFinancialTransaction(), topiaContext); + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( + entry.getFinancialTransaction(), topiaContext); EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); entryDAO.create(entry); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -393,4 +383,22 @@ doFinally(topiaContext, log); } } + + protected void commitTransaction(TopiaContext topiaContext) throws TopiaException { + try { + topiaContext.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } + + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext topiaContext; + // basic check done, make check in database + // TODO move it into JTA + topiaContext = rootContext.beginTransaction(); + return topiaContext; + } } \ 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 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -80,9 +80,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); //check rules before create the account accountingRules.createFiscalPeriodRules(fiscalPeriod, transaction); @@ -93,8 +91,7 @@ //create fiscalPeriodDAO.create(fiscalPeriod); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -114,16 +111,13 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); result = fiscalPeriodDAO.findAll(); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -144,9 +138,7 @@ TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); @@ -160,8 +152,7 @@ } } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -178,9 +169,7 @@ FiscalPeriod result = null; TopiaContext transaction = null; try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); @@ -215,7 +204,7 @@ //open transaction for check try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); if (fiscalPeriod.getLocked()==true){ throw new LimaBusinessException("Fiscal Period already blocked"); @@ -232,7 +221,7 @@ //open transaction for update try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); @@ -246,8 +235,7 @@ fiscalPeriodDAO.update(fiscalPeriod); - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -264,7 +252,7 @@ public void removeAllFiscalPeriods() throws LimaException{ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); @@ -277,8 +265,7 @@ fiscalPeriodDAO.delete(fiscalPeriod); } - // commit - transaction.commitTransaction(); + commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -287,4 +274,23 @@ doFinally(transaction, log); } } + + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext transaction; + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + return transaction; + } + + protected void commitTransaction(TopiaContext transaction) throws TopiaException { + try { + transaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } + } 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 2010-05-27 14:36:34 UTC (rev 2913) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-05-27 15:06:34 UTC (rev 2914) @@ -73,7 +73,7 @@ TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); reportsDatas = generateAccountReportsWithTransaction(account, beginDate, @@ -106,13 +106,16 @@ // First subaccount List<Account> accounts = account.getSubAccounts(); if (accounts.size() == 0){ - reportsDatas = generateSubAccountReportsWithTransaction(account, beginDate, endDate, topiaContext); + reportsDatas = generateSubAccountReportsWithTransaction(account, + beginDate, endDate, topiaContext); } //Second many account else { List<Entry> entries = new ArrayList<Entry>(); for (Account subAccount : accounts) { - ReportsDatas subReportsDatas = generateAccountReportsWithTransaction(subAccount, beginDate, endDate, topiaContext); + ReportsDatas subReportsDatas = + generateAccountReportsWithTransaction(subAccount, + beginDate,endDate, topiaContext); debit += subReportsDatas.getAmountDebit(); credit += subReportsDatas.getAmountCredit(); entries.addAll(subReportsDatas.getListEntry()); @@ -196,8 +199,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -249,8 +251,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - // commit - topiaContext.commitTransaction(); + commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -275,7 +276,7 @@ // Get all entries with a topia query TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); EntryDAO entryDAO= LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); TopiaQuery query = entryDAO.createQuery("E"); String transactionDateProperty = @@ -321,8 +322,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - // commit - topiaTransaction.commitTransaction(); + commitTransaction(topiaTransaction); } catch (TopiaException ex) { doCatch(topiaTransaction, ex, log); @@ -348,11 +348,13 @@ TopiaContext topiaTransaction = null; try { - topiaTransaction = rootContext.beginTransaction(); + topiaTransaction = beginTransaction(); //for each account create a balance sheet with a ReportsDatas for (Account account : accountService.getAllSubAccounts()) { - ReportsDatas reportsDatas = generateSubAccountBalanceWithTransaction(account, beginDate, endDate, topiaTransaction); + ReportsDatas reportsDatas = + generateSubAccountBalanceWithTransaction(account, beginDate, + endDate, topiaTransaction); reportsDatas.setAccount(account); // add balance sheet to balance trial balanceTrial.addReportsDatas(reportsDatas); @@ -382,4 +384,20 @@ return balanceTrial; } + + protected TopiaContext beginTransaction() throws TopiaException { + TopiaContext topiaTransaction; + topiaTransaction = rootContext.beginTransaction(); + return topiaTransaction; + } + + protected void commitTransaction(TopiaContext topiaTransaction) throws TopiaException { + try { + topiaTransaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + } + } }
participants (1)
-
jpepin@users.chorem.org