use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (TableRecord r : create().select(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME, when(TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name())).when(TABLES.STORAGE_TYPE.like(inline("%TEMPORARY%")), inline(TableType.TEMPORARY.name())).else_(inline(TableType.TABLE.name())).convertFrom(TableType::valueOf).as("table_type"), TABLES.REMARKS, VIEWS.VIEW_DEFINITION).from(TABLES).leftJoin(VIEWS).on(TABLES.TABLE_SCHEMA.eq(VIEWS.TABLE_SCHEMA)).and(TABLES.TABLE_NAME.eq(VIEWS.TABLE_NAME)).where(TABLES.TABLE_SCHEMA.in(getInputSchemata())).orderBy(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME).fetch(mapping(TableRecord::new))) {
SchemaDefinition schema = getSchema(r.schema);
String source = r.source;
if (source != null && !source.toLowerCase().startsWith("create"))
source = "create view \"" + r.table + "\" as " + source;
if (schema != null)
result.add(new H2TableDefinition(schema, r.table, r.comment, r.type, source));
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method getDomains2_0.
private List<DomainDefinition> getDomains2_0() {
List<DomainDefinition> result = new ArrayList<>();
Domains d = Tables.DOMAINS.as("d");
DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
for (Record record : create().select(d.DOMAIN_SCHEMA, d.DOMAIN_NAME, d.DATA_TYPE, d.CHARACTER_MAXIMUM_LENGTH, coalesce(d.DATETIME_PRECISION, d.NUMERIC_PRECISION).as(d.NUMERIC_PRECISION), d.NUMERIC_SCALE, d.DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(d).leftJoin(dc).on(d.DOMAIN_CATALOG.eq(dc.DOMAIN_CATALOG)).and(d.DOMAIN_SCHEMA.eq(dc.DOMAIN_SCHEMA)).and(d.DOMAIN_NAME.eq(dc.DOMAIN_NAME)).where(d.DOMAIN_SCHEMA.in(getInputSchemata())).and(d.DATA_TYPE.ne(inline("ENUM"))).orderBy(d.DOMAIN_SCHEMA, d.DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(d.DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(d.DATA_TYPE), record.get(d.CHARACTER_MAXIMUM_LENGTH), record.get(d.NUMERIC_PRECISION), record.get(d.NUMERIC_SCALE), true, record.get(d.DOMAIN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
result.add(domain);
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
for (Record record : primaryKeys(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(CONSTRAINTS.TABLE_SCHEMA));
if (schema != null) {
String tableName = record.get(CONSTRAINTS.TABLE_NAME);
String primaryKey = record.get(CONSTRAINTS.CONSTRAINT_NAME);
String columnName = record.get(INDEXES.COLUMN_NAME);
TableDefinition table = getTable(schema, tableName);
if (table != null)
relations.addPrimaryKey(primaryKey, table, table.getColumn(columnName));
}
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method getInlineEnums2_0.
private void getInlineEnums2_0(List<EnumDefinition> result) {
// TODO: Re-generate the H2 schema and use generated code to run this query
create().resultQuery(("" + "select c.TABLE_SCHEMA , c.TABLE_NAME , c.COLUMN_NAME , array_agg(ev.value_name order by ev.VALUE_ORDINAL)\n" + "from INFORMATION_SCHEMA.ENUM_VALUES ev\n" + "join information_schema.columns c\n" + "on ev.OBJECT_SCHEMA = c.TABLE_SCHEMA\n" + "and ev.OBJECT_NAME = c.TABLE_NAME\n" + "and ev.ENUM_IDENTIFIER = c.DTD_IDENTIFIER\n" + "where ev.OBJECT_TYPE = 'TABLE'\n" + "and c.DOMAIN_NAME IS NULL\n" + "group by c.TABLE_SCHEMA , c.TABLE_NAME , c.COLUMN_NAME\n" + "order by 1, 2, 3\n" + "")).coerce(COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME, COLUMNS.COLUMN_NAME, arrayAgg(COLUMNS.COLUMN_NAME)).forEach(r -> {
SchemaDefinition schema = getSchema(r.value1());
if (schema == null)
return;
// [#1237] Don't generate enum classes for columns in MySQL tables
// that are excluded from code generation
TableDefinition tableDefinition = getTable(schema, r.value2());
if (tableDefinition != null) {
ColumnDefinition columnDefinition = tableDefinition.getColumn(r.value3());
if (columnDefinition != null) {
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition, columnDefinition.getType()) == null) {
String name = r.value2() + "_" + r.value3();
DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, "");
for (String string : r.value4()) definition.addLiteral(string);
result.add(definition);
}
}
}
});
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class H2Database method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : uniqueKeys(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(CONSTRAINTS.TABLE_SCHEMA));
if (schema != null) {
String tableName = record.get(CONSTRAINTS.TABLE_NAME);
String primaryKey = record.get(CONSTRAINTS.CONSTRAINT_NAME);
String columnName = record.get(INDEXES.COLUMN_NAME);
TableDefinition table = getTable(schema, tableName);
if (table != null)
relations.addUniqueKey(primaryKey, table, table.getColumn(columnName));
}
}
}
Aggregations