From 3726b347b4b6a13ff71ccc1dddd10bdc3810aae5 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 6 Jun 2019 10:16:21 +0200 Subject: [PATCH] [jOOQ/jOOQ#8744] H2: Support INSERT ... ON CONFLICT DO UPDATE Support this clause by emulating it with MERGE. --- .../org/jooq/InsertOnConflictDoUpdateStep.java | 3 ++- .../org/jooq/InsertOnConflictWhereStep.java | 17 +++++++++-------- jOOQ/src/main/java/org/jooq/InsertQuery.java | 12 ++++++------ .../main/java/org/jooq/LoaderOptionsStep.java | 3 ++- .../java/org/jooq/impl/InsertQueryImpl.java | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/InsertOnConflictDoUpdateStep.java b/jOOQ/src/main/java/org/jooq/InsertOnConflictDoUpdateStep.java index 40b0901ac3..b7c8fe72a0 100644 --- a/jOOQ/src/main/java/org/jooq/InsertOnConflictDoUpdateStep.java +++ b/jOOQ/src/main/java/org/jooq/InsertOnConflictDoUpdateStep.java @@ -42,6 +42,7 @@ import static org.jooq.SQLDialect.CUBRID; // ... import static org.jooq.SQLDialect.DERBY; import static org.jooq.SQLDialect.FIREBIRD; +import static org.jooq.SQLDialect.H2; import static org.jooq.SQLDialect.HSQLDB; // ... // ... @@ -73,7 +74,7 @@ public interface InsertOnConflictDoUpdateStep { /** * Add the DO UPDATE clause. */ - @Support({ CUBRID, DERBY, FIREBIRD, HSQLDB, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES, SQLITE }) InsertOnDuplicateSetStep doUpdate(); /** diff --git a/jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java b/jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java index c2024143de..e835da5798 100644 --- a/jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java +++ b/jOOQ/src/main/java/org/jooq/InsertOnConflictWhereStep.java @@ -40,6 +40,7 @@ package org.jooq; // ... import static org.jooq.SQLDialect.CUBRID; import static org.jooq.SQLDialect.DERBY; +import static org.jooq.SQLDialect.H2; // ... import static org.jooq.SQLDialect.POSTGRES; import static org.jooq.SQLDialect.SQLITE; @@ -91,7 +92,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * Add a WHERE clause to the INSERT statement's * ON DUPLICATE KEY UPDATE or ON CONFLICT ... DO UPDATE clause. */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) InsertOnConflictConditionStep where(Condition condition); /** @@ -99,7 +100,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * ON DUPLICATE KEY UPDATE or ON CONFLICT ... DO UPDATE clause, * connecting them with each other using {@link Operator#AND}. */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) InsertOnConflictConditionStep where(Condition... conditions); /** @@ -107,14 +108,14 @@ public interface InsertOnConflictWhereStep extends InsertRetur * ON DUPLICATE KEY UPDATE or ON CONFLICT ... DO UPDATE clause, * connecting them with each other using {@link Operator#AND}. */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) InsertOnConflictConditionStep where(Collection conditions); /** * Add a WHERE clause to the INSERT statement's * ON DUPLICATE KEY UPDATE or ON CONFLICT ... DO UPDATE clause. */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) InsertOnConflictConditionStep where(Field field); /** @@ -129,7 +130,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * @see DSL#condition(SQL) * @see SQL */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) @PlainSQL InsertOnConflictConditionStep where(SQL sql); @@ -145,7 +146,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * @see DSL#condition(String) * @see SQL */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) @PlainSQL InsertOnConflictConditionStep where(String sql); @@ -162,7 +163,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * @see DSL#sql(String, Object...) * @see SQL */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) @PlainSQL InsertOnConflictConditionStep where(String sql, Object... bindings); @@ -179,7 +180,7 @@ public interface InsertOnConflictWhereStep extends InsertRetur * @see DSL#sql(String, QueryPart...) * @see SQL */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) @PlainSQL InsertOnConflictConditionStep where(String sql, QueryPart... parts); diff --git a/jOOQ/src/main/java/org/jooq/InsertQuery.java b/jOOQ/src/main/java/org/jooq/InsertQuery.java index 4229e5872e..e019a9299a 100644 --- a/jOOQ/src/main/java/org/jooq/InsertQuery.java +++ b/jOOQ/src/main/java/org/jooq/InsertQuery.java @@ -265,7 +265,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param condition The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Condition condition); /** @@ -277,7 +277,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param conditions The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Condition... conditions); /** @@ -289,7 +289,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param conditions The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Collection conditions); /** @@ -301,7 +301,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param condition The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Operator operator, Condition condition); /** @@ -313,7 +313,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param conditions The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Operator operator, Condition... conditions); /** @@ -325,7 +325,7 @@ public interface InsertQuery extends StoreQuery, Insert * * @param conditions The condition */ - @Support({ CUBRID, DERBY, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, POSTGRES, SQLITE }) void addConditions(Operator operator, Collection conditions); /** diff --git a/jOOQ/src/main/java/org/jooq/LoaderOptionsStep.java b/jOOQ/src/main/java/org/jooq/LoaderOptionsStep.java index 564716a25c..ac1c5dabb5 100644 --- a/jOOQ/src/main/java/org/jooq/LoaderOptionsStep.java +++ b/jOOQ/src/main/java/org/jooq/LoaderOptionsStep.java @@ -42,6 +42,7 @@ package org.jooq; import static org.jooq.SQLDialect.CUBRID; // ... import static org.jooq.SQLDialect.DERBY; +import static org.jooq.SQLDialect.H2; import static org.jooq.SQLDialect.HSQLDB; // ... import static org.jooq.SQLDialect.MARIADB; @@ -110,7 +111,7 @@ public interface LoaderOptionsStep extends LoaderSourceStep * the default. This cannot be combined with {@link #onDuplicateKeyError()} * or {@link #onDuplicateKeyIgnore()} */ - @Support({ CUBRID, DERBY, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) LoaderOptionsStep onDuplicateKeyUpdate(); /** diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index 26d9662b9a..f291f319b6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -294,7 +294,6 @@ final class InsertQueryImpl extends AbstractStoreQuery impl case CUBRID: - case H2: case MARIADB: case MYSQL: { @@ -402,6 +401,7 @@ final class InsertQueryImpl extends AbstractStoreQuery impl case DERBY: + case H2: case HSQLDB: { ctx.visit(toMerge(ctx.configuration())); break;