MCPcopy
hub / github.com/jOOQ/jOOQ / parseMerge

Method parseMerge

jOOQ/src/main/java/org/jooq/impl/ParserImpl.java:2692–2812  ·  view source on GitHub ↗
(WithImpl with)

Source from the content-addressed store, hash-verified

2690 }
2691
2692 private final Merge<?> parseMerge(WithImpl with) {
2693 parseKeyword("MERGE");
2694 parseKeywordIf("INTO");
2695 Table<?> target = parseTableName();
2696
2697 if (parseKeywordIf("AS") || !peekKeyword("USING"))
2698 target = target.as(parseIdentifier());
2699
2700 parseKeyword("USING");
2701 Table<?> table = null;
2702 Select<?> using = null;
2703
2704 if (parseIf('(')) {
2705 using = parseSelect();
2706 parse(')');
2707 }
2708 else {
2709 table = parseTableName();
2710 }
2711
2712 TableLike<?> usingTable = parseCorrelationNameIf(table != null ? table : using, () -> peekKeyword("ON"));
2713 parseKeyword("ON");
2714 Condition on = parseCondition();
2715 boolean update = false;
2716 boolean insert = false;
2717 MergeUsingStep<?> s1 = (with == null ? dsl.mergeInto(target) : with.mergeInto(target));
2718 MergeMatchedStep<?> s2 = s1.using(usingTable).on(on);
2719
2720 for (;;) {
2721 Map<Field<?>, Object> updateSet;
2722 Condition updateAnd = null;
2723 Condition updateWhere = null;
2724 Condition deleteWhere = null;
2725 List<Field<?>> insertColumns = null;
2726 List<Field<?>> insertValues = null;
2727 Condition insertAnd = null;
2728 Condition insertWhere = null;
2729
2730 boolean notMatchedBySource = false;
2731
2732 if (parseKeywordIf("WHEN MATCHED") || (notMatchedBySource = parseKeywordIf("WHEN NOT MATCHED BY SOURCE"))) {
2733 update = true;
2734
2735 if (parseKeywordIf("AND"))
2736 updateAnd = parseCondition();
2737
2738 if (parseKeywordIf("THEN DELETE")) {
2739 s2 = notMatchedBySource
2740 ? updateAnd != null
2741 ? s2.whenNotMatchedBySourceAnd(updateAnd).thenDelete()
2742 : s2.whenNotMatchedBySource().thenDelete()
2743 : updateAnd != null
2744 ? s2.whenMatchedAnd(updateAnd).thenDelete()
2745 : s2.whenMatchedThenDelete();
2746 }
2747 else {
2748 parseKeyword("THEN UPDATE SET");
2749 updateSet = parseSetClauseList();

Callers 2

parseQueryMethod · 0.95
parseWithMethod · 0.95

Calls 15

parseKeywordMethod · 0.95
parseKeywordIfMethod · 0.95
parseTableNameMethod · 0.95
peekKeywordMethod · 0.95
parseIdentifierMethod · 0.95
parseSelectMethod · 0.95
parseMethod · 0.95
parseConditionMethod · 0.95
parseSetClauseListMethod · 0.95
parseUniqueListMethod · 0.95
parseFieldNameMethod · 0.95

Tested by

no test coverage detected