Search in sources :

Example 11 with DefaultDataTypeDefinition

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

the class H2RoutineDefinition method init2_0.

private void init2_0() {
    Result<?> result = create().select(PARAMETERS.PARAMETER_MODE, PARAMETERS.PARAMETER_NAME, nvl(concat(ELEMENT_TYPES.DATA_TYPE, inline(" ARRAY")), PARAMETERS.DATA_TYPE).as(PARAMETERS.DATA_TYPE), nvl(ELEMENT_TYPES.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.CHARACTER_MAXIMUM_LENGTH).as(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), nvl(ELEMENT_TYPES.NUMERIC_PRECISION, PARAMETERS.NUMERIC_PRECISION).as(PARAMETERS.NUMERIC_PRECISION), nvl(ELEMENT_TYPES.NUMERIC_SCALE, PARAMETERS.NUMERIC_SCALE).as(PARAMETERS.NUMERIC_SCALE), PARAMETERS.ORDINAL_POSITION).from(PARAMETERS).join(ROUTINES).on(PARAMETERS.SPECIFIC_SCHEMA.eq(ROUTINES.SPECIFIC_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.eq(ROUTINES.SPECIFIC_NAME)).leftJoin(ELEMENT_TYPES).on(PARAMETERS.SPECIFIC_SCHEMA.eq(ELEMENT_TYPES.OBJECT_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.eq(ELEMENT_TYPES.OBJECT_NAME)).and(PARAMETERS.DTD_IDENTIFIER.eq(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(PARAMETERS.SPECIFIC_SCHEMA.eq(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.eq(specificName)).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch();
    for (Record record : result) {
        String inOut = record.get(PARAMETERS.PARAMETER_MODE);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(PARAMETERS.DATA_TYPE), record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, (String) null);
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME).replaceAll("@", ""), record.get(PARAMETERS.ORDINAL_POSITION, int.class), type);
        addParameter(InOutDefinition.getFromString(inOut), parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) ParameterDefinition(org.jooq.meta.ParameterDefinition) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition)

Example 12 with DefaultDataTypeDefinition

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

the class PostgresMaterializedViewDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    Columns col = COLUMNS;
    PgAttribute a = PG_ATTRIBUTE.as("a");
    PgAttrdef ad = PG_ATTRDEF.as("ad");
    PgType t = PG_TYPE.as("t");
    PgType bt = PG_TYPE.as("bt");
    PgClass c = PG_CLASS.as("c");
    PgCollation co = PG_COLLATION.as("co");
    PgNamespace nt = PG_NAMESPACE.as("nt");
    PgNamespace nc = PG_NAMESPACE.as("nc");
    PgNamespace nbt = PG_NAMESPACE.as("nbt");
    PgNamespace nco = PG_NAMESPACE.as("nco");
    for (Record record : create().select(field("({0})::information_schema.sql_identifier", col.COLUMN_NAME.getDataType(), a.ATTNAME).as(col.COLUMN_NAME), field("({0})::information_schema.cardinal_number", col.ORDINAL_POSITION.getDataType(), a.ATTNUM).as(col.ORDINAL_POSITION), field("({0})::information_schema.character_data", col.DATA_TYPE.getDataType(), when(t.TYPTYPE.eq(inline("d")), when(bt.TYPELEM.ne(inline(0L)).and(bt.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nbt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, t.TYPBASETYPE)).otherwise(inline("USER-DEFINED"))).otherwise(when(t.TYPELEM.ne(inline(0L)).and(t.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, a.ATTTYPID)).otherwise(inline("USER-DEFINED")))).as(col.DATA_TYPE), field("(information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.CHARACTER_MAXIMUM_LENGTH.getDataType()).as(col.CHARACTER_MAXIMUM_LENGTH), field("(information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_PRECISION.getDataType()).as(col.NUMERIC_PRECISION), field("(information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_SCALE.getDataType()).as(col.NUMERIC_SCALE), field("({0})::information_schema.yes_or_no", col.IS_NULLABLE.getDataType(), when(condition(a.ATTNOTNULL).or(t.TYPTYPE.eq(inline("d")).and(t.TYPNOTNULL)), inline("NO")).otherwise(inline("YES"))).as(col.IS_NULLABLE), field("(pg_get_expr({0}, {1}))::information_schema.character_data", col.COLUMN_DEFAULT.getDataType(), ad.ADBIN, ad.ADRELID).as(col.COLUMN_DEFAULT), field("({0})::information_schema.sql_identifier", col.UDT_SCHEMA.getDataType(), nvl(nbt.NSPNAME, nt.NSPNAME)).as(col.UDT_SCHEMA), field("({0})::information_schema.sql_identifier", col.UDT_NAME.getDataType(), nvl(bt.TYPNAME, t.TYPNAME)).as(col.UDT_NAME), PG_DESCRIPTION.DESCRIPTION).from(a.leftJoin(ad).on(a.ATTRELID.eq(ad.ADRELID)).and(a.ATTNUM.eq(ad.ADNUM)).join(c.join(nc).on(c.RELNAMESPACE.eq(nc.OID))).on(a.ATTRELID.eq(c.OID)).join(t.join(nt).on(t.TYPNAMESPACE.eq(nt.OID))).on(a.ATTTYPID.eq(t.OID))).leftJoin(bt.join(nbt).on(bt.TYPNAMESPACE.eq(nbt.OID))).on(t.TYPTYPE.eq(inline("d")).and(t.TYPBASETYPE.eq(bt.OID))).leftJoin(co.join(nco).on(co.COLLNAMESPACE.eq(nco.OID))).on(a.ATTCOLLATION.eq(co.OID).and(nco.NSPNAME.ne(inline("pg_catalog")).or(co.COLLNAME.ne(inline("default"))))).leftJoin(PG_DESCRIPTION).on(PG_DESCRIPTION.OBJOID.eq(c.OID)).and(PG_DESCRIPTION.OBJSUBID.eq(a.ATTNUM.coerce(PG_DESCRIPTION.OBJSUBID))).where(not(condition("pg_is_other_temp_schema({0})", nc.OID)).and(a.ATTNUM.gt(inline((short) 0))).and(not(a.ATTISDROPPED)).and(c.RELKIND.eq(inline("m"))).and(nc.NSPNAME.in(getSchema().getName())).and(c.RELNAME.eq(getName()))).orderBy(a.ATTNUM)) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(COLUMNS.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(COLUMNS.DATA_TYPE), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), record.get(COLUMNS.COLUMN_DEFAULT), name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME)));
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).startsWith("nextval"), record.get(PG_DESCRIPTION.DESCRIPTION)));
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) PgType(org.jooq.meta.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) PgAttrdef(org.jooq.meta.postgres.pg_catalog.tables.PgAttrdef) ArrayList(java.util.ArrayList) Columns(org.jooq.meta.postgres.information_schema.tables.Columns) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) PgClass(org.jooq.meta.postgres.pg_catalog.tables.PgClass) Record(org.jooq.Record) PgAttribute(org.jooq.meta.postgres.pg_catalog.tables.PgAttribute) PgCollation(org.jooq.meta.postgres.pg_catalog.tables.PgCollation) PgNamespace(org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)

Example 13 with DefaultDataTypeDefinition

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

the class PostgresTableDefinition method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    PostgresDatabase database = (PostgresDatabase) getDatabase();
    Field<String> dataType = when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).when(COLUMNS.DATA_TYPE.eq(inline("USER-DEFINED")).and(COLUMNS.UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(COLUMNS.DATA_TYPE);
    Field<String> udtSchema = COLUMNS.UDT_SCHEMA;
    Field<Integer> precision = nvl(COLUMNS.DATETIME_PRECISION, COLUMNS.NUMERIC_PRECISION);
    Field<String> serialColumnDefault = inline("nextval('%_seq'::regclass)");
    Field<String> generationExpression = COLUMNS.GENERATION_EXPRESSION;
    Field<String> attgenerated = database.is12() ? PG_ATTRIBUTE.ATTGENERATED : inline("s");
    Condition isSerial = lower(COLUMNS.COLUMN_DEFAULT).likeIgnoreCase(serialColumnDefault);
    Condition isIdentity10 = COLUMNS.IS_IDENTITY.eq(inline("YES"));
    // [#9200] only use COLUMN_DEFAULT for ColumnDefinition#isIdentity() if
    // table has no column with IS_IDENTITY = 'YES'
    Condition isIdentity = database.is10() ? isIdentity10.or(count().filterWhere(isIdentity10).over().eq(inline(0)).and(isSerial)) : isSerial;
    for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, dataType.as(COLUMNS.DATA_TYPE), // [#8067] [#11658] A more robust / sophisticated decoding might be available
    nvl(COLUMNS.CHARACTER_MAXIMUM_LENGTH, when(COLUMNS.UDT_NAME.in(inline("_varchar"), inline("_bpchar"), inline("_char")), PG_ATTRIBUTE.ATTTYPMOD.sub(inline(4)))).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), precision.as(COLUMNS.NUMERIC_PRECISION), COLUMNS.NUMERIC_SCALE, (when(isIdentity, inline("YES"))).as(COLUMNS.IS_IDENTITY), COLUMNS.IS_NULLABLE, generationExpression.as(COLUMNS.GENERATION_EXPRESSION), attgenerated.as(PG_ATTRIBUTE.ATTGENERATED), (when(isIdentity, inline(null, String.class)).else_(COLUMNS.COLUMN_DEFAULT)).as(COLUMNS.COLUMN_DEFAULT), coalesce(COLUMNS.DOMAIN_SCHEMA, udtSchema).as(COLUMNS.UDT_SCHEMA), coalesce(COLUMNS.DOMAIN_NAME, COLUMNS.UDT_NAME).as(COLUMNS.UDT_NAME), PG_DESCRIPTION.DESCRIPTION).from(COLUMNS).join(PG_NAMESPACE).on(COLUMNS.TABLE_SCHEMA.eq(PG_NAMESPACE.NSPNAME)).join(PG_CLASS).on(PG_CLASS.RELNAME.eq(COLUMNS.TABLE_NAME)).and(PG_CLASS.RELNAMESPACE.eq(PG_NAMESPACE.OID)).join(PG_ATTRIBUTE).on(PG_ATTRIBUTE.ATTRELID.eq(PG_CLASS.OID)).and(PG_ATTRIBUTE.ATTNAME.eq(COLUMNS.COLUMN_NAME)).leftJoin(PG_DESCRIPTION).on(PG_DESCRIPTION.OBJOID.eq(PG_CLASS.OID)).and(PG_DESCRIPTION.OBJSUBID.eq(COLUMNS.ORDINAL_POSITION)).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).orderBy(COLUMNS.ORDINAL_POSITION)) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(COLUMNS.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(COLUMNS.DATA_TYPE), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), record.get(COLUMNS.COLUMN_DEFAULT), name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME))).generatedAlwaysAs(record.get(COLUMNS.GENERATION_EXPRESSION)).generationOption("s".equals(record.get(PG_ATTRIBUTE.ATTGENERATED)) ? GenerationOption.STORED : "v".equals(record.get(PG_ATTRIBUTE.ATTGENERATED)) ? GenerationOption.VIRTUAL : null);
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), record.get(COLUMNS.ORDINAL_POSITION, int.class), type, record.get(COLUMNS.IS_IDENTITY, boolean.class), record.get(PG_DESCRIPTION.DESCRIPTION));
        result.add(column);
    }
    return result;
}
Also used : Condition(org.jooq.Condition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) Record(org.jooq.Record)

Example 14 with DefaultDataTypeDefinition

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

the class PostgresUDTDefinition method getElements0.

@Override
protected List<AttributeDefinition> getElements0() throws SQLException {
    List<AttributeDefinition> result = new ArrayList<>();
    for (Record record : create().select(ATTRIBUTES.ATTRIBUTE_NAME, ATTRIBUTES.ORDINAL_POSITION, coalesce(DOMAINS.DATA_TYPE, when(ATTRIBUTES.DATA_TYPE.eq(inline("USER-DEFINED")).and(ATTRIBUTES.ATTRIBUTE_UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(ATTRIBUTES.DATA_TYPE)).as(ATTRIBUTES.DATA_TYPE), coalesce(DOMAINS.CHARACTER_MAXIMUM_LENGTH, ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH).as(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH), coalesce(DOMAINS.NUMERIC_PRECISION, ATTRIBUTES.NUMERIC_PRECISION).as(ATTRIBUTES.NUMERIC_PRECISION), coalesce(DOMAINS.NUMERIC_SCALE, ATTRIBUTES.NUMERIC_SCALE).as(ATTRIBUTES.NUMERIC_SCALE), ATTRIBUTES.IS_NULLABLE, ATTRIBUTES.ATTRIBUTE_DEFAULT, ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA, ATTRIBUTES.ATTRIBUTE_UDT_NAME).from(ATTRIBUTES).leftJoin(DOMAINS).on(ATTRIBUTES.ATTRIBUTE_UDT_CATALOG.eq(DOMAINS.DOMAIN_CATALOG)).and(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA.eq(DOMAINS.DOMAIN_SCHEMA)).and(ATTRIBUTES.ATTRIBUTE_UDT_NAME.eq(DOMAINS.DOMAIN_NAME)).where(ATTRIBUTES.UDT_SCHEMA.equal(getSchema().getName())).and(ATTRIBUTES.UDT_NAME.equal(getName())).orderBy(ATTRIBUTES.ORDINAL_POSITION).fetch()) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema == null ? getSchema() : typeSchema, record.get(ATTRIBUTES.DATA_TYPE), record.get(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH), record.get(ATTRIBUTES.NUMERIC_PRECISION), record.get(ATTRIBUTES.NUMERIC_SCALE), record.get(ATTRIBUTES.IS_NULLABLE, boolean.class), record.get(ATTRIBUTES.ATTRIBUTE_DEFAULT), name(record.get(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA), record.get(ATTRIBUTES.ATTRIBUTE_UDT_NAME)));
        AttributeDefinition column = new DefaultAttributeDefinition(this, record.get(ATTRIBUTES.ATTRIBUTE_NAME), record.get(ATTRIBUTES.ORDINAL_POSITION), type);
        result.add(column);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) AttributeDefinition(org.jooq.meta.AttributeDefinition) DefaultAttributeDefinition(org.jooq.meta.DefaultAttributeDefinition) Record(org.jooq.Record) DefaultAttributeDefinition(org.jooq.meta.DefaultAttributeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition)

Example 15 with DefaultDataTypeDefinition

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

the class PostgresTableValuedFunction method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    Routines r = ROUTINES;
    Parameters p = PARAMETERS;
    PgNamespace pg_n = PG_NAMESPACE;
    PgProc pg_p = PG_PROC;
    Columns c = COLUMNS;
    PgType pg_t = PG_TYPE;
    Field<Integer> pPrecision = pNumericPrecision(p);
    Field<Integer> cPrecision = nvl(c.DATETIME_PRECISION, c.NUMERIC_PRECISION);
    Field<Integer> rPrecision = nvl(r.DATETIME_PRECISION, r.NUMERIC_PRECISION);
    for (Record record : create().select(p.PARAMETER_NAME, rowNumber().over(partitionBy(p.SPECIFIC_NAME).orderBy(p.ORDINAL_POSITION)).as(p.ORDINAL_POSITION), p.DATA_TYPE, p.CHARACTER_MAXIMUM_LENGTH, pPrecision.as(p.NUMERIC_PRECISION), p.NUMERIC_SCALE, inline("true").as(c.IS_NULLABLE), (((PostgresDatabase) getDatabase()).is94() ? PARAMETERS.PARAMETER_DEFAULT : inline((String) null)).as(c.COLUMN_DEFAULT), p.UDT_SCHEMA, p.UDT_NAME).from(r).join(p).on(row(r.SPECIFIC_CATALOG, r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME).eq(p.SPECIFIC_CATALOG, p.SPECIFIC_SCHEMA, p.SPECIFIC_NAME)).join(pg_n).on(r.SPECIFIC_SCHEMA.eq(pg_n.NSPNAME)).join(pg_p).on(pg_p.PRONAMESPACE.eq(pg_n.OID)).and(pg_p.PRONAME.concat("_").concat(pg_p.OID).eq(r.SPECIFIC_NAME)).where(r.SPECIFIC_NAME.eq(specificName)).and(p.PARAMETER_MODE.ne("IN")).and(pg_p.PRORETSET).unionAll(// from INFORMATION_SCHEMA.TABLES
    select(coalesce(c.COLUMN_NAME, getName()).as(c.COLUMN_NAME), coalesce(c.ORDINAL_POSITION, inline(1)).as(c.ORDINAL_POSITION), coalesce(c.DATA_TYPE, r.DATA_TYPE).as(c.DATA_TYPE), coalesce(c.CHARACTER_MAXIMUM_LENGTH, r.CHARACTER_MAXIMUM_LENGTH).as(c.CHARACTER_MAXIMUM_LENGTH), coalesce(cPrecision, rPrecision).as(c.NUMERIC_PRECISION), coalesce(c.NUMERIC_SCALE, r.NUMERIC_SCALE).as(c.NUMERIC_SCALE), coalesce(c.IS_NULLABLE, "true").as(c.IS_NULLABLE), coalesce(c.COLUMN_DEFAULT, inline((String) null)).as(c.COLUMN_DEFAULT), coalesce(c.UDT_SCHEMA, inline((String) null)).as(c.UDT_SCHEMA), coalesce(c.UDT_NAME, r.UDT_NAME, field(select(pg_t.TYPNAME).from(pg_t).where(pg_t.OID.eq(pg_p.PRORETTYPE)))).as(c.UDT_NAME)).from(r).leftOuterJoin(c).on(row(r.TYPE_UDT_CATALOG, r.TYPE_UDT_SCHEMA, r.TYPE_UDT_NAME).eq(c.TABLE_CATALOG, c.TABLE_SCHEMA, c.TABLE_NAME)).join(pg_n).on(r.SPECIFIC_SCHEMA.eq(pg_n.NSPNAME)).join(pg_p).on(pg_p.PRONAMESPACE.eq(pg_n.OID)).and(pg_p.PRONAME.concat("_").concat(pg_p.OID).eq(r.SPECIFIC_NAME)).where(r.SPECIFIC_NAME.eq(specificName)).and(row(r.SPECIFIC_CATALOG, r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME).notIn(select(p.SPECIFIC_CATALOG, p.SPECIFIC_SCHEMA, p.SPECIFIC_NAME).from(p).where(p.PARAMETER_MODE.eq("OUT")))).and(pg_p.PRORETSET)).orderBy(2)) {
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(p.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(p.DATA_TYPE), record.get(p.CHARACTER_MAXIMUM_LENGTH), record.get(p.NUMERIC_PRECISION), record.get(p.NUMERIC_SCALE), record.get(c.IS_NULLABLE, boolean.class), record.get(c.COLUMN_DEFAULT), name(record.get(p.UDT_SCHEMA), record.get(p.UDT_NAME)));
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.PARAMETER_NAME), result.size() + 1, type, defaultString(record.get(c.COLUMN_DEFAULT)).startsWith("nextval"), null));
    }
    return result;
}
Also used : Routines(org.jooq.meta.postgres.information_schema.tables.Routines) SchemaDefinition(org.jooq.meta.SchemaDefinition) Parameters(org.jooq.meta.postgres.information_schema.tables.Parameters) PgType(org.jooq.meta.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Columns(org.jooq.meta.postgres.information_schema.tables.Columns) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) PgProc(org.jooq.meta.postgres.pg_catalog.tables.PgProc) Record(org.jooq.Record) PgNamespace(org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)

Aggregations

DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)36 Record (org.jooq.Record)30 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)30 ArrayList (java.util.ArrayList)27 SchemaDefinition (org.jooq.meta.SchemaDefinition)19 ColumnDefinition (org.jooq.meta.ColumnDefinition)14 DefaultColumnDefinition (org.jooq.meta.DefaultColumnDefinition)14 DefaultParameterDefinition (org.jooq.meta.DefaultParameterDefinition)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)7 ParameterDefinition (org.jooq.meta.ParameterDefinition)7 SequenceDefinition (org.jooq.meta.SequenceDefinition)7 DefaultDomainDefinition (org.jooq.meta.DefaultDomainDefinition)5 DomainDefinition (org.jooq.meta.DomainDefinition)5 Rdb$fields (org.jooq.meta.firebird.rdb.tables.Rdb$fields)4 Name (org.jooq.Name)3 PgNamespace (org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)3 PgType (org.jooq.meta.postgres.pg_catalog.tables.PgType)3 Rdb$procedureParameters (org.jooq.meta.firebird.rdb.tables.Rdb$procedureParameters)2 DomainConstraints (org.jooq.meta.hsqldb.information_schema.tables.DomainConstraints)2 Columns (org.jooq.meta.postgres.information_schema.tables.Columns)2