
public abstract class DataFileReader extends Object
| Constructor and Description |
|---|
DataFileReader() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
asCsv(Collection<String> data)
Convert a collection of elements read from the data file (the column names in the internal database) into a CSV
string.
|
protected String |
asQuestionCsv(Collection<String> data)
Convert a collection of elements read from the data file (the column names in the internal database) into a CSV
string of question marks.
|
protected void |
createTable(String tableName,
String createTableCommand,
Connection connection)
Execute a command to create a table.
|
abstract int |
insert()
Insert the data from the input file into the database.
|
protected int |
insert(Connection connection,
String tableName,
String insertString,
String dataFile,
String dateFormat,
Map<String,Integer> insertedColInfo,
Collection<Integer> dateFields)
Perform the insertion into the database.
|
protected String |
updateCreateTableCommand(String columnName,
Integer columnIndex,
String columnType,
Map<String,Integer> insertedColDetails,
StringBuilder createTableCommand,
String tableName,
String sectionName,
StringBuilder errors)
Create or append to a string command in the form "CREATE TABLE IF NOT EXISTS [table] ([col1], [col2], ...,
[coln]) values (?,?,...,?)" from the details read from the configuration file.
|
protected final String asCsv(Collection<String> data)
data - the collection of column names.protected final String asQuestionCsv(Collection<String> data)
data - the collection of column names.protected final String updateCreateTableCommand(String columnName, Integer columnIndex, String columnType, Map<String,Integer> insertedColDetails, StringBuilder createTableCommand, String tableName, String sectionName, StringBuilder errors)
updateCreateTableCommand(ID, 1, " VARCHAR(128), ", new HashMap(), createTableCommand, TABLE_NAME, SECTION_NAME, errors);
columnName - the name of the column in the tablecolumnIndex - the location in the csv file where it appears.columnType - the type of column e.g. "INT", "VARCHAR(128) NOT NULL" etc.insertedColDetails - a map containing the name of the column and the location in the csv file where it
appears i.e. columnName, columnIndex.createTableCommand - a StringBuilder object that we append to to create the create table command.tableName - the name of the table that is being created.sectionName - the name of the section in the configuration file that configures the data.errors - a stringbuilder object to which we will append error messages.protected final void createTable(String tableName, String createTableCommand, Connection connection) throws SQLException
tableName - the name of the table to be created.createTableCommand - the command to create the table.connection - the database connection to use to create the table.SQLException - if a SQL error has been encountered.protected final int insert(Connection connection, String tableName, String insertString, String dataFile, String dateFormat, Map<String,Integer> insertedColInfo, Collection<Integer> dateFields)
connection - the connection to the database.tableName - the name of the table into which the data will be put.insertString - the command used to insert a row into the database.dataFile - the [CSV] file that contained the data.dateFormat - the format of the date in the file.insertedColInfo - a map of column name to column in the data file.dateFields - a collection of columns in the csv file that contains date fields.public abstract int insert()
Copyright © 2015 University of Glasgow. All rights reserved.