use of org.jooq.meta.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.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.ParameterDefinition 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);
}
}
use of org.jooq.meta.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 (specificName.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()), parameter.getComment());
switch(parameter.getParameterMode()) {
case IN:
addParameter(InOutDefinition.IN, p);
break;
case INOUT:
addParameter(InOutDefinition.INOUT, p);
break;
case OUT:
addParameter(InOutDefinition.OUT, p);
break;
}
}
}
}
use of org.jooq.meta.ParameterDefinition in project jOOQ by jOOQ.
the class JavaGenerator method printParameterDeclarations.
private void printParameterDeclarations(JavaWriter out, List<ParameterDefinition> parameters, boolean parametersAsField, String separator) {
for (ParameterDefinition parameter : parameters) {
final String memberName = getStrategy().getJavaMemberName(parameter);
if (scala) {
if (parametersAsField)
out.println("%s%s: %s[%s]", separator, scalaWhitespaceSuffix(memberName), Field.class, refExtendsNumberType(out, parameter.getType(resolver(out))));
else
out.println("%s%s: %s", separator, scalaWhitespaceSuffix(memberName), refNumberType(out, parameter.getType(resolver(out))));
} else if (kotlin) {
if (parametersAsField)
out.println("%s%s: %s<%s?>", separator, memberName, Field.class, refExtendsNumberType(out, parameter.getType(resolver(out))));
else
out.println("%s%s: %s%s", separator, memberName, refNumberType(out, parameter.getType(resolver(out))), kotlinNullability(parameter));
} else {
if (parametersAsField)
out.println("%s%s<%s> %s", separator, Field.class, refExtendsNumberType(out, parameter.getType(resolver(out))), memberName);
else
out.println("%s%s %s", separator, refNumberType(out, parameter.getType(resolver(out))), memberName);
}
separator = ", ";
}
}
use of org.jooq.meta.ParameterDefinition in project jOOQ by jOOQ.
the class JavaGenerator method printConvenienceMethodFunction.
protected void printConvenienceMethodFunction(JavaWriter out, RoutineDefinition function, boolean instance) {
// [#281] - Java can't handle more than 255 method parameters
if (function.getInParameters().size() > 254) {
log.info("Too many parameters", "Function " + function + " has more than 254 in parameters. Skipping generation of convenience method.");
return;
}
final String className = out.ref(getStrategy().getFullJavaClassName(function));
final String functionName = function.getQualifiedOutputName();
final String functionTypeFull = getJavaType(function.getReturnType(resolver(out)), out);
final String functionType = out.ref(functionTypeFull);
final String methodName = getStrategy().getJavaMethodName(function, Mode.DEFAULT);
// [#3456] Local variables should not collide with actual function arguments
final String configurationArgument = disambiguateJavaMemberName(function.getInParameters(), "configuration");
final String localVar = disambiguateJavaMemberName(function.getInParameters(), "f");
if (!printDeprecationIfUnknownType(out, functionTypeFull) && !printDeprecationIfUnknownTypes(out, function.getInParameters()))
out.javadoc("Call <code>%s</code>", functionName);
if (scala)
out.println("%sdef %s(", visibility(), methodName);
else if (kotlin)
out.println("%sfun %s(", visibility(), methodName);
else
out.println("%s%s%s %s(", visibility(), !instance ? "static " : "", functionType, methodName);
String separator = " ";
if (!instance) {
if (scala)
out.println("%s%s: %s", separator, scalaWhitespaceSuffix(configurationArgument), Configuration.class);
else if (kotlin)
out.println("%s%s: %s", separator, configurationArgument, Configuration.class);
else
out.println("%s%s %s", separator, Configuration.class, configurationArgument);
separator = ", ";
}
for (ParameterDefinition parameter : function.getInParameters()) {
// Skip SELF parameter
if (instance && parameter.equals(function.getInParameters().get(0)))
continue;
final String paramType = refNumberType(out, parameter.getType(resolver(out)));
final String paramMember = getStrategy().getJavaMemberName(parameter);
if (scala)
out.println("%s%s: %s", separator, scalaWhitespaceSuffix(paramMember), paramType);
else if (kotlin)
out.println("%s%s: %s%s", separator, paramMember, paramType, kotlinNullability(parameter));
else
out.println("%s%s %s", separator, paramType, paramMember);
separator = ", ";
}
if (scala) {
out.println("): %s = {", functionType);
out.println("val %s = new %s()", localVar, className);
} else if (kotlin) {
out.println("): %s? {", functionType);
out.println("val %s = %s()", localVar, className);
} else {
out.println(") {");
out.println("%s %s = new %s();", className, localVar, className);
}
for (ParameterDefinition parameter : function.getInParameters()) {
final String paramSetter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String paramMember = (instance && parameter.equals(function.getInParameters().get(0))) ? "this" : getStrategy().getJavaMemberName(parameter);
out.println("%s.%s(%s)%s", localVar, paramSetter, paramMember, semicolon);
}
out.println();
out.println("%s.execute(%s)%s", localVar, instance ? "configuration()" : configurationArgument, semicolon);
if (scala)
out.println("%s.getReturnValue", localVar);
else if (kotlin)
out.println("return %s.returnValue", localVar);
else
out.println("return %s.getReturnValue();", localVar);
out.println("}");
}
Aggregations