Search in sources :

Example 16 with TableDefinition

use of org.jooq.util.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.getColumn(columnName));
        }
    }
}
Also used : TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 17 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class DerbyDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("P")) {
        SchemaDefinition schema = getSchema(record.get(Sysschemas.SCHEMANAME));
        String key = record.get(Sysconstraints.CONSTRAINTNAME);
        String tableName = record.get(Systables.TABLENAME);
        String descriptor = record.get(Sysconglomerates.DESCRIPTOR, String.class);
        TableDefinition table = getTable(schema, tableName);
        if (table != null) {
            for (int index : decode(descriptor)) {
                relations.addPrimaryKey(key, table.getColumn(index));
            }
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 18 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class DerbyDatabase method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<TableDefinition>();
    for (Record record : create().select(Sysschemas.SCHEMANAME, Systables.TABLENAME, Systables.TABLEID).from(SYSTABLES).join(SYSSCHEMAS).on(Systables.SCHEMAID.equal(Sysschemas.SCHEMAID)).where(Sysschemas.SCHEMANAME.in(getInputSchemata())).orderBy(Sysschemas.SCHEMANAME, Systables.TABLENAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(Sysschemas.SCHEMANAME));
        String name = record.get(Systables.TABLENAME);
        String id = record.get(Systables.TABLEID);
        DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id);
        result.add(table);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 19 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class FirebirdDatabase method loadForeignKeys.

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
    Rdb$relationConstraints pk = RDB$RELATION_CONSTRAINTS.as("pk");
    Rdb$relationConstraints fk = RDB$RELATION_CONSTRAINTS.as("fk");
    Rdb$refConstraints rc = RDB$REF_CONSTRAINTS.as("rc");
    Rdb$indexSegments isp = RDB$INDEX_SEGMENTS.as("isp");
    Rdb$indexSegments isf = RDB$INDEX_SEGMENTS.as("isf");
    for (Record record : create().selectDistinct(fk.RDB$CONSTRAINT_NAME.trim().as("fk"), fk.RDB$RELATION_NAME.trim().as("fkTable"), isf.RDB$FIELD_NAME.trim().as("fkField"), pk.RDB$CONSTRAINT_NAME.trim().as("pk"), pk.RDB$RELATION_NAME.trim().as("pkTable")).from(fk).join(rc).on(fk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONSTRAINT_NAME)).join(pk).on(pk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONST_NAME_UQ)).join(isp).on(isp.RDB$INDEX_NAME.eq(pk.RDB$INDEX_NAME)).join(isf).on(isf.RDB$INDEX_NAME.eq(fk.RDB$INDEX_NAME)).where(isp.RDB$FIELD_POSITION.eq(isf.RDB$FIELD_POSITION)).orderBy(fk.RDB$CONSTRAINT_NAME.asc(), isf.RDB$FIELD_POSITION.asc()).fetch()) {
        String pkName = record.get("pk", String.class);
        String pkTable = record.get("pkTable", String.class);
        String fkName = record.get("fk", String.class);
        String fkTable = record.get("fkTable", String.class);
        String fkField = record.get("fkField", String.class);
        TableDefinition tdReferencing = getTable(getSchemata().get(0), fkTable, true);
        TableDefinition tdReferenced = getTable(getSchemata().get(0), pkTable, true);
        if (tdReferenced != null && tdReferencing != null) {
            ColumnDefinition referencingColumn = tdReferencing.getColumn(fkField);
            relations.addForeignKey(fkName, pkName, referencingColumn, getSchemata().get(0));
        }
    }
}
Also used : TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record) Rdb$relationConstraints(org.jooq.util.firebird.rdb.tables.Rdb$relationConstraints) Rdb$indexSegments(org.jooq.util.firebird.rdb.tables.Rdb$indexSegments) Rdb$refConstraints(org.jooq.util.firebird.rdb.tables.Rdb$refConstraints) ColumnDefinition(org.jooq.util.ColumnDefinition)

Example 20 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class FirebirdDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations r) throws SQLException {
    for (Record record : fetchKeys("PRIMARY KEY")) {
        String tableName = record.get(RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME.trim());
        String fieldName = record.get(RDB$INDEX_SEGMENTS.RDB$FIELD_NAME.trim());
        String key = record.get(RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_NAME.trim());
        TableDefinition td = getTable(this.getSchemata().get(0), tableName);
        if (td != null) {
            ColumnDefinition cd = td.getColumn(fieldName);
            r.addPrimaryKey(key, cd);
        }
    }
}
Also used : TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record) ColumnDefinition(org.jooq.util.ColumnDefinition)

Aggregations

TableDefinition (org.jooq.util.TableDefinition)37 Record (org.jooq.Record)32 SchemaDefinition (org.jooq.util.SchemaDefinition)28 ColumnDefinition (org.jooq.util.ColumnDefinition)14 ArrayList (java.util.ArrayList)9 KeyColumnUsage (org.jooq.util.xml.jaxb.KeyColumnUsage)3 HashMap (java.util.HashMap)2 DefaultCheckConstraintDefinition (org.jooq.util.DefaultCheckConstraintDefinition)2 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)2 EnumDefinition (org.jooq.util.EnumDefinition)2 StringReader (java.io.StringReader)1 Name (org.jooq.Name)1 Record5 (org.jooq.Record5)1 Record6 (org.jooq.Record6)1 Schema (org.jooq.Schema)1 CSVReader (org.jooq.tools.csv.CSVReader)1 Rdb$indexSegments (org.jooq.util.firebird.rdb.tables.Rdb$indexSegments)1 Rdb$refConstraints (org.jooq.util.firebird.rdb.tables.Rdb$refConstraints)1 Rdb$relationConstraints (org.jooq.util.firebird.rdb.tables.Rdb$relationConstraints)1 CheckConstraints (org.jooq.util.hsqldb.information_schema.tables.CheckConstraints)1