Search in sources :

Example 1 with Routines

use of org.jooq.util.postgres.information_schema.tables.Routines in project jOOQ by jOOQ.

the class PostgresTableValuedFunction method getElements0.

@Override
public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
    Routines r = ROUTINES;
    Parameters p = PARAMETERS;
    PgNamespace pg_n = PG_NAMESPACE;
    PgProc pg_p = PG_PROC;
    Columns c = COLUMNS;
    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, 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(oid(pg_n))).and(pg_p.PRONAME.eq(r.ROUTINE_NAME)).where(r.SPECIFIC_NAME.eq(specificName)).and(p.PARAMETER_MODE.ne("IN")).and(pg_p.PRORETSET).unionAll(// from INFORMATION_SCHEMA.TABLES
    select(nvl(c.COLUMN_NAME, getName()).as(c.COLUMN_NAME), // Type inference doesn't seem to be possible here with Java 8... ?
    nvl(c.ORDINAL_POSITION, DSL.<Integer>inline(1)).as(c.ORDINAL_POSITION), nvl(c.DATA_TYPE, r.DATA_TYPE).as(c.DATA_TYPE), nvl(c.CHARACTER_MAXIMUM_LENGTH, r.CHARACTER_MAXIMUM_LENGTH).as(c.CHARACTER_MAXIMUM_LENGTH), nvl(c.NUMERIC_PRECISION, r.NUMERIC_PRECISION).as(c.NUMERIC_PRECISION), nvl(c.NUMERIC_SCALE, r.NUMERIC_SCALE).as(c.NUMERIC_SCALE), nvl(c.IS_NULLABLE, "true").as(c.IS_NULLABLE), nvl(c.COLUMN_DEFAULT, inline((String) null)).as(c.COLUMN_DEFAULT), nvl(c.UDT_SCHEMA, inline((String) null)).as(c.UDT_SCHEMA), nvl(c.UDT_NAME, r.UDT_NAME).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(oid(pg_n))).and(pg_p.PRONAME.concat("_").concat(oid(pg_p)).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)));
        ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.PARAMETER_NAME), record.get(p.ORDINAL_POSITION, int.class), type, defaultString(record.get(c.COLUMN_DEFAULT)).startsWith("nextval"), null);
        result.add(column);
    }
    return result;
}
Also used : Routines(org.jooq.util.postgres.information_schema.tables.Routines) SchemaDefinition(org.jooq.util.SchemaDefinition) Parameters(org.jooq.util.postgres.information_schema.tables.Parameters) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) Columns(org.jooq.util.postgres.information_schema.tables.Columns) StringUtils.defaultString(org.jooq.tools.StringUtils.defaultString) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) DefaultColumnDefinition(org.jooq.util.DefaultColumnDefinition) PgProc(org.jooq.util.postgres.pg_catalog.tables.PgProc) Record(org.jooq.Record) PgNamespace(org.jooq.util.postgres.pg_catalog.tables.PgNamespace)

Example 2 with Routines

use of org.jooq.util.postgres.information_schema.tables.Routines in project jOOQ by jOOQ.

the class PostgresDatabase method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    Routines r1 = ROUTINES.as("r1");
    for (Record record : create().select(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME, r1.SPECIFIC_NAME, // Ignore the data type when there is at least one out parameter
    when(condition("{0} && ARRAY['o','b']::\"char\"[]", PG_PROC.PROARGMODES), inline("void")).otherwise(r1.DATA_TYPE).as("data_type"), r1.CHARACTER_MAXIMUM_LENGTH, r1.NUMERIC_PRECISION, r1.NUMERIC_SCALE, r1.TYPE_UDT_SCHEMA, r1.TYPE_UDT_NAME, // Calculate overload index if applicable
    when(count().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME)).gt(one()), rowNumber().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME).orderBy(r1.SPECIFIC_NAME))).as("overload"), PG_PROC.PROISAGG).from(r1).join(PG_NAMESPACE).on(PG_NAMESPACE.NSPNAME.eq(r1.SPECIFIC_SCHEMA)).join(PG_PROC).on(PG_PROC.PRONAMESPACE.eq(oid(PG_NAMESPACE))).and(PG_PROC.PRONAME.concat("_").concat(oid(PG_PROC)).eq(r1.SPECIFIC_NAME)).where(r1.ROUTINE_SCHEMA.in(getInputSchemata())).and(tableValuedFunctions() ? condition(not(PG_PROC.PRORETSET)) : trueCondition()).orderBy(r1.ROUTINE_SCHEMA.asc(), r1.ROUTINE_NAME.asc(), field(name("overload")).asc()).fetch()) {
        result.add(new PostgresRoutineDefinition(this, record));
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) Routines(org.jooq.util.postgres.information_schema.tables.Routines) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Aggregations

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