Search in sources :

Example 61 with SchemaDefinition

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

the class FirebirdDatabase method getDomains0.

@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
    List<DomainDefinition> result = new ArrayList<>();
    Rdb$fields f = RDB$FIELDS;
    for (Record record : create().select(trim(f.RDB$FIELD_NAME).as(f.RDB$FIELD_NAME), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), DSL.bitOr(f.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(f.RDB$NULL_FLAG), trim(f.RDB$VALIDATION_SOURCE).as(f.RDB$VALIDATION_SOURCE), trim(f.RDB$DEFAULT_SOURCE).as(f.RDB$DEFAULT_SOURCE)).from(f).where(f.RDB$FIELD_NAME.notLike(any("RDB$%", "SEC$%", "MON$%"))).orderBy(f.RDB$FIELD_NAME)) {
        SchemaDefinition schema = getSchemata().get(0);
        DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(f.RDB$NULL_FLAG) == 0, record.get(f.RDB$DEFAULT_SOURCE) == null ? null : record.get(f.RDB$DEFAULT_SOURCE).replaceAll("(?i:default )", ""));
        DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(f.RDB$FIELD_NAME), baseType);
        if (!StringUtils.isBlank(record.get(f.RDB$VALIDATION_SOURCE)))
            domain.addCheckClause(record.get(f.RDB$VALIDATION_SOURCE).replaceAll("(?i:check )", ""));
        result.add(domain);
    }
    return result;
}
Also used : DefaultDomainDefinition(org.jooq.meta.DefaultDomainDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultDomainDefinition(org.jooq.meta.DefaultDomainDefinition) DomainDefinition(org.jooq.meta.DomainDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) Rdb$fields(org.jooq.meta.firebird.rdb.tables.Rdb$fields) ArrayList(java.util.ArrayList) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 62 with SchemaDefinition

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

the class FirebirdDatabase method getSchemata0.

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

Example 63 with SchemaDefinition

use of org.jooq.meta.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, table.getColumn(index));
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Example 64 with SchemaDefinition

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

the class DerbyDatabase method loadCheckConstraints.

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
    for (Record record : create().select(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME, SYSCHECKS.sysconstraints().systables().TABLENAME, SYSCHECKS.sysconstraints().CONSTRAINTNAME, SYSCHECKS.CHECKDEFINITION).from(SYSCHECKS).where(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME.in(getInputSchemata()))) {
        SchemaDefinition schema = getSchema(record.get(SYSCHECKS.sysconstraints().systables().sysschemas().SCHEMANAME));
        TableDefinition table = getTable(schema, record.get(SYSCHECKS.sysconstraints().systables().TABLENAME));
        if (table != null) {
            relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(SYSCHECKS.sysconstraints().CONSTRAINTNAME), record.get(SYSCHECKS.CHECKDEFINITION)));
        }
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) DefaultCheckConstraintDefinition(org.jooq.meta.DefaultCheckConstraintDefinition)

Example 65 with SchemaDefinition

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

the class DerbyDatabase method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<>();
    for (Record record : create().select(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME, SYSTABLES.TABLEID, when(SYSTABLES.TABLETYPE.eq(inline("V")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).as("table_type"), SYSVIEWS.VIEWDEFINITION).from(SYSTABLES).leftJoin(SYSVIEWS).on(SYSTABLES.TABLEID.eq(SYSVIEWS.TABLEID)).where(SYSTABLES.sysschemas().SCHEMANAME.cast(VARCHAR(32672)).in(getInputSchemata())).orderBy(SYSTABLES.sysschemas().SCHEMANAME, SYSTABLES.TABLENAME)) {
        SchemaDefinition schema = getSchema(record.get(SYSTABLES.sysschemas().SCHEMANAME));
        String name = record.get(SYSTABLES.TABLENAME);
        String id = record.get(SYSTABLES.TABLEID);
        TableType tableType = record.get("table_type", TableType.class);
        String source = record.get(SYSVIEWS.VIEWDEFINITION);
        DerbyTableDefinition table = new DerbyTableDefinition(schema, name, id, tableType, source);
        result.add(table);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableType(org.jooq.TableOptions.TableType) ArrayList(java.util.ArrayList) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Aggregations

SchemaDefinition (org.jooq.meta.SchemaDefinition)81 Record (org.jooq.Record)51 ArrayList (java.util.ArrayList)46 TableDefinition (org.jooq.meta.TableDefinition)44 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)22 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)21 ColumnDefinition (org.jooq.meta.ColumnDefinition)14 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)14 IndexDefinition (org.jooq.meta.IndexDefinition)12 SequenceDefinition (org.jooq.meta.SequenceDefinition)12 List (java.util.List)10 DefaultIndexColumnDefinition (org.jooq.meta.DefaultIndexColumnDefinition)10 DomainDefinition (org.jooq.meta.DomainDefinition)9 RoutineDefinition (org.jooq.meta.RoutineDefinition)9 Result (org.jooq.Result)8 AbstractIndexDefinition (org.jooq.meta.AbstractIndexDefinition)8 DefaultCheckConstraintDefinition (org.jooq.meta.DefaultCheckConstraintDefinition)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)8 PackageDefinition (org.jooq.meta.PackageDefinition)8 TableType (org.jooq.TableOptions.TableType)7