Class DefaultCsvCallback<T>
- java.lang.Object
-
- io.ebean.text.csv.DefaultCsvCallback<T>
-
- Type Parameters:
T-
- All Implemented Interfaces:
CsvCallback<T>
public class DefaultCsvCallback<T> extends Object implements CsvCallback<T>
Provides the default implementation of CsvCallback.This handles transaction creation (if no current transaction existed) and transaction commit or rollback on error.
For customising the processing you can extend this object and override the appropriate methods.
-
-
Constructor Summary
Constructors Constructor Description DefaultCsvCallback()Construct with a default batch size of 30 and logging info messages every 1000 rows.DefaultCsvCallback(int persistBatchSize, int logInfoFrequency)Construct with explicit batch size and logging info frequency.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbegin(Database server)Create a transaction if required.voidend(int row)Commit the transaction if one was created.voidendWithError(int row, Exception e)Rollback the transaction if one was created.voidprocessBean(int row, String[] line, T bean)Will save the bean.booleanprocessLine(int row, String[] line)Validate that the content is valid and return false if the row should be ignored.voidreadHeader(String[] line)Override to read the heading line.
-
-
-
Constructor Detail
-
DefaultCsvCallback
public DefaultCsvCallback()
Construct with a default batch size of 30 and logging info messages every 1000 rows.
-
DefaultCsvCallback
public DefaultCsvCallback(int persistBatchSize, int logInfoFrequency)
Construct with explicit batch size and logging info frequency.
-
-
Method Detail
-
begin
public void begin(Database server)
Create a transaction if required.- Specified by:
beginin interfaceCsvCallback<T>
-
readHeader
public void readHeader(String[] line)
Override to read the heading line.This is only called if
CsvReader.setHasHeader(boolean, boolean)is set to true.By default this does nothing (effectively ignoring the heading).
- Specified by:
readHeaderin interfaceCsvCallback<T>- Parameters:
line- the header line content.
-
processLine
public boolean processLine(int row, String[] line)
Validate that the content is valid and return false if the row should be ignored.By default this just returns true.
Override this to add custom validation logic returning false if you want the row to be ignored. For example, if all the content is empty return false to ignore the row (rather than having the processing fail with some error).
- Specified by:
processLinein interfaceCsvCallback<T>
-
processBean
public void processBean(int row, String[] line, T bean)
Will save the bean.Override this method to customise the bean (set additional properties etc) or to control the saving of other related beans (when you can't/don't want to use Cascade.PERSIST etc).
- Specified by:
processBeanin interfaceCsvCallback<T>- 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
public void end(int row)
Commit the transaction if one was created.- Specified by:
endin interfaceCsvCallback<T>
-
endWithError
public void endWithError(int row, Exception e)
Rollback the transaction if one was created.- Specified by:
endWithErrorin interfaceCsvCallback<T>- Parameters:
row- the row that the error has occurred one- the error that occurred
-
-