Search in sources :

Example 11 with DefaultDataTypeDefinition

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

the class XMLRoutineDefinition method init0.

@Override
protected void init0() {
    for (Parameter parameter : info.getParameters()) {
        Name parameterRoutineName = name(parameter.getSpecificCatalog(), parameter.getSpecificSchema(), parameter.getSpecificPackage(), parameter.getSpecificName());
        if (getQualifiedNamePart().equals(parameterRoutineName)) {
            DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), parameter.getDataType(), parameter.getCharacterMaximumLength(), parameter.getNumericPrecision(), parameter.getNumericScale(), null, parameter.getParameterDefault());
            ParameterDefinition p = new DefaultParameterDefinition(this, parameter.getParameterName(), parameter.getOrdinalPosition(), type, !StringUtils.isBlank(parameter.getParameterDefault()), StringUtils.isBlank(parameter.getParameterName()));
            switch(parameter.getParameterMode()) {
                case IN:
                    addParameter(InOutDefinition.IN, p);
                    break;
                case INOUT:
                    addParameter(InOutDefinition.INOUT, p);
                    break;
                case OUT:
                    addParameter(InOutDefinition.OUT, p);
                    break;
            }
        }
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Parameter(org.jooq.util.xml.jaxb.Parameter) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Name(org.jooq.Name) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 12 with DefaultDataTypeDefinition

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

the class FirebirdRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$fields f = RDB$FIELDS.as("f");
    int i = 0;
    for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_TYPE, p.RDB$PARAMETER_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).orderBy(p.RDB$PARAMETER_TYPE.desc(), p.RDB$PARAMETER_NUMBER.asc())) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(p.RDB$PARAMETER_NAME), i++, type);
        addParameter(record.get(p.RDB$PARAMETER_TYPE, int.class).equals(0) ? InOutDefinition.IN : InOutDefinition.OUT, parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$fields(org.jooq.util.firebird.rdb.tables.Rdb$fields) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$procedureParameters(org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 13 with DefaultDataTypeDefinition

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

the class FirebirdTableDefinition method getElements0.

@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    Rdb$relationFields r = RDB$RELATION_FIELDS.as("r");
    Rdb$fields f = RDB$FIELDS.as("f");
    // DatabaseMetaData implementation
    for (Record record : create().select(r.RDB$FIELD_NAME.trim(), r.RDB$DESCRIPTION, r.RDB$DEFAULT_VALUE, DSL.bitOr(r.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(r.RDB$NULL_FLAG), r.RDB$DEFAULT_SOURCE, r.RDB$FIELD_POSITION, // [#3342] FIELD_LENGTH should be ignored for LOBs
    CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), f.RDB$FIELD_SUB_TYPE).from(r).leftOuterJoin(f).on(r.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(r.RDB$RELATION_NAME.eq(getName())).orderBy(r.RDB$FIELD_POSITION).fetch()) {
        DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(r.RDB$NULL_FLAG) == 0, record.get(r.RDB$DEFAULT_SOURCE));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(r.RDB$FIELD_NAME.trim()), record.get(r.RDB$FIELD_POSITION), type, false, null);
        result.add(column);
    }
    return result;
}
Also used : Rdb$relationFields(org.jooq.util.firebird.rdb.tables.Rdb$relationFields) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) Rdb$fields(org.jooq.util.firebird.rdb.tables.Rdb$fields) ArrayList(java.util.ArrayList) Record(org.jooq.Record) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 14 with DefaultDataTypeDefinition

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

the class FirebirdTableValuedFunction method getElements0.

@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$fields f = RDB$FIELDS.as("f");
    // DatabaseMetaData implementation
    for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_NAME.trim(), p.RDB$DESCRIPTION, p.RDB$DEFAULT_VALUE, DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE, // [#3342] FIELD_LENGTH should be ignored for LOBs
    CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), f.RDB$FIELD_SUB_TYPE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).and(p.RDB$PARAMETER_TYPE.eq((short) 1)).orderBy(p.RDB$PARAMETER_NUMBER)) {
        DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.RDB$PARAMETER_NAME.trim()), record.get(p.RDB$PARAMETER_NUMBER), type, false, null);
        result.add(column);
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) Rdb$fields(org.jooq.util.firebird.rdb.tables.Rdb$fields) ArrayList(java.util.ArrayList) Record(org.jooq.Record) Rdb$procedureParameters(org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition)

Example 15 with DefaultDataTypeDefinition

use of org.jooq.util.DefaultDataTypeDefinition 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)

Aggregations

DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)29 DataTypeDefinition (org.jooq.util.DataTypeDefinition)25 ArrayList (java.util.ArrayList)22 Record (org.jooq.Record)22 SchemaDefinition (org.jooq.util.SchemaDefinition)14 ColumnDefinition (org.jooq.util.ColumnDefinition)13 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)13 DefaultParameterDefinition (org.jooq.util.DefaultParameterDefinition)7 DefaultSequenceDefinition (org.jooq.util.DefaultSequenceDefinition)7 SequenceDefinition (org.jooq.util.SequenceDefinition)7 ParameterDefinition (org.jooq.util.ParameterDefinition)6 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)3 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)3 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)3 Rdb$procedureParameters (org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters)2 Columns (org.jooq.util.postgres.information_schema.tables.Columns)2 PgType (org.jooq.util.postgres.pg_catalog.tables.PgType)2 Name (org.jooq.Name)1 Schema (org.jooq.Schema)1 AttributeDefinition (org.jooq.util.AttributeDefinition)1