lineNumber++;
if (line.length == 0 || (line.length == 1 && StringUtils.trimToNull(line[0]) == null)) {
continue; //nothing on this line
}
InsertStatement insertStatement = this.createStatement(getCatalogName(), getSchemaName(), getTableName());
for (int i=0; i<headers.length; i++) {
String columnName = null;
if( i >= line.length ) {
throw new UnexpectedLiquibaseException("CSV Line " + lineNumber + " has only " + (i-1) + " columns, the header has " + headers.length);
}
Object value = line[i];
ColumnConfig columnConfig = getColumnConfig(i, headers[i].trim());
if (columnConfig != null) {
columnName = columnConfig.getName();
if ("skip".equalsIgnoreCase(columnConfig.getType())) {
continue;
}
if (value.toString().equalsIgnoreCase("NULL")) {
value = "NULL";
} else if (columnConfig.getType() != null) {
ColumnConfig valueConfig = new ColumnConfig();
if (columnConfig.getType().equalsIgnoreCase("BOOLEAN")) {
valueConfig.setValueBoolean(BooleanParser.parseBoolean(value.toString().toLowerCase()));
} else if (columnConfig.getType().equalsIgnoreCase("NUMERIC")) {
valueConfig.setValueNumeric(value.toString());
} else if (columnConfig.getType().toLowerCase().contains("date") ||columnConfig.getType().toLowerCase().contains("time")) {
valueConfig.setValueDate(value.toString());
} else if (columnConfig.getType().equalsIgnoreCase("STRING")) {
valueConfig.setValue(value.toString());
} else if (columnConfig.getType().equalsIgnoreCase("COMPUTED")) {
liquibase.statement.DatabaseFunction function = new liquibase.statement.DatabaseFunction(value.toString());
valueConfig.setValueComputed(function);
} else {
throw new UnexpectedLiquibaseException("loadData type of "+columnConfig.getType()+" is not supported. Please use BOOLEAN, NUMERIC, DATE, STRING, COMPUTED or SKIP");
}
value = valueConfig.getValueObject();
}
}
if (columnName == null) {
columnName = headers[i];
}
if (columnName.contains("(") || columnName.contains(")") && database instanceof AbstractJdbcDatabase) {
columnName = ((AbstractJdbcDatabase) database).quoteObject(columnName, Column.class);
}
insertStatement.addColumnValue(columnName, value);
}
statements.add(insertStatement);
}
return statements.toArray(new SqlStatement[statements.size()]);