use of org.jooq.JoinType in project jOOQ by jOOQ.
the class DefaultParseContext method parseJoinedTableIf.
private final Table<?> parseJoinedTableIf(Table<?> left, BooleanSupplier forbiddenKeywords) {
JoinType joinType = parseJoinTypeIf();
if (joinType == null)
return null;
Table<?> right = joinType.qualified() ? parseTable(forbiddenKeywords) : parseLateral(forbiddenKeywords);
TableOptionalOnStep<?> s0;
TablePartitionByStep<?> s1;
TableOnStep<?> s2;
s2 = s1 = (TablePartitionByStep<?>) (s0 = left.join(right, joinType));
switch(joinType) {
case LEFT_OUTER_JOIN:
case FULL_OUTER_JOIN:
case RIGHT_OUTER_JOIN:
if (!ignoreProEdition() && parseKeywordIf("PARTITION BY")) {
requireProEdition();
}
case JOIN:
case STRAIGHT_JOIN:
case LEFT_SEMI_JOIN:
case LEFT_ANTI_JOIN:
if (parseKeywordIf("ON"))
return s2.on(parseCondition());
else if (parseKeywordIf("USING"))
return parseJoinUsing(s2);
else // [#9476] MySQL treats INNER JOIN and CROSS JOIN as the same
if (joinType == JOIN)
return s0;
else
throw expected("ON", "USING");
case CROSS_JOIN:
// [#9476] MySQL treats INNER JOIN and CROSS JOIN as the same
if (parseKeywordIf("ON"))
return left.join(right).on(parseCondition());
else if (parseKeywordIf("USING"))
return parseJoinUsing(left.join(right));
default:
return s0;
}
}
use of org.jooq.JoinType in project jOOQ by jOOQ.
the class ParserImpl method parseJoinedTableIf.
private static final Table<?> parseJoinedTableIf(ParserContext ctx, Table<?> left) {
JoinType joinType = parseJoinTypeIf(ctx);
if (joinType == null)
return null;
Table<?> right = parseTableFactor(ctx);
TableOptionalOnStep<?> result1 = left.join(right, joinType);
Table<?> result2 = result1;
switch(joinType) {
case JOIN:
case LEFT_OUTER_JOIN:
case FULL_OUTER_JOIN:
case RIGHT_OUTER_JOIN:
case OUTER_APPLY:
{
boolean on = parseKeywordIf(ctx, "ON");
if (on) {
result2 = result1.on(parseCondition(ctx));
} else {
parseKeyword(ctx, "USING");
parse(ctx, '(');
result2 = result1.using(Tools.fieldsByName(parseIdentifiers(ctx).toArray(EMPTY_STRING)));
parse(ctx, ')');
}
break;
}
}
return result2;
}
use of org.jooq.JoinType in project jOOQ by jOOQ.
the class JoinTable method accept.
@Override
public final void accept(Context<?> ctx) {
JoinType translatedType = translateType(ctx);
Clause translatedClause = translateClause(translatedType);
Keyword keyword = translateKeyword(ctx, translatedType);
toSQLTable(ctx, lhs);
switch(translatedType) {
case LEFT_SEMI_JOIN:
case LEFT_ANTI_JOIN:
if (TRUE.equals(ctx.data(DATA_COLLECT_SEMI_ANTI_JOIN))) {
@SuppressWarnings("unchecked") List<Condition> semiAntiJoinPredicates = (List<Condition>) ctx.data(DATA_COLLECTED_SEMI_ANTI_JOIN);
if (semiAntiJoinPredicates == null) {
semiAntiJoinPredicates = new ArrayList<>();
ctx.data(DATA_COLLECTED_SEMI_ANTI_JOIN, semiAntiJoinPredicates);
}
Condition c = !using.isEmpty() ? usingCondition() : condition;
switch(translatedType) {
case LEFT_SEMI_JOIN:
semiAntiJoinPredicates.add(exists(selectOne().from(rhs).where(c)));
break;
case LEFT_ANTI_JOIN:
semiAntiJoinPredicates.add(notExists(selectOne().from(rhs).where(c)));
break;
}
return;
}
}
ctx.formatIndentStart().formatSeparator().start(translatedClause).visit(keyword).sql(' ');
toSQLTable(ctx, rhs);
// CROSS JOIN and NATURAL JOIN do not have any condition clauses
if (translatedType.qualified()) {
ctx.formatIndentStart();
toSQLJoinCondition(ctx);
ctx.formatIndentEnd();
} else if (OUTER_APPLY == translatedType && EMULATE_APPLY.contains(ctx.dialect())) {
ctx.formatIndentStart().formatSeparator().start(TABLE_JOIN_ON).visit(K_ON).sql(" 1 = 1").end(TABLE_JOIN_ON).formatIndentEnd();
}
ctx.end(translatedClause).formatIndentEnd();
}
Aggregations