Search in sources :

Example 1 with ParameterDefinition

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

the class MySQLRoutineDefinition method init55.

private void init55() {
    // table is available, which is much more reliable than mysql.proc
    for (Record record : create().select(Parameters.ORDINAL_POSITION, Parameters.PARAMETER_NAME, Parameters.PARAMETER_MODE, Parameters.DATA_TYPE, Parameters.DTD_IDENTIFIER, Parameters.CHARACTER_MAXIMUM_LENGTH, Parameters.NUMERIC_PRECISION, Parameters.NUMERIC_SCALE).from(PARAMETERS).where(Parameters.SPECIFIC_SCHEMA.eq(getSchema().getInputName())).and(Parameters.SPECIFIC_NAME.eq(getInputName())).and(Parameters.ROUTINE_TYPE.eq(procType.name())).orderBy(Parameters.ORDINAL_POSITION.asc()).fetch()) {
        String inOut = record.get(Parameters.PARAMETER_MODE);
        String dataType = record.get(Parameters.DATA_TYPE);
        // [#519] Some types have unsigned versions
        if (getDatabase().supportsUnsignedTypes()) {
            if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
                if (record.get(Parameters.DTD_IDENTIFIER).toLowerCase().contains("unsigned")) {
                    dataType += "unsigned";
                }
            }
        }
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(Parameters.CHARACTER_MAXIMUM_LENGTH), record.get(Parameters.NUMERIC_PRECISION), record.get(Parameters.NUMERIC_SCALE), null, (String) null);
        if (inOut == null) {
            addParameter(InOutDefinition.RETURN, new DefaultParameterDefinition(this, "RETURN_VALUE", -1, type));
        } else {
            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.util.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 2 with ParameterDefinition

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

the class H2RoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    for (Record record : create().select(FunctionColumns.COLUMN_NAME, FunctionColumns.TYPE_NAME, FunctionColumns.PRECISION, FunctionColumns.SCALE, FunctionColumns.POS, FunctionColumns.NULLABLE, FunctionColumns.COLUMN_DEFAULT).from(FUNCTION_COLUMNS).where(FunctionColumns.ALIAS_SCHEMA.equal(getSchema().getName())).and(FunctionColumns.ALIAS_NAME.equal(getName())).and(FunctionColumns.POS.gt(0)).orderBy(FunctionColumns.POS.asc()).fetch()) {
        String paramName = record.get(FunctionColumns.COLUMN_NAME);
        String typeName = record.get(FunctionColumns.TYPE_NAME);
        Integer precision = record.get(FunctionColumns.PRECISION);
        Short scale = record.get(FunctionColumns.SCALE);
        int position = record.get(FunctionColumns.POS);
        boolean nullable = record.get(FunctionColumns.NULLABLE, boolean.class);
        String defaultValue = record.get(FunctionColumns.COLUMN_DEFAULT);
        // It is only used internally by H2 to provide a connection to the current database.
        if (position == 0 && H2DataType.OTHER.getTypeName().equalsIgnoreCase(typeName)) {
            continue;
        }
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), typeName, precision, precision, scale, nullable, defaultValue);
        ParameterDefinition parameter = new DefaultParameterDefinition(this, paramName, position, type);
        addParameter(InOutDefinition.IN, parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 3 with ParameterDefinition

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

the class XMLRoutineDefinition method init0.

@Override
protected void init0() {
    for (Parameter parameter : info.getParameters()) {
        Name parameterRoutineName = name(parameter.getSpecificCatalog(), parameter.getSpecificSchema(), parameter.getSpecificPackage(), parameter.getSpecificName());
        if (getQualifiedNamePart().equals(parameterRoutineName)) {
            DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), parameter.getDataType(), parameter.getCharacterMaximumLength(), parameter.getNumericPrecision(), parameter.getNumericScale(), null, parameter.getParameterDefault());
            ParameterDefinition p = new DefaultParameterDefinition(this, parameter.getParameterName(), parameter.getOrdinalPosition(), type, !StringUtils.isBlank(parameter.getParameterDefault()), StringUtils.isBlank(parameter.getParameterName()));
            switch(parameter.getParameterMode()) {
                case IN:
                    addParameter(InOutDefinition.IN, p);
                    break;
                case INOUT:
                    addParameter(InOutDefinition.INOUT, p);
                    break;
                case OUT:
                    addParameter(InOutDefinition.OUT, p);
                    break;
            }
        }
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Parameter(org.jooq.util.xml.jaxb.Parameter) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Name(org.jooq.Name) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 4 with ParameterDefinition

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

the class FirebirdRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$fields f = RDB$FIELDS.as("f");
    int i = 0;
    for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_TYPE, p.RDB$PARAMETER_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).orderBy(p.RDB$PARAMETER_TYPE.desc(), p.RDB$PARAMETER_NUMBER.asc())) {
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(p.RDB$PARAMETER_NAME), i++, type);
        addParameter(record.get(p.RDB$PARAMETER_TYPE, int.class).equals(0) ? InOutDefinition.IN : InOutDefinition.OUT, parameter);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$fields(org.jooq.util.firebird.rdb.tables.Rdb$fields) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Rdb$procedureParameters(org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Example 5 with ParameterDefinition

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

the class PostgresRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    for (Record record : create().select(PARAMETERS.PARAMETER_NAME, PARAMETERS.DATA_TYPE, PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE, PARAMETERS.UDT_SCHEMA, PARAMETERS.UDT_NAME, PARAMETERS.ORDINAL_POSITION, PARAMETERS.PARAMETER_MODE, ((PostgresDatabase) getDatabase()).is94() ? PARAMETERS.PARAMETER_DEFAULT : inline((String) null).as(PARAMETERS.PARAMETER_DEFAULT)).from(PARAMETERS).where(PARAMETERS.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.equal(specificName)).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch()) {
        String inOut = record.get(PARAMETERS.PARAMETER_MODE);
        SchemaDefinition typeSchema = null;
        String schemaName = record.get(PARAMETERS.UDT_SCHEMA);
        if (schemaName != null)
            typeSchema = getDatabase().getSchema(schemaName);
        DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(PARAMETERS.DATA_TYPE), record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, record.get(PARAMETERS.PARAMETER_DEFAULT), name(record.get(PARAMETERS.UDT_SCHEMA), record.get(PARAMETERS.UDT_NAME)));
        ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME), record.get(PARAMETERS.ORDINAL_POSITION), type, record.get(PARAMETERS.PARAMETER_DEFAULT) != null, StringUtils.isBlank(record.get(PARAMETERS.PARAMETER_NAME)));
        addParameter(InOutDefinition.getFromString(inOut), parameter);
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DefaultParameterDefinition(org.jooq.util.DefaultParameterDefinition) ParameterDefinition(org.jooq.util.ParameterDefinition)

Aggregations

DataTypeDefinition (org.jooq.util.DataTypeDefinition)6 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)6 DefaultParameterDefinition (org.jooq.util.DefaultParameterDefinition)6 ParameterDefinition (org.jooq.util.ParameterDefinition)6 Record (org.jooq.Record)5 Name (org.jooq.Name)1 SchemaDefinition (org.jooq.util.SchemaDefinition)1 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)1 Rdb$procedureParameters (org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters)1 Parameter (org.jooq.util.xml.jaxb.Parameter)1