Search in sources :

Example 11 with TableDefinition

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

the class H2Database 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.REMARKS).from(TABLES).where(Tables.TABLE_SCHEMA.in(getInputSchemata())).orderBy(Tables.TABLE_SCHEMA, Tables.TABLE_NAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
        if (schema != null) {
            String name = record.get(Tables.TABLE_NAME);
            String comment = record.get(Tables.REMARKS);
            H2TableDefinition table = new H2TableDefinition(schema, name, comment);
            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 12 with TableDefinition

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

the class HSQLDBDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("PRIMARY KEY")) {
        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.addPrimaryKey(key, table.getColumn(columnName));
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 13 with TableDefinition

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

the class XMLDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) {
    for (KeyColumnUsage usage : keyColumnUsage(PRIMARY_KEY)) {
        SchemaDefinition schema = getSchema(usage.getConstraintSchema());
        String key = usage.getConstraintName();
        String tableName = usage.getTableName();
        String columnName = usage.getColumnName();
        TableDefinition table = getTable(schema, tableName);
        if (table != null) {
            relations.addPrimaryKey(key, table.getColumn(columnName));
        }
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition)

Example 14 with TableDefinition

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

the class XMLDatabase method loadForeignKeys.

@Override
protected void loadForeignKeys(DefaultRelations relations) {
    for (ReferentialConstraint constraint : info().getReferentialConstraints()) {
        if (getInputSchemata().contains(constraint.getConstraintSchema())) {
            for (KeyColumnUsage usage : info().getKeyColumnUsages()) {
                if (StringUtils.equals(constraint.getConstraintCatalog(), usage.getConstraintCatalog()) && StringUtils.equals(constraint.getConstraintSchema(), usage.getConstraintSchema()) && StringUtils.equals(constraint.getConstraintName(), usage.getConstraintName())) {
                    SchemaDefinition foreignKeySchema = getSchema(constraint.getConstraintSchema());
                    SchemaDefinition uniqueKeySchema = getSchema(constraint.getUniqueConstraintSchema());
                    String foreignKey = usage.getConstraintName();
                    String foreignKeyTable = usage.getTableName();
                    String foreignKeyColumn = usage.getColumnName();
                    String uniqueKey = constraint.getUniqueConstraintName();
                    TableDefinition referencingTable = getTable(foreignKeySchema, foreignKeyTable);
                    if (referencingTable != null) {
                        ColumnDefinition referencingColumn = referencingTable.getColumn(foreignKeyColumn);
                        relations.addForeignKey(foreignKey, uniqueKey, referencingColumn, uniqueKeySchema);
                    }
                }
            }
        }
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.util.SchemaDefinition) ReferentialConstraint(org.jooq.util.xml.jaxb.ReferentialConstraint) TableDefinition(org.jooq.util.TableDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition)

Example 15 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)

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