E - The type of the generated objectspublic abstract class AbstractCsvDataProvider<E> extends AbstractCsvReader<E> implements DataProvider
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCsvDataProvider(File importPath)
Initializes the converter from a path.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumnMapping(String column,
String property)
Defines the mapping from a column name to a property name.
|
void |
addConverter(String column,
CsvPropertyConverter<?> converter)
Registers the converter to use for a specific column.
|
protected boolean |
applyColumn(E entity,
String column,
String value)
Converts a column value to a property value and sets that property for an entity.
|
void |
buildEntities()
Starts the generation of the SQL file from the list of CSV files.
|
protected <T> T |
convertColumn(String column,
Class<T> targetType,
String value)
Tries to convert the given string to a value of the given type for the given column.
|
protected Collection<? extends E> |
createEntities(Map<String,String> row)
Builds one or more entities from the given row.
|
protected E |
createEntity()
Creates a new empty entity for the current converter.
|
protected E |
createEntity(Map<String,String> row)
Builds one entity from the given row.
|
protected Class<E> |
getEntityClass()
The class of the created entities.
|
int |
getOrder()
Defaults to 0.
|
protected void |
useTableColumns()
Maps the table columns of the singular properties to the CSV columns.
|
void |
writeEntities(EntitySqlGenerator sqlGenerator)
Writes all created entities.
|
getDefaultEncoding, openCsvListReader, readImportFilesprotected AbstractCsvDataProvider(File importPath)
importPath - the path to a CSV file or to a directory that contains the *.csv filespublic void addColumnMapping(String column, String property)
column - the name of the columnproperty - the name of the propertypublic void addConverter(String column, CsvPropertyConverter<?> converter)
column - the name of the columnconverter - used to convert that column from CSV to a Java valueprotected boolean applyColumn(E entity, String column, String value)
entity - the entity to modifycolumn - the name of the current columnvalue - the value of the property (converts the property, if nessecary)true if an appropriate property was found, false if a matching property was not found and
#isIgnoreUnknownColumns() is trueIllegalArgumentException - if a matching property was not found or the was not convertedpublic void buildEntities()
throws IOException
buildEntities in interface DataProviderIOException - if something happens during any possible import of the generated entitiesprotected <T> T convertColumn(String column, Class<T> targetType, String value)
column - the name of the columntargetType - the target typevalue - the string representation of the valueprotected Collection<? extends E> createEntities(Map<String,String> row)
createEntities in class AbstractCsvReader<E>row - contains the mapping from the header names to the current row dataprotected E createEntity()
createEntities(Map).protected E createEntity(Map<String,String> row)
row - contains the mapping from the header names to the current row dataprotected Class<E> getEntityClass()
public int getOrder()
getOrder in interface DataProviderprotected void useTableColumns()
public void writeEntities(EntitySqlGenerator sqlGenerator) throws IOException
writeEntities in interface DataProvidersqlGenerator - the SQL file generatorIOException - if the generator throws oneCopyright © 2016 fastnate.org. All rights reserved.