use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class DerbyDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (Record record : create().select(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME, SYSTABLES.TABLEID, when(SYSTABLES.TABLETYPE.eq(inline("V")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).as("table_type"), SYSVIEWS.VIEWDEFINITION).from(SYSTABLES).leftJoin(SYSVIEWS).on(SYSTABLES.TABLEID.eq(SYSVIEWS.TABLEID)).where(SYSTABLES.sysschemas().SCHEMANAME.cast(VARCHAR(32672)).in(getInputSchemata())).orderBy(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME)) {
SchemaDefinition schema = getSchema(record.get(SYSTABLES.sysschemas().SCHEMANAME));
String name = record.get(SYSTABLES.TABLENAME);
String id = record.get(SYSTABLES.TABLEID);
TableType tableType = record.get("table_type", TableType.class);
String source = record.get(SYSVIEWS.VIEWDEFINITION);
DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id, tableType, source);
result.add(table);
}
return result;
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<>();
for (TableDefinition tableDefinition : getTables(getSchemata().get(0))) {
for (Record record : create().fetch("SHOW COLUMNS FROM {0} WHERE TYPE LIKE 'ENUM(%)'", field(name(tableDefinition.getInputName())))) {
String table = tableDefinition.getInputName();
String column = record.get("Field", String.class);
String columnType = record.get("Type", String.class);
String name = table + "_" + column;
ColumnDefinition columnDefinition = tableDefinition.getColumn(column);
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition) == null) {
DefaultEnumDefinition definition = new DefaultEnumDefinition(getSchemata().get(0), name, "");
for (String string : columnType.replaceAll("ENUM\\(|\\)", "").split(",")) {
definition.addLiteral(string.trim().replaceAll("'", ""));
}
result.add(definition);
}
}
}
return result;
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys(DB_INDEX.IS_PRIMARY_KEY.isTrue())) {
String key = record.get("constraint_name", String.class);
String tableName = record.get(DB_CLASS.CLASS_NAME);
String columnName = record.get(DB_INDEX_KEY.KEY_ATTR_NAME);
TableDefinition table = getTable(getSchemata().get(0), tableName);
if (table != null)
relations.addPrimaryKey(key, table, table.getColumn(columnName));
}
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(final DefaultRelations relations) throws SQLException {
create().connection(connection -> {
DatabaseMetaData meta = connection.getMetaData();
for (String table : create().selectDistinct(DB_INDEX.CLASS_NAME).from(DB_INDEX).where(DB_INDEX.IS_FOREIGN_KEY.isTrue()).collect(intoList())) {
for (Record record : create().fetch(meta.getImportedKeys(null, null, table))) {
String foreignKeyName = record.get("FKTABLE_NAME", String.class) + "__" + record.get("FK_NAME", String.class);
String foreignKeyTableName = record.get("FKTABLE_NAME", String.class);
String foreignKeyColumnName = record.get("FKCOLUMN_NAME", String.class);
String uniqueKeyName = record.get("PKTABLE_NAME", String.class) + "__" + record.get("PK_NAME", String.class);
String uniqueKeyTableName = record.get("PKTABLE_NAME", String.class);
TableDefinition foreignKeyTable = getTable(getSchemata().get(0), foreignKeyTableName);
TableDefinition uniqueKeyTable = getTable(getSchemata().get(0), uniqueKeyTableName);
if (foreignKeyTable != null && uniqueKeyTable != null)
relations.addForeignKey(foreignKeyName, foreignKeyTable, foreignKeyTable.getColumn(foreignKeyColumnName), uniqueKeyName, uniqueKeyTable);
}
}
});
}
use of org.jooq.meta.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys(DB_INDEX.IS_UNIQUE.isTrue().and(DB_INDEX.IS_PRIMARY_KEY.isFalse()))) {
String key = record.get("constraint_name", String.class);
String tableName = record.get(DB_CLASS.CLASS_NAME);
String columnName = record.get(DB_INDEX_KEY.KEY_ATTR_NAME);
TableDefinition table = getTable(getSchemata().get(0), tableName);
if (table != null)
relations.addUniqueKey(key, table, table.getColumn(columnName));
}
}
Aggregations