Search in sources :

Example 1 with RoutineDefinition

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

the class MySQLDatabase method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    try {
        create(true).fetchCount(PROC);
    } catch (DataAccessException e) {
        log.warn("Table unavailable", "The `mysql`.`proc` table is unavailable. Stored procedures cannot be loaded. Check if you have sufficient grants");
        return result;
    }
    Result<Record6<String, String, String, byte[], byte[], ProcType>> records = create().select(Proc.DB, Proc.NAME, Proc.COMMENT, Proc.PARAM_LIST, Proc.RETURNS, Proc.TYPE).from(PROC).where(DB.in(getInputSchemata())).orderBy(DB, Proc.NAME).fetch();
    Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups = records.intoGroups(new Field[] { Proc.DB, Proc.NAME });
    // procedures and functions with the same signature.
    for (Entry<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> entry : groups.entrySet()) {
        Result<?> overloads = entry.getValue();
        for (int i = 0; i < overloads.size(); i++) {
            Record record = overloads.get(i);
            SchemaDefinition schema = getSchema(record.get(DB));
            String name = record.get(Proc.NAME);
            String comment = record.get(Proc.COMMENT);
            String params = new String(record.get(Proc.PARAM_LIST));
            String returns = new String(record.get(Proc.RETURNS));
            ProcType type = record.get(Proc.TYPE);
            if (overloads.size() > 1) {
                result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, "_" + type.name()));
            } else {
                result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null));
            }
        }
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) Result(org.jooq.Result) ProcType(org.jooq.util.mysql.mysql.enums.ProcType) Record6(org.jooq.Record6) Record(org.jooq.Record) DataAccessException(org.jooq.exception.DataAccessException)

Example 2 with RoutineDefinition

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

the class H2Database method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    for (Record record : create().select(FunctionAliases.ALIAS_SCHEMA, FunctionAliases.ALIAS_NAME, FunctionAliases.REMARKS, FunctionAliases.DATA_TYPE, FunctionAliases.RETURNS_RESULT, TypeInfo.TYPE_NAME, TypeInfo.PRECISION, TypeInfo.MAXIMUM_SCALE).from(FUNCTION_ALIASES).leftOuterJoin(TYPE_INFO).on(FunctionAliases.DATA_TYPE.equal(TypeInfo.DATA_TYPE)).and(TypeInfo.POS.equal(0)).where(FunctionAliases.ALIAS_SCHEMA.in(getInputSchemata())).and(FunctionAliases.RETURNS_RESULT.in((short) 1, (short) 2)).orderBy(FunctionAliases.ALIAS_NAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(FunctionAliases.ALIAS_SCHEMA));
        if (schema != null) {
            String name = record.get(FunctionAliases.ALIAS_NAME);
            String comment = record.get(FunctionAliases.REMARKS);
            String typeName = record.get(TypeInfo.TYPE_NAME);
            Integer precision = record.get(TypeInfo.PRECISION);
            Short scale = record.get(TypeInfo.MAXIMUM_SCALE);
            result.add(new H2RoutineDefinition(schema, name, comment, typeName, precision, scale));
        }
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 3 with RoutineDefinition

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

the class HSQLDBDatabase method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    for (Record record : create().select(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME, ROUTINES.SPECIFIC_NAME, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, ROUTINES.DATA_TYPE).as("datatype"), ROUTINES.NUMERIC_PRECISION, ROUTINES.NUMERIC_SCALE, field(ROUTINES.ROUTINE_DEFINITION.likeRegex(".*(?i:(\\w+\\s+)+aggregate\\s+function).*")).as("aggregate")).from(ROUTINES).leftOuterJoin(ELEMENT_TYPES).on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(ROUTINES.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata())).orderBy(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME).fetch()) {
        String datatype = record.get("datatype", String.class);
        // [#3285] We currently do not recognise HSQLDB table-valued functions as such.
        if (datatype != null && datatype.toUpperCase().startsWith("ROW")) {
            JooqLogger.getLogger(getClass()).info("A row : " + datatype);
            datatype = "ROW";
        }
        result.add(new HSQLDBRoutineDefinition(getSchema(record.get(ROUTINES.ROUTINE_SCHEMA)), record.get(ROUTINES.ROUTINE_NAME), record.get(ROUTINES.SPECIFIC_NAME), datatype, record.get(ROUTINES.NUMERIC_PRECISION), record.get(ROUTINES.NUMERIC_SCALE), record.get("aggregate", boolean.class)));
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) ArrayList(java.util.ArrayList) Record(org.jooq.Record)

Example 4 with RoutineDefinition

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

Example 5 with RoutineDefinition

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

the class XMLDatabase method getRoutines0.

@Override
protected List<RoutineDefinition> getRoutines0() {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
    for (Routine routine : info().getRoutines()) {
        if (isBlank(routine.getSpecificPackage()) && isBlank(routine.getRoutinePackage())) {
            String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
            if (getInputSchemata().contains(schemaName)) {
                SchemaDefinition schema = getSchema(schemaName);
                result.add(new XMLRoutineDefinition(schema, null, info(), routine));
            }
        }
    }
    return result;
}
Also used : RoutineDefinition(org.jooq.util.RoutineDefinition) SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) Routine(org.jooq.util.xml.jaxb.Routine)

Aggregations

ArrayList (java.util.ArrayList)5 RoutineDefinition (org.jooq.util.RoutineDefinition)5 Record (org.jooq.Record)4 SchemaDefinition (org.jooq.util.SchemaDefinition)3 Record6 (org.jooq.Record6)1 Result (org.jooq.Result)1 DataAccessException (org.jooq.exception.DataAccessException)1 ProcType (org.jooq.util.mysql.mysql.enums.ProcType)1 Routines (org.jooq.util.postgres.information_schema.tables.Routines)1 Routine (org.jooq.util.xml.jaxb.Routine)1