use of org.jooq.meta.EnumDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<>();
// [#2736] This table is unavailable in Amazon Redshift
if (exists(PG_ENUM)) {
// cross-version compatible enum literal ordering
for (Identifier type : create().select(PG_TYPE.pgNamespace().NSPNAME, PG_TYPE.TYPNAME).from(PG_TYPE).where(PG_TYPE.pgNamespace().NSPNAME.in(getInputSchemata())).and(PG_TYPE.OID.in(select(PG_ENUM.ENUMTYPID).from(PG_ENUM))).orderBy(PG_TYPE.pgNamespace().NSPNAME, PG_TYPE.TYPNAME).fetch(mapping(Identifier::new))) {
DefaultEnumDefinition definition = null;
for (String label : enumLabels(type.schema, type.name)) {
SchemaDefinition schema = getSchema(type.schema);
String typeName = String.valueOf(type.name);
if (definition == null || !definition.getName().equals(typeName)) {
definition = new DefaultEnumDefinition(schema, typeName, null);
result.add(definition);
}
definition.addLiteral(label);
}
}
}
return result;
}
use of org.jooq.meta.EnumDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<>();
for (ColumnRecord r : create().select(COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME, COLUMNS.COLUMN_NAME, COLUMNS.COLUMN_TYPE, COLUMNS.COLUMN_COMMENT).from(COLUMNS).where(COLUMNS.COLUMN_TYPE.like("enum(%)").and(COLUMNS.TABLE_SCHEMA.in(workaroundFor5213(getInputSchemata())))).orderBy(COLUMNS.TABLE_SCHEMA.asc(), COLUMNS.TABLE_NAME.asc(), COLUMNS.COLUMN_NAME.asc()).fetch(mapping(ColumnRecord::new))) {
SchemaDefinition schema = getSchema(r.schema);
String name = r.table + "_" + r.column;
// [#1237] Don't generate enum classes for columns in MySQL tables
// that are excluded from code generation
TableDefinition tableDefinition = getTable(schema, r.table);
if (tableDefinition != null) {
ColumnDefinition columnDefinition = tableDefinition.getColumn(r.column);
if (columnDefinition != null) {
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition, columnDefinition.getType()) == null) {
DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, r.comment);
CSVReader reader = new CSVReader(new StringReader(r.type.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.meta.EnumDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateEnums.
protected void generateEnums(SchemaDefinition schema) {
log.info("Generating ENUMs");
for (EnumDefinition e : database.getEnums(schema)) {
try {
generateEnum(e);
} catch (Exception ex) {
log.error("Error while generating enum " + e, ex);
}
}
watch.splitInfo("Enums generated");
}
use of org.jooq.meta.EnumDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<>();
for (TableDefinition tableDefinition : getTables(getSchemata().get(0))) {
for (Record record : create().fetch("SHOW COLUMNS FROM {0} WHERE TYPE LIKE 'ENUM(%)'", field(name(tableDefinition.getInputName())))) {
String table = tableDefinition.getInputName();
String column = record.get("Field", String.class);
String columnType = record.get("Type", String.class);
String name = table + "_" + column;
ColumnDefinition columnDefinition = tableDefinition.getColumn(column);
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition) == null) {
DefaultEnumDefinition definition = new DefaultEnumDefinition(getSchemata().get(0), name, "");
for (String string : columnType.replaceAll("ENUM\\(|\\)", "").split(",")) {
definition.addLiteral(string.trim().replaceAll("'", ""));
}
result.add(definition);
}
}
}
return result;
}
Aggregations