[jOOQ/jOOQ#10052] Added parser support for MERGE .. DELETE WHERE

This commit is contained in:
Lukas Eder 2020-04-09 14:10:44 +02:00
parent 651af3bbea
commit 8407d26bc8
2 changed files with 17 additions and 8 deletions

View File

@ -98,7 +98,7 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
*/
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
MergeNotMatchedStep<R> deleteWhere(Condition condition);
MergeMatchedStep<R> deleteWhere(Condition condition);
/**
* Add an additional <code>DELETE WHERE</code> clause to the preceding
@ -110,7 +110,7 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
*/
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
MergeNotMatchedStep<R> deleteWhere(Field<Boolean> condition);
MergeMatchedStep<R> deleteWhere(Field<Boolean> condition);
/**
* Add an additional <code>DELETE WHERE</code> clause to the preceding
@ -132,5 +132,5 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
*/
@Deprecated
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
MergeNotMatchedStep<R> deleteWhere(Boolean condition);
MergeMatchedStep<R> deleteWhere(Boolean condition);
}

View File

@ -456,7 +456,9 @@ import org.jooq.LikeEscapeStep;
// ...
import org.jooq.Merge;
import org.jooq.MergeFinalStep;
import org.jooq.MergeMatchedDeleteStep;
import org.jooq.MergeMatchedStep;
import org.jooq.MergeMatchedWhereStep;
import org.jooq.MergeUsingStep;
import org.jooq.Meta;
import org.jooq.Name;
@ -2048,6 +2050,7 @@ final class ParserImpl implements Parser {
Map<Field<?>, Object> updateSet = null;
Condition updateAnd = null;
Condition updateWhere = null;
Condition deleteWhere = null;
MergeUsingStep<?> s1 = (with == null ? ctx.dsl.mergeInto(target) : with.mergeInto(target));
MergeMatchedStep<?> s2 = s1.using(usingTable).on(on);
@ -2071,11 +2074,17 @@ final class ParserImpl implements Parser {
if (updateAnd == null && parseKeywordIf(ctx, "WHERE"))
updateWhere = parseCondition(ctx);
s2 = updateAnd != null
? s2.whenMatchedAnd(updateAnd).thenUpdate().set(updateSet)
: updateWhere != null
? s2.whenMatchedThenUpdate().set(updateSet).where(updateWhere)
: s2.whenMatchedThenUpdate().set(updateSet);
if (updateAnd == null && parseKeywordIf(ctx, "DELETE WHERE"))
deleteWhere = parseCondition(ctx);
if (updateAnd != null) {
s2.whenMatchedAnd(updateAnd).thenUpdate().set(updateSet);
}
else {
MergeMatchedWhereStep<?> s3 = s2.whenMatchedThenUpdate().set(updateSet);
MergeMatchedDeleteStep<?> s4 = updateWhere != null ? s3.where(updateWhere) : s3;
s2 = deleteWhere != null ? s4.deleteWhere(deleteWhere) : s3;
}
}
}
else if (!insert && (insert = parseKeywordIf(ctx, "WHEN NOT MATCHED"))) {