diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java index 2ebb8ca14e..73687896c3 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/XMLGenerator.java @@ -83,6 +83,7 @@ import org.jooq.util.xml.jaxb.Schema; import org.jooq.util.xml.jaxb.Sequence; import org.jooq.util.xml.jaxb.Table; import org.jooq.util.xml.jaxb.TableConstraint; +import org.jooq.util.xml.jaxb.TableType; /** * @author Lukas Eder @@ -146,6 +147,13 @@ public class XMLGenerator extends AbstractGenerator { table.setTableCatalog(catalogName); table.setTableSchema(schemaName); table.setTableName(tableName); + table.setTableType( + t.isView() + ? TableType.VIEW + : t.isTemporary() + ? TableType.GLOBAL_TEMPORARY + : TableType.BASE_TABLE + ); if (generateCommentsOnTables()) table.setComment(t.getComment()); diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java index 7cfd4ce9a0..bc3808b3b1 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLDatabase.java @@ -82,6 +82,7 @@ import org.jooq.Name; import org.jooq.SQLDialect; import org.jooq.SortOrder; import org.jooq.Source; +import org.jooq.TableOptions.TableType; import org.jooq.exception.IOException; import org.jooq.impl.DSL; import org.jooq.meta.AbstractDatabase; @@ -546,7 +547,16 @@ public class XMLDatabase extends AbstractDatabase { if (getInputSchemata().contains(table.getTableSchema())) { SchemaDefinition schema = getSchema(table.getTableSchema()); - result.add(new XMLTableDefinition(schema, info(), table, table.getComment())); + TableType tableType; + + switch (table.getTableType()) { + case GLOBAL_TEMPORARY: tableType = TableType.TEMPORARY; break; + case VIEW: tableType = TableType.VIEW; break; + case BASE_TABLE: + default: tableType = TableType.TABLE; break; + } + + result.add(new XMLTableDefinition(schema, info(), table, table.getComment(), tableType)); } } diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLTableDefinition.java b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLTableDefinition.java index 0f319c522f..3523b5e063 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLTableDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/xml/XMLTableDefinition.java @@ -44,6 +44,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import org.jooq.TableOptions.TableType; import org.jooq.meta.AbstractTableDefinition; import org.jooq.meta.ColumnDefinition; import org.jooq.meta.DataTypeDefinition; @@ -68,7 +69,11 @@ public class XMLTableDefinition extends AbstractTableDefinition { } public XMLTableDefinition(SchemaDefinition schema, InformationSchema info, Table table, String comment) { - super(schema, table.getTableName(), comment); + this(schema, info, table, comment, TableType.TABLE); + } + + public XMLTableDefinition(SchemaDefinition schema, InformationSchema info, Table table, String comment, TableType tableType) { + super(schema, table.getTableName(), comment, tableType); this.info = info; this.table = table; diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java index 2c1bf5d267..0bb7d11a32 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaExport.java @@ -72,6 +72,7 @@ import org.jooq.util.xml.jaxb.KeyColumnUsage; import org.jooq.util.xml.jaxb.ReferentialConstraint; import org.jooq.util.xml.jaxb.TableConstraint; import org.jooq.util.xml.jaxb.TableConstraintType; +import org.jooq.util.xml.jaxb.TableType; /** * @author Lukas Eder @@ -227,6 +228,17 @@ final class InformationSchemaExport { if (!StringUtils.isBlank(t.getSchema().getName())) it.setTableSchema(t.getSchema().getName()); + switch (t.getOptions().type()) { + case MATERIALIZED_VIEW: + case VIEW: it.setTableType(TableType.VIEW); break; + case TEMPORARY: it.setTableType(TableType.GLOBAL_TEMPORARY); break; + case FUNCTION: + case TABLE: + case EXPRESSION: + case UNKNOWN: + default: it.setTableType(TableType.BASE_TABLE); break; + } + it.setTableName(t.getName()); it.setComment(t.getComment()); result.getTables().add(it); diff --git a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java index 23bc60c11f..da6d77cffe 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InformationSchemaMetaImpl.java @@ -62,6 +62,8 @@ import org.jooq.Sequence; import org.jooq.SortField; import org.jooq.Table; import org.jooq.TableField; +import org.jooq.TableOptions; +import org.jooq.TableOptions.TableType; import org.jooq.UniqueKey; import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.util.xml.jaxb.CheckConstraint; @@ -171,7 +173,16 @@ final class InformationSchemaMetaImpl extends AbstractMeta { continue tableLoop; } - InformationSchemaTable it = new InformationSchemaTable(xt.getTableName(), schema, xt.getComment()); + TableType tableType; + + switch (xt.getTableType()) { + case GLOBAL_TEMPORARY: tableType = TableType.TEMPORARY; break; + case VIEW: tableType = TableType.VIEW; break; + case BASE_TABLE: + default: tableType = TableType.TABLE; break; + } + + InformationSchemaTable it = new InformationSchemaTable(xt.getTableName(), schema, xt.getComment(), tableType); tables.add(it); tablesByName.put(name(xt.getTableCatalog(), xt.getTableSchema(), xt.getTableName()), it); } @@ -584,7 +595,7 @@ final class InformationSchemaMetaImpl extends AbstractMeta { */ private static final long serialVersionUID = 7290709749127378187L; - public InformationSchemaSchema(String name, Catalog catalog, String comment) { + InformationSchemaSchema(String name, Catalog catalog, String comment) { super(name, catalog, comment); } @@ -612,8 +623,8 @@ final class InformationSchemaMetaImpl extends AbstractMeta { final List> checks = new ArrayList<>(); final List indexes = new ArrayList<>(); - public InformationSchemaTable(String name, Schema schema, String comment) { - super(name, schema, null, null, comment); + InformationSchemaTable(String name, Schema schema, String comment, TableType tableType) { + super(DSL.name(name), schema, null, null, DSL.comment(comment), TableOptions.of(tableType)); } @Override diff --git a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/Table.java b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/Table.java index d42fb479bb..803a61fcf9 100644 --- a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/Table.java +++ b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/Table.java @@ -5,6 +5,7 @@ import java.io.Serializable; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.jooq.util.jaxb.tools.StringAdapter; @@ -25,6 +26,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder; * <element name="table_catalog" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * <element name="table_schema" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * <element name="table_name" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="table_type" type="{http://www.jooq.org/xsd/jooq-meta-3.12.0.xsd}TableType"/> * <element name="comment" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * </all> * </restriction> @@ -54,6 +56,9 @@ public class Table implements Serializable, XMLAppendable @XmlElement(name = "table_name", required = true) @XmlJavaTypeAdapter(StringAdapter.class) protected String tableName; + @XmlElement(name = "table_type", required = true, defaultValue = "BASE TABLE") + @XmlSchemaType(name = "string") + protected TableType tableType = TableType.BASE_TABLE; @XmlJavaTypeAdapter(StringAdapter.class) protected String comment; @@ -81,6 +86,14 @@ public class Table implements Serializable, XMLAppendable this.tableName = value; } + public TableType getTableType() { + return tableType; + } + + public void setTableType(TableType value) { + this.tableType = value; + } + public String getComment() { return comment; } @@ -104,6 +117,11 @@ public class Table implements Serializable, XMLAppendable return this; } + public Table withTableType(TableType value) { + setTableType(value); + return this; + } + public Table withComment(String value) { setComment(value); return this; @@ -114,6 +132,7 @@ public class Table implements Serializable, XMLAppendable builder.append("table_catalog", tableCatalog); builder.append("table_schema", tableSchema); builder.append("table_name", tableName); + builder.append("table_type", tableType); builder.append("comment", comment); } @@ -163,6 +182,15 @@ public class Table implements Serializable, XMLAppendable return false; } } + if (tableType == null) { + if (other.tableType!= null) { + return false; + } + } else { + if (!tableType.equals(other.tableType)) { + return false; + } + } if (comment == null) { if (other.comment!= null) { return false; @@ -182,6 +210,7 @@ public class Table implements Serializable, XMLAppendable result = ((prime*result)+((tableCatalog == null)? 0 :tableCatalog.hashCode())); result = ((prime*result)+((tableSchema == null)? 0 :tableSchema.hashCode())); result = ((prime*result)+((tableName == null)? 0 :tableName.hashCode())); + result = ((prime*result)+((tableType == null)? 0 :tableType.hashCode())); result = ((prime*result)+((comment == null)? 0 :comment.hashCode())); return result; } diff --git a/jOOQ/src/main/java/org/jooq/util/xml/jaxb/TableType.java b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/TableType.java new file mode 100644 index 0000000000..54aefcc16d --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/util/xml/jaxb/TableType.java @@ -0,0 +1,65 @@ + +package org.jooq.util.xml.jaxb; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for TableType. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="TableType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="BASE TABLE"/>
+ *     <enumeration value="VIEW"/>
+ *     <enumeration value="GLOBAL TEMPORARY"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "TableType") +@XmlEnum +public enum TableType { + + @XmlEnumValue("BASE TABLE") + BASE_TABLE("BASE TABLE"), + VIEW("VIEW"), + @XmlEnumValue("GLOBAL TEMPORARY") + GLOBAL_TEMPORARY("GLOBAL TEMPORARY"); + private final String value; + + TableType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static TableType fromValue(String v) { + for (TableType c: TableType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + + @Override + public String toString() { + switch (this) { + case BASE_TABLE: + return "BASE TABLE"; + case GLOBAL_TEMPORARY: + return "GLOBAL TEMPORARY"; + default: + return this.name(); + } + } + +} diff --git a/jOOQ/src/main/resources/xsd/jooq-meta-3.13.0.xsd b/jOOQ/src/main/resources/xsd/jooq-meta-3.13.0.xsd index 24aa618e8c..2e8ec12768 100644 --- a/jOOQ/src/main/resources/xsd/jooq-meta-3.13.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-meta-3.13.0.xsd @@ -88,6 +88,7 @@ + @@ -338,4 +339,12 @@ + + + + + + + +