use of org.jooq.impl.SQLDataType.BOOLEAN in project jOOQ by jOOQ.
the class PostgresDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<>();
if (!canUseRoutines())
return result;
Routines r1 = ROUTINES.as("r1");
// [#7785] The pg_proc.proisagg column has been replaced incompatibly in PostgreSQL 11
Field<Boolean> isAgg = (is11() ? field(PG_PROC.PROKIND.eq(inline("a"))) : field("{0}.proisagg", SQLDataType.BOOLEAN, PG_PROC)).as("is_agg");
return create().select(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME, r1.SPECIFIC_NAME, r1.ROUTINE_TYPE, when(r1.DATA_TYPE.eq(inline("USER-DEFINED")).and(r1.TYPE_UDT_NAME.eq(inline("geometry"))), inline("geometry")).else_(canCombineArrays() ? when(condition("{0} && ARRAY['o','b']::\"char\"[]", PG_PROC.PROARGMODES), inline("void")).else_(r1.DATA_TYPE) : r1.DATA_TYPE).as("data_type"), r1.CHARACTER_MAXIMUM_LENGTH, // [#12048] TODO: Maintain whether we know the precision or not
when(r1.NUMERIC_PRECISION.isNull().and(r1.DATA_TYPE.in(inline("time"), inline("timetz"), inline("time without time zone"), inline("time with time zone"), inline("timestamp"), inline("timestamptz"), inline("timestamp without time zone"), inline("timestamp with time zone"))), inline(6)).else_(r1.NUMERIC_PRECISION).as(r1.NUMERIC_PRECISION), r1.NUMERIC_SCALE, r1.TYPE_UDT_SCHEMA, r1.TYPE_UDT_NAME, // Calculate overload index if applicable
when(count().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME)).gt(one()), rowNumber().over(partitionBy(r1.ROUTINE_SCHEMA, r1.ROUTINE_NAME).orderBy(// replace(field("pg_get_function_arguments({0})", VARCHAR, PG_PROC.OID), inline('"'), inline("")),
r1.SPECIFIC_NAME))).as("overload"), isAgg).from(r1).join(PG_NAMESPACE).on(PG_NAMESPACE.NSPNAME.eq(r1.SPECIFIC_SCHEMA)).join(PG_PROC).on(PG_PROC.PRONAMESPACE.eq(PG_NAMESPACE.OID)).and(is12() ? condition("nameconcatoid({0}, {1}) = {2}", PG_PROC.PRONAME, PG_PROC.OID, r1.SPECIFIC_NAME) : PG_PROC.PRONAME.concat("_").concat(PG_PROC.OID).eq(r1.SPECIFIC_NAME)).where(r1.ROUTINE_SCHEMA.in(getInputSchemata())).and(tableValuedFunctions() ? condition(not(PG_PROC.PRORETSET)) : noCondition()).and(!getIncludeTriggerRoutines() ? r1.DATA_TYPE.isDistinctFrom(inline("trigger")) : noCondition()).orderBy(r1.ROUTINE_SCHEMA.asc(), r1.ROUTINE_NAME.asc(), field(name("overload")).asc()).collect(mapping(r -> new PostgresRoutineDefinition(this, r), Collectors.<RoutineDefinition>toList()));
}
use of org.jooq.impl.SQLDataType.BOOLEAN in project jOOQ by jOOQ.
the class DefaultParseContext method parsePredicate.
private final QueryPart parsePredicate() {
Condition condition;
switch(characterUpper()) {
case 'D':
break;
case 'E':
if (parseKeywordIf("EXISTS"))
return exists(parseParenthesised(c -> parseWithOrSelect()));
break;
case 'I':
break;
case 'J':
if ((condition = parsePredicateJSONExistsIf()) != null)
return condition;
break;
case 'R':
if (parseKeywordIf("REGEXP_LIKE"))
return parseFunctionArgs2(Field::likeRegex);
break;
case 'S':
if (!ignoreProEdition() && parseFunctionNameIf("ST_CONTAINS", "SDO_CONTAINS") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_CROSSES") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_DISJOINT") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_EQUALS", "SDO_EQUAL") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_INTERSECTS") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_ISCLOSED") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_ISEMPTY") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_OVERLAPS", "SDO_OVERLAPS") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_TOUCHES", "SDO_TOUCH") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_WITHIN", "SDO_INSIDE") && requireProEdition()) {
}
break;
case 'U':
if (parseKeywordIf("UNIQUE"))
// javac can't infer this (?)
return unique(this.<Select<?>>parseParenthesised(c -> parseWithOrSelect()));
break;
case 'X':
if ((condition = parsePredicateXMLExistsIf()) != null)
return condition;
break;
}
FieldOrRow left;
Comparator comp;
TSQLOuterJoinComparator outer;
boolean not;
boolean notOp = false;
left = parseConcat();
int p = position();
not = parseKeywordIf("NOT");
boolean isField = left instanceof Field;
if (!not && !ignoreProEdition() && ((outer = parseTSQLOuterJoinComparatorIf()) != null) && requireProEdition()) {
Condition result = null;
return result;
} else if (!not && (comp = parseComparatorIf()) != null) {
boolean all = parseKeywordIf("ALL");
boolean any = !all && (parseKeywordIf("ANY") || parseKeywordIf("SOME"));
if (all || any)
parse('(');
// TODO equal degrees
Condition result = all ? isField ? peekSelectOrWith(true) ? ((Field) left).compare(comp, DSL.all(parseWithOrSelect(1))) : ((Field) left).compare(comp, DSL.all(parseList(',', c -> c.parseField()).toArray(EMPTY_FIELD))) : // TODO: Support quantifiers also for rows
new RowSubqueryCondition((Row) left, DSL.all(parseWithOrSelect(((Row) left).size())), comp) : any ? isField ? peekSelectOrWith(true) ? ((Field) left).compare(comp, DSL.any(parseWithOrSelect(1))) : ((Field) left).compare(comp, DSL.any(parseList(',', c -> c.parseField()).toArray(EMPTY_FIELD))) : // TODO: Support quantifiers also for rows
new RowSubqueryCondition((Row) left, DSL.any(parseWithOrSelect(((Row) left).size())), comp) : isField ? ((Field) left).compare(comp, toField(parseConcat())) : new RowCondition((Row) left, parseRow(((Row) left).size(), true), comp);
if (all || any)
parse(')');
return result;
} else if (!not && parseKeywordIf("IS")) {
not = parseKeywordIf("NOT");
if (parseKeywordIf("NULL"))
return not ? isField ? ((Field) left).isNotNull() : ((Row) left).isNotNull() : isField ? ((Field) left).isNull() : ((Row) left).isNull();
else if (isField && parseKeywordIf("JSON"))
return not ? ((Field) left).isNotJson() : ((Field) left).isJson();
else if (isField && parseKeywordIf("DOCUMENT"))
return not ? ((Field) left).isNotDocument() : ((Field) left).isDocument();
not = parseKeywordIf("DISTINCT FROM") == not;
if (left instanceof Field) {
Field f = (Field) left;
Field right = toField(parseConcat());
return not ? f.isNotDistinctFrom(right) : f.isDistinctFrom(right);
} else {
Row right = parseRow(((Row) left).size(), true);
return new RowIsDistinctFrom((Row) left, right, not);
}
} else if (!not && parseIf("@>")) {
return toField(left).contains((Field) toField(parseConcat()));
} else if (!forbidden.contains(FK_IN) && parseKeywordIf("IN")) {
Condition result;
// [#12691] Some dialects support A IN B syntax without parentheses for single element in lists
if (isField && !peek('(')) {
result = not ? ((Field) left).notIn(parseConcat()) : ((Field) left).in(parseConcat());
} else {
parse('(');
if (peek(')'))
result = not ? isField ? ((Field) left).notIn(EMPTY_FIELD) : new RowInCondition((Row) left, new QueryPartList<>(), true) : isField ? ((Field) left).in(EMPTY_FIELD) : new RowInCondition((Row) left, new QueryPartList<>(), false);
else if (peekSelectOrWith(true))
result = not ? isField ? ((Field) left).notIn(parseWithOrSelect(1)) : new RowSubqueryCondition((Row) left, parseWithOrSelect(((Row) left).size()), NOT_IN) : isField ? ((Field) left).in(parseWithOrSelect(1)) : new RowSubqueryCondition((Row) left, parseWithOrSelect(((Row) left).size()), IN);
else
result = not ? isField ? ((Field) left).notIn(parseList(',', c -> c.parseField())) : new RowInCondition((Row) left, new QueryPartList<>(parseList(',', c -> parseRow(((Row) left).size()))), true) : isField ? ((Field) left).in(parseList(',', c -> c.parseField())) : new RowInCondition((Row) left, new QueryPartList<>(parseList(',', c -> parseRow(((Row) left).size()))), false);
parse(')');
}
return result;
} else if (parseKeywordIf("BETWEEN")) {
boolean symmetric = !parseKeywordIf("ASYMMETRIC") && parseKeywordIf("SYMMETRIC");
FieldOrRow r1 = isField ? parseConcat() : parseRow(((Row) left).size());
parseKeyword("AND");
FieldOrRow r2 = isField ? parseConcat() : parseRow(((Row) left).size());
return symmetric ? not ? isField ? ((Field) left).notBetweenSymmetric((Field) r1, (Field) r2) : new RowBetweenCondition((Row) left, (Row) r1, not, symmetric, (Row) r2) : isField ? ((Field) left).betweenSymmetric((Field) r1, (Field) r2) : new RowBetweenCondition((Row) left, (Row) r1, not, symmetric, (Row) r2) : not ? isField ? ((Field) left).notBetween((Field) r1, (Field) r2) : new RowBetweenCondition((Row) left, (Row) r1, not, symmetric, (Row) r2) : isField ? ((Field) left).between((Field) r1, (Field) r2) : new RowBetweenCondition((Row) left, (Row) r1, not, symmetric, (Row) r2);
} else if (isField && (parseKeywordIf("LIKE") || parseOperatorIf("~~") || (notOp = parseOperatorIf("!~~")))) {
if (parseKeywordIf("ANY")) {
parse('(');
if (peekSelectOrWith(true)) {
Select<?> select = parseWithOrSelect();
parse(')');
LikeEscapeStep result = (not ^ notOp) ? ((Field) left).notLike(any(select)) : ((Field) left).like(any(select));
return parseEscapeClauseIf(result);
} else {
List<Field<?>> fields;
if (parseIf(')')) {
fields = emptyList();
} else {
fields = parseList(',', c -> toField(parseConcat()));
parse(')');
}
Field<String>[] fieldArray = fields.toArray(new Field[0]);
LikeEscapeStep result = (not ^ notOp) ? ((Field<String>) left).notLike(any(fieldArray)) : ((Field<String>) left).like(any(fieldArray));
return parseEscapeClauseIf(result);
}
} else if (parseKeywordIf("ALL")) {
parse('(');
if (peekSelectOrWith(true)) {
Select<?> select = parseWithOrSelect();
parse(')');
LikeEscapeStep result = (not ^ notOp) ? ((Field) left).notLike(all(select)) : ((Field) left).like(all(select));
return parseEscapeClauseIf(result);
} else {
List<Field<?>> fields;
if (parseIf(')')) {
fields = emptyList();
} else {
fields = parseList(',', c -> toField(parseConcat()));
parse(')');
}
Field<String>[] fieldArray = fields.toArray(new Field[0]);
LikeEscapeStep result = (not ^ notOp) ? ((Field<String>) left).notLike(all(fieldArray)) : ((Field<String>) left).like(all(fieldArray));
return parseEscapeClauseIf(result);
}
} else {
Field right = toField(parseConcat());
LikeEscapeStep like = (not ^ notOp) ? ((Field) left).notLike(right) : ((Field) left).like(right);
return parseEscapeClauseIf(like);
}
} else if (isField && (parseKeywordIf("ILIKE") || parseOperatorIf("~~*") || (notOp = parseOperatorIf("!~~*")))) {
Field right = toField(parseConcat());
LikeEscapeStep like = (not ^ notOp) ? ((Field) left).notLikeIgnoreCase(right) : ((Field) left).likeIgnoreCase(right);
return parseEscapeClauseIf(like);
} else if (isField && (parseKeywordIf("REGEXP") || parseKeywordIf("RLIKE") || parseKeywordIf("LIKE_REGEX") || parseOperatorIf("~") || (notOp = parseOperatorIf("!~")))) {
Field right = toField(parseConcat());
return (not ^ notOp) ? ((Field) left).notLikeRegex(right) : ((Field) left).likeRegex(right);
} else if (isField && parseKeywordIf("SIMILAR TO")) {
Field right = toField(parseConcat());
LikeEscapeStep like = not ? ((Field) left).notSimilarTo(right) : ((Field) left).similarTo(right);
return parseEscapeClauseIf(like);
} else if (left instanceof Row && ((Row) left).size() == 2 && parseKeywordIf("OVERLAPS")) {
Row leftRow = (Row) left;
Row rightRow = parseRow(2);
Row2 leftRow2 = row(leftRow.field(0), leftRow.field(1));
Row2 rightRow2 = row(rightRow.field(0), rightRow.field(1));
return leftRow2.overlaps(rightRow2);
} else {
position(p);
return left;
}
}
use of org.jooq.impl.SQLDataType.BOOLEAN 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.impl.SQLDataType.BOOLEAN in project jOOQ by jOOQ.
the class DefaultParseContext method parseGeneralSetFunctionIf.
private final Field<?> parseGeneralSetFunctionIf() {
boolean distinct;
Field arg;
ComputationalOperation operation = parseComputationalOperationIf();
if (operation == null)
return null;
parse('(');
switch(operation) {
case AVG:
case MAX:
case MIN:
case SUM:
case PRODUCT:
distinct = parseSetQuantifier();
break;
default:
distinct = false;
break;
}
arg = parseField();
switch(operation) {
case MAX:
case MIN:
{
if (!distinct && parseIf(',')) {
List<Field<?>> fields = parseList(',', c -> c.parseField());
parse(')');
return operation == ComputationalOperation.MAX ? greatest(arg, fields.toArray(EMPTY_FIELD)) : least(arg, fields.toArray(EMPTY_FIELD));
}
}
}
parse(')');
switch(operation) {
case ANY_VALUE:
return anyValue(arg);
case AVG:
return distinct ? avgDistinct(arg) : avg(arg);
case MAX:
return distinct ? maxDistinct(arg) : max(arg);
case MIN:
return distinct ? minDistinct(arg) : min(arg);
case SUM:
return distinct ? sumDistinct(arg) : sum(arg);
case PRODUCT:
return distinct ? productDistinct(arg) : product(arg);
case MEDIAN:
return median(arg);
case EVERY:
return every(arg);
case ANY:
return boolOr(arg);
case STDDEV_POP:
return stddevPop(arg);
case STDDEV_SAMP:
return stddevSamp(arg);
case VAR_POP:
return varPop(arg);
case VAR_SAMP:
return varSamp(arg);
default:
throw exception("Unsupported computational operation");
}
}
use of org.jooq.impl.SQLDataType.BOOLEAN in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldJSONArrayConstructorIf.
private final Field<?> parseFieldJSONArrayConstructorIf() {
boolean jsonb = false;
if (parseFunctionNameIf("JSON_ARRAY", "JSON_BUILD_ARRAY") || (jsonb = parseFunctionNameIf("JSONB_BUILD_ARRAY"))) {
parse('(');
if (parseIf(')'))
return jsonb ? jsonbArray() : jsonArray();
List<Field<?>> result = null;
JSONOnNull onNull = parseJSONNullTypeIf();
DataType<?> returning = parseJSONReturningIf();
if (onNull == null && returning == null) {
result = parseList(',', c -> c.parseField());
onNull = parseJSONNullTypeIf();
returning = parseJSONReturningIf();
}
parse(')');
JSONArrayNullStep<?> s1 = result == null ? jsonb ? jsonbArray() : jsonArray() : jsonb ? jsonbArray(result) : jsonArray(result);
JSONArrayReturningStep<?> s2 = onNull == NULL_ON_NULL ? s1.nullOnNull() : onNull == ABSENT_ON_NULL ? s1.absentOnNull() : s1;
return returning == null ? s2 : s2.returning(returning);
}
return null;
}
Aggregations