diff --git a/src/main/java/com/salesforce/dataloader/dao/DataReader.java b/src/main/java/com/salesforce/dataloader/dao/DataReader.java index 8a48ba42..a7061f46 100644 --- a/src/main/java/com/salesforce/dataloader/dao/DataReader.java +++ b/src/main/java/com/salesforce/dataloader/dao/DataReader.java @@ -39,15 +39,6 @@ * @since 8.0 */ public interface DataReader extends DataAccessObject { - - /** - * Get a row of data from a data source - * - * @return a {@link Row} containing all the keys and values of a row - * @throws DataAccessObjectException - */ - Row readRow() throws DataAccessObjectException; - /** * Get a row of data from a data source * diff --git a/src/main/java/com/salesforce/dataloader/dao/csv/CSVFileReader.java b/src/main/java/com/salesforce/dataloader/dao/csv/CSVFileReader.java index 7824aec1..6e56b389 100644 --- a/src/main/java/com/salesforce/dataloader/dao/csv/CSVFileReader.java +++ b/src/main/java/com/salesforce/dataloader/dao/csv/CSVFileReader.java @@ -47,7 +47,6 @@ import com.salesforce.dataloader.exception.DataAccessObjectException; import com.salesforce.dataloader.exception.DataAccessObjectInitializationException; import com.salesforce.dataloader.exception.DataAccessRowException; -import com.salesforce.dataloader.model.Row; import com.salesforce.dataloader.model.TableHeader; import com.salesforce.dataloader.model.TableRow; import com.salesforce.dataloader.util.AppUtil; @@ -205,15 +204,6 @@ record = csvReader.nextRecord(); } return trow; } - - @Override - public Row readRow() throws DataAccessObjectException { - TableRow tableRow = readTableRow(); - if (tableRow == null) { - return null; - } - return tableRow.convertToRow(); - } /** * @return Names of output columns being read during each readRow call diff --git a/src/main/java/com/salesforce/dataloader/dao/database/DatabaseReader.java b/src/main/java/com/salesforce/dataloader/dao/database/DatabaseReader.java index 80804aa9..5efa42db 100644 --- a/src/main/java/com/salesforce/dataloader/dao/database/DatabaseReader.java +++ b/src/main/java/com/salesforce/dataloader/dao/database/DatabaseReader.java @@ -29,7 +29,6 @@ import java.sql.*; import java.util.*; -import com.salesforce.dataloader.model.Row; import com.salesforce.dataloader.model.TableHeader; import com.salesforce.dataloader.model.TableRow; @@ -217,15 +216,6 @@ protected TableRow readTableRowFromDAO() throws DataAccessObjectException { throw new DataAccessObjectException(errMsg, e); } } - - @Override - public Row readRow() throws DataAccessObjectException { - TableRow tableRow = readTableRow(); - if (tableRow == null) { - return null; - } - return tableRow.convertToRow(); - } @Override public List getColumnNames() { diff --git a/src/main/java/com/salesforce/dataloader/ui/CSVViewerDialog.java b/src/main/java/com/salesforce/dataloader/ui/CSVViewerDialog.java index fa31860c..f946e64a 100644 --- a/src/main/java/com/salesforce/dataloader/ui/CSVViewerDialog.java +++ b/src/main/java/com/salesforce/dataloader/ui/CSVViewerDialog.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; -import java.util.ArrayList; import java.util.List; import org.apache.logging.log4j.Logger; @@ -57,7 +56,7 @@ import com.salesforce.dataloader.dao.csv.CSVFileReader; import com.salesforce.dataloader.exception.DataAccessObjectException; import com.salesforce.dataloader.exception.DataAccessObjectInitializationException; -import com.salesforce.dataloader.model.Row; +import com.salesforce.dataloader.model.TableRow; import com.salesforce.dataloader.ui.csvviewer.CSVContentProvider; import com.salesforce.dataloader.ui.csvviewer.CSVLabelProvider; import com.salesforce.dataloader.util.AppUtil; @@ -292,23 +291,23 @@ private void updateCSVTable(CSVFileReader csvReader) { List> rowList = new ArrayList>(); for (int i = 0; i < numberOfRows; i++) { - Row rowMap; + TableRow row; try { - rowMap = csvReader.readRow(); + row = csvReader.readTableRow(); } catch (DataAccessObjectException e) { break; } - if (!DAORowUtil.isValidRow(rowMap)) { + if (!DAORowUtil.isValidTableRow(row)) { break; } List columns = csvReader.getColumnNames(); - List row = new ArrayList(); - row.add(0, String.valueOf(i + 1)); + List listOfRowCells = new ArrayList(); + listOfRowCells.add(0, String.valueOf(i + 1)); for(String column : columns) { - row.add(rowMap.get(column)); + listOfRowCells.add(row.get(column)); } - rowList.add(row); + rowList.add(listOfRowCells); } csvReader.close(); csvTblViewer.setInput(rowList); diff --git a/src/main/java/com/salesforce/dataloader/util/DAORowUtil.java b/src/main/java/com/salesforce/dataloader/util/DAORowUtil.java index e1ef0879..17b76da6 100644 --- a/src/main/java/com/salesforce/dataloader/util/DAORowUtil.java +++ b/src/main/java/com/salesforce/dataloader/util/DAORowUtil.java @@ -215,7 +215,7 @@ private void rowToStart(AppConfig cfg, DataReader daoReader) throws DataAccessOb // keep skipping over rows until we run into an invalid row or we have gotten // to the starting row while (daoReader.getCurrentRowNumber() < rowToStart) { - if (!DAORowUtil.isValidRow(daoReader.readRow())) break; + if (!DAORowUtil.isValidTableRow(daoReader.readTableRow())) break; } } } diff --git a/src/test/java/com/salesforce/dataloader/dao/CsvTest.java b/src/test/java/com/salesforce/dataloader/dao/CsvTest.java index dd7eb51d..6c32f0ac 100644 --- a/src/test/java/com/salesforce/dataloader/dao/CsvTest.java +++ b/src/test/java/com/salesforce/dataloader/dao/CsvTest.java @@ -37,6 +37,7 @@ import com.salesforce.dataloader.dao.csv.CSVFileReader; import com.salesforce.dataloader.dao.csv.CSVFileWriter; import com.salesforce.dataloader.model.Row; +import com.salesforce.dataloader.model.TableRow; import com.salesforce.dataloader.util.AppUtil; import static org.junit.Assert.assertEquals; @@ -105,12 +106,12 @@ private void testCSVReadBasic(String csvFile) throws Exception { assertEquals(COLUMN_2_NAME, headerRow.get(1)); assertEquals(COLUMN_3_NAME, headerRow.get(2)); - Row firstRow = csv.readRow(); + TableRow firstRow = csv.readTableRow(); assertEquals("row1-1", firstRow.get(COLUMN_1_NAME)); assertEquals("row1-2", firstRow.get(COLUMN_2_NAME)); assertEquals("row1-3", firstRow.get(COLUMN_3_NAME)); - Row secondRow = csv.readRow(); + TableRow secondRow = csv.readTableRow(); assertEquals("row2-1", secondRow.get(COLUMN_1_NAME)); assertEquals("row2-2", secondRow.get(COLUMN_2_NAME)); assertEquals("row2-3", secondRow.get(COLUMN_3_NAME)); @@ -170,19 +171,19 @@ public void testReadingSeparatedValues () throws Exception { CSVFileReader csv = new CSVFileReader(f, getController().getAppConfig(), false, false); csv.open(); - Row firstRow = csv.readRow(); + TableRow firstRow = csv.readTableRow(); assertEquals("somev1", firstRow.get("some")); - assertEquals(4, firstRow.size()); - Row secondRow = csv.readRow(); + assertEquals(4, firstRow.getNonEmptyCellsCount()); + TableRow secondRow = csv.readTableRow(); assertEquals("somev2", secondRow.get("some")); csv.close(); getController().getAppConfig().setValue("loader.csvOther", false); csv = new CSVFileReader(f, getController().getAppConfig(), false, false); csv.open(); - firstRow = csv.readRow(); + firstRow = csv.readTableRow(); assertEquals("col12!somev1", firstRow.get("column2!some")); - assertEquals(3, firstRow.size()); + assertEquals(3, firstRow.getNonEmptyCellsCount()); csv.close(); } @@ -195,10 +196,10 @@ public void testReadingEscapedValues() throws Exception { CSVFileReader csv = new CSVFileReader(f, getController().getAppConfig(), false, false); csv.open(); - Row firstRow = csv.readRow(); + TableRow firstRow = csv.readTableRow(); assertEquals("\"The Best\" Account", firstRow.get(COLUMN_1_NAME)); - Row secondRow = csv.readRow(); + TableRow secondRow = csv.readTableRow(); assertEquals("The \"Best\" Account", secondRow.get(COLUMN_1_NAME)); csv.close(); @@ -210,7 +211,7 @@ public void testCsvWithManyRowsCanBeParsed() throws Exception { csvFileReader.open(); assertEquals(20000, csvFileReader.getTotalRows()); int count = 0; - for(Row row = csvFileReader.readRow(); row != null; row = csvFileReader.readRow(), count++); + for(TableRow row = csvFileReader.readTableRow(); row != null; row = csvFileReader.readTableRow(), count++); assertEquals(20000, count); } @@ -262,15 +263,15 @@ private void compareWriterFile(String filePath, String delimiterStr, boolean ign } //check that row 1 is valid - Row firstRow = csv.readRow(); + TableRow firstRow = csv.readTableRow(); for (String headerColumn : writeHeader) { - assertEquals(row1.get(headerColumn), firstRow.get(headerColumn)); + assertEquals(row1.get(headerColumn), firstRow.get(headerColumn)); } //check that row 2 is valid - Row secondRow = csv.readRow(); + TableRow secondRow = csv.readTableRow(); for (String headerColumn : writeHeader) { - assertEquals(row2.get(headerColumn), secondRow.get(headerColumn)); + assertEquals(row2.get(headerColumn), secondRow.get(headerColumn)); } csv.close(); if (isQueryResultsCSV) { diff --git a/src/test/java/com/salesforce/dataloader/process/CsvExtractProcessTest.java b/src/test/java/com/salesforce/dataloader/process/CsvExtractProcessTest.java index 33f3fd23..dca675a5 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvExtractProcessTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvExtractProcessTest.java @@ -181,9 +181,9 @@ public void testPolymorphicRelationshipExtract() throws Exception { // open the results of the extraction final CSVFileReader rdr = new CSVFileReader(new File(argmap.get(AppConfig.PROP_DAO_NAME)), getController().getAppConfig(), true, false); rdr.open(); - Row row = rdr.readRow(); + TableRow row = rdr.readTableRow(); assertNotNull(row); - assertEquals(5,row.size()); + assertEquals(5,row.getNonEmptyCellsCount()); // validate the extract results are correct. assertEquals(leadidArr[0], row.get("LID")); assertTrue(userInfo.getUserFullName().contains(row.get("LNAME").toString())); @@ -191,7 +191,7 @@ public void testPolymorphicRelationshipExtract() throws Exception { assertEquals(uid, row.get("OID")); assertEquals(uid,row.get("OWNID")); // validate that we have read the only result. there should be only one. - assertNull(rdr.readRow()); + assertNull(rdr.readTableRow()); } finally { // cleanup here since the parent doesn't clean up leads getBinding().delete(leadidArr); @@ -342,13 +342,13 @@ private void testBinaryDataInRTFQueryResult(String inclueRTFBinaryData) throws E controller = runProcess(queryArgMap, 1); CSVFileReader queryResultsReader = new CSVFileReader(new File(queryArgMap.get(AppConfig.PROP_DAO_NAME)), getController().getAppConfig(), true, false); queryResultsReader.open(); - Row queryResultsRow = queryResultsReader.readRow(); + TableRow queryResultsRow = queryResultsReader.readTableRow(); String queryResultsRTVal = (String)queryResultsRow.get("RICHTEXT__c"); if ("true".equalsIgnoreCase(inclueRTFBinaryData)) { CSVFileReader uploadedCSVReader = new CSVFileReader(new File(getTestDataDir() + "/acctsWithBinaryDataInRTF.csv"), getController().getAppConfig(), true, false); uploadedCSVReader.open(); - Row uploadedRow = uploadedCSVReader.readRow(); + TableRow uploadedRow = uploadedCSVReader.readTableRow(); String uploadedRTVal = (String)queryResultsRow.get("RICHTEXT__c"); assertEquals("Binary data in query result file does not match uploaded data: " + queryArgMap.get(AppConfig.PROP_DAO_NAME), queryResultsRTVal, uploadedRTVal); diff --git a/src/test/java/com/salesforce/dataloader/process/CsvProcessTest.java b/src/test/java/com/salesforce/dataloader/process/CsvProcessTest.java index 3e14012d..28079e02 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvProcessTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvProcessTest.java @@ -120,8 +120,8 @@ public void testInsertAccountWithMultipleBatchesCSV() throws ProcessInitializati String successFileName = controller.getAppConfig().getString(AppConfig.PROP_OUTPUT_SUCCESS); File successFile = new File(successFileName); CSVFileReader csvReader = new CSVFileReader(successFile, controller.getAppConfig(), false, false); - Row row1 = csvReader.readRow(); - Row row2 = csvReader.readRow(); + TableRow row1 = csvReader.readTableRow(); + TableRow row2 = csvReader.readTableRow(); String oracleIdRow1 = (String)row1.get("oracle_id"); String oracleIdRow2 = (String)row2.get("oracle_id"); if (oracleIdRow1 == null) { diff --git a/src/test/java/com/salesforce/dataloader/process/CsvProcessWithOffsetTest.java b/src/test/java/com/salesforce/dataloader/process/CsvProcessWithOffsetTest.java index f78ed6c9..9a1addb5 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvProcessWithOffsetTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvProcessWithOffsetTest.java @@ -43,6 +43,7 @@ import com.salesforce.dataloader.exception.DataAccessObjectException; import com.salesforce.dataloader.exception.DataAccessObjectInitializationException; import com.salesforce.dataloader.model.Row; +import com.salesforce.dataloader.model.TableRow; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -173,30 +174,30 @@ private void verifyOffsetFromInputAndOutputFiles(int numberOfOffsetRows, AppConf } // Initializations of row results - Row firstInputOffsetAdjustedRow = new Row(); - Row lastInputRow = new Row(); - Row firstSuccessRow = new Row(); - Row lastSuccessRow = new Row(); - Row firstErrorRow = new Row(); - Row lastErrorRow = new Row(); + TableRow firstInputOffsetAdjustedRow = null; + TableRow lastInputRow = null; + TableRow firstSuccessRow = null; + TableRow lastSuccessRow = null; + TableRow firstErrorRow = null; + TableRow lastErrorRow = null; // The next few if statements deal with the edge statements on file size...(i.e. suppose that there are no // errors) if (numberOfSuccessRows > 0) { - getFirstRow(firstSuccessRow, successFileReader, true, 0); - getLastRow(lastSuccessRow, successFileReader, true); + firstSuccessRow = getFirstRow(successFileReader, true, 0); + lastSuccessRow = getLastRow(successFileReader, true); } if (numberOfErrorRows > 0) { - getFirstRow(firstErrorRow, errorFileReader, false, 0); - getLastRow(lastErrorRow, errorFileReader, false); + firstErrorRow = getFirstRow(errorFileReader, false, 0); + lastErrorRow = getLastRow(errorFileReader, false); } if (numberOfInputRows > 0) { final CSVFileReader inputFileReader = openConfiguredPath(cfg, AppConfig.PROP_DAO_NAME); - getFirstRow(firstInputOffsetAdjustedRow, inputFileReader, false, numberOfOffsetRows); - getLastRow(lastInputRow, inputFileReader, false); + firstInputOffsetAdjustedRow = getFirstRow(inputFileReader, false, numberOfOffsetRows); + lastInputRow = getLastRow(inputFileReader, false); } // Requirement I: First offset-adjusted row of input matches to either the error or success file's first row @@ -226,40 +227,27 @@ private CSVFileReader openConfiguredPath(AppConfig cfg, String configSetting) return rdr; } - private void getFirstRow(Row rowResult, CSVFileReader reader, boolean isSuccessFile, int rowOffset) + private TableRow getFirstRow(CSVFileReader reader, boolean isSuccessFile, int rowOffset) throws Exception { - Row firstRow = reader.readRow(); + TableRow firstRow = reader.readTableRow(); for (int i = 0; i < rowOffset; i++) { - firstRow = reader.readRow(); // then, for each, move down one row - } - - if (isSuccessFile) { - // Also ask for ID - rowResult.put("ID", firstRow.get("ID")); - } - if (firstRow != null && firstRow.get("NAME") != null) { - rowResult.put("NAME", firstRow.get("NAME")); + firstRow = reader.readTableRow(); // then, for each, move down one row } + return firstRow; } - private void getLastRow(Row rowResult, CSVFileReader reader, boolean isSuccessFile) + private TableRow getLastRow(CSVFileReader reader, boolean isSuccessFile) throws Exception { - Row tempRow = new Row(); - Row lastRow = new Row(); + TableRow tempRow = null; + TableRow lastRow = null; // get to the last row: - while ((tempRow = reader.readRow()) != null) { + while ((tempRow = reader.readTableRow()) != null) { lastRow = tempRow; } - - if (isSuccessFile) { - // Also ask for ID - rowResult.put("ID", lastRow.get("ID")); - } - - rowResult.put("NAME", lastRow.get("NAME")); + return lastRow; } private Map getRowOffsetTestConfig(Object offset, int numInserts) throws DataAccessObjectException { diff --git a/src/test/java/com/salesforce/dataloader/process/NAProcessTest.java b/src/test/java/com/salesforce/dataloader/process/NAProcessTest.java index fc8d92da..9bcb44cd 100644 --- a/src/test/java/com/salesforce/dataloader/process/NAProcessTest.java +++ b/src/test/java/com/salesforce/dataloader/process/NAProcessTest.java @@ -215,7 +215,7 @@ private String getCsvFieldValue(String csvFile, String fieldName) throws Excepti CSVFileReader reader = new CSVFileReader(new File(csvFile), getController().getAppConfig(), true, false); reader.open(); assertEquals(1, reader.getTotalRows()); - String fieldValue = (String)reader.readRow().get(fieldName); + String fieldValue = (String)reader.readTableRow().get(fieldName); reader.close(); return fieldValue; } diff --git a/src/test/java/com/salesforce/dataloader/process/ProcessExtractTestBase.java b/src/test/java/com/salesforce/dataloader/process/ProcessExtractTestBase.java index e721e681..ae02331c 100644 --- a/src/test/java/com/salesforce/dataloader/process/ProcessExtractTestBase.java +++ b/src/test/java/com/salesforce/dataloader/process/ProcessExtractTestBase.java @@ -43,8 +43,7 @@ import com.salesforce.dataloader.dao.csv.CSVFileReader; import com.salesforce.dataloader.exception.DataAccessObjectException; import com.salesforce.dataloader.exception.ProcessInitializationException; -import com.salesforce.dataloader.model.Row; -import com.sforce.soap.partner.SaveResult; +import com.salesforce.dataloader.model.TableRow; import com.sforce.soap.partner.sobject.SObject; import com.sforce.ws.ConnectionException; @@ -156,9 +155,9 @@ protected void verifyIdsInCSV(Controller control, String[] ids, boolean checkPho resultReader.open(); // go through item by item and assert that it's there - Row row; + TableRow row; int currentRow = 0; - while ((row = resultReader.readRow()) != null) { + while ((row = resultReader.readTableRow()) != null) { final String resultId = (String)row.get(AppConfig.ID_COLUMN_NAME); assertValidId(resultId); String resultPhone = (String)row.get("Phone"); @@ -272,9 +271,9 @@ protected void runTestSelectFieldsSoql() throws ProcessInitializationException, resultReader.open(); // go through item by item and assert that it's there - Row row; + TableRow row; int rowIdx = 0; - while ((row = resultReader.readRow()) != null) { + while ((row = resultReader.readTableRow()) != null) { final String resultId = (String)row.get(AppConfig.ID_COLUMN_NAME); assertValidId(resultId); assertEquals(resultId, testFieldIds[rowIdx]); @@ -364,7 +363,7 @@ private void doRunSoqlRelationshipTest(String contactId, String accountId, final runProcess(argMap, 1); final CSVFileReader resultReader = new CSVFileReader(new File(argMap.get(AppConfig.PROP_DAO_NAME)), getController().getAppConfig(), true, false); try { - final Row resultRow = resultReader.readRow(); + final TableRow resultRow = resultReader.readTableRow(); assertEquals("Query returned incorrect Contact ID", contactId, resultRow.get("CONTACT_ID")); assertEquals("Query returned incorrect Contact Name", "First 000000 Last 000000", resultRow.get("CONTACT_NAME")); @@ -463,7 +462,8 @@ protected void runTestExtractAccountCsvAggregate() throws ConnectionException, P runProcess(argMap, 1, true); final CSVFileReader resultReader = new CSVFileReader(new File(argMap.get(AppConfig.PROP_DAO_NAME)), getController().getAppConfig(), true, false); try { - assertEquals(String.valueOf(numRecords - 1), resultReader.readRow().get("MAX(NUMBEROFEMPLOYEES)")); + String maxNumEmployees = (String)resultReader.readTableRow().get("MAX(NUMBEROFEMPLOYEES)"); + assertEquals(String.valueOf(numRecords - 1), maxNumEmployees); } finally { resultReader.close(); } diff --git a/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java b/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java index 8380cc69..8562e14f 100644 --- a/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java +++ b/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java @@ -52,7 +52,6 @@ import com.salesforce.dataloader.dyna.SforceDynaBean; import com.salesforce.dataloader.exception.*; import com.salesforce.dataloader.exception.UnsupportedOperationException; -import com.salesforce.dataloader.model.Row; import com.salesforce.dataloader.model.TableRow; import com.salesforce.dataloader.util.AppUtil; import com.salesforce.dataloader.util.Base64; @@ -791,7 +790,7 @@ protected void verifySuccessFile(Controller ctl, int numInserts, int numUpdates, assertNumRowsInCSVFile(successFile, numInserts + numUpdates); boolean isBulkV2Operation = ctl.getAppConfig().isBulkV2APIEnabled(); - Row row = null; + TableRow row = null; CSVFileReader rdr = new CSVFileReader(new File(successFile), getController().getAppConfig(), true, false); String expectedUpdateStatusVal = UPDATE_MSGS.get(ctl.getAppConfig().getOperationInfo()); String expectedInsertStatusVal = INSERT_MSG; @@ -801,7 +800,7 @@ protected void verifySuccessFile(Controller ctl, int numInserts, int numUpdates, } int insertsFound = 0; int updatesFound = 0; - while ((row = rdr.readRow()) != null) { + while ((row = rdr.readTableRow()) != null) { String id = (String)row.get(AppConfig.ID_COLUMN_NAME); if (id == null) { id = (String)row.get(AppConfig.ID_COLUMN_NAME_IN_BULKV2);