Search in sources :

Example 21 with SchemaDefinition

use of org.jooq.util.SchemaDefinition 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 22 with SchemaDefinition

use of org.jooq.util.SchemaDefinition 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 23 with SchemaDefinition

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

the class FirebirdDatabase method getSchemata0.

@Override
protected List<SchemaDefinition> getSchemata0() throws SQLException {
    List<SchemaDefinition> result = new ArrayList<SchemaDefinition>();
    result.add(new SchemaDefinition(this, "", ""));
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList)

Example 24 with SchemaDefinition

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

the class PostgresDatabase method getDomains0.

@SuppressWarnings("unchecked")
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
    List<DomainDefinition> result = new ArrayList<DomainDefinition>();
    if (existAll(PG_CONSTRAINT, PG_TYPE)) {
        PgNamespace n = PG_NAMESPACE.as("n");
        PgConstraint c = PG_CONSTRAINT.as("c");
        PgType d = PG_TYPE.as("d");
        PgType b = PG_TYPE.as("b");
        Field<String[]> src = field(name("domains", "src"), String[].class);
        for (Record record : create().withRecursive("domains", "domain_id", "base_id", "typbasetype", "src").as(select(oid(d), oid(d), d.TYPBASETYPE, array(c.CONSRC)).from(d).join(n).on(oid(n).eq(d.TYPNAMESPACE)).leftJoin(c).on(oid(d).eq(c.CONTYPID)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).unionAll(select(field(name("domains", "domain_id"), Long.class), oid(d), d.TYPBASETYPE, decode().when(c.CONSRC.isNull(), src).otherwise(arrayAppend(src, c.CONSRC))).from(name("domains")).join(d).on(field(name("domains", d.TYPBASETYPE.getName())).eq(oid(d))).leftJoin(c).on(oid(d).eq(c.CONTYPID)))).select(n.NSPNAME, d.TYPNAME, d.TYPNOTNULL, d.TYPDEFAULT, b.TYPNAME, b.TYPLEN, src).from(d).join(name("domains")).on(field(name("domains", "typbasetype")).eq(0)).and(field(name("domains", "domain_id")).eq(oid(d))).join(b).on(field(name("domains", "base_id")).eq(oid(b))).join(n).on(oid(n).eq(d.TYPNAMESPACE)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata()))) {
            SchemaDefinition schema = getSchema(record.get(n.NSPNAME));
            DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(b.TYPNAME), record.get(b.TYPLEN), record.get(b.TYPLEN), // ?
            0, !record.get(d.TYPNOTNULL, boolean.class), record.get(d.TYPDEFAULT), name(record.get(n.NSPNAME), record.get(b.TYPNAME)));
            DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.TYPNAME), baseType);
            domain.addCheckClause(record.get(src));
            result.add(domain);
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DomainDefinition(org.jooq.util.DomainDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgType(org.jooq.util.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgConstraint(org.jooq.util.postgres.pg_catalog.tables.PgConstraint) Record(org.jooq.Record) PgNamespace(org.jooq.util.postgres.pg_catalog.tables.PgNamespace)

Example 25 with SchemaDefinition

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

the class PostgresDatabase 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));
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Aggregations

SchemaDefinition (org.jooq.util.SchemaDefinition)51 Record (org.jooq.Record)36 ArrayList (java.util.ArrayList)29 TableDefinition (org.jooq.util.TableDefinition)28 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)14 DataTypeDefinition (org.jooq.util.DataTypeDefinition)13 ColumnDefinition (org.jooq.util.ColumnDefinition)12 DefaultSequenceDefinition (org.jooq.util.DefaultSequenceDefinition)7 SequenceDefinition (org.jooq.util.SequenceDefinition)7 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)4 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)4 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 RoutineDefinition (org.jooq.util.RoutineDefinition)3 KeyColumnUsage (org.jooq.util.xml.jaxb.KeyColumnUsage)3 Record6 (org.jooq.Record6)2 Schema (org.jooq.Schema)2 DefaultCheckConstraintDefinition (org.jooq.util.DefaultCheckConstraintDefinition)2 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)2 EnumDefinition (org.jooq.util.EnumDefinition)2 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2