use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class H2Database method loadCheckConstraints2_0.
private void loadCheckConstraints2_0(DefaultRelations relations) {
CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
for (Record record : create().select(cc.tableConstraints().TABLE_SCHEMA, cc.tableConstraints().TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(cc).where(cc.tableConstraints().TABLE_SCHEMA.in(getInputSchemata()))) {
SchemaDefinition schema = getSchema(record.get(cc.tableConstraints().TABLE_SCHEMA));
TableDefinition table = getTable(schema, record.get(cc.tableConstraints().TABLE_NAME));
if (table != null) {
relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(cc.CONSTRAINT_NAME), record.get(cc.CHECK_CLAUSE)));
}
}
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (Record record : create().select(SYSTEM_TABLES.TABLE_SCHEM, SYSTEM_TABLES.TABLE_NAME, inline("").as(ROUTINES.SPECIFIC_NAME), SYSTEM_TABLES.REMARKS, when(SYSTEM_TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).trim().as("table_type"), when(VIEWS.VIEW_DEFINITION.lower().like(inline("create%")), VIEWS.VIEW_DEFINITION).else_(inline("create view \"").concat(SYSTEM_TABLES.TABLE_NAME).concat("\" as ").concat(VIEWS.VIEW_DEFINITION)).as(VIEWS.VIEW_DEFINITION)).from(SYSTEM_TABLES).leftJoin(VIEWS).on(SYSTEM_TABLES.TABLE_SCHEM.eq(VIEWS.TABLE_SCHEMA)).and(SYSTEM_TABLES.TABLE_NAME.eq(VIEWS.TABLE_NAME)).where(SYSTEM_TABLES.TABLE_SCHEM.in(getInputSchemata())).unionAll(tableValuedFunctions() ? select(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME, ROUTINES.SPECIFIC_NAME, inline(""), inline(TableType.FUNCTION.name()), ROUTINES.ROUTINE_DEFINITION).from(ROUTINES).where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata())).and(ROUTINES.ROUTINE_TYPE.eq(inline("FUNCTION"))).and(ROUTINES.DATA_TYPE.startsWith(inline("ROW("))) : select(inline(""), inline(""), inline(""), inline(""), inline(TableType.FUNCTION.name()), inline("")).where(falseCondition())).orderBy(SYSTEM_TABLES.TABLE_SCHEM, SYSTEM_TABLES.TABLE_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(SYSTEM_TABLES.TABLE_SCHEM));
String name = record.get(SYSTEM_TABLES.TABLE_NAME);
String specificName = record.get(ROUTINES.SPECIFIC_NAME);
String comment = record.get(SYSTEM_TABLES.REMARKS);
TableType tableType = record.get("table_type", TableType.class);
String source = record.get(VIEWS.VIEW_DEFINITION);
if (tableType == TableType.FUNCTION)
result.add(new HSQLDBTableValuedFunction(schema, name, specificName, comment, source));
else
result.add(new HSQLDBTableDefinition(schema, name, comment, tableType, source));
}
return result;
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getIndexes0.
@Override
protected List<IndexDefinition> getIndexes0() throws SQLException {
List<IndexDefinition> result = new ArrayList<>();
// Same implementation as in H2Database and MySQLDatabase
Map<Record, Result<Record>> indexes = create().select(SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.NON_UNIQUE, SYSTEM_INDEXINFO.COLUMN_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION, SYSTEM_INDEXINFO.ASC_OR_DESC).from(SYSTEM_INDEXINFO).where(SYSTEM_INDEXINFO.TABLE_SCHEM.in(getInputSchemata())).and(getIncludeSystemIndexes() ? noCondition() : SYSTEM_INDEXINFO.INDEX_NAME.notLike("SYS!_IDX!_%", '!')).orderBy(SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION).fetchGroups(new Field[] { SYSTEM_INDEXINFO.TABLE_SCHEM, SYSTEM_INDEXINFO.TABLE_NAME, SYSTEM_INDEXINFO.INDEX_NAME, SYSTEM_INDEXINFO.NON_UNIQUE }, new Field[] { SYSTEM_INDEXINFO.COLUMN_NAME, SYSTEM_INDEXINFO.ORDINAL_POSITION, SYSTEM_INDEXINFO.ASC_OR_DESC });
indexLoop: for (Entry<Record, Result<Record>> entry : indexes.entrySet()) {
final Record index = entry.getKey();
final Result<Record> cols = entry.getValue();
final SchemaDefinition tableSchema = getSchema(index.get(SYSTEM_INDEXINFO.TABLE_SCHEM));
if (tableSchema == null)
continue indexLoop;
final String indexName = index.get(SYSTEM_INDEXINFO.INDEX_NAME);
final String tableName = index.get(SYSTEM_INDEXINFO.TABLE_NAME);
final TableDefinition table = getTable(tableSchema, tableName);
if (table == null)
continue indexLoop;
final boolean unique = !index.get(SYSTEM_INDEXINFO.NON_UNIQUE, boolean.class);
// [#6310] [#6620] Function-based indexes are not yet supported
for (Record column : cols) if (table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)) == null)
continue indexLoop;
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
List<IndexColumnDefinition> indexColumns = new ArrayList<>();
{
for (Record column : cols) {
indexColumns.add(new DefaultIndexColumnDefinition(this, table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)), "D".equals(column.get(SYSTEM_INDEXINFO.ASC_OR_DESC)) ? SortOrder.DESC : SortOrder.ASC, column.get(SYSTEM_INDEXINFO.ORDINAL_POSITION, int.class)));
}
}
@Override
protected List<IndexColumnDefinition> getIndexColumns0() {
return indexColumns;
}
});
}
return result;
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : uniqueKeys(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(KEY_COLUMN_USAGE.TABLE_SCHEMA));
String key = record.get(KEY_COLUMN_USAGE.CONSTRAINT_NAME);
String tableName = record.get(KEY_COLUMN_USAGE.TABLE_NAME);
String columnName = record.get(KEY_COLUMN_USAGE.COLUMN_NAME);
TableDefinition table = getTable(schema, tableName);
if (table != null)
relations.addUniqueKey(key, table, table.getColumn(columnName));
}
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method loadCheckConstraints.
@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
if (is8_0_16()) {
for (Record record : create().select(TABLE_CONSTRAINTS.TABLE_SCHEMA, TABLE_CONSTRAINTS.TABLE_NAME, CHECK_CONSTRAINTS.CONSTRAINT_NAME, CHECK_CONSTRAINTS.CHECK_CLAUSE, // https://jira.mariadb.org/browse/MDEV-21201
TABLE_CONSTRAINTS.CONSTRAINT_CATALOG, TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA).from(TABLE_CONSTRAINTS).join(CHECK_CONSTRAINTS).using(this instanceof MariaDBDatabase ? new Field[] { TABLE_CONSTRAINTS.CONSTRAINT_CATALOG, TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA, // MariaDB has this column, but not MySQL
TABLE_CONSTRAINTS.TABLE_NAME, TABLE_CONSTRAINTS.CONSTRAINT_NAME } : new Field[] { TABLE_CONSTRAINTS.CONSTRAINT_CATALOG, TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA, TABLE_CONSTRAINTS.CONSTRAINT_NAME }).where(TABLE_CONSTRAINTS.TABLE_SCHEMA.in(getInputSchemata())).orderBy(TABLE_CONSTRAINTS.TABLE_SCHEMA, TABLE_CONSTRAINTS.TABLE_NAME, TABLE_CONSTRAINTS.CONSTRAINT_NAME)) {
SchemaDefinition schema = getSchema(record.get(TABLE_CONSTRAINTS.TABLE_SCHEMA));
TableDefinition table = getTable(schema, record.get(TABLE_CONSTRAINTS.TABLE_NAME));
if (table != null) {
relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(CHECK_CONSTRAINTS.CONSTRAINT_NAME), record.get(CHECK_CONSTRAINTS.CHECK_CLAUSE)));
}
}
}
}
Aggregations