Search in sources :

Example 1 with Parameters

use of org.jooq.meta.postgres.information_schema.tables.Parameters 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)

Example 2 with Parameters

use of org.jooq.meta.postgres.information_schema.tables.Parameters in project jOOQ by jOOQ.

the class PostgresRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Parameters p = PARAMETERS;
    Field<Integer> count = count().filterWhere(p.PARAMETER_NAME.ne(inline(""))).over(partitionBy(p.SPECIFIC_NAME, p.PARAMETER_NAME));
    Field<Integer> c = count.as("c");
    for (Record record : create().select(p.PARAMETER_NAME, when(p.DATA_TYPE.eq(inline("USER-DEFINED")).and(p.UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(p.DATA_TYPE).as(p.DATA_TYPE), p.CHARACTER_MAXIMUM_LENGTH, pNumericPrecision(p).as(p.NUMERIC_PRECISION), p.NUMERIC_SCALE, p.UDT_SCHEMA, p.UDT_NAME, p.ORDINAL_POSITION, p.PARAMETER_MODE, ((PostgresDatabase) getDatabase()).is94() ? p.PARAMETER_DEFAULT : inline((String) null).as(p.PARAMETER_DEFAULT), c).from(p).where(p.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(p.SPECIFIC_NAME.equal(specificName)).orderBy(p.ORDINAL_POSITION.asc())) {
        String parameterName = record.get(p.PARAMETER_NAME);
        String inOut = record.get(p.PARAMETER_MODE);
        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), null, record.get(p.PARAMETER_DEFAULT), name(record.get(p.UDT_SCHEMA), record.get(p.UDT_NAME)));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, parameterName, record.get(p.ORDINAL_POSITION), type, record.get(p.PARAMETER_DEFAULT) != null, StringUtils.isBlank(parameterName), "", record.get(c) > 1 ? record.get(p.ORDINAL_POSITION, String.class) : null);
        addParameter(InOutDefinition.getFromString(inOut), parameter);
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) Parameters(org.jooq.meta.postgres.information_schema.tables.Parameters) 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)

Aggregations

Record (org.jooq.Record)2 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)2 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)2 SchemaDefinition (org.jooq.meta.SchemaDefinition)2 Parameters (org.jooq.meta.postgres.information_schema.tables.Parameters)2 ArrayList (java.util.ArrayList)1 ColumnDefinition (org.jooq.meta.ColumnDefinition)1 DefaultColumnDefinition (org.jooq.meta.DefaultColumnDefinition)1 DefaultParameterDefinition (org.jooq.meta.DefaultParameterDefinition)1 ParameterDefinition (org.jooq.meta.ParameterDefinition)1 Columns (org.jooq.meta.postgres.information_schema.tables.Columns)1 Routines (org.jooq.meta.postgres.information_schema.tables.Routines)1 PgNamespace (org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)1 PgProc (org.jooq.meta.postgres.pg_catalog.tables.PgProc)1 PgType (org.jooq.meta.postgres.pg_catalog.tables.PgType)1 StringUtils.defaultString (org.jooq.tools.StringUtils.defaultString)1