Search in sources :

Example 1 with TableDefinition

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

the class CUBRIDDatabase method getEnums0.

@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
    List<EnumDefinition> result = new ArrayList<EnumDefinition>();
    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;
}
Also used : ArrayList(java.util.ArrayList) TableDefinition(org.jooq.util.TableDefinition) DefaultEnumDefinition(org.jooq.util.DefaultEnumDefinition) Record(org.jooq.Record) EnumDefinition(org.jooq.util.EnumDefinition) DefaultEnumDefinition(org.jooq.util.DefaultEnumDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition)

Example 2 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 3 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 4 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 5 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)

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