use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class JDBCDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Schema schema : getSchemasFromMeta()) {
SchemaDefinition s = getSchema(schema.getName());
if (s != null) {
for (Table<?> table : schema.getTables()) {
TableDefinition t = getTable(s, table.getName());
if (t != null) {
UniqueKey<?> key = table.getPrimaryKey();
if (key != null) {
for (Field<?> field : key.getFields()) {
ColumnDefinition c = t.getColumn(field.getName());
relations.addPrimaryKey("PK_" + key.getTable().getName(), c);
}
}
}
}
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys(false)) {
SchemaDefinition schema = getSchema(record.get(Statistics.TABLE_SCHEMA));
String constraintName = record.get(Statistics.INDEX_NAME);
String tableName = record.get(Statistics.TABLE_NAME);
String columnName = record.get(Statistics.COLUMN_NAME);
String key = getKeyName(tableName, constraintName);
TableDefinition table = getTable(schema, tableName);
if (table != null) {
relations.addUniqueKey(key, table.getColumn(columnName));
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
// [#3520] PostgreSQL INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS contains incomplete information about foreign keys
// The (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME) tuple is non-unique, in case two tables share the
// same CONSTRAINT_NAME.
// The JDBC driver implements this correctly through the pg_catalog, although the sorting and column name casing is wrong, too.
Result<Record> result = create().fetch(getConnection().getMetaData().getExportedKeys(null, null, null)).sortAsc("key_seq").sortAsc("fk_name").sortAsc("fktable_name").sortAsc("fktable_schem");
for (Record record : result) {
SchemaDefinition foreignKeySchema = getSchema(record.get("fktable_schem", String.class));
SchemaDefinition uniqueKeySchema = getSchema(record.get("pktable_schem", String.class));
String foreignKey = record.get("fk_name", String.class);
String foreignKeyTable = record.get("fktable_name", String.class);
String foreignKeyColumn = record.get("fkcolumn_name", String.class);
String uniqueKey = record.get("pk_name", String.class);
TableDefinition referencingTable = getTable(foreignKeySchema, foreignKeyTable);
if (referencingTable != null) {
// [#986] Add the table name as a namespace prefix to the key
// name. In Postgres, foreign key names are only unique per table
ColumnDefinition referencingColumn = referencingTable.getColumn(foreignKeyColumn);
relations.addForeignKey(foreignKeyTable + "__" + foreignKey, uniqueKey, referencingColumn, uniqueKeySchema);
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<TableDefinition>();
for (Record record : create().select(DB_CLASS.CLASS_NAME).from(DB_CLASS).orderBy(DB_CLASS.CLASS_NAME.asc()).fetch()) {
String name = record.get(DB_CLASS.CLASS_NAME);
CUBRIDTableDefinition table = new CUBRIDTableDefinition(getSchemata().get(0), name, null);
result.add(table);
}
return result;
}
use of org.jooq.util.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.getColumn(columnName));
}
}
}
Aggregations