com.avaje.ebean.text.csv
Interface CsvCallback<T>

Type Parameters:
T -
All Known Implementing Classes:
DefaultCsvCallback

public interface CsvCallback<T>

Provides callback methods for customisation of CSV processing.

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.

Author:
rbygrave

Method Summary
 void begin(EbeanServer server)
          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 Detail

begin

void begin(EbeanServer server)
The processing is about to begin.

Typically the callback will create a transaction, set batch mode, batch size etc.


readHeader

void readHeader(String[] line)
Read the header row.

This is only called if CsvReader.setHasHeader(boolean) has been set to true.

Parameters:
line - the header line content.

processLine

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. Gives ability to handle bad data... empty rows etc and ignore it rather than fail.


processBean

void processBean(int row,
                 String[] line,
                 T bean)
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 processed
line - the content that has been used to load the bean
bean - 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

void endWithError(int row,
                  Exception e)
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 occured on
e - the error that occured


Copyright © 2010. All Rights Reserved.