[jOOQ/jOOQ#2370] Add org.jooq.TableType (WIP)
This commit is contained in:
parent
67a12ec93c
commit
40a7e347f2
@ -71,6 +71,12 @@ public enum TableType {
|
||||
*/
|
||||
FUNCTION,
|
||||
|
||||
/**
|
||||
* A table expression, such as a derived table, a joined table, a common
|
||||
* table expression, etc.
|
||||
*/
|
||||
EXPRESSION,
|
||||
|
||||
/**
|
||||
* A table type that is unknown to jOOQ.
|
||||
*/
|
||||
|
||||
@ -121,44 +121,22 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
private static final long serialVersionUID = 3155496238969274871L;
|
||||
private static final Clause[] CLAUSES = { TABLE };
|
||||
|
||||
private final TableType type;
|
||||
private Schema tableschema;
|
||||
private transient DataType<R> tabletype;
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name) {
|
||||
this(name, null, null);
|
||||
AbstractTable(TableType type, Name name) {
|
||||
this(type, name, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name, Schema)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name, Schema schema) {
|
||||
this(name, schema, null);
|
||||
AbstractTable(TableType type, Name name, Schema schema) {
|
||||
this(type, name, schema, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name, Schema, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name, Schema schema, String comment) {
|
||||
this(DSL.name(name), schema, DSL.comment(comment));
|
||||
}
|
||||
|
||||
AbstractTable(Name name) {
|
||||
this(name, null, null);
|
||||
}
|
||||
|
||||
AbstractTable(Name name, Schema schema) {
|
||||
this(name, schema, null);
|
||||
}
|
||||
|
||||
AbstractTable(Name name, Schema schema, Comment comment) {
|
||||
AbstractTable(TableType type, Name name, Schema schema, Comment comment) {
|
||||
super(qualify(schema, name), comment);
|
||||
|
||||
this.type = type;
|
||||
this.tableschema = schema;
|
||||
}
|
||||
|
||||
@ -415,7 +393,7 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements
|
||||
|
||||
@Override
|
||||
public final TableType getType() {
|
||||
return TableType.UNKNOWN;
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -53,6 +53,7 @@ import org.jooq.Param;
|
||||
// ...
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
import org.jooq.UDTRecord;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
import org.jooq.util.h2.H2DataType;
|
||||
@ -84,7 +85,7 @@ final class ArrayTable extends AbstractTable<Record> {
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
ArrayTable(Field<?> array, Name alias, Name[] fieldAliases) {
|
||||
super(alias);
|
||||
super(TableType.EXPRESSION, alias);
|
||||
|
||||
Class<?> arrayType;
|
||||
|
||||
@ -271,7 +272,7 @@ final class ArrayTable extends AbstractTable<Record> {
|
||||
private static final long serialVersionUID = 2662639259338694177L;
|
||||
|
||||
DialectArrayTable() {
|
||||
super(alias);
|
||||
super(TableType.EXPRESSION, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -49,6 +49,8 @@ import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* Essentially, this is the same as <code>ArrayTable</code>, except that it simulates
|
||||
@ -79,7 +81,7 @@ final class ArrayTableEmulation extends AbstractTable<Record> {
|
||||
}
|
||||
|
||||
ArrayTableEmulation(Object[] array, Name alias, Name fieldAlias) {
|
||||
super(alias);
|
||||
super(TableType.EXPRESSION, alias);
|
||||
|
||||
this.array = array;
|
||||
this.alias = alias;
|
||||
|
||||
@ -48,6 +48,7 @@ import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -64,7 +65,7 @@ final class CommonTableExpressionImpl<R extends Record> extends AbstractTable<R>
|
||||
private final Fields<R> fields;
|
||||
|
||||
CommonTableExpressionImpl(DerivedColumnListImpl name, Select<R> select) {
|
||||
super(name.name);
|
||||
super(TableType.EXPRESSION, name.name);
|
||||
|
||||
this.name = name;
|
||||
this.select = select;
|
||||
|
||||
@ -44,6 +44,7 @@ import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -55,7 +56,7 @@ final class DerivedTable<R extends Record> extends AbstractTable<R> {
|
||||
private final Select<R> query;
|
||||
|
||||
DerivedTable(Select<R> query) {
|
||||
super("select");
|
||||
super(TableType.EXPRESSION, DSL.name("select"));
|
||||
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -83,7 +84,7 @@ final class Dual extends AbstractTable<Record> {
|
||||
}
|
||||
|
||||
Dual(boolean force) {
|
||||
super(DSL.name("dual"), (Schema) null);
|
||||
super(TableType.EXPRESSION, DSL.name("dual"), (Schema) null);
|
||||
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
|
||||
/**
|
||||
@ -59,7 +60,7 @@ final class FunctionTable<R extends Record> extends AbstractTable<R> {
|
||||
private final Field<?> function;
|
||||
|
||||
FunctionTable(Field<?> function) {
|
||||
super("function_table");
|
||||
super(TableType.FUNCTION, DSL.name("function_table"));
|
||||
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ import org.jooq.Name;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -70,7 +71,7 @@ final class GenerateSeries extends AbstractTable<Record1<Integer>> {
|
||||
}
|
||||
|
||||
GenerateSeries(Field<Integer> from, Field<Integer> to, Field<Integer> step) {
|
||||
super("generate_series");
|
||||
super(TableType.EXPRESSION, DSL.name("generate_series"));
|
||||
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
|
||||
@ -70,7 +70,7 @@ final class HintedTable<R extends Record> extends AbstractTable<R> {
|
||||
}
|
||||
|
||||
HintedTable(AbstractTable<R> delegate, Keyword keywords, QueryPartList<Name> arguments) {
|
||||
super(delegate.getName(), delegate.getSchema());
|
||||
super(delegate.getType(), delegate.getQualifiedName(), delegate.getSchema());
|
||||
|
||||
this.delegate = delegate;
|
||||
this.keywords = keywords;
|
||||
|
||||
@ -126,6 +126,7 @@ import org.jooq.TableOnConditionStep;
|
||||
import org.jooq.TableOptionalOnStep;
|
||||
import org.jooq.TableOuterJoinStep;
|
||||
import org.jooq.TablePartitionByStep;
|
||||
import org.jooq.TableType;
|
||||
import org.jooq.conf.RenderOptionalKeyword;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
@ -175,7 +176,7 @@ implements
|
||||
|
||||
|
||||
|
||||
super("join");
|
||||
super(TableType.EXPRESSION, DSL.name("join"));
|
||||
|
||||
this.lhs = lhs.asTable();
|
||||
this.rhs = rhs.asTable();
|
||||
|
||||
@ -43,6 +43,7 @@ import org.jooq.Context;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -56,7 +57,7 @@ final class Lateral<R extends Record> extends AbstractTable<R> {
|
||||
private final Table<R> table;
|
||||
|
||||
Lateral(Table<R> table) {
|
||||
super(table.getName(), table.getSchema());
|
||||
super(TableType.EXPRESSION, table.getQualifiedName(), table.getSchema());
|
||||
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@ -351,5 +351,6 @@ package org.jooq.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -62,7 +63,7 @@ final class RowsFrom extends AbstractTable<Record> {
|
||||
private final TableList tables;
|
||||
|
||||
RowsFrom(Table<?>... tables) {
|
||||
super("rows from");
|
||||
super(TableType.EXPRESSION, DSL.name("rowsfrom"));
|
||||
|
||||
this.tables = new TableList(Arrays.asList(tables));
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ import org.jooq.Name;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -53,7 +54,7 @@ final class SQLTable extends AbstractTable<Record> {
|
||||
private final QueryPart delegate;
|
||||
|
||||
SQLTable(QueryPart delegate) {
|
||||
super(delegate.toString());
|
||||
super(TableType.EXPRESSION, DSL.name(delegate.toString()));
|
||||
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ final class TableAlias<R extends Record> extends AbstractTable<R> {
|
||||
}
|
||||
|
||||
TableAlias(Table<R> table, Name alias, Name[] fieldAliases, boolean wrapInParentheses) {
|
||||
super(alias, table.getSchema());
|
||||
super(table.getType(), alias, table.getSchema());
|
||||
|
||||
this.alias = new Alias<>(table, this, alias, fieldAliases, wrapInParentheses);
|
||||
this.aliasedFields = init(fieldAliases);
|
||||
|
||||
@ -62,6 +62,7 @@ import org.jooq.Row;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
import org.jooq.tools.StringUtils;
|
||||
|
||||
/**
|
||||
@ -164,7 +165,7 @@ public class TableImpl<R extends Record> extends AbstractTable<R> {
|
||||
}
|
||||
|
||||
public TableImpl(Name name, Schema schema, Table<?> child, ForeignKey<?, R> path, Table<R> aliased, Field<?>[] parameters, Comment comment) {
|
||||
super(name, schema, comment);
|
||||
super(TableType.TABLE, name, schema, comment);
|
||||
|
||||
this.fields = new Fields<>();
|
||||
this.child = child;
|
||||
|
||||
@ -49,6 +49,7 @@ import org.jooq.Record;
|
||||
import org.jooq.Row;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableType;
|
||||
|
||||
/**
|
||||
* An implementation for the <code>VALUES(...)</code> table constructor
|
||||
@ -65,7 +66,7 @@ final class Values<R extends Record> extends AbstractTable<R> {
|
||||
private final Row[] rows;
|
||||
|
||||
Values(Row[] rows) {
|
||||
super("values");
|
||||
super(TableType.EXPRESSION, DSL.name("values"));
|
||||
|
||||
this.rows = assertNotEmpty(rows);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ final class WithTable<R extends Record> extends AbstractTable<R> {
|
||||
private final String hint;
|
||||
|
||||
WithTable(AbstractTable<R> delegate, String hint) {
|
||||
super(delegate.getName(), delegate.getSchema());
|
||||
super(delegate.getType(), delegate.getQualifiedName(), delegate.getSchema());
|
||||
|
||||
this.delegate = delegate;
|
||||
this.hint = hint;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user