This is an automated email from the ASF dual-hosted git repository. shruthirajaram pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/fineract.git
commit 3846ea6a2501dc7f501920e248d09db35b2c8d31 Merge: 9c24d6b 67317b1 Author: ShruthiRajaram <shru...@confluxtechnologies.com> AuthorDate: Tue Dec 25 18:16:26 2018 +0530 FINERACT-186 batch job optimisation .../savings/domain/SavingsAccountRepository.java | 4 ++ .../service/SavingsSchedularServiceImpl.java | 52 +++++++++++++--------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --cc fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java index df939f6,ef93d7f..bb4eb22 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java @@@ -47,6 -48,8 +49,8 @@@ public interface SavingsAccountReposito SavingsAccount findByIdAndDepositAccountType(@Param("accountId") Long accountId, @Param("depositAccountTypeId") Integer depositAccountTypeId); - @Query("from SavingsAccount sa where sa.accountNumber = :accountNumber and sa.status in (100, 200, 300, 303, 304) ") + @Query("select sa from SavingsAccount sa where sa.accountNumber = :accountNumber and sa.status in (100, 200, 300, 303, 304) ") SavingsAccount findNonClosedAccountByAccountNumber(@Param("accountNumber") String accountNumber); + + Page<SavingsAccount> findByStatus(Integer status,Pageable pageable); } diff --cc fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java index e3f2f0c,c50d9b5..16c4266 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsSchedularServiceImpl.java @@@ -43,36 -45,42 +45,44 @@@ public class SavingsSchedularServiceImp @Autowired public SavingsSchedularServiceImpl(final SavingsAccountAssembler savingAccountAssembler, final SavingsAccountWritePlatformService savingsAccountWritePlatformService, - final SavingsAccountRepositoryWrapper savingAccountRepositoryWrapper, - final SavingsAccountReadPlatformService savingAccountReadPlatformService) { - final SavingsAccountReadPlatformService savingAccountReadPlatformService, - final SavingsAccountRepository savingsAccountRepository) { ++ final SavingsAccountReadPlatformService savingAccountReadPlatformService, final SavingsAccountRepository savingsAccountRepository) { this.savingAccountAssembler = savingAccountAssembler; this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; - this.savingAccountRepositoryWrapper = savingAccountRepositoryWrapper; this.savingAccountReadPlatformService = savingAccountReadPlatformService; + this.savingsAccountRepository = savingsAccountRepository; } @CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS) @Override public void postInterestForAccounts() throws JobExecutionException { - final List<SavingsAccount> savingsAccounts = this.savingAccountRepositoryWrapper.findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE - .getValue()); - int offSet = 0; ++ int page = 0; + Integer initialSize = 500; + Integer totalPageSize = 0; StringBuffer sb = new StringBuffer(); - for (final SavingsAccount savingsAccount : savingsAccounts) { - try { - this.savingAccountAssembler.assignSavingAccountHelpers(savingsAccount); - boolean postInterestAsOn = false; - LocalDate transactionDate = null; - this.savingsAccountWritePlatformService.postInterest(savingsAccount, postInterestAsOn, transactionDate); - } catch (Exception e) { - Throwable realCause = e; - if (e.getCause() != null) { - realCause = e.getCause(); + do { - PageRequest pageRequest = new PageRequest(offSet, initialSize); ++ PageRequest pageRequest = new PageRequest(page, initialSize); + Page<SavingsAccount> savingsAccounts = this.savingsAccountRepository.findByStatus(SavingsAccountStatusType.ACTIVE.getValue(), + pageRequest); + for (SavingsAccount savingsAccount : savingsAccounts.getContent()) { + try { + this.savingAccountAssembler.assignSavingAccountHelpers(savingsAccount); - this.savingsAccountWritePlatformService.postInterest(savingsAccount); ++ boolean postInterestAsOn = false; ++ LocalDate transactionDate = null; ++ this.savingsAccountWritePlatformService.postInterest(savingsAccount, postInterestAsOn, ++ transactionDate); + } catch (Exception e) { + Throwable realCause = e; + if (e.getCause() != null) { + realCause = e.getCause(); + } + sb.append("failed to post interest for Savings with id " + savingsAccount.getId() + " with message " + + realCause.getMessage()); } - sb.append("failed to post interest for Savings with id " + savingsAccount.getId() + " with message " - + realCause.getMessage()); } - } - - offSet++; ++ page++; + totalPageSize = savingsAccounts.getTotalPages(); - } while (offSet < totalPageSize); ++ } while (page < totalPageSize); + if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); } }