This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 76c960d99dd536626923c2932f623a2131ce0cad Author: David Cossé <cosse@codelutin.com> Date: Sun Oct 15 23:30:24 2017 +0200 refs #1396 amélioration de la vitesse d'exéction de l'import des entrées EBP --- .../chorem/lima/business/api/EntryBookService.java | 3 ++ .../business/api/FinancialTransactionService.java | 7 +++ .../lima/business/ejb/EntryBookServiceImpl.java | 51 +++++++++++++++++----- .../ejb/FinancialTransactionServiceImpl.java | 22 +++++++++- .../lima/business/ejb/ImportServiceImpl.java | 46 ++++++++++++------- lima-swing/src/main/assembly/lima | 7 +-- lima-swing/src/main/assembly/lima.bat | 2 +- 7 files changed, 106 insertions(+), 32 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java index 7e0ccda1..6b9a796d 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java @@ -26,6 +26,7 @@ import org.chorem.lima.business.exceptions.AlreadyExistEntryBookException; import org.chorem.lima.business.exceptions.LimaException; import org.chorem.lima.business.exceptions.UsedEntryBookException; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; import java.util.List; @@ -70,6 +71,8 @@ public interface EntryBookService { */ boolean createOrUpdateEntryBook(EntryBook entryBook); + EntryBook createImportedNewEntryBook(EntryBook entryBook, List<FinancialPeriod> financialPeriods); + /** * Create new entry book. * diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java index 43eb7825..254c6928 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java @@ -35,6 +35,7 @@ import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -62,6 +63,8 @@ public interface FinancialTransactionService { */ Entry createNewEntry(); + void createImportedFinancialTransactions(Collection<FinancialTransaction> financialtransactions); + FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException, LockedFinancialPeriodException, LockedEntryBookException; @@ -90,6 +93,8 @@ public interface FinancialTransactionService { List<FinancialTransaction> searchFinancialTransaction(FinancialTransactionCondition financialTransactionFilter); + void createdImportedEntry(Entry entry); + Entry createEntry(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException; void updateEntry(Entry entry) throws LockedEntryBookException, LockedFinancialPeriodException; @@ -164,4 +169,6 @@ public interface FinancialTransactionService { List<Entry> addLetter(List<Entry> entries) throws UnbalancedEntriesException, LockedEntryBookException; List<Entry> removeLetter(String letter); + + void createdImportedEntries(Collection<Entry> values); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java index f2df8971..c91cd3e7 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java @@ -42,6 +42,7 @@ import org.nuiton.util.beans.BinderFactory; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; +import java.util.ArrayList; import java.util.List; /** @@ -80,6 +81,20 @@ public class EntryBookServiceImpl extends AbstractLimaService implements EntryBo } @Override + public EntryBook createImportedNewEntryBook(EntryBook entryBook, List<FinancialPeriod> financialPeriods) { + + EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao(); + EntryBook result = entryBookTopiaDao.create(entryBook); + + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooksToSave = getClosedPeriodicEntryBooks(result, financialPeriods); + ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); + closedPeriodicEntryBookTopiaDao.createAll(closedPeriodicEntryBooksToSave); + + return result; + + } + + @Override public EntryBook createEntryBook(EntryBook entryBook) throws AlreadyExistEntryBookException { EntryBook result; // check if entrybook with is name already exist @@ -101,14 +116,16 @@ public class EntryBookServiceImpl extends AbstractLimaService implements EntryBo return result; } - protected void createClosedPeriodicEntryBook(EntryBook entryBook) { - //create ClosedPeriodicEntryBook for all unblocked financial period - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = - getDaoHelper().getClosedPeriodicEntryBookDao(); - FinancialPeriodTopiaDao financialPeriodTopiaDao = - getDaoHelper().getFinancialPeriodDao(); - // for all unblocked financialperiod - List<FinancialPeriod> financialPeriods = financialPeriodTopiaDao.forProperties(FinancialPeriod.PROPERTY_LOCKED, false).findAll(); + protected void createClosedPeriodicEntryBook(EntryBook entryBook, List<FinancialPeriod> financialPeriods) { + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooksToSave = getClosedPeriodicEntryBooks(entryBook, financialPeriods); + + ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); + // create it + closedPeriodicEntryBookTopiaDao.createAll(closedPeriodicEntryBooksToSave); + } + + protected List<ClosedPeriodicEntryBook> getClosedPeriodicEntryBooks(EntryBook entryBook, List<FinancialPeriod> financialPeriods) { + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooksToSave = new ArrayList<>(); for (FinancialPeriod financialPeriod : financialPeriods) { //new closed periodic entrybook @@ -118,9 +135,21 @@ public class EntryBookServiceImpl extends AbstractLimaService implements EntryBo closedPeriodicEntryBook.setEntryBook(entryBook); // set financial period closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); - // create it - closedPeriodicEntryBookTopiaDao.create(closedPeriodicEntryBook); - } + + closedPeriodicEntryBooksToSave.add(closedPeriodicEntryBook); + + } return closedPeriodicEntryBooksToSave; + } + + protected void createClosedPeriodicEntryBook(EntryBook entryBook) { + + //create ClosedPeriodicEntryBook for all unblocked financial period + FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); + + // for all unblocked financialperiod + List<FinancialPeriod> financialPeriods = financialPeriodTopiaDao.forProperties(FinancialPeriod.PROPERTY_LOCKED, false).findAll(); + + createClosedPeriodicEntryBook(entryBook, financialPeriods); } @Override diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java index b8fbabd1..95028251 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java @@ -128,6 +128,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme public FinancialTransaction createNewFinancialTransaction(){ FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); FinancialTransaction financialTransaction = financialtransactionTopiaDao.newInstance(); + financialTransaction.setEntry(Lists.newArrayList()); return financialTransaction; } @@ -139,6 +140,13 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme } @Override + public void createImportedFinancialTransactions(Collection<FinancialTransaction> financialTransactions) { + FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); + + financialtransactionTopiaDao.createAll(financialTransactions); + } + + @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LockedFinancialPeriodException, LockedEntryBookException, BeforeFirstFiscalPeriodException, AfterLastFiscalPeriodException { FinancialTransaction financialTransaction = createFinancialTransaction(financialtransaction, true); @@ -159,7 +167,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); if (financialtransaction.getEntry() == null) { - financialtransaction.setEntry(Lists.<Entry>newArrayList()); + financialtransaction.setEntry(Lists.newArrayList()); } FinancialTransaction result = financialtransactionTopiaDao.create(financialtransaction); @@ -392,6 +400,12 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme return entries; } + @Override + public void createdImportedEntries(Collection<Entry> entries) { + EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); + entryTopiaDao.createAll(entries); + } + public String findLastLetter(List<String> letters) { String result; @@ -580,6 +594,12 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme } @Override + public void createdImportedEntry(Entry entry) { + EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); + entryTopiaDao.create(entry); + } + + @Override public Entry createEntry(Entry entry) throws LockedFinancialPeriodException, LockedEntryBookException { AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java index 554c3195..3149378b 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java @@ -23,6 +23,7 @@ package org.chorem.lima.business.ejb; */ import com.google.common.base.Function; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; @@ -75,6 +76,8 @@ import org.chorem.lima.business.utils.EntryEBPComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodTopiaDao; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; @@ -993,6 +996,13 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ Date fiscalPeriodsEndingDate = fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate(); Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBeginDate, fiscalPeriodsEndingDate); + FinancialPeriodTopiaDao financialPeriodTopiaDao = + getDaoHelper().getFinancialPeriodDao(); + + // for all unblocked financialperiod + List<FinancialPeriod> financialPeriods = financialPeriodTopiaDao.forProperties(FinancialPeriod.PROPERTY_LOCKED, false).findAll(); + + Map<FinancialTransaction, Entry> financialTransactionsToSave = new HashMap<>(); for (EntryEBP entryEBP : entryEBPs) { Date dateEcr = entryEBP.getDatEcr(); @@ -1004,13 +1014,15 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ } // create entry else { - // creation of the entry + // creation of the entry (not persisted yet) // initialisation of this attributs - Entry entry = createEntry(entryEBP, account); + // entry is validate don't redo all check + Entry entry = createNewEntry(entryEBP, account); try { // find financial transactions for entry period and entrybook - addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr); + FinancialTransaction transaction = persistImportedEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr, financialPeriods); + financialTransactionsToSave.put(transaction, entry); } catch (LockedFinancialPeriodException | LockedEntryBookException | AlreadyExistEntryBookException | AfterLastFiscalPeriodException | BeforeFirstFiscalPeriodException e) { result.addException(e); @@ -1020,6 +1032,11 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ } result.increaseCreated(); } + List<FinancialTransaction> transactions = Lists.newArrayList(financialTransactionsToSave.keySet()); + financialTransactionService.createImportedFinancialTransactions(transactions); + List<Entry> entries = Lists.newArrayList(financialTransactionsToSave.values()); + financialTransactionService.createdImportedEntries(entries); + if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); log.info("Imported form EBP : " + entryEBPs.size() + " entries in " @@ -1032,7 +1049,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return results; } - protected Entry createEntry(EntryEBP entryEBP, final Account account) { + protected Entry createNewEntry(EntryEBP entryEBP, final Account account) { Entry entry; BigDecimal debit; entry = financialTransactionService.createNewEntry(); @@ -1054,14 +1071,10 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return entry; } - protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { + protected FinancialTransaction persistImportedEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr, List<FinancialPeriod> financialPeriods) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { - EntryBook entryBook = getEntryBook(indexedEntryBooks, entryBookCode); - Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.get(entryBook); - if (financialTransactionsByDate == null) { - financialTransactionsByDate = new HashMap<>(); - entryBookFinancialTransactionByDate.put(entryBook, financialTransactionsByDate); - } + EntryBook entryBook = getOrCreateEntryBook(indexedEntryBooks, entryBookCode, financialPeriods); + Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.computeIfAbsent(entryBook, k -> new HashMap<>()); // create transaction FinancialTransaction financialTransaction = financialTransactionsByDate.get(dateEcr); @@ -1075,14 +1088,15 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ financialTransaction = financialTransactionService.createNewFinancialTransaction(); financialTransaction.setEntryBook(entryBook); financialTransaction.setTransactionDate(dateEcr); - financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); + //financialTransaction = financialTransactionService.createImportedFinancialTransactions(financialTransaction); financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction); } - financialTransaction.addEntry(entry); - financialTransactionService.createEntry(entry); +// financialTransaction.addEntry(entry); +// financialTransactionService.createdImportedEntry(entry); + return financialTransaction; } - protected EntryBook getEntryBook(Map<String, EntryBook> indexedEntryBooks, String entryBookCode) throws AlreadyExistEntryBookException { + protected EntryBook getOrCreateEntryBook(Map<String, EntryBook> indexedEntryBooks, String entryBookCode, List<FinancialPeriod> financialPeriods) throws AlreadyExistEntryBookException { EntryBook entryBook; // entryBook loading entryBook = indexedEntryBooks.get(entryBookCode); @@ -1093,7 +1107,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ entryBook.setCode(entryBookCode); //financialTransaction = null; // create it - entryBook = entryBookService.createEntryBook(entryBook); + entryBook = entryBookService.createImportedNewEntryBook(entryBook, financialPeriods); indexedEntryBooks.put(entryBook.getCode(), entryBook); } return entryBook; diff --git a/lima-swing/src/main/assembly/lima b/lima-swing/src/main/assembly/lima index cdc295e8..b57b3201 100755 --- a/lima-swing/src/main/assembly/lima +++ b/lima-swing/src/main/assembly/lima @@ -1,9 +1,10 @@ #!/bin/sh -MX=512M +MX=1024M +MS=1024M cd `dirname $0` if [ -n "$JAVA_HOME" ]; then - $JAVA_HOME/bin/java -Xmx$MX -Xms$MX -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar ./lima.jar $* + $JAVA_HOME/bin/java -Xmx$MX -Xms$MS -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar ./lima.jar $* else - java -Xmx$MX -Xms$MX -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar ./lima.jar $* + java -Xmx$MX -Xms$MS -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar ./lima.jar $* fi cd "$OLDPWD" diff --git a/lima-swing/src/main/assembly/lima.bat b/lima-swing/src/main/assembly/lima.bat index 1a75eb00..5cda5d78 100644 --- a/lima-swing/src/main/assembly/lima.bat +++ b/lima-swing/src/main/assembly/lima.bat @@ -1,2 +1,2 @@ -java -Xmx1024M -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar lima.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 +java -Xms1024M -Xmx1024M -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -jar lima.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.