[jOOQ/jOOQ#9799] Make TableOptions available through code generation

This commit is contained in:
Lukas Eder 2020-02-06 18:07:19 +01:00
parent ce6d4ca20f
commit 0fef1bb67e
18 changed files with 140 additions and 74 deletions

View File

@ -47,6 +47,7 @@ import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.not;
import static org.jooq.impl.DSL.nullif;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.when;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.meta.derby.sys.tables.Syschecks.SYSCHECKS;
import static org.jooq.meta.derby.sys.tables.Sysconglomerates.SYSCONGLOMERATES;
@ -69,6 +70,7 @@ import org.jooq.Record5;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractDatabase;
import org.jooq.meta.AbstractIndexDefinition;
@ -420,7 +422,9 @@ public class DerbyDatabase extends AbstractDatabase {
for (Record record : create().select(
Sysschemas.SCHEMANAME,
Systables.TABLENAME,
Systables.TABLEID)
Systables.TABLEID,
when(Systables.TABLETYPE.eq(inline("V")), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).as("table_type"))
.from(SYSTABLES)
.join(SYSSCHEMAS)
.on(Systables.SCHEMAID.equal(Sysschemas.SCHEMAID))
@ -428,14 +432,14 @@ public class DerbyDatabase extends AbstractDatabase {
.where(Sysschemas.SCHEMANAME.cast(VARCHAR(32672)).in(getInputSchemata()))
.orderBy(
Sysschemas.SCHEMANAME,
Systables.TABLENAME)
.fetch()) {
Systables.TABLENAME)) {
SchemaDefinition schema = getSchema(record.get(Sysschemas.SCHEMANAME));
String name = record.get(Systables.TABLENAME);
String id = record.get(Systables.TABLEID);
TableType tableType = record.get("table_type", TableType.class);
DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id);
DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id, tableType);
result.add(table);
}

View File

@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -62,8 +63,8 @@ public class DerbyTableDefinition extends AbstractTableDefinition {
private final String tableid;
public DerbyTableDefinition(SchemaDefinition schema, String name, String tableid) {
super(schema, name, "");
public DerbyTableDefinition(SchemaDefinition schema, String name, String tableid, TableType tableType) {
super(schema, name, "", tableType);
this.tableid = tableid;
}

View File

@ -47,6 +47,7 @@ import static org.jooq.impl.DSL.nullif;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.trim;
import static org.jooq.impl.DSL.when;
import static org.jooq.impl.DSL.zero;
import static org.jooq.meta.firebird.rdb.Tables.RDB$CHECK_CONSTRAINTS;
import static org.jooq.meta.firebird.rdb.Tables.RDB$GENERATORS;
@ -71,6 +72,7 @@ import org.jooq.Record3;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractDatabase;
import org.jooq.meta.AbstractIndexDefinition;
@ -381,17 +383,18 @@ public class FirebirdDatabase extends AbstractDatabase {
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (Record3<String, Boolean, String> record : create()
for (Record3<String, String, String> record : create()
.select(
RDB$RELATIONS.RDB$RELATION_NAME.trim(),
inline(false).as("table_valued_function"),
RDB$RELATIONS.RDB$DESCRIPTION.trim())
RDB$RELATIONS.RDB$DESCRIPTION.trim(),
when(RDB$RELATIONS.RDB$RELATION_TYPE.eq(inline((short) 1)), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).trim().as("table_type"))
.from(RDB$RELATIONS)
.unionAll(
select(
RDB$PROCEDURES.RDB$PROCEDURE_NAME.trim(),
inline(true).as("table_valued_function"),
inline(""))
inline(""),
inline(TableType.FUNCTION.name()).trim())
.from(RDB$PROCEDURES)
// "selectable" procedures
@ -402,10 +405,12 @@ public class FirebirdDatabase extends AbstractDatabase {
)
.orderBy(1)) {
if (record.value2())
TableType tableType = record.get("table_type", TableType.class);
if (TableType.FUNCTION == tableType)
result.add(new FirebirdTableValuedFunction(getSchemata().get(0), record.value1(), ""));
else
result.add(new FirebirdTableDefinition(getSchemata().get(0), record.value1(), record.value3()));
result.add(new FirebirdTableDefinition(getSchemata().get(0), record.value1(), record.value2(), tableType));
}
return result;

View File

@ -78,7 +78,7 @@ public class FirebirdRoutineDefinition extends AbstractRoutineDefinition {
p.RDB$PARAMETER_TYPE,
p.RDB$PARAMETER_NAME.trim().as(p.RDB$PARAMETER_NAME),
FIELD_TYPE(f).as("FIELD_TYPE"),
CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"),
CHARACTER_LENGTH(f).as("CHAR_LEN"),
f.RDB$FIELD_PRECISION,
FIELD_SCALE(f).as("FIELD_SCALE"),
DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG),
@ -94,7 +94,7 @@ public class FirebirdRoutineDefinition extends AbstractRoutineDefinition {
getDatabase(),
getSchema(),
record.get("FIELD_TYPE", String.class),
record.get("CHARACTER_LENGTH", short.class),
record.get("CHAR_LEN", short.class),
record.get(f.RDB$FIELD_PRECISION),
record.get("FIELD_SCALE", Integer.class),
record.get(p.RDB$NULL_FLAG) == 0,

View File

@ -49,6 +49,7 @@ import java.util.List;
import java.util.regex.Pattern;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
@ -69,6 +70,10 @@ public class FirebirdTableDefinition extends AbstractTableDefinition {
super(schema, name, comment);
}
public FirebirdTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
super(schema, name, comment, tableType);
}
@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
@ -88,7 +93,7 @@ public class FirebirdTableDefinition extends AbstractTableDefinition {
r.RDB$FIELD_POSITION,
// [#3342] FIELD_LENGTH should be ignored for LOBs
CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"),
CHARACTER_LENGTH(f).as("CHAR_LEN"),
f.RDB$FIELD_PRECISION,
FIELD_SCALE(f).as("FIELD_SCALE"),
FIELD_TYPE(f).as("FIELD_TYPE"),
@ -110,7 +115,7 @@ public class FirebirdTableDefinition extends AbstractTableDefinition {
getDatabase(),
getSchema(),
record.get("FIELD_TYPE", String.class),
record.get("CHARACTER_LENGTH", short.class),
record.get("CHAR_LEN", short.class),
record.get(f.RDB$FIELD_PRECISION),
record.get("FIELD_SCALE", Integer.class),
record.get(r.RDB$NULL_FLAG) == 0,

View File

@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
@ -66,7 +67,7 @@ public class FirebirdTableValuedFunction extends AbstractTableDefinition {
private final FirebirdRoutineDefinition routine;
public FirebirdTableValuedFunction(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
super(schema, name, comment, TableType.FUNCTION);
routine = new FirebirdRoutineDefinition(schema, name);
}
@ -90,7 +91,7 @@ public class FirebirdTableValuedFunction extends AbstractTableDefinition {
p.RDB$DEFAULT_SOURCE,
// [#3342] FIELD_LENGTH should be ignored for LOBs
CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"),
CHARACTER_LENGTH(f).as("CHAR_LEN"),
f.RDB$FIELD_PRECISION,
FIELD_SCALE(f).as("FIELD_SCALE"),
FIELD_TYPE(f).as("FIELD_TYPE"),
@ -105,7 +106,7 @@ public class FirebirdTableValuedFunction extends AbstractTableDefinition {
getDatabase(),
getSchema(),
record.get("FIELD_TYPE", String.class),
record.get("CHARACTER_LENGTH", short.class),
record.get("CHAR_LEN", short.class),
record.get(f.RDB$FIELD_PRECISION),
record.get("FIELD_SCALE", Integer.class),
record.get(p.RDB$NULL_FLAG) == 0,
@ -127,11 +128,6 @@ public class FirebirdTableValuedFunction extends AbstractTableDefinition {
return result;
}
@Override
public boolean isTableValuedFunction() {
return true;
}
@Override
protected List<ParameterDefinition> getParameters0() {
return routine.getInParameters();

View File

@ -452,16 +452,14 @@ public class H2Database extends AbstractDatabase {
Tables.TABLE_SCHEMA,
Tables.TABLE_NAME,
when(Tables.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name()))
.when(Tables.TABLE_TYPE.eq(inline("TABLE")),
when(Tables.STORAGE_TYPE.like(inline("%TEMPORARY%")), inline(TableType.TEMPORARY.name()))
.else_(inline(TableType.TABLE.name()))).as("table_type"),
.when(Tables.STORAGE_TYPE.like(inline("%TEMPORARY%")), inline(TableType.TEMPORARY.name()))
.else_(inline(TableType.TABLE.name())).as("table_type"),
Tables.REMARKS)
.from(TABLES)
.where(Tables.TABLE_SCHEMA.in(getInputSchemata()))
.orderBy(
Tables.TABLE_SCHEMA,
Tables.TABLE_NAME)
.fetch()) {
Tables.TABLE_NAME)) {
SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));

View File

@ -44,6 +44,7 @@ import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.nvl;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.when;
import static org.jooq.meta.hsqldb.information_schema.Tables.CHECK_CONSTRAINTS;
import static org.jooq.meta.hsqldb.information_schema.Tables.COLUMNS;
import static org.jooq.meta.hsqldb.information_schema.Tables.ELEMENT_TYPES;
@ -69,6 +70,7 @@ import org.jooq.Record4;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractDatabase;
import org.jooq.meta.AbstractIndexDefinition;
@ -399,18 +401,21 @@ public class HSQLDBDatabase extends AbstractDatabase {
.select(
SYSTEM_TABLES.TABLE_SCHEM,
SYSTEM_TABLES.TABLE_NAME,
SYSTEM_TABLES.REMARKS)
SYSTEM_TABLES.REMARKS,
when(SYSTEM_TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).trim().as("table_type"))
.from(SYSTEM_TABLES)
.where(SYSTEM_TABLES.TABLE_SCHEM.in(getInputSchemata()))
.orderBy(
SYSTEM_TABLES.TABLE_SCHEM,
SYSTEM_TABLES.TABLE_NAME)) {
SYSTEM_TABLES.TABLE_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(SYSTEM_TABLES.TABLE_SCHEM));
String name = record.get(SYSTEM_TABLES.TABLE_NAME);
String comment = record.get(SYSTEM_TABLES.REMARKS);
TableType tableType = record.get("table_type", TableType.class);
result.add(new HSQLDBTableDefinition(schema, name, comment));
result.add(new HSQLDBTableDefinition(schema, name, comment, tableType));
}
return result;

View File

@ -51,6 +51,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -63,9 +64,13 @@ import org.jooq.meta.SchemaDefinition;
*/
public class HSQLDBTableDefinition extends AbstractTableDefinition {
public HSQLDBTableDefinition(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
}
public HSQLDBTableDefinition(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
}
public HSQLDBTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
super(schema, name, comment, tableType);
}
@Override
public List<ColumnDefinition> getElements0() throws SQLException {

View File

@ -41,6 +41,7 @@ package org.jooq.meta.mysql;
import static org.jooq.impl.DSL.falseCondition;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.when;
import static org.jooq.meta.mysql.information_schema.Tables.CHECK_CONSTRAINTS;
import static org.jooq.meta.mysql.information_schema.Tables.COLUMNS;
import static org.jooq.meta.mysql.information_schema.Tables.KEY_COLUMN_USAGE;
@ -69,6 +70,7 @@ import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractDatabase;
import org.jooq.meta.AbstractIndexDefinition;
@ -427,7 +429,9 @@ public class MySQLDatabase extends AbstractDatabase {
for (Record record : create().select(
Tables.TABLE_SCHEMA,
Tables.TABLE_NAME,
Tables.TABLE_COMMENT)
Tables.TABLE_COMMENT,
when(Tables.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).as("table_type"))
.from(TABLES)
// [#5213] Duplicate schema value to work around MySQL issue https://bugs.mysql.com/bug.php?id=86022
@ -445,8 +449,9 @@ public class MySQLDatabase extends AbstractDatabase {
SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
String name = record.get(Tables.TABLE_NAME);
String comment = record.get(Tables.TABLE_COMMENT);
TableType tableType = record.get("table_type", TableType.class);
MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment);
MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment, tableType);
result.add(table);
}

View File

@ -52,6 +52,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -71,6 +72,10 @@ public class MySQLTableDefinition extends AbstractTableDefinition {
super(schema, name, comment);
}
public MySQLTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
super(schema, name, comment, tableType);
}
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();

View File

@ -107,6 +107,7 @@ import org.jooq.Select;
import org.jooq.SortOrder;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions.TableType;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
@ -387,8 +388,8 @@ public class PostgresDatabase extends AbstractDatabase {
List<TableDefinition> result = new ArrayList<>();
Map<Name, PostgresTableDefinition> map = new HashMap<>();
Select<Record6<String, String, String, Boolean, Boolean, String>> empty =
select(inline(""), inline(""), inline(""), inline(false), inline(false), inline(""))
Select<Record5<String, String, String, String, String>> empty =
select(inline(""), inline(""), inline(""), inline(""), inline(""))
.where(falseCondition());
for (Record record : create()
@ -398,9 +399,9 @@ public class PostgresDatabase extends AbstractDatabase {
TABLES.TABLE_SCHEMA,
TABLES.TABLE_NAME,
TABLES.TABLE_NAME.as("specific_name"),
inline(false).as("table_valued_function"),
inline(false).as("materialized_view"),
PG_DESCRIPTION.DESCRIPTION)
PG_DESCRIPTION.DESCRIPTION,
when(TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).as("table_type"))
.from(TABLES)
.join(PG_NAMESPACE)
.on(TABLES.TABLE_SCHEMA.eq(PG_NAMESPACE.NSPNAME))
@ -435,9 +436,8 @@ public class PostgresDatabase extends AbstractDatabase {
field("{0}::varchar", PG_NAMESPACE.NSPNAME.getDataType(), PG_NAMESPACE.NSPNAME),
field("{0}::varchar", PG_CLASS.RELNAME.getDataType(), PG_CLASS.RELNAME),
field("{0}::varchar", PG_CLASS.RELNAME.getDataType(), PG_CLASS.RELNAME),
inline(false).as("table_valued_function"),
inline(true).as("materialized_view"),
PG_DESCRIPTION.DESCRIPTION)
PG_DESCRIPTION.DESCRIPTION,
inline(TableType.MATERIALIZED_VIEW.name()).as("table_type"))
.from(PG_CLASS)
.join(PG_NAMESPACE)
.on(PG_CLASS.RELNAMESPACE.eq(oid(PG_NAMESPACE)))
@ -455,9 +455,8 @@ public class PostgresDatabase extends AbstractDatabase {
ROUTINES.ROUTINE_SCHEMA,
ROUTINES.ROUTINE_NAME,
ROUTINES.SPECIFIC_NAME,
inline(true).as("table_valued_function"),
inline(false).as("materialized_view"),
inline(""))
inline(""),
inline(TableType.FUNCTION.name()).as("table_type"))
.from(ROUTINES)
.join(PG_NAMESPACE).on(ROUTINES.SPECIFIC_SCHEMA.eq(PG_NAMESPACE.NSPNAME))
.join(PG_PROC).on(PG_PROC.PRONAMESPACE.eq(oid(PG_NAMESPACE)))
@ -472,20 +471,21 @@ public class PostgresDatabase extends AbstractDatabase {
SchemaDefinition schema = getSchema(record.get(TABLES.TABLE_SCHEMA));
String name = record.get(TABLES.TABLE_NAME);
boolean tableValuedFunction = record.get("table_valued_function", boolean.class);
boolean materializedView = record.get("materialized_view", boolean.class);
String comment = record.get(PG_DESCRIPTION.DESCRIPTION, String.class);
TableType tableType = record.get("table_type", TableType.class);
if (tableValuedFunction) {
result.add(new PostgresTableValuedFunction(schema, name, record.get(ROUTINES.SPECIFIC_NAME), comment));
}
else if (materializedView) {
result.add(new PostgresMaterializedViewDefinition(schema, name, comment));
}
else {
PostgresTableDefinition t = new PostgresTableDefinition(schema, name, comment);
result.add(t);
map.put(name(schema.getName(), name), t);
switch (tableType) {
case FUNCTION:
result.add(new PostgresTableValuedFunction(schema, name, record.get(ROUTINES.SPECIFIC_NAME), comment));
break;
case MATERIALIZED_VIEW:
result.add(new PostgresMaterializedViewDefinition(schema, name, comment));
break;
default:
PostgresTableDefinition t = new PostgresTableDefinition(schema, name, comment, tableType);
result.add(t);
map.put(name(schema.getName(), name), t);
break;
}
}

View File

@ -61,6 +61,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -81,7 +82,7 @@ import org.jooq.meta.postgres.pg_catalog.tables.PgType;
public class PostgresMaterializedViewDefinition extends AbstractTableDefinition {
public PostgresMaterializedViewDefinition(SchemaDefinition schema, String name, String comment) {
super(schema, name, comment);
super(schema, name, comment, TableType.MATERIALIZED_VIEW);
}
@Override

View File

@ -60,6 +60,7 @@ import java.util.List;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -76,6 +77,10 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
super(schema, name, comment);
}
public PostgresTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
super(schema, name, comment, tableType);
}
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();

View File

@ -60,6 +60,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.DataTypeDefinition;
@ -83,7 +84,7 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
private final String specificName;
public PostgresTableValuedFunction(SchemaDefinition schema, String name, String specificName, String comment) {
super(schema, name, comment);
super(schema, name, comment, TableType.FUNCTION);
this.routine = new PostgresRoutineDefinition(schema.getDatabase(), schema.getInputName(), name, specificName);
this.specificName = specificName;
@ -212,9 +213,4 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
protected List<ParameterDefinition> getParameters0() {
return routine.getInParameters();
}
@Override
public boolean isTableValuedFunction() {
return true;
}
}

View File

@ -42,6 +42,7 @@ import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.noCondition;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DSL.when;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.meta.sqlite.sqlite_master.SQLiteMaster.SQLITE_MASTER;
@ -58,6 +59,7 @@ import org.jooq.Record;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.SortOrder;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractDatabase;
import org.jooq.meta.AbstractIndexDefinition;
@ -317,13 +319,19 @@ public class SQLiteDatabase extends AbstractDatabase {
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (String name : create().select(SQLiteMaster.NAME)
.from(SQLITE_MASTER)
.where(SQLiteMaster.TYPE.in("table", "view"))
.orderBy(SQLiteMaster.NAME)
.fetch(SQLiteMaster.NAME)) {
for (Record record : create()
.select(
SQLiteMaster.NAME,
when(SQLiteMaster.TYPE.eq(inline("view")), inline(TableType.VIEW.name()))
.else_(inline(TableType.TABLE.name())).as("table_type"))
.from(SQLITE_MASTER)
.where(SQLiteMaster.TYPE.in("table", "view"))
.orderBy(SQLiteMaster.NAME)) {
SQLiteTableDefinition table = new SQLiteTableDefinition(getSchemata().get(0), name, "");
String name = record.get(SQLiteMaster.NAME);
TableType tableType = record.get("table_type", TableType.class);
SQLiteTableDefinition table = new SQLiteTableDefinition(getSchemata().get(0), name, "", tableType);
result.add(table);
}

View File

@ -49,6 +49,7 @@ import java.util.List;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.TableOptions.TableType;
import org.jooq.impl.DSL;
import org.jooq.meta.AbstractTableDefinition;
import org.jooq.meta.ColumnDefinition;
@ -70,6 +71,10 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
super(schema, name, comment);
}
public SQLiteTableDefinition(SchemaDefinition schema, String name, String comment, TableType tableType) {
super(schema, name, comment, tableType);
}
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();

View File

@ -78,6 +78,28 @@ public final class TableOptions implements Serializable {
this.select = select;
}
/**
* Get a new {@link TableOptions} object for a given table type.
*/
public static final TableOptions of(TableType tableType) {
switch (tableType) {
case EXPRESSION:
return expression();
case FUNCTION:
return function();
case MATERIALIZED_VIEW:
return materializedView();
case TEMPORARY:
return temporaryTable();
case VIEW:
return view();
case TABLE:
case UNKNOWN:
default:
return table();
}
}
/**
* Create a new {@link TableOptions} object for a {@link TableType#TABLE}.
*/