Skip to content

Commit

Permalink
improvements around load rate calculator
Browse files Browse the repository at this point in the history
- better encapsulation of DaoLoadVisitor.initLoadRateCalculator() method
- open the CSV file if not open in CSVFileReader.getTotalRows()
  • Loading branch information
ashitsalesforce committed Jul 3, 2023
1 parent e2742f6 commit 12409f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ protected boolean visit() throws DataAccessObjectException, ParameterLoadExcepti
if (daoRowList == null || daoRowList.size() == 0) return false;
int daoRowCount = 0;

getVisitor().initLoadRateCalculator();
for (final Row daoRow : daoRowList) {
if (!DAORowUtil.isValidRow(daoRow)) {
getVisitor().setRowConversionStatus(daoRowNumBase + daoRowCount++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected DAOLoadVisitor(Controller controller, ILoaderProgress monitor, DataWri
if (newRichTextRegex != null && !newRichTextRegex.isBlank()) {
this.richTextRegex = newRichTextRegex;
}
this.initLoadRateCalculator();
}

public void setRowConversionStatus(int dataSourceRow, boolean conversionSuccess) {
Expand Down Expand Up @@ -223,8 +224,14 @@ protected boolean writeStatus() {
return true;
}

public void initLoadRateCalculator() throws DataAccessObjectException {
getRateCalculator().start(((DataReader)getController().getDao()).getTotalRows());
private void initLoadRateCalculator() {
try {
DataReader dao = (DataReader)getController().getDao();
getRateCalculator().start(dao.getTotalRows());
} catch (Exception e) {
logger.error("Unable to get total rows to upload from CSV or database");
getRateCalculator().start(0);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public List<String> getColumnNames() {
public int getTotalRows() throws DataAccessObjectException {
if (totalRows == 0) {
if (!isOpen) {
throw new IllegalStateException("File is not open");
open();
}
totalRows = DAORowUtil.calculateTotalRows(this);
}
Expand Down

0 comments on commit 12409f3

Please sign in to comment.