- All Known Implementing Classes:
DefaultCsvCallback
You can provide your own CsvCallback implementation to customise the CSV processing. It is expected that the DefaultCsvCallback provides a good base class that you can extend.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
The processing is about to begin.void
end
(int row) The processing has ended successfully.void
endWithError
(int row, Exception e) The processing has ended due to an error.void
processBean
(int row, String[] line, T bean) Called for each bean after it has been loaded from the CSV content.boolean
processLine
(int row, String[] line) Check that the row should be processed - return true to process the row or false to ignore the row.void
readHeader
(String[] line) Read the header row.
-
Method Details
-
begin
The processing is about to begin.Typically the callback will create a transaction, set batch mode, batch size etc.
-
readHeader
Read the header row.This is only called if
CsvReader.setHasHeader(boolean, boolean)
has been set to true.- Parameters:
line
- the header line content.
-
processLine
Check that the row should be processed - return true to process the row or false to ignore the row. Gives ability to handle bad data... empty rows etc and ignore it rather than fail. -
processBean
Called for each bean after it has been loaded from the CSV content.This allows you to process the bean however you like.
When you use a CsvCallback the CsvReader *WILL NOT* create a transaction and will not save the bean for you. You have complete control and must do these things yourself (if that is want you want).
- Parameters:
row
- the index of the content being processedline
- the content that has been used to load the beanbean
- the entity bean after it has been loaded from the csv content
-
end
void end(int row) The processing has ended successfully.Typically the callback will commit the transaction.
-
endWithError
The processing has ended due to an error.This gives the callback the opportunity to rollback the transaction if one was created.
- Parameters:
row
- the row that the error has occurred one
- the error that occurred
-