Search in sources :

Example 1 with JoinType

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;
    }
}
Also used : JoinType(org.jooq.JoinType) TablePartitionByStep(org.jooq.TablePartitionByStep)

Example 2 with JoinType

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;
}
Also used : JoinType(org.jooq.JoinType)

Example 3 with JoinType

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();
}
Also used : Condition(org.jooq.Condition) Keyword(org.jooq.Keyword) RenderOptionalKeyword(org.jooq.conf.RenderOptionalKeyword) JoinType(org.jooq.JoinType) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) Clause(org.jooq.Clause)

Aggregations

JoinType (org.jooq.JoinType)3 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Clause (org.jooq.Clause)1 Condition (org.jooq.Condition)1 Keyword (org.jooq.Keyword)1 TablePartitionByStep (org.jooq.TablePartitionByStep)1 RenderOptionalKeyword (org.jooq.conf.RenderOptionalKeyword)1