use of org.jooq.impl.DSL.any 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;
}
}
Aggregations