CE-1955 - Add rowNo to BulkLoadFileRow, set by FileToRowsInterface objects

This commit is contained in:
2024-11-27 11:46:24 -06:00
parent 6672f95987
commit 17fc976877
8 changed files with 65 additions and 11 deletions

View File

@ -36,6 +36,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
private boolean useLast = false;
private BulkLoadFileRow last;
int rowNo = 0;
/***************************************************************************
@ -65,6 +66,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
@Override
public BulkLoadFileRow next()
{
rowNo++;
if(iterator == null)
{
throw new IllegalStateException("Object was not init'ed");
@ -99,6 +101,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
@Override
public void unNext()
{
rowNo--;
useLast = true;
}
@ -122,4 +125,15 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
this.iterator = iterator;
}
/*******************************************************************************
** Getter for rowNo
**
*******************************************************************************/
@Override
public int getRowNo()
{
return rowNo;
}
}

View File

@ -92,7 +92,7 @@ public class CsvFileToRows extends AbstractIteratorBasedFileToRows<CSVRecord> im
values[i++] = s;
}
return (new BulkLoadFileRow(values));
return (new BulkLoadFileRow(values, getRowNo()));
}

View File

@ -66,6 +66,12 @@ public interface FileToRowsInterface extends AutoCloseable, Iterator<BulkLoadFil
void init(InputStream inputStream) throws QException;
/***************************************************************************
**
***************************************************************************/
int getRowNo();
/***************************************************************************
**
***************************************************************************/

View File

@ -116,7 +116,7 @@ public class XlsxFileToRows extends AbstractIteratorBasedFileToRows<org.dhatim.f
}
}
return new BulkLoadFileRow(values);
return new BulkLoadFileRow(values, getRowNo());
}

View File

@ -33,6 +33,7 @@ import java.util.stream.Collectors;
*******************************************************************************/
public class BulkLoadFileRow implements Serializable
{
private int rowNo;
private Serializable[] values;
@ -41,9 +42,10 @@ public class BulkLoadFileRow implements Serializable
** Constructor
**
*******************************************************************************/
public BulkLoadFileRow(Serializable[] values)
public BulkLoadFileRow(Serializable[] values, int rowNo)
{
this.values = values;
this.rowNo = rowNo;
}
@ -150,8 +152,8 @@ public class BulkLoadFileRow implements Serializable
return false;
}
BulkLoadFileRow row = (BulkLoadFileRow) o;
return Objects.deepEquals(values, row.values);
BulkLoadFileRow that = (BulkLoadFileRow) o;
return rowNo == that.rowNo && Objects.deepEquals(values, that.values);
}
@ -162,6 +164,38 @@ public class BulkLoadFileRow implements Serializable
@Override
public int hashCode()
{
return Arrays.hashCode(values);
return Objects.hash(rowNo, Arrays.hashCode(values));
}
/*******************************************************************************
** Getter for rowNo
*******************************************************************************/
public int getRowNo()
{
return (this.rowNo);
}
/*******************************************************************************
** Setter for rowNo
*******************************************************************************/
public void setRowNo(int rowNo)
{
this.rowNo = rowNo;
}
/*******************************************************************************
** Fluent setter for rowNo
*******************************************************************************/
public BulkLoadFileRow withRowNo(int rowNo)
{
this.rowNo = rowNo;
return (this);
}
}

View File

@ -52,8 +52,8 @@ class CsvFileToRowsTest extends BaseTest
BulkLoadFileRow headerRow = fileToRowsInterface.next();
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
assertEquals(new BulkLoadFileRow(new String[] { "one", "two", "three" }), headerRow);
assertEquals(new BulkLoadFileRow(new String[] { "1", "2", "3", "4" }), bodyRow);
assertEquals(new BulkLoadFileRow(new String[] { "one", "two", "three" }, 1), headerRow);
assertEquals(new BulkLoadFileRow(new String[] { "1", "2", "3", "4" }, 2), bodyRow);
assertFalse(fileToRowsInterface.hasNext());
}

View File

@ -81,6 +81,6 @@ public class TestFileToRows extends AbstractIteratorBasedFileToRows<Serializable
@Override
public BulkLoadFileRow makeRow(Serializable[] values)
{
return (new BulkLoadFileRow(values));
return (new BulkLoadFileRow(values, getRowNo()));
}
}

View File

@ -66,8 +66,8 @@ class XlsxFileToRowsTest extends BaseTest
BulkLoadFileRow headerRow = fileToRowsInterface.next();
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
assertEquals(new BulkLoadFileRow(new String[] {"Id", "First Name", "Last Name", "Birth Date"}), headerRow);
assertEquals(new BulkLoadFileRow(new Serializable[] {1, "Darin", "Jonson", LocalDateTime.of(1980, Month.JANUARY, 31, 0, 0)}), bodyRow);
assertEquals(new BulkLoadFileRow(new String[] {"Id", "First Name", "Last Name", "Birth Date"}, 1), headerRow);
assertEquals(new BulkLoadFileRow(new Serializable[] {1, "Darin", "Jonson", LocalDateTime.of(1980, Month.JANUARY, 31, 0, 0)}, 2), bodyRow);
///////////////////////////////////////////////////////////////////////////////////////
// make sure there's at least a limit (less than 20) to how many more rows there are //