ptuomola commented on a change in pull request #1024:
URL: https://github.com/apache/fineract/pull/1024#discussion_r439197387



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanArrearsAgingServiceImpl.java
##########
@@ -423,18 +423,14 @@ public OriginalScheduleExtractor(final String 
loanIdsAsString) {
 
             while (rs.next()) {
                 Long loanId = rs.getLong("loanId");
-                List<LoanSchedulePeriodData> periodDatas = new ArrayList<>();
-                LoanSchedulePeriodData loanSchedulePeriodData = 
fetchLoanSchedulePeriodData(rs);
-                periodDatas.add(loanSchedulePeriodData);
-                while (rs.next()) {
-                    Long tempLoanId = rs.getLong("loanId");
-                    if (loanId.equals(tempLoanId)) {

Review comment:
       As far as I can see, the logic is trying to build a map of (loanId, 
periodData). There may be multiple rows in the ResultSet and these must 
therefore be merged to be part of the same entry in the map.
   
   The previous code does it by:
   
   1. Read one LoanId from resultset and create a map entry
   2. In a loop, keep fetching next row from result set. 
       - If the next row has the same loanId, then add it to the same map entry 
and fetch next
       - If the next row has a different loanId, go back one row in result set 
and start from step 1
   
   The problem is the "go back one row" which is not supported by some JDBC 
drivers.
   
   But an equivalent way of building the same map (at least in my view would 
be):
   
   1. Iterate through the result set. For each row's loanId: 
   - If we already have a map entry for that loanId, add the dates to the 
existing entry
   - If we don't yet have a map entry for that loanId, create a new one and add 
the dates to that
   
   No rs.previous() required, and either way you should end up with the same 
Map - as far as I can see..
   
   But I don't have a way to test this code, so a bit concerned I may have 
missed something...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to