Search in sources :

Example 1 with Routines

use of org.jooq.meta.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<>();
    if (!canUseRoutines())
        return result;
    Routines r1 = ROUTINES.as("r1");
    // [#7785] The pg_proc.proisagg column has been replaced incompatibly in PostgreSQL 11
    Field<Boolean> isAgg = (is11() ? field(PG_PROC.PROKIND.eq(inline("a"))) : field("{0}.proisagg", SQLDataType.BOOLEAN, PG_PROC)).as("is_agg");
    return create().select(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME, r1.SPECIFIC_NAME, r1.ROUTINE_TYPE, when(r1.DATA_TYPE.eq(inline("USER-DEFINED")).and(r1.TYPE_UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(canCombineArrays() ? when(condition("{0} && ARRAY['o','b']::\"char\"[]", PG_PROC.PROARGMODES), inline("void")).else_(r1.DATA_TYPE) : r1.DATA_TYPE).as("data_type"), r1.CHARACTER_MAXIMUM_LENGTH, // [#12048] TODO: Maintain whether we know the precision or not
    when(r1.NUMERIC_PRECISION.isNull().and(r1.DATA_TYPE.in(inline("time"), inline("timetz"), inline("time without time zone"), inline("time with time zone"), inline("timestamp"), inline("timestamptz"), inline("timestamp without time zone"), inline("timestamp with time zone"))), inline(6)).else_(r1.NUMERIC_PRECISION).as(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(// replace(field("pg_get_function_arguments({0})", VARCHAR, PG_PROC.OID), inline('"'), inline("")),
    r1.SPECIFIC_NAME))).as("overload"), isAgg).from(r1).join(PG_NAMESPACE).on(PG_NAMESPACE.NSPNAME.eq(r1.SPECIFIC_SCHEMA)).join(PG_PROC).on(PG_PROC.PRONAMESPACE.eq(PG_NAMESPACE.OID)).and(is12() ? condition("nameconcatoid({0}, {1}) = {2}", PG_PROC.PRONAME, PG_PROC.OID, r1.SPECIFIC_NAME) : PG_PROC.PRONAME.concat("_").concat(PG_PROC.OID).eq(r1.SPECIFIC_NAME)).where(r1.ROUTINE_SCHEMA.in(getInputSchemata())).and(tableValuedFunctions() ? condition(not(PG_PROC.PRORETSET)) : noCondition()).and(!getIncludeTriggerRoutines() ? r1.DATA_TYPE.isDistinctFrom(inline("trigger")) : noCondition()).orderBy(r1.ROUTINE_SCHEMA.asc(), r1.ROUTINE_NAME.asc(), field(name("overload")).asc()).collect(mapping(r -> new PostgresRoutineDefinition(this, r), Collectors.<RoutineDefinition>toList()));
}
Also used : RoutineDefinition(org.jooq.meta.RoutineDefinition) Routines(org.jooq.meta.postgres.information_schema.tables.Routines) DSL(org.jooq.impl.DSL) DefaultIndexColumnDefinition(org.jooq.meta.DefaultIndexColumnDefinition) Records.intoList(org.jooq.Records.intoList) DefaultDomainDefinition(org.jooq.meta.DefaultDomainDefinition) DSL.field(org.jooq.impl.DSL.field) DefaultSequenceDefinition(org.jooq.meta.DefaultSequenceDefinition) DSL.condition(org.jooq.impl.DSL.condition) POSTGRES(org.jooq.SQLDialect.POSTGRES) DSL.when(org.jooq.impl.DSL.when) Condition(org.jooq.Condition) ColumnDefinition(org.jooq.meta.ColumnDefinition) BigDecimal(java.math.BigDecimal) Record5(org.jooq.Record5) RoutineDefinition(org.jooq.meta.RoutineDefinition) IndexColumnDefinition(org.jooq.meta.IndexColumnDefinition) Record1(org.jooq.Record1) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DSL.values(org.jooq.impl.DSL.values) BigInteger(java.math.BigInteger) SQLDialect(org.jooq.SQLDialect) PG_INDEX(org.jooq.meta.postgres.pg_catalog.Tables.PG_INDEX) Record6(org.jooq.Record6) Select(org.jooq.Select) PG_ENUM(org.jooq.meta.postgres.pg_catalog.Tables.PG_ENUM) DSL.partitionBy(org.jooq.impl.DSL.partitionBy) PostgresDSL.arrayAppend(org.jooq.util.postgres.PostgresDSL.arrayAppend) Result(org.jooq.Result) TableType(org.jooq.TableOptions.TableType) BOOLEAN(org.jooq.impl.SQLDataType.BOOLEAN) TableField(org.jooq.TableField) SQLDataType(org.jooq.impl.SQLDataType) DSL.noCondition(org.jooq.impl.DSL.noCondition) ParserException(org.jooq.impl.ParserException) DOMAINS(org.jooq.meta.postgres.information_schema.Tables.DOMAINS) Records.mapping(org.jooq.Records.mapping) AbstractIndexDefinition(org.jooq.meta.AbstractIndexDefinition) SequenceDefinition(org.jooq.meta.SequenceDefinition) DefaultEnumDefinition(org.jooq.meta.DefaultEnumDefinition) DSL.not(org.jooq.impl.DSL.not) PgType(org.jooq.meta.postgres.pg_catalog.tables.PgType) PG_DESCRIPTION(org.jooq.meta.postgres.pg_catalog.Tables.PG_DESCRIPTION) TableDefinition(org.jooq.meta.TableDefinition) DSL.row(org.jooq.impl.DSL.row) IndexDefinition(org.jooq.meta.IndexDefinition) ArrayList(java.util.ArrayList) CHECK_CONSTRAINTS(org.jooq.meta.postgres.information_schema.Tables.CHECK_CONSTRAINTS) SQLException(java.sql.SQLException) DSL.sql(org.jooq.impl.DSL.sql) KEY_COLUMN_USAGE(org.jooq.meta.postgres.information_schema.Tables.KEY_COLUMN_USAGE) PgNamespace(org.jooq.meta.postgres.pg_catalog.tables.PgNamespace) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) Record(org.jooq.Record) PG_SEQUENCE(org.jooq.meta.postgres.pg_catalog.Tables.PG_SEQUENCE) TABLES(org.jooq.meta.postgres.information_schema.Tables.TABLES) Rows.toRowArray(org.jooq.Rows.toRowArray) PG_CONSTRAINT(org.jooq.meta.postgres.pg_catalog.Tables.PG_CONSTRAINT) SchemaDefinition(org.jooq.meta.SchemaDefinition) PG_TYPE(org.jooq.meta.postgres.pg_catalog.Tables.PG_TYPE) DSL.table(org.jooq.impl.DSL.table) AbstractDatabase(org.jooq.meta.AbstractDatabase) CatalogDefinition(org.jooq.meta.CatalogDefinition) PgIndex(org.jooq.meta.postgres.pg_catalog.tables.PgIndex) DSL.power(org.jooq.impl.DSL.power) COLUMNS(org.jooq.meta.postgres.information_schema.Tables.COLUMNS) VIEWS(org.jooq.meta.postgres.information_schema.Tables.VIEWS) PgInherits(org.jooq.meta.postgres.pg_catalog.tables.PgInherits) Table(org.jooq.Table) DSL.rowNumber(org.jooq.impl.DSL.rowNumber) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) PackageDefinition(org.jooq.meta.PackageDefinition) PG_PROC(org.jooq.meta.postgres.pg_catalog.Tables.PG_PROC) ResultQuery(org.jooq.ResultQuery) DSLContext(org.jooq.DSLContext) PgClass(org.jooq.meta.postgres.pg_catalog.tables.PgClass) SortOrder(org.jooq.SortOrder) Routines(org.jooq.meta.postgres.information_schema.tables.Routines) DSL.name(org.jooq.impl.DSL.name) PG_INHERITS(org.jooq.meta.postgres.pg_catalog.Tables.PG_INHERITS) JooqLogger(org.jooq.tools.JooqLogger) KeyColumnUsage(org.jooq.meta.postgres.information_schema.tables.KeyColumnUsage) Name(org.jooq.Name) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) Field(org.jooq.Field) DSL.select(org.jooq.impl.DSL.select) Collectors(java.util.stream.Collectors) PG_NAMESPACE(org.jooq.meta.postgres.pg_catalog.Tables.PG_NAMESPACE) PARAMETERS(org.jooq.meta.postgres.information_schema.Tables.PARAMETERS) DomainDefinition(org.jooq.meta.DomainDefinition) List(java.util.List) INTEGER(org.jooq.impl.SQLDataType.INTEGER) HSQLDBDatabase(org.jooq.meta.hsqldb.HSQLDBDatabase) PG_DEPEND(org.jooq.meta.postgres.pg_catalog.Tables.PG_DEPEND) SEQUENCES(org.jooq.meta.postgres.information_schema.Tables.SEQUENCES) DefaultCheckConstraintDefinition(org.jooq.meta.DefaultCheckConstraintDefinition) DefaultRelations(org.jooq.meta.DefaultRelations) DSL.count(org.jooq.impl.DSL.count) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DSL.decode(org.jooq.impl.DSL.decode) DSL.nullif(org.jooq.impl.DSL.nullif) HashMap(java.util.HashMap) ParseUnknownFunctions(org.jooq.conf.ParseUnknownFunctions) DSL.replace(org.jooq.impl.DSL.replace) DECIMAL_INTEGER(org.jooq.impl.SQLDataType.DECIMAL_INTEGER) PgConstraint(org.jooq.meta.postgres.pg_catalog.tables.PgConstraint) BIGINT(org.jooq.impl.SQLDataType.BIGINT) NUMERIC(org.jooq.impl.SQLDataType.NUMERIC) DSL.selectFrom(org.jooq.impl.DSL.selectFrom) Collectors.mapping(java.util.stream.Collectors.mapping) ArrayDefinition(org.jooq.meta.ArrayDefinition) UDTDefinition(org.jooq.meta.UDTDefinition) DSL.inline(org.jooq.impl.DSL.inline) CheckConstraints(org.jooq.meta.postgres.information_schema.tables.CheckConstraints) DataAccessException(org.jooq.exception.DataAccessException) ATTRIBUTES(org.jooq.meta.postgres.information_schema.Tables.ATTRIBUTES) DSL.cast(org.jooq.impl.DSL.cast) ForcedType(org.jooq.meta.jaxb.ForcedType) PG_CLASS(org.jooq.meta.postgres.pg_catalog.Tables.PG_CLASS) DSL.one(org.jooq.impl.DSL.one) ROUTINES(org.jooq.meta.postgres.information_schema.Tables.ROUTINES) Collectors.toList(java.util.stream.Collectors.toList) Record12(org.jooq.Record12) DSL.max(org.jooq.impl.DSL.max) DSL.array(org.jooq.impl.DSL.array) EnumDefinition(org.jooq.meta.EnumDefinition) ResultQueryDatabase(org.jooq.meta.ResultQueryDatabase) CommonTableExpression(org.jooq.CommonTableExpression) ArrayList(java.util.ArrayList)

Example 2 with Routines

use of org.jooq.meta.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<>();
    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

ArrayList (java.util.ArrayList)2 Record (org.jooq.Record)2 ColumnDefinition (org.jooq.meta.ColumnDefinition)2 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)2 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)2 SchemaDefinition (org.jooq.meta.SchemaDefinition)2 Routines (org.jooq.meta.postgres.information_schema.tables.Routines)2 PgNamespace (org.jooq.meta.postgres.pg_catalog.tables.PgNamespace)2 PgType (org.jooq.meta.postgres.pg_catalog.tables.PgType)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Collectors.mapping (java.util.stream.Collectors.mapping)1 Collectors.toList (java.util.stream.Collectors.toList)1 CommonTableExpression (org.jooq.CommonTableExpression)1