Search in sources :

Example 11 with ParameterDefinition

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

the class JavaGenerator method printConvenienceMethodTableValuedFunction.

protected void printConvenienceMethodTableValuedFunction(JavaWriter out, TableDefinition function, String methodName) {
    // [#281] - Java can't handle more than 255 method parameters
    if (function.getParameters().size() > 254) {
        log.info("Too many parameters", "Function " + function + " has more than 254 in parameters. Skipping generation of convenience method.");
        return;
    }
    final String recordClassName = out.ref(getStrategy().getFullJavaClassName(function, Mode.RECORD));
    // [#3456] Local variables should not collide with actual function arguments
    final String configurationArgument = disambiguateJavaMemberName(function.getParameters(), "configuration");
    // [#5765] To prevent name clashes, this identifier is not imported
    final String functionName = getStrategy().getFullJavaIdentifier(function);
    if (!printDeprecationIfUnknownTypes(out, function.getParameters()))
        out.javadoc("Call <code>%s</code>.", function.getQualifiedOutputName());
    if (scala)
        out.println("%sdef %s(", visibility(), methodName);
    else if (kotlin)
        out.println("%sfun %s(", visibility(), methodName);
    else
        out.println("%sstatic %s<%s> %s(", visibility(), Result.class, recordClassName, methodName);
    String separator = "  ";
    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);
    printParameterDeclarations(out, function.getParameters(), false, ", ");
    if (scala) {
        out.println("): %s[%s] = %s.dsl().selectFrom(%s.call(", Result.class, recordClassName, configurationArgument, functionName);
    } else if (kotlin) {
        out.println("): %s<%s> = %s.dsl().selectFrom(%s.call(", Result.class, recordClassName, configurationArgument, functionName);
    } else {
        out.println(") {");
        out.println("return %s.dsl().selectFrom(%s.call(", configurationArgument, functionName);
    }
    separator = "  ";
    for (ParameterDefinition parameter : function.getParameters()) {
        out.println("%s%s", separator, getStrategy().getJavaMemberName(parameter));
        separator = ", ";
    }
    if (scala || kotlin)
        out.println(")).fetch()");
    else
        out.println(")).fetch();").println("}");
}
Also used : Configuration(org.jooq.Configuration) Result(org.jooq.Result) CloseResult(org.jooq.codegen.GeneratorWriter.CloseResult) ParameterDefinition(org.jooq.meta.ParameterDefinition)

Example 12 with ParameterDefinition

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

the class H2RoutineDefinition method init1_4.

private void init1_4() {
    for (Record record : create().select(FUNCTION_COLUMNS.COLUMN_NAME, FUNCTION_COLUMNS.TYPE_NAME, FUNCTION_COLUMNS.PRECISION, FUNCTION_COLUMNS.SCALE, FUNCTION_COLUMNS.POS, FUNCTION_COLUMNS.NULLABLE, FUNCTION_COLUMNS.COLUMN_DEFAULT).from(FUNCTION_COLUMNS).where(FUNCTION_COLUMNS.ALIAS_SCHEMA.equal(getSchema().getName())).and(FUNCTION_COLUMNS.ALIAS_NAME.equal(getName())).and(FUNCTION_COLUMNS.POS.gt(0)).and(getOverload() == null ? noCondition() : FUNCTION_COLUMNS.COLUMN_COUNT.eq(FUNCTION_COLUMNS.COLUMN_COUNT.getDataType().convert(getOverload()))).orderBy(FUNCTION_COLUMNS.POS.asc()).fetch()) {
        String paramName = record.get(FUNCTION_COLUMNS.COLUMN_NAME);
        String typeName = record.get(FUNCTION_COLUMNS.TYPE_NAME);
        Integer precision = record.get(FUNCTION_COLUMNS.PRECISION);
        Short scale = record.get(FUNCTION_COLUMNS.SCALE);
        int position = record.get(FUNCTION_COLUMNS.POS);
        boolean nullable = record.get(FUNCTION_COLUMNS.NULLABLE, boolean.class);
        String defaultValue = record.get(FUNCTION_COLUMNS.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.meta.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) ParameterDefinition(org.jooq.meta.ParameterDefinition) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition)

Example 13 with ParameterDefinition

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

the class HSQLDBRoutineDefinition method init0.

@Override
protected void init0() throws SQLException {
    Result<?> result = create().select(PARAMETERS.PARAMETER_MODE, PARAMETERS.PARAMETER_NAME, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, PARAMETERS.DATA_TYPE).as("datatype"), PARAMETERS.CHARACTER_MAXIMUM_LENGTH, PARAMETERS.NUMERIC_PRECISION, PARAMETERS.NUMERIC_SCALE, PARAMETERS.ORDINAL_POSITION).from(PARAMETERS).join(ROUTINES).on(PARAMETERS.SPECIFIC_SCHEMA.equal(ROUTINES.SPECIFIC_SCHEMA)).and(PARAMETERS.SPECIFIC_NAME.equal(ROUTINES.SPECIFIC_NAME)).leftOuterJoin(ELEMENT_TYPES).on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(PARAMETERS.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(PARAMETERS.SPECIFIC_SCHEMA.equal(getSchema().getName())).and(PARAMETERS.SPECIFIC_NAME.equal(this.specificName)).and(condition(val(!isAggregate())).or(PARAMETERS.ORDINAL_POSITION.eq(1L))).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("datatype", String.class), 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);
    }
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) Record(org.jooq.Record) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) ParameterDefinition(org.jooq.meta.ParameterDefinition) DefaultParameterDefinition(org.jooq.meta.DefaultParameterDefinition)

Example 14 with ParameterDefinition

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

the class JavaGenerator method printConvenienceMethodProcedure.

protected void printConvenienceMethodProcedure(JavaWriter out, RoutineDefinition procedure, boolean instance) {
    // [#281] - Java can't handle more than 255 method parameters
    if (procedure.getInParameters().size() > 254) {
        log.info("Too many parameters", "Procedure " + procedure + " has more than 254 in parameters. Skipping generation of convenience method.");
        return;
    }
    final String className = out.ref(getStrategy().getFullJavaClassName(procedure));
    final String configurationArgument = disambiguateJavaMemberName(procedure.getInParameters(), "configuration");
    final String localVar = disambiguateJavaMemberName(procedure.getInParameters(), "p");
    final List<ParameterDefinition> outParams = list(procedure.getReturnValue(), procedure.getOutParameters());
    final String methodName = getStrategy().getJavaMethodName(procedure, Mode.DEFAULT);
    final String firstOutParamType = outParams.size() == 1 ? out.ref(getJavaType(outParams.get(0).getType(resolver(out)), out)) : "";
    if (!printDeprecationIfUnknownTypes(out, procedure.getAllParameters()))
        out.javadoc("Call <code>%s</code>", procedure.getQualifiedOutputName());
    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 " : "", outParams.size() == 0 ? "void" : outParams.size() == 1 ? firstOutParamType : className, 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 : procedure.getInParameters()) {
        // Skip SELF parameter
        if (instance && parameter.equals(procedure.getInParameters().get(0)))
            continue;
        final String memberName = getStrategy().getJavaMemberName(parameter);
        final String typeName = refNumberType(out, parameter.getType(resolver(out)));
        if (scala)
            out.println("%s%s: %s", separator, scalaWhitespaceSuffix(memberName), typeName);
        else if (kotlin)
            out.println("%s%s: %s?", separator, memberName, typeName);
        else
            out.println("%s%s %s", separator, typeName, memberName);
        separator = ", ";
    }
    if (scala) {
        out.println("): %s = {", outParams.size() == 0 ? "Unit" : outParams.size() == 1 ? firstOutParamType : className);
        out.println("val %s = new %s", localVar, className);
    } else if (kotlin) {
        out.println("): %s%s {", outParams.size() == 0 ? "Unit" : outParams.size() == 1 ? firstOutParamType : className, outParams.size() == 1 ? "?" : "");
        out.println("val %s = %s()", localVar, className);
    } else {
        out.println(") {");
        out.println("%s %s = new %s();", className, localVar, className);
    }
    for (ParameterDefinition parameter : procedure.getInParameters()) {
        final String setter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
        final String arg = (instance && parameter.equals(procedure.getInParameters().get(0))) ? "this" : getStrategy().getJavaMemberName(parameter);
        out.println("%s.%s(%s)%s", localVar, setter, arg, semicolon);
    }
    out.println();
    out.println("%s.execute(%s)%s", localVar, instance ? "configuration()" : configurationArgument, semicolon);
    if (outParams.size() > 0) {
        final ParameterDefinition parameter = outParams.get(0);
        // Avoid disambiguation for RETURN_VALUE getter
        final String getter = parameter == procedure.getReturnValue() ? "getReturnValue" : getStrategy().getJavaGetterName(parameter, Mode.DEFAULT);
        final boolean isUDT = parameter.getType(resolver(out)).isUDT();
        if (instance) {
            // [#3117] Avoid funny call-site ambiguity if this is a UDT that is implemented by an interface
            if (generateInterfaces() && isUDT) {
                final String columnTypeInterface = out.ref(getJavaType(parameter.getType(resolver(out, Mode.INTERFACE)), out, Mode.INTERFACE));
                if (scala)
                    out.println("from(%s.%s.asInstanceOf[%s])", localVar, getter, columnTypeInterface);
                else if (kotlin)
                    out.println("from(%s.%s() as %s);", localVar, getter, columnTypeInterface);
                else
                    out.println("from((%s) %s.%s());", columnTypeInterface, localVar, getter);
            } else {
                out.println("from(%s.%s%s)%s", localVar, getter, emptyparens, semicolon);
            }
        }
        if (outParams.size() == 1)
            out.println("return %s.%s%s%s", localVar, getter, emptyparens, semicolon);
        else if (outParams.size() > 1)
            out.println("return %s%s", localVar, semicolon);
    }
    out.println("}");
}
Also used : Configuration(org.jooq.Configuration) ParameterDefinition(org.jooq.meta.ParameterDefinition)

Example 15 with ParameterDefinition

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

the class XMLGenerator method exportRoutine.

private void exportRoutine(InformationSchema is, RoutineDefinition r, String catalogName, String schemaName) {
    String specificName = r.getName() + (isBlank(r.getOverload()) ? "" : "_" + r.getOverload());
    Routine routine = new Routine();
    routine.setRoutineCatalog(catalogName);
    routine.setSpecificCatalog(catalogName);
    routine.setRoutineSchema(schemaName);
    routine.setSpecificSchema(schemaName);
    if (r.getPackage() != null) {
        routine.setRoutinePackage(r.getPackage().getName());
        routine.setSpecificPackage(r.getPackage().getName());
    }
    routine.setRoutineName(r.getName());
    routine.setSpecificName(specificName);
    if (generateCommentsOnRoutines())
        routine.setComment(r.getComment());
    if (r.getReturnValue() == null) {
        routine.setRoutineType(RoutineType.PROCEDURE);
    } else {
        routine.setRoutineType(RoutineType.FUNCTION);
        routine.setDataType(r.getReturnType().getType());
        routine.setCharacterMaximumLength(r.getReturnType().getLength());
        routine.setNumericPrecision(r.getReturnType().getPrecision());
        routine.setNumericScale(r.getReturnType().getScale());
    }
    is.getRoutines().add(routine);
    int i = 1;
    for (ParameterDefinition p : r.getAllParameters()) {
        if (p != r.getReturnValue()) {
            Parameter parameter = new Parameter();
            parameter.setSpecificCatalog(catalogName);
            parameter.setSpecificSchema(schemaName);
            if (r.getPackage() != null)
                parameter.setSpecificPackage(r.getPackage().getName());
            parameter.setSpecificName(specificName);
            parameter.setOrdinalPosition(i++);
            parameter.setParameterName(p.getName());
            if (generateCommentsOnParameters())
                parameter.setComment(p.getComment());
            boolean in = r.getInParameters().contains(p);
            boolean out = r.getOutParameters().contains(p);
            if (in && out)
                parameter.setParameterMode(ParameterMode.INOUT);
            else if (in)
                parameter.setParameterMode(ParameterMode.IN);
            else if (out)
                parameter.setParameterMode(ParameterMode.OUT);
            parameter.setDataType(p.getType().getType());
            parameter.setCharacterMaximumLength(p.getType().getLength());
            parameter.setNumericPrecision(p.getType().getPrecision());
            parameter.setNumericScale(p.getType().getScale());
            parameter.setParameterDefault(p.getType().getDefaultValue());
            is.getParameters().add(parameter);
        }
    }
}
Also used : Parameter(org.jooq.util.xml.jaxb.Parameter) Routine(org.jooq.util.xml.jaxb.Routine) CheckConstraint(org.jooq.util.xml.jaxb.CheckConstraint) ReferentialConstraint(org.jooq.util.xml.jaxb.ReferentialConstraint) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint) ParameterDefinition(org.jooq.meta.ParameterDefinition)

Aggregations

ParameterDefinition (org.jooq.meta.ParameterDefinition)15 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)8 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)8 Record (org.jooq.Record)7 DefaultParameterDefinition (org.jooq.meta.DefaultParameterDefinition)7 Field (org.jooq.Field)4 OrderField (org.jooq.OrderField)4 SelectField (org.jooq.SelectField)4 TableField (org.jooq.TableField)4 UDTField (org.jooq.UDTField)4 Configuration (org.jooq.Configuration)3 SchemaDefinition (org.jooq.meta.SchemaDefinition)3 AggregateFunction (org.jooq.AggregateFunction)2 Parameter (org.jooq.Parameter)2 Internal (org.jooq.impl.Internal)2 PostgresRoutineDefinition (org.jooq.meta.postgres.PostgresRoutineDefinition)2 Parameter (org.jooq.util.xml.jaxb.Parameter)2 DatatypeConverter (jakarta.xml.bind.DatatypeConverter)1 File (java.io.File)1 IOException (java.io.IOException)1