Skip to content

Commit

Permalink
Merge pull request #1389 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
do not re-read from the same CSV or database during an operation if c…
  • Loading branch information
ashitsalesforce authored Nov 28, 2024
2 parents 9e07e27 + 701780c commit 1fb10bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/salesforce/dataloader/dao/DAORowCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class DAORowCache {
private ArrayList<TableRow> rowList = new ArrayList<TableRow>();
private int currentRowIndex = 0;
private int totalRows = 0;
private int cachedRows = 0;

public DAORowCache() {
}
Expand All @@ -44,16 +44,23 @@ public void resetCurrentRowIndex() {

public TableRow getCurrentRow() {
AppConfig appConfig = AppConfig.getCurrentConfig();
if (currentRowIndex >= totalRows
if (currentRowIndex >= cachedRows
|| !appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
return null;
}
return rowList.get(currentRowIndex++);
}

public void addRow(TableRow row) {
rowList.add(row);
// add a row to the cache only if it is not cached already
if (currentRowIndex >= cachedRows) {
rowList.add(row);
cachedRows++;
}
currentRowIndex++;
totalRows++;
}

public int getCachedRows() {
return cachedRows;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ public void open() throws DataAccessObjectInitializationException {
if (isOpen) {
close();
}
if (!appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)
|| rowCache.getCachedRows() == 0) {
initalizeInput(csvDelimiters);
readHeaderRow();
}
currentRowNumber = 0;
rowCache.resetCurrentRowIndex();

initalizeInput(csvDelimiters);
readHeaderRow();
isOpen = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,22 @@ public void open() throws DataAccessObjectInitializationException {
* @param params
* @throws DataAccessObjectInitializationException
*/
public void open(Map<String,Object> params) throws DataAccessObjectInitializationException {
currentRowNumber = 0;
try {
setupQuery(params);
} catch (DataAccessObjectInitializationException e) {
throw e;
} catch (Exception e) {
throw new DataAccessObjectInitializationException(e.getMessage(), e);
private void open(Map<String,Object> params) throws DataAccessObjectInitializationException {
if (dbContext.isOpen()) {
close();
}
if (!appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)
|| rowCache.getCachedRows() == 0) {
try {
setupQuery(params);
} catch (DataAccessObjectInitializationException e) {
throw e;
} catch (Exception e) {
throw new DataAccessObjectInitializationException(e.getMessage(), e);
}
}
currentRowNumber = 0;
rowCache.resetCurrentRowIndex();
dbContext.setOpen(true);
}

Expand Down

0 comments on commit 1fb10bc

Please sign in to comment.