From 0002c41e8983716821baf1a3cb92d91e3ff99e86 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Mon, 10 Aug 2015 17:12:15 +0200 Subject: [PATCH] [#4299] Add support for PostgreSQL 9.5 - FOR UPDATE SKIP LOCKED --- .../org/jooq/SelectForUpdateWaitStep.java | 21 ++++++------ jOOQ/src/main/java/org/jooq/SelectQuery.java | 33 +++++++++---------- .../main/java/org/jooq/impl/SelectImpl.java | 12 +++---- .../java/org/jooq/impl/SelectQueryImpl.java | 14 ++++---- 4 files changed, 37 insertions(+), 43 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/SelectForUpdateWaitStep.java b/jOOQ/src/main/java/org/jooq/SelectForUpdateWaitStep.java index 7c5a88e0bb..b161451872 100644 --- a/jOOQ/src/main/java/org/jooq/SelectForUpdateWaitStep.java +++ b/jOOQ/src/main/java/org/jooq/SelectForUpdateWaitStep.java @@ -42,6 +42,7 @@ package org.jooq; // ... import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.SQLDialect.POSTGRES_9_5; /** * This type is used for the {@link Select}'s DSL API when selecting generic @@ -109,15 +110,13 @@ public interface SelectForUpdateWaitStep extends SelectOptionS @Support({ POSTGRES }) SelectOptionStep noWait(); - /* [pro] xx - xxx - x xxx x xxxxxxxxxxxxxxxxx xxxxxx xx xxx xxxxxxxxx xxxxxxxxxxxxx xxxxxx xx - x xxx xxx xx xxx xxxxxx - x - x xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxx xxx xxxx - x xxxxxxx - xx - xxxxxxxxxxxxxxxx - xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx - xx [/pro] */ + /** + * Add a WAIT clause to the FOR UPDATE clause at + * the end of the query. + * + * @see SelectQuery#setForUpdateSkipLocked() see LockProvider for more + * details + */ + @Support({ POSTGRES_9_5 }) + SelectOptionStep skipLocked(); } diff --git a/jOOQ/src/main/java/org/jooq/SelectQuery.java b/jOOQ/src/main/java/org/jooq/SelectQuery.java index f74b98d233..560e278885 100644 --- a/jOOQ/src/main/java/org/jooq/SelectQuery.java +++ b/jOOQ/src/main/java/org/jooq/SelectQuery.java @@ -55,6 +55,7 @@ import static org.jooq.SQLDialect.MARIADB; import static org.jooq.SQLDialect.MYSQL; // ... import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.SQLDialect.POSTGRES_9_5; import static org.jooq.SQLDialect.SQLITE; // ... // ... @@ -788,24 +789,22 @@ public interface SelectQuery extends Select, ConditionProvi @Support({ POSTGRES }) void setForUpdateNoWait(); - /* [pro] xx - xxx - x xxxx xxxxx xxxxx xxx xxxxxxxxxx xxx xxxxxxx xxxx xxx xxx xxxxxxx - x xxxxxxxxx xxxxxxxxxxxxx xxxxxxx xx xxxx xxxxx xxx xxxxxxx xxxx xxxx xxx - x xxxxxx xxxx xxxx xxx xxxxxx xxxxxxxxxx xxxxx xxxx xx xxx xxxxxxxxxx - x xxx - x xxxx xxxxxxxxxxxxx xxxx xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxx xxxxx xxx - x xxxxxx xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxx xx xx xxx xxxxxxxxxx xxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xx xxxxxxxxx xx xxx xx xxxxx xxxxxxxxx - x xxxx - x xxxxxxxxxxxxxxx - x xxxxx - xx - xxxxxxxxxxxxxxxx - xxxx xxxxxxxxxxxxxxxxxxxxxxxxx + /** + * Some RDBMS allow for specifying the locking mode for the applied + * FOR UPDATE clause. In this case, the session will skip all + * locked rows from the select statement, whose lock is not available. + *

+ * This automatically sets the {@link #setForUpdate(boolean)} flag, and + * unsets the {@link #setForShare(boolean)} flag, if it was previously set. + *

+ * This has been observed to be supported by any of these dialects: + *

    + *
  • Oracle
  • + *
+ */ + @Support({POSTGRES_9_5}) + void setForUpdateSkipLocked(); - xx [/pro] */ /** * Sets the "FOR SHARE" flag onto the query. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java index 00076f28e3..396430c79c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java @@ -1874,14 +1874,12 @@ class SelectImpl extends AbstractResultQuery implement forUpdateWait = 0; } - /* [pro] xx - xxxxxxxxx - xxxxxx xxxxx xxxx xxxxxxxxxxxxxxxxxxxxxxxx x - xxxxxxxxxxxxxxxxxxx - xxxxxxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxx - xxxxxxxxxxxxx x xx - x - xx [/pro] */ + @Override + public final void setForUpdateSkipLocked() { + setForUpdate(true); + forUpdateMode = ForUpdateMode.SKIP_LOCKED; + forUpdateWait = 0; + } @Override public final void setForShare(boolean forShare) {