use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method loadCheckConstraints.
@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
TableConstraints tc = TABLE_CONSTRAINTS.as("tc");
CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
for (Record record : create().select(tc.TABLE_SCHEMA, tc.TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(tc).join(cc).using(tc.CONSTRAINT_CATALOG, tc.CONSTRAINT_SCHEMA, tc.CONSTRAINT_NAME).where(tc.TABLE_SCHEMA.in(getInputSchemata())).fetch()) {
SchemaDefinition schema = getSchema(record.get(tc.TABLE_SCHEMA));
TableDefinition table = getTable(schema, record.get(tc.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.util.TableDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys("UNIQUE")) {
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.getColumn(columnName));
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<TableDefinition>();
for (Record record : create().select(Tables.TABLE_SCHEMA, Tables.TABLE_NAME, Tables.TABLE_COMMENT).from(TABLES).where(Tables.TABLE_SCHEMA.in(getInputSchemata())).orderBy(Tables.TABLE_SCHEMA, Tables.TABLE_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
String name = record.get(Tables.TABLE_NAME);
String comment = record.get(Tables.TABLE_COMMENT);
MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment);
result.add(table);
}
return result;
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
for (Record record : create().select(ReferentialConstraints.CONSTRAINT_SCHEMA, ReferentialConstraints.CONSTRAINT_NAME, ReferentialConstraints.TABLE_NAME, ReferentialConstraints.REFERENCED_TABLE_NAME, ReferentialConstraints.UNIQUE_CONSTRAINT_NAME, ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA, KeyColumnUsage.COLUMN_NAME).from(REFERENTIAL_CONSTRAINTS).join(KEY_COLUMN_USAGE).on(ReferentialConstraints.CONSTRAINT_SCHEMA.equal(KeyColumnUsage.CONSTRAINT_SCHEMA)).and(ReferentialConstraints.CONSTRAINT_NAME.equal(KeyColumnUsage.CONSTRAINT_NAME)).where(ReferentialConstraints.CONSTRAINT_SCHEMA.in(getInputSchemata())).orderBy(KeyColumnUsage.CONSTRAINT_SCHEMA.asc(), KeyColumnUsage.CONSTRAINT_NAME.asc(), KeyColumnUsage.ORDINAL_POSITION.asc()).fetch()) {
SchemaDefinition foreignKeySchema = getSchema(record.get(ReferentialConstraints.CONSTRAINT_SCHEMA));
SchemaDefinition uniqueKeySchema = getSchema(record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA));
String foreignKey = record.get(ReferentialConstraints.CONSTRAINT_NAME);
String foreignKeyColumn = record.get(KeyColumnUsage.COLUMN_NAME);
String foreignKeyTableName = record.get(ReferentialConstraints.TABLE_NAME);
String referencedKey = record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_NAME);
String referencedTableName = record.get(ReferentialConstraints.REFERENCED_TABLE_NAME);
TableDefinition foreignKeyTable = getTable(foreignKeySchema, foreignKeyTableName);
if (foreignKeyTable != null) {
ColumnDefinition column = foreignKeyTable.getColumn(foreignKeyColumn);
String key = getKeyName(referencedTableName, referencedKey);
relations.addForeignKey(foreignKey, key, column, uniqueKeySchema);
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class H2Database method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys("UNIQUE")) {
SchemaDefinition schema = getSchema(record.get(Constraints.TABLE_SCHEMA));
if (schema != null) {
String tableName = record.get(Constraints.TABLE_NAME);
String primaryKey = record.get(Constraints.CONSTRAINT_NAME);
String columnName = record.get(Indexes.COLUMN_NAME);
TableDefinition table = getTable(schema, tableName);
if (table != null) {
relations.addUniqueKey(primaryKey, table.getColumn(columnName));
}
}
}
}
Aggregations