E - The type of the generated objectspublic abstract class AbstractCsvDataProvider<E> extends AbstractCsvReader<E> implements DataProvider
| Modifier and Type | Field and Description |
|---|---|
private Map<String,CsvPropertyConverter<?>> |
columnConverter |
private Map<String,String> |
columnProperties |
private Collection<E> |
entities |
private Set<String> |
ignoredColumns |
private boolean |
ignoreUnknownColumns
Indicates to ignore any column that can't be mapped to a property.
|
private static Map<Class<?>,CsvPropertyConverter<?>> |
PROPERTY_CONVERTER |
| 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.
|
void |
addIgnoredColumn(String column)
Ignores a column during import.
|
protected boolean |
applyColumn(E entity,
String column,
String value)
Converts a column value to a property value and sets that property for an entity.
|
private boolean |
applyColumn(E entity,
String column,
String property,
String value) |
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.
|
private <T> CsvPropertyConverter<? super T> |
findConverter(Class<T> targetType) |
Collection<E> |
getEntities() |
protected Class<E> |
getEntityClass()
The class of the created entities.
|
int |
getOrder()
Defaults to 0.
|
boolean |
isIgnoredColumn(String column)
Indicates that the given column is ignored during import.
|
boolean |
isIgnoreUnknownColumns()
Indicates to ignore any column that can't be mapped to a property.
|
void |
setIgnoreUnknownColumns(boolean ignoreUnknownColumns)
Indicates to ignore any column that can't be mapped to a property.
|
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, readImportFilesprivate static final Map<Class<?>,CsvPropertyConverter<?>> PROPERTY_CONVERTER
private final Collection<E> entities
private final Map<String,CsvPropertyConverter<?>> columnConverter
private boolean ignoreUnknownColumns
protected 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 valuepublic void addIgnoredColumn(String column)
column - the name of the column that is ignoredprotected 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 convertedprivate boolean applyColumn(E entity, String column, String property, String value) throws IllegalAccessException, InvocationTargetException
public 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 dataprivate <T> CsvPropertyConverter<? super T> findConverter(Class<T> targetType)
protected Class<E> getEntityClass()
public int getOrder()
getOrder in interface DataProviderpublic boolean isIgnoredColumn(String column)
column - the name of the columntrue if the column is not importedprotected void useTableColumns()
public void writeEntities(EntitySqlGenerator sqlGenerator) throws IOException
writeEntities in interface DataProvidersqlGenerator - the SQL file generatorIOException - if the generator throws one@Generated(value="lombok") public Collection<E> getEntities()
@Generated(value="lombok") public boolean isIgnoreUnknownColumns()
@Generated(value="lombok") public void setIgnoreUnknownColumns(boolean ignoreUnknownColumns)
Copyright © 2020 fastnate.org. All rights reserved.