[jOOQ/jOOQ#9801] Make TableOptions available through InformationSchema

This commit is contained in:
Lukas Eder 2020-02-10 12:26:31 +01:00
parent 7daa6b365f
commit b0aab86afa
8 changed files with 155 additions and 6 deletions

View File

@ -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());

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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<Check<Record>> checks = new ArrayList<>();
final List<Index> 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

View File

@ -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;
* &lt;element name="table_catalog" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="table_schema" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;element name="table_name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="table_type" type="{http://www.jooq.org/xsd/jooq-meta-3.12.0.xsd}TableType"/&gt;
* &lt;element name="comment" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
* &lt;/all&gt;
* &lt;/restriction&gt;
@ -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;
}

View File

@ -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;
/**
* <p>Java class for TableType.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;simpleType name="TableType"&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
* &lt;enumeration value="BASE TABLE"/&gt;
* &lt;enumeration value="VIEW"/&gt;
* &lt;enumeration value="GLOBAL TEMPORARY"/&gt;
* &lt;/restriction&gt;
* &lt;/simpleType&gt;
* </pre>
*
*/
@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();
}
}
}

View File

@ -88,6 +88,7 @@
<element name="table_catalog" type="string" minOccurs="0" maxOccurs="1" />
<element name="table_schema" type="string" minOccurs="0" maxOccurs="1" />
<element name="table_name" type="string" minOccurs="1" maxOccurs="1" />
<element name="table_type" type="tns:TableType" minOccurs="1" maxOccurs="1" default="BASE TABLE"/>
<element name="comment" type="string" minOccurs="0" maxOccurs="1" />
</all>
</complexType>
@ -338,4 +339,12 @@
<enumeration value="USER-DEFINED TYPE"/>
</restriction>
</simpleType>
<simpleType name="TableType">
<restriction base="string">
<enumeration value="BASE TABLE"/>
<enumeration value="VIEW"/>
<enumeration value="GLOBAL TEMPORARY"/>
</restriction>
</simpleType>
</schema>