Class TCsvReader<T>
- java.lang.Object
-
- io.ebeaninternal.server.text.csv.TCsvReader<T>
-
- All Implemented Interfaces:
CsvReader<T>
public class TCsvReader<T> extends Object implements CsvReader<T>
Implementation of the CsvReader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TCsvReader.CsvColumn
Processes a column in the csv content.
-
Constructor Summary
Constructors Constructor Description TCsvReader(EbeanServer server, BeanDescriptor<T> descriptor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDateTime(String propertyName, String dateTimeFormat)
Add a property with a custom Date/Time/Timestamp format using the default Locale.void
addDateTime(String propertyName, String dateTimeFormat, Locale locale)
Add a property with a custom Date/Time/Timestamp format.void
addIgnore()
Ignore the next column of data.void
addProperty(String propertyName)
Define the property which will be loaded from the next column of data.void
addProperty(String propertyName, StringParser parser)
Define the next property and use a custom StringParser to convert the string content into the appropriate type for the property.void
process(Reader reader)
Automatically create a transaction if required to process all the CSV content from the reader.void
process(Reader reader, CsvCallback<T> callback)
Process the CSV content passing the bean to the CsvCallback after each row.void
setAddPropertiesFromHeader()
Same as setHasHeader(true,true);void
setDefaultDateFormat(String defaultDateFormat)
Set the default format to use for Date types.void
setDefaultLocale(Locale defaultLocale)
Explicitly set the default Locale.void
setDefaultTimeFormat(String defaultTimeFormat)
Set the default format to use for Time types.void
setDefaultTimestampFormat(String defaultTimestampFormat)
Set the default format to use for Timestamp types.void
setHasHeader(boolean hasHeader, boolean addPropertiesFromHeader)
Set to true if there is a header row that should be ignored.void
setIgnoreHeader()
Same as setHasHeader(true, false);void
setLogInfoFrequency(int logInfoFrequency)
Set the frequency with which a INFO message will be logged showing the progress of the processing.void
setPersistBatchSize(int persistBatchSize)
Set the batch size for using JDBC statement batching.
-
-
-
Constructor Detail
-
TCsvReader
public TCsvReader(EbeanServer server, BeanDescriptor<T> descriptor)
-
-
Method Detail
-
setDefaultLocale
public void setDefaultLocale(Locale defaultLocale)
Description copied from interface:CsvReader
Explicitly set the default Locale.- Specified by:
setDefaultLocale
in interfaceCsvReader<T>
-
setDefaultTimeFormat
public void setDefaultTimeFormat(String defaultTimeFormat)
Description copied from interface:CsvReader
Set the default format to use for Time types.- Specified by:
setDefaultTimeFormat
in interfaceCsvReader<T>
-
setDefaultDateFormat
public void setDefaultDateFormat(String defaultDateFormat)
Description copied from interface:CsvReader
Set the default format to use for Date types.- Specified by:
setDefaultDateFormat
in interfaceCsvReader<T>
-
setDefaultTimestampFormat
public void setDefaultTimestampFormat(String defaultTimestampFormat)
Description copied from interface:CsvReader
Set the default format to use for Timestamp types.- Specified by:
setDefaultTimestampFormat
in interfaceCsvReader<T>
-
setPersistBatchSize
public void setPersistBatchSize(int persistBatchSize)
Description copied from interface:CsvReader
Set the batch size for using JDBC statement batching.By default this is set to 20 and setting this to 1 will disable the use of JDBC statement batching.
- Specified by:
setPersistBatchSize
in interfaceCsvReader<T>
-
setIgnoreHeader
public void setIgnoreHeader()
Description copied from interface:CsvReader
Same as setHasHeader(true, false);This indicates that there is a header but that it should be ignored.
- Specified by:
setIgnoreHeader
in interfaceCsvReader<T>
-
setAddPropertiesFromHeader
public void setAddPropertiesFromHeader()
Description copied from interface:CsvReader
Same as setHasHeader(true,true);This will use a header to define all the properties to load using the default formats for time, date and datetime types.
- Specified by:
setAddPropertiesFromHeader
in interfaceCsvReader<T>
-
setHasHeader
public void setHasHeader(boolean hasHeader, boolean addPropertiesFromHeader)
Description copied from interface:CsvReader
Set to true if there is a header row that should be ignored.If addPropertiesFromHeader is true then all the properties are added using the default time,date and timestamp formats.
If you have a mix of dateTime formats you can not use this method and must add the properties yourself.
- Specified by:
setHasHeader
in interfaceCsvReader<T>
-
setLogInfoFrequency
public void setLogInfoFrequency(int logInfoFrequency)
Description copied from interface:CsvReader
Set the frequency with which a INFO message will be logged showing the progress of the processing. You might set this to 1000 or 10000 etc.If this is not set then no INFO messages will be logged.
- Specified by:
setLogInfoFrequency
in interfaceCsvReader<T>
-
addIgnore
public void addIgnore()
Description copied from interface:CsvReader
Ignore the next column of data.
-
addProperty
public void addProperty(String propertyName)
Description copied from interface:CsvReader
Define the property which will be loaded from the next column of data.This takes into account the data type of the property and handles the String to object conversion automatically.
- Specified by:
addProperty
in interfaceCsvReader<T>
-
addDateTime
public void addDateTime(String propertyName, String dateTimeFormat)
Description copied from interface:CsvReader
Add a property with a custom Date/Time/Timestamp format using the default Locale. This will convert the string into the appropriate java type for the given property (Date, Calendar, SQL Date, Time, Timestamp, JODA etc).- Specified by:
addDateTime
in interfaceCsvReader<T>
-
addDateTime
public void addDateTime(String propertyName, String dateTimeFormat, Locale locale)
Description copied from interface:CsvReader
Add a property with a custom Date/Time/Timestamp format. This will convert the string into the appropriate java type for the given property (Date, Calendar, SQL Date, Time, Timestamp, JODA etc).- Specified by:
addDateTime
in interfaceCsvReader<T>
-
addProperty
public void addProperty(String propertyName, StringParser parser)
Description copied from interface:CsvReader
Define the next property and use a custom StringParser to convert the string content into the appropriate type for the property.- Specified by:
addProperty
in interfaceCsvReader<T>
-
process
public void process(Reader reader) throws Exception
Description copied from interface:CsvReader
Automatically create a transaction if required to process all the CSV content from the reader.This will check for a current transaction. If there is no current transaction then one is started and will commit (or rollback) at the end of processing. This will also set the persistBatchSize on the transaction.
-
process
public void process(Reader reader, CsvCallback<T> callback) throws Exception
Description copied from interface:CsvReader
Process the CSV content passing the bean to the CsvCallback after each row.This provides you with the ability to modify and process the bean.
When using a CsvCallback the reader WILL NOT create a transaction or save the bean(s) for you. If you want to insert the processed beans you must create your own transaction and save the bean(s) yourself.
-
-