[#7917] Partial implementation (still a moving target in H2)

This commit is contained in:
lukaseder 2018-10-09 10:14:03 +02:00
parent 6f76dd4dd2
commit 590a15ca3c
15 changed files with 296 additions and 31 deletions

View File

@ -38,6 +38,7 @@
package org.jooq.meta.h2;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.select;
import static org.jooq.meta.h2.information_schema.tables.Columns.COLUMNS;
import static org.jooq.meta.h2.information_schema.tables.Constraints.CONSTRAINTS;
@ -89,6 +90,7 @@ import org.jooq.meta.UDTDefinition;
import org.jooq.meta.h2.information_schema.tables.Columns;
import org.jooq.meta.h2.information_schema.tables.Constraints;
import org.jooq.meta.h2.information_schema.tables.CrossReferences;
import org.jooq.meta.h2.information_schema.tables.Domains;
import org.jooq.meta.h2.information_schema.tables.FunctionAliases;
import org.jooq.meta.h2.information_schema.tables.Indexes;
import org.jooq.meta.h2.information_schema.tables.Schemata;
@ -478,24 +480,33 @@ public class H2Database extends AbstractDatabase {
if (!is1_4_197())
return result;
Result<Record4<String, String, String, String>> records = create()
.select(
Columns.TABLE_SCHEMA,
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();
getInlineEnums(result);
getDomainEnums(result);
return result;
}
private void getInlineEnums(List<EnumDefinition> result) {
enumLoop:
for (Record record : create()
.select(
Columns.TABLE_SCHEMA,
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())) {
for (Record record : records) {
SchemaDefinition schema = getSchema(record.get(Columns.TABLE_SCHEMA));
if (schema == null)
continue enumLoop;
String table = record.get(Columns.TABLE_NAME);
String column = record.get(Columns.COLUMN_NAME);
@ -522,17 +533,52 @@ public class H2Database extends AbstractDatabase {
,true // Strict quotes
);
for (String string : reader.next()) {
for (String string : reader.next())
definition.addLiteral(string);
}
result.add(definition);
}
}
}
}
}
return result;
private void getDomainEnums(List<EnumDefinition> result) {
enumLoop:
for (Record record : create()
.select(
Domains.DOMAIN_SCHEMA,
Domains.DOMAIN_NAME,
Domains.SQL)
.from(Domains.DOMAINS)
.where(Domains.TYPE_NAME.eq(inline("ENUM")))
.and(Domains.DOMAIN_SCHEMA.in(getInputSchemata()))
.orderBy(
Domains.DOMAIN_SCHEMA,
Domains.DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(Domains.DOMAIN_SCHEMA));
if (schema == null)
continue enumLoop;
String name = record.get(Domains.DOMAIN_NAME);
String sql = record.get(Domains.SQL);
DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, "");
CSVReader reader = new CSVReader(
new StringReader(sql.replaceAll("(?i:(^.*as enum\\()|(\\).*$))", ""))
,',' // Separator
,'\'' // Quote character
,true // Strict quotes
);
for (String string : reader.next())
definition.addLiteral(string);
result.add(definition);
}
}
@Override

View File

@ -18,7 +18,7 @@ import org.jooq.impl.CatalogImpl;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DefaultCatalog extends CatalogImpl {
private static final long serialVersionUID = -1741973376;
private static final long serialVersionUID = 517390160;
/**
* The reference instance of <code></code>

View File

@ -14,6 +14,7 @@ import org.jooq.impl.SchemaImpl;
import org.jooq.meta.h2.information_schema.tables.Columns;
import org.jooq.meta.h2.information_schema.tables.Constraints;
import org.jooq.meta.h2.information_schema.tables.CrossReferences;
import org.jooq.meta.h2.information_schema.tables.Domains;
import org.jooq.meta.h2.information_schema.tables.FunctionAliases;
import org.jooq.meta.h2.information_schema.tables.FunctionColumns;
import org.jooq.meta.h2.information_schema.tables.Indexes;
@ -29,7 +30,7 @@ import org.jooq.meta.h2.information_schema.tables.TypeInfo;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class InformationSchema extends SchemaImpl {
private static final long serialVersionUID = -426534875;
private static final long serialVersionUID = 200165715;
/**
* The reference instance of <code>INFORMATION_SCHEMA</code>
@ -51,6 +52,11 @@ public class InformationSchema extends SchemaImpl {
*/
public final CrossReferences CROSS_REFERENCES = org.jooq.meta.h2.information_schema.tables.CrossReferences.CROSS_REFERENCES;
/**
* The table <code>INFORMATION_SCHEMA.DOMAINS</code>.
*/
public final Domains DOMAINS = org.jooq.meta.h2.information_schema.tables.Domains.DOMAINS;
/**
* The table <code>INFORMATION_SCHEMA.FUNCTION_ALIASES</code>.
*/
@ -114,6 +120,7 @@ public class InformationSchema extends SchemaImpl {
Columns.COLUMNS,
Constraints.CONSTRAINTS,
CrossReferences.CROSS_REFERENCES,
Domains.DOMAINS,
FunctionAliases.FUNCTION_ALIASES,
FunctionColumns.FUNCTION_COLUMNS,
Indexes.INDEXES,

View File

@ -7,6 +7,7 @@ package org.jooq.meta.h2.information_schema;
import org.jooq.meta.h2.information_schema.tables.Columns;
import org.jooq.meta.h2.information_schema.tables.Constraints;
import org.jooq.meta.h2.information_schema.tables.CrossReferences;
import org.jooq.meta.h2.information_schema.tables.Domains;
import org.jooq.meta.h2.information_schema.tables.FunctionAliases;
import org.jooq.meta.h2.information_schema.tables.FunctionColumns;
import org.jooq.meta.h2.information_schema.tables.Indexes;
@ -36,6 +37,11 @@ public class Tables {
*/
public static final CrossReferences CROSS_REFERENCES = org.jooq.meta.h2.information_schema.tables.CrossReferences.CROSS_REFERENCES;
/**
* The table <code>INFORMATION_SCHEMA.DOMAINS</code>.
*/
public static final Domains DOMAINS = org.jooq.meta.h2.information_schema.tables.Domains.DOMAINS;
/**
* The table <code>INFORMATION_SCHEMA.FUNCTION_ALIASES</code>.
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Columns extends TableImpl<Record> {
private static final long serialVersionUID = -443290501;
private static final long serialVersionUID = -1247184254;
/**
* The reference instance of <code>INFORMATION_SCHEMA.COLUMNS</code>
@ -101,6 +102,21 @@ public class Columns extends TableImpl<Record> {
*/
public static final TableField<Record, Integer> NUMERIC_SCALE = createField("NUMERIC_SCALE", org.jooq.impl.SQLDataType.INTEGER, COLUMNS, "");
/**
* The column <code>INFORMATION_SCHEMA.COLUMNS.DATETIME_PRECISION</code>.
*/
public static final TableField<Record, Integer> DATETIME_PRECISION = createField("DATETIME_PRECISION", org.jooq.impl.SQLDataType.INTEGER, COLUMNS, "");
/**
* The column <code>INFORMATION_SCHEMA.COLUMNS.INTERVAL_TYPE</code>.
*/
public static final TableField<Record, String> INTERVAL_TYPE = createField("INTERVAL_TYPE", org.jooq.impl.SQLDataType.VARCHAR(2147483647), COLUMNS, "");
/**
* The column <code>INFORMATION_SCHEMA.COLUMNS.INTERVAL_PRECISION</code>.
*/
public static final TableField<Record, Integer> INTERVAL_PRECISION = createField("INTERVAL_PRECISION", org.jooq.impl.SQLDataType.INTEGER, COLUMNS, "");
/**
* The column <code>INFORMATION_SCHEMA.COLUMNS.CHARACTER_SET_NAME</code>.
*/
@ -161,6 +177,11 @@ public class Columns extends TableImpl<Record> {
*/
public static final TableField<Record, String> COLUMN_ON_UPDATE = createField("COLUMN_ON_UPDATE", org.jooq.impl.SQLDataType.VARCHAR(2147483647), COLUMNS, "");
/**
* The column <code>INFORMATION_SCHEMA.COLUMNS.IS_VISIBLE</code>.
*/
public static final TableField<Record, String> IS_VISIBLE = createField("IS_VISIBLE", org.jooq.impl.SQLDataType.VARCHAR(2147483647), COLUMNS, "");
/**
* No further instances allowed
*/
@ -176,6 +197,10 @@ public class Columns extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Columns(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, COLUMNS);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Constraints extends TableImpl<Record> {
private static final long serialVersionUID = -235741806;
private static final long serialVersionUID = -815790932;
/**
* The reference instance of <code>INFORMATION_SCHEMA.CONSTRAINTS</code>
@ -116,6 +117,10 @@ public class Constraints extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Constraints(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, CONSTRAINTS);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class CrossReferences extends TableImpl<Record> {
private static final long serialVersionUID = 854586497;
private static final long serialVersionUID = -1128530622;
/**
* The reference instance of <code>INFORMATION_SCHEMA.CROSS_REFERENCES</code>
@ -121,6 +122,10 @@ public class CrossReferences extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> CrossReferences(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, CROSS_REFERENCES);
}
/**
* {@inheritDoc}
*/

View File

@ -0,0 +1,136 @@
/*
* This file is generated by jOOQ.
*/
package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.impl.DSL;
import org.jooq.impl.TableImpl;
import org.jooq.meta.h2.information_schema.InformationSchema;
/**
* This class is generated by jOOQ.
*/
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Domains extends TableImpl<Record> {
private static final long serialVersionUID = -1042876127;
/**
* The reference instance of <code>INFORMATION_SCHEMA.DOMAINS</code>
*/
public static final Domains DOMAINS = new Domains();
/**
* The class holding records for this type
*/
@Override
public Class<Record> getRecordType() {
return Record.class;
}
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.DOMAIN_CATALOG</code>.
*/
public static final TableField<Record, String> DOMAIN_CATALOG = createField("DOMAIN_CATALOG", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.DOMAIN_SCHEMA</code>.
*/
public static final TableField<Record, String> DOMAIN_SCHEMA = createField("DOMAIN_SCHEMA", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.DOMAIN_NAME</code>.
*/
public static final TableField<Record, String> DOMAIN_NAME = createField("DOMAIN_NAME", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.COLUMN_DEFAULT</code>.
*/
public static final TableField<Record, String> COLUMN_DEFAULT = createField("COLUMN_DEFAULT", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.IS_NULLABLE</code>.
*/
public static final TableField<Record, String> IS_NULLABLE = createField("IS_NULLABLE", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.DATA_TYPE</code>.
*/
public static final TableField<Record, Integer> DATA_TYPE = createField("DATA_TYPE", org.jooq.impl.SQLDataType.INTEGER, DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.PRECISION</code>.
*/
public static final TableField<Record, Integer> PRECISION = createField("PRECISION", org.jooq.impl.SQLDataType.INTEGER, DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.SCALE</code>.
*/
public static final TableField<Record, Integer> SCALE = createField("SCALE", org.jooq.impl.SQLDataType.INTEGER, DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.TYPE_NAME</code>.
*/
public static final TableField<Record, String> TYPE_NAME = createField("TYPE_NAME", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.SELECTIVITY</code>.
*/
public static final TableField<Record, Integer> SELECTIVITY = createField("SELECTIVITY", org.jooq.impl.SQLDataType.INTEGER, DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.CHECK_CONSTRAINT</code>.
*/
public static final TableField<Record, String> CHECK_CONSTRAINT = createField("CHECK_CONSTRAINT", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.REMARKS</code>.
*/
public static final TableField<Record, String> REMARKS = createField("REMARKS", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.SQL</code>.
*/
public static final TableField<Record, String> SQL = createField("SQL", org.jooq.impl.SQLDataType.VARCHAR(2147483647), DOMAINS, "");
/**
* The column <code>INFORMATION_SCHEMA.DOMAINS.ID</code>.
*/
public static final TableField<Record, Integer> ID = createField("ID", org.jooq.impl.SQLDataType.INTEGER, DOMAINS, "");
/**
* No further instances allowed
*/
private Domains() {
this(DSL.name("DOMAINS"), null);
}
private Domains(Name alias, Table<Record> aliased) {
this(alias, aliased, null);
}
private Domains(Name alias, Table<Record> aliased, Field<?>[] parameters) {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Domains(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, DOMAINS);
}
/**
* {@inheritDoc}
*/
@Override
public Schema getSchema() {
return InformationSchema.INFORMATION_SCHEMA;
}
}

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class FunctionAliases extends TableImpl<Record> {
private static final long serialVersionUID = -162900236;
private static final long serialVersionUID = -819150211;
/**
* The reference instance of <code>INFORMATION_SCHEMA.FUNCTION_ALIASES</code>
@ -111,6 +112,10 @@ public class FunctionAliases extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> FunctionAliases(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, FUNCTION_ALIASES);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class FunctionColumns extends TableImpl<Record> {
private static final long serialVersionUID = -1296724475;
private static final long serialVersionUID = 169336202;
/**
* The reference instance of <code>INFORMATION_SCHEMA.FUNCTION_COLUMNS</code>
@ -136,6 +137,10 @@ public class FunctionColumns extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> FunctionColumns(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, FUNCTION_COLUMNS);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Indexes extends TableImpl<Record> {
private static final long serialVersionUID = -311554387;
private static final long serialVersionUID = -1466822713;
/**
* The reference instance of <code>INFORMATION_SCHEMA.INDEXES</code>
@ -161,6 +162,10 @@ public class Indexes extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Indexes(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, INDEXES);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Schemata extends TableImpl<Record> {
private static final long serialVersionUID = -1744936991;
private static final long serialVersionUID = -1587750899;
/**
* The reference instance of <code>INFORMATION_SCHEMA.SCHEMATA</code>
@ -91,6 +92,10 @@ public class Schemata extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Schemata(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, SCHEMATA);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Sequences extends TableImpl<Record> {
private static final long serialVersionUID = 1226404694;
private static final long serialVersionUID = -1118138960;
/**
* The reference instance of <code>INFORMATION_SCHEMA.SEQUENCES</code>
@ -111,6 +112,10 @@ public class Sequences extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Sequences(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, SEQUENCES);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Tables extends TableImpl<Record> {
private static final long serialVersionUID = 1327832751;
private static final long serialVersionUID = -356028407;
/**
* The reference instance of <code>INFORMATION_SCHEMA.TABLES</code>
@ -111,6 +112,10 @@ public class Tables extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> Tables(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, TABLES);
}
/**
* {@inheritDoc}
*/

View File

@ -5,6 +5,7 @@ package org.jooq.meta.h2.information_schema.tables;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
@ -21,7 +22,7 @@ import org.jooq.meta.h2.information_schema.InformationSchema;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class TypeInfo extends TableImpl<Record> {
private static final long serialVersionUID = 922808969;
private static final long serialVersionUID = -504092352;
/**
* The reference instance of <code>INFORMATION_SCHEMA.TYPE_INFO</code>
@ -121,6 +122,10 @@ public class TypeInfo extends TableImpl<Record> {
super(alias, null, aliased, parameters, DSL.comment(""));
}
public <O extends Record> TypeInfo(Table<O> child, ForeignKey<O, Record> key) {
super(child, key, TYPE_INFO);
}
/**
* {@inheritDoc}
*/