use of org.jooq.AggregateFunction in project jOOQ by jOOQ.
the class JavaGenerator method printConvenienceMethodFunctionAsField.
protected void printConvenienceMethodFunctionAsField(JavaWriter out, RoutineDefinition function, boolean parametersAsField) {
// [#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;
}
// meaning
if (parametersAsField && function.getInParameters().isEmpty())
return;
final String functionTypeFull = getJavaType(function.getReturnType(resolver(out)), out);
final String functionType = out.ref(functionTypeFull);
final String className = out.ref(getStrategy().getFullJavaClassName(function));
final String localVar = disambiguateJavaMemberName(function.getInParameters(), "f");
final String methodName = getStrategy().getJavaMethodName(function, Mode.DEFAULT);
if (!printDeprecationIfUnknownType(out, functionTypeFull) && !printDeprecationIfUnknownTypes(out, function.getInParameters()))
out.javadoc("Get <code>%s</code> as a field.", function.getQualifiedOutputName());
if (scala)
out.print("%sdef %s(", visibility(), methodName);
else if (kotlin)
out.print("%sfun %s(", visibility(), methodName);
else
out.print("%sstatic %s<%s> %s(", visibility(), function.isAggregate() ? AggregateFunction.class : Field.class, functionType, methodName);
if (!function.getInParameters().isEmpty())
out.println();
printParameterDeclarations(out, function.getInParameters(), parametersAsField, " ");
if (scala) {
out.println("): %s[%s] = {", function.isAggregate() ? AggregateFunction.class : Field.class, functionType);
out.println("val %s = new %s", localVar, className);
} else if (kotlin) {
out.println("): %s<%s?> {", function.isAggregate() ? AggregateFunction.class : Field.class, 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 = getStrategy().getJavaMemberName(parameter);
out.println("%s.%s(%s)%s", localVar, paramSetter, paramMember, semicolon);
}
out.println();
out.println("return %s.as%s%s%s", localVar, function.isAggregate() ? "AggregateFunction" : "Field", emptyparens, semicolon);
out.println("}");
}
use of org.jooq.AggregateFunction in project jOOQ by jOOQ.
the class DefaultParseContext method parseSpecialAggregateFunctionIf.
private final Field<?> parseSpecialAggregateFunctionIf() {
if (parseFunctionNameIf("GROUP_CONCAT")) {
parse('(');
GroupConcatOrderByStep s1;
GroupConcatSeparatorStep s2;
AggregateFunction<String> s3;
if (parseKeywordIf("DISTINCT"))
s1 = DSL.groupConcatDistinct(parseField());
else
s1 = DSL.groupConcat(parseField());
if (parseKeywordIf("ORDER BY"))
s2 = s1.orderBy(parseList(',', c -> c.parseSortField()));
else
s2 = s1;
if (parseKeywordIf("SEPARATOR"))
s3 = s2.separator(parseStringLiteral());
else
s3 = s2;
parse(')');
return s3;
}
return null;
}
use of org.jooq.AggregateFunction in project jOOQ by jOOQ.
the class DefaultParseContext method parseCountIf.
private final AggregateFunction<?> parseCountIf() {
if (parseFunctionNameIf("COUNT")) {
parse('(');
boolean distinct = parseSetQuantifier();
if (parseIf('*') && parse(')'))
if (distinct)
return countDistinct(asterisk());
else
return count();
Field<?>[] fields = null;
QualifiedAsterisk asterisk = null;
Row row = parseRowIf();
if (row != null)
fields = row.fields();
else if ((asterisk = parseQualifiedAsteriskIf()) == null)
fields = distinct ? parseList(',', c -> c.parseField()).toArray(EMPTY_FIELD) : new Field[] { parseField() };
parse(')');
if (distinct)
if (fields == null)
return countDistinct(asterisk);
else if (fields.length == 1)
return countDistinct(fields[0]);
else
return countDistinct(fields);
else if (fields == null)
return count(asterisk);
else
return count(fields[0]);
}
return null;
}
use of org.jooq.AggregateFunction in project jOOQ by jOOQ.
the class JavaGenerator method printConvenienceMethodFunctionAsField.
protected void printConvenienceMethodFunctionAsField(JavaWriter out, RoutineDefinition function, boolean parametersAsField) {
// [#281] - Java can't handle more than 255 method parameters
if (function.getInParameters().size() > 254) {
log.warn("Too many parameters", "Function " + function + " has more than 254 in parameters. Skipping generation of convenience method.");
return;
}
// meaning
if (parametersAsField && function.getInParameters().isEmpty()) {
return;
}
final String className = out.ref(getStrategy().getFullJavaClassName(function));
final String localVar = disambiguateJavaMemberName(function.getInParameters(), "f");
out.tab(1).javadoc("Get <code>%s</code> as a field.", function.getQualifiedOutputName());
if (scala)
out.tab(1).print("def %s(", getStrategy().getJavaMethodName(function, Mode.DEFAULT));
else
out.tab(1).print("public static %s<%s> %s(", function.isAggregate() ? AggregateFunction.class : Field.class, out.ref(getJavaType(function.getReturnType())), getStrategy().getJavaMethodName(function, Mode.DEFAULT));
String separator = "";
for (ParameterDefinition parameter : function.getInParameters()) {
out.print(separator);
if (scala) {
out.print("%s : ", getStrategy().getJavaMemberName(parameter));
if (parametersAsField) {
out.print("%s[%s]", Field.class, refExtendsNumberType(out, parameter.getType()));
} else {
out.print(refNumberType(out, parameter.getType()));
}
} else {
if (parametersAsField) {
out.print("%s<%s>", Field.class, refExtendsNumberType(out, parameter.getType()));
} else {
out.print(refNumberType(out, parameter.getType()));
}
out.print(" %s", getStrategy().getJavaMemberName(parameter));
}
separator = ", ";
}
if (scala) {
out.println(") : %s[%s] = {", function.isAggregate() ? AggregateFunction.class : Field.class, out.ref(getJavaType(function.getReturnType())));
out.tab(2).println("val %s = new %s", localVar, className);
} else {
out.println(") {");
out.tab(2).println("%s %s = new %s();", className, localVar, className);
}
for (ParameterDefinition parameter : function.getInParameters()) {
final String paramSetter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String paramMember = getStrategy().getJavaMemberName(parameter);
if (scala)
out.tab(2).println("%s.%s(%s)", localVar, paramSetter, paramMember);
else
out.tab(2).println("%s.%s(%s);", localVar, paramSetter, paramMember);
}
out.println();
if (scala)
out.tab(2).println("return %s.as%s", localVar, function.isAggregate() ? "AggregateFunction" : "Field");
else
out.tab(2).println("return %s.as%s();", localVar, function.isAggregate() ? "AggregateFunction" : "Field");
out.tab(1).println("}");
}
use of org.jooq.AggregateFunction in project jOOQ by jOOQ.
the class DefaultParseContext method parseAggregateFunctionIf.
private final Field<?> parseAggregateFunctionIf(boolean basic, AggregateFunction<?> f) {
AggregateFunction<?> agg = null;
AggregateFilterStep<?> filter = null;
WindowBeforeOverStep<?> over = null;
Object keep = null;
Field<?> result = null;
Condition condition = null;
keep = over = filter = agg = f != null ? f : parseCountIf();
if (filter == null) {
Field<?> field = parseGeneralSetFunctionIf();
if (field != null && !(field instanceof AggregateFunction))
return field;
keep = over = filter = agg = (AggregateFunction<?>) field;
}
if (filter == null && !basic)
over = filter = agg = parseBinarySetFunctionIf();
if (filter == null && !basic)
over = filter = parseOrderedSetFunctionIf();
if (filter == null && !basic)
over = filter = parseArrayAggFunctionIf();
if (filter == null && !basic)
over = filter = parseMultisetAggFunctionIf();
if (filter == null && !basic)
over = filter = parseXMLAggFunctionIf();
if (filter == null && !basic)
over = filter = parseJSONArrayAggFunctionIf();
if (filter == null && !basic)
over = filter = parseJSONObjectAggFunctionIf();
if (filter == null)
over = parseCountIfIf();
if (filter == null && over == null)
if (!basic)
return parseSpecialAggregateFunctionIf();
else
return null;
if (keep != null && filter != null && !basic && !ignoreProEdition() && parseKeywordIf("KEEP")) {
requireProEdition();
} else if (filter != null && !basic && parseKeywordIf("FILTER")) {
parse('(');
parseKeyword("WHERE");
condition = parseCondition();
parse(')');
result = over = filter.filterWhere(condition);
} else if (filter != null)
result = filter;
else
result = over;
if (!basic && parseKeywordIf("OVER")) {
Object nameOrSpecification = parseWindowNameOrSpecification(filter != null);
if (nameOrSpecification instanceof Name)
result = over.over((Name) nameOrSpecification);
else if (nameOrSpecification instanceof WindowSpecification)
result = over.over((WindowSpecification) nameOrSpecification);
else
result = over.over();
}
return result;
}
Aggregations