use of org.jooq.meta.DefaultParameterDefinition 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$functionArguments a = RDB$FUNCTION_ARGUMENTS.as("a");
Rdb$fields f = RDB$FIELDS.as("f");
int i = 0;
for (Record record : returnValue == null ? 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("CHAR_LEN"), 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()) : create().select(a.RDB$ARGUMENT_POSITION.as(p.RDB$PARAMETER_NUMBER), inline(0).as(p.RDB$PARAMETER_TYPE), a.RDB$ARGUMENT_NAME.trim().as(p.RDB$PARAMETER_NAME), FIELD_TYPE(f).as("FIELD_TYPE"), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), DSL.bitOr(a.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), a.RDB$DEFAULT_SOURCE).from(a).leftOuterJoin(f).on(a.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(a.RDB$FUNCTION_NAME.eq(getName())).and(a.RDB$ARGUMENT_POSITION.gt(inline((short) 0))).orderBy(a.RDB$ARGUMENT_POSITION)) {
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", 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);
}
}
use of org.jooq.meta.DefaultParameterDefinition in project jOOQ by jOOQ.
the class H2RoutineDefinition method init2_0.
private void init2_0() {
Result<?> result = create().select(PARAMETERS.PARAMETER_MODE, PARAMETERS.PARAMETER_NAME, nvl(concat(ELEMENT_TYPES.DATA_TYPE, inline(" ARRAY")), PARAMETERS.DATA_TYPE).as(PARAMETERS.DATA_TYPE), nvl(ELEMENT_TYPES.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.CHARACTER_MAXIMUM_LENGTH).as(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), nvl(ELEMENT_TYPES.NUMERIC_PRECISION, PARAMETERS.NUMERIC_PRECISION).as(PARAMETERS.NUMERIC_PRECISION), nvl(ELEMENT_TYPES.NUMERIC_SCALE, PARAMETERS.NUMERIC_SCALE).as(PARAMETERS.NUMERIC_SCALE), PARAMETERS.ORDINAL_POSITION).from(PARAMETERS).join(ROUTINES).on(PARAMETERS.SPECIFIC_SCHEMA.eq(ROUTINES.SPECIFIC_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.eq(ROUTINES.SPECIFIC_NAME)).leftJoin(ELEMENT_TYPES).on(PARAMETERS.SPECIFIC_SCHEMA.eq(ELEMENT_TYPES.OBJECT_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.eq(ELEMENT_TYPES.OBJECT_NAME)).and(PARAMETERS.DTD_IDENTIFIER.eq(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(PARAMETERS.SPECIFIC_SCHEMA.eq(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.eq(specificName)).orderBy(PARAMETERS.ORDINAL_POSITION.asc()).fetch();
for (Record record : result) {
String inOut = record.get(PARAMETERS.PARAMETER_MODE);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(PARAMETERS.DATA_TYPE), record.get(PARAMETERS.CHARACTER_MAXIMUM_LENGTH), record.get(PARAMETERS.NUMERIC_PRECISION), record.get(PARAMETERS.NUMERIC_SCALE), null, (String) null);
ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(PARAMETERS.PARAMETER_NAME).replaceAll("@", ""), record.get(PARAMETERS.ORDINAL_POSITION, int.class), type);
addParameter(InOutDefinition.getFromString(inOut), parameter);
}
}
use of org.jooq.meta.DefaultParameterDefinition 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.in(getSchema().getInputName(), 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);
}
}
}
use of org.jooq.meta.DefaultParameterDefinition in project jOOQ by jOOQ.
the class MySQLRoutineDefinition method createParameter.
private ParameterDefinition createParameter(Matcher matcher, int group, int columnIndex, String paramName) {
String paramType = matcher.group(group + 1);
Number precision = 0;
Number scale = 0;
if (!StringUtils.isBlank(matcher.group(group + 2))) {
precision = Integer.valueOf(matcher.group(group + 2));
}
if (!StringUtils.isBlank(matcher.group(group + 3))) {
scale = Integer.valueOf(matcher.group(group + 3));
}
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), paramType, precision, precision, scale, null, (String) null);
return new DefaultParameterDefinition(this, paramName, columnIndex, type);
}
use of org.jooq.meta.DefaultParameterDefinition 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);
}
}
Aggregations