use of org.jooq.tools.csv.CSVReader in project jOOQ by jOOQ.
the class MySQLDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<EnumDefinition>();
Result<Record5<String, String, String, String, String>> records = create().select(Columns.TABLE_SCHEMA, Columns.COLUMN_COMMENT, Columns.TABLE_NAME, Columns.COLUMN_NAME, Columns.COLUMN_TYPE).from(COLUMNS).where(Columns.COLUMN_TYPE.like("enum(%)").and(Columns.TABLE_SCHEMA.in(getInputSchemata()))).orderBy(Columns.TABLE_SCHEMA.asc(), Columns.TABLE_NAME.asc(), Columns.COLUMN_NAME.asc()).fetch();
for (Record record : records) {
SchemaDefinition schema = getSchema(record.get(Columns.TABLE_SCHEMA));
String comment = record.get(Columns.COLUMN_COMMENT);
String table = record.get(Columns.TABLE_NAME);
String column = record.get(Columns.COLUMN_NAME);
String name = table + "_" + column;
String columnType = record.get(Columns.COLUMN_TYPE);
// [#1237] Don't generate enum classes for columns in MySQL tables
// that are excluded from code generation
TableDefinition tableDefinition = getTable(schema, table);
if (tableDefinition != null) {
ColumnDefinition columnDefinition = tableDefinition.getColumn(column);
if (columnDefinition != null) {
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition, columnDefinition.getType()) == null) {
DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, comment);
CSVReader reader = new CSVReader(new StringReader(columnType.replaceAll("(^enum\\()|(\\)$)", "")), // Separator
',', // Quote character
'\'', // Strict quotes
true);
for (String string : reader.next()) {
definition.addLiteral(string);
}
result.add(definition);
}
}
}
}
return result;
}
use of org.jooq.tools.csv.CSVReader in project jOOQ by jOOQ.
the class DefaultDSLContext method fetchFromCSV.
@Override
public Result<Record> fetchFromCSV(String string, boolean header, char delimiter) {
CSVReader reader = new CSVReader(new StringReader(string), delimiter);
List<String[]> list = null;
try {
list = reader.readAll();
} catch (IOException e) {
throw new DataAccessException("Could not read the CSV string", e);
} finally {
try {
reader.close();
} catch (IOException ignore) {
}
}
return fetchFromStringData(list, header);
}
use of org.jooq.tools.csv.CSVReader in project jOOQ by jOOQ.
the class AbstractDatabase method getConfiguredEnums.
private final List<EnumDefinition> getConfiguredEnums() {
List<EnumDefinition> result = new ArrayList<EnumDefinition>();
for (EnumType enumType : configuredEnumTypes) {
String name = enumType.getName();
DefaultEnumDefinition e = new DefaultEnumDefinition(getSchemata().get(0), name, null, true);
String literals = enumType.getLiterals();
try {
@SuppressWarnings("resource") CSVReader reader = new CSVReader(new StringReader(literals));
e.addLiterals(reader.readNext());
} catch (IOException ignore) {
}
result.add(e);
}
return result;
}
use of org.jooq.tools.csv.CSVReader in project jOOQ by jOOQ.
the class LoaderImpl method executeCSV.
private final void executeCSV() throws IOException {
CSVReader reader = null;
try {
if (ignoreRows == 1) {
reader = new CSVReader(data.reader(), separator, quote, 0);
source = Tools.fieldsByName(reader.next());
} else {
reader = new CSVReader(data.reader(), separator, quote, ignoreRows);
}
executeSQL(reader);
}// They are propagated, and not swallowed
catch (SQLException e) {
throw Tools.translate(null, e);
} finally {
if (reader != null)
reader.close();
}
}
Aggregations