Skip to content

Commit 96960bf

Browse files
committed
HHH-19336 - Proper implementation for JPA extended locking scope
HHH-19459 - LockScope, FollowOnLocking HHH-19501 - Session#lock w/ pessimistic locks for scopes HHH-19502 - Disallow SKIP_LOCKED with Session#lock HHH-19503 - Track a Dialect's level of support for locking joined tables
1 parent 1702d69 commit 96960bf

File tree

22 files changed

+125
-40
lines changed

22 files changed

+125
-40
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/AltibaseDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.hibernate.dialect.OracleDialect;
2626
import org.hibernate.dialect.function.CommonFunctionFactory;
2727
import org.hibernate.dialect.function.OracleTruncFunction;
28+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2829
import org.hibernate.dialect.pagination.LimitHandler;
2930
import org.hibernate.dialect.sequence.SequenceSupport;
3031
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -585,9 +586,9 @@ public boolean supportsFromClauseInUpdate() {
585586
}
586587

587588
@Override
588-
public boolean supportsOuterJoinForUpdate() {
589+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
589590
// "SELECT FOR UPDATE can only be used with a single-table SELECT statement"
590-
return false;
591+
return OuterJoinLockingLevel.UNSUPPORTED;
591592
}
592593

593594
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.dialect.lock.LockingStrategy;
2222
import org.hibernate.dialect.lock.PessimisticReadUpdateLockingStrategy;
2323
import org.hibernate.dialect.lock.PessimisticWriteUpdateLockingStrategy;
24+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2425
import org.hibernate.dialect.pagination.LimitHandler;
2526
import org.hibernate.dialect.pagination.TopLimitHandler;
2627
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -314,8 +315,9 @@ public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockO
314315
}
315316

316317
@Override
317-
public boolean supportsOuterJoinForUpdate() {
318-
return false;
318+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
319+
// InterSystems Cache' does not current support "SELECT ... FOR UPDATE" syntax at all
320+
return OuterJoinLockingLevel.UNSUPPORTED;
319321
}
320322

321323
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.hibernate.dialect.function.PostgreSQLTruncFunction;
3535
import org.hibernate.dialect.identity.CockroachDBIdentityColumnSupport;
3636
import org.hibernate.dialect.identity.IdentityColumnSupport;
37+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
3738
import org.hibernate.dialect.pagination.LimitHandler;
3839
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
3940
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
@@ -1084,8 +1085,8 @@ public String getForUpdateSkipLockedString(String aliases) {
10841085
}
10851086

10861087
@Override
1087-
public boolean supportsOuterJoinForUpdate() {
1088-
return false;
1088+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
1089+
return OuterJoinLockingLevel.UNSUPPORTED;
10891090
}
10901091

10911092
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hibernate.dialect.function.TrimFunction;
2828
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
2929
import org.hibernate.dialect.identity.IdentityColumnSupport;
30+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
3031
import org.hibernate.dialect.pagination.DB2LimitHandler;
3132
import org.hibernate.dialect.pagination.LegacyDB2LimitHandler;
3233
import org.hibernate.dialect.pagination.LimitHandler;
@@ -810,8 +811,8 @@ public String getReadLockString(int timeout) {
810811
}
811812

812813
@Override
813-
public boolean supportsOuterJoinForUpdate() {
814-
return false;
814+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
815+
return OuterJoinLockingLevel.UNSUPPORTED;
815816
}
816817

817818
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
3131
import org.hibernate.dialect.identity.IdentityColumnSupport;
3232
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
33+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
3334
import org.hibernate.dialect.pagination.LimitHandler;
3435
import org.hibernate.community.dialect.sequence.DerbySequenceSupport;
3536
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -607,9 +608,9 @@ public String getReadLockString(int timeout) {
607608
}
608609

609610
@Override
610-
public boolean supportsOuterJoinForUpdate() {
611+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
611612
//TODO: check this!
612-
return false;
613+
return OuterJoinLockingLevel.UNSUPPORTED;
613614
}
614615

615616
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.hibernate.dialect.function.InsertSubstringOverlayEmulation;
2929
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
3030
import org.hibernate.dialect.identity.IdentityColumnSupport;
31+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
3132
import org.hibernate.dialect.pagination.AbstractLimitHandler;
3233
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
3334
import org.hibernate.dialect.pagination.LimitHandler;
@@ -613,9 +614,9 @@ public String getReadLockString(int timeout) {
613614
}
614615

615616
@Override
616-
public boolean supportsOuterJoinForUpdate() {
617+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
617618
//TODO: check this!
618-
return false;
619+
return OuterJoinLockingLevel.UNSUPPORTED;
619620
}
620621

621622
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.hibernate.dialect.TimeZoneSupport;
3838
import org.hibernate.dialect.function.CommonFunctionFactory;
3939
import org.hibernate.dialect.identity.IdentityColumnSupport;
40+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
4041
import org.hibernate.dialect.pagination.LimitHandler;
4142
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
4243
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -697,10 +698,10 @@ public boolean supportsLockTimeouts() {
697698
}
698699

699700
@Override
700-
public boolean supportsOuterJoinForUpdate() {
701+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
701702
// "WITH LOCK can only be used with a top-level, single-table SELECT statement"
702703
// https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-select.html#fblangref25-dml-with-lock
703-
return false;
704+
return OuterJoinLockingLevel.UNSUPPORTED;
704705
}
705706

706707
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.hibernate.dialect.Dialect;
1414
import org.hibernate.dialect.function.CommonFunctionFactory;
1515
import org.hibernate.dialect.identity.IdentityColumnSupport;
16+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
1617
import org.hibernate.dialect.pagination.LimitHandler;
1718
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
1819
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -313,8 +314,8 @@ public LimitHandler getLimitHandler() {
313314
}
314315

315316
@Override
316-
public boolean supportsOuterJoinForUpdate() {
317-
return false;
317+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
318+
return OuterJoinLockingLevel.UNSUPPORTED;
318319
}
319320

320321
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.hibernate.dialect.function.PostgreSQLTruncRoundFunction;
3737
import org.hibernate.dialect.identity.IdentityColumnSupport;
3838
import org.hibernate.dialect.identity.PostgreSQLIdentityColumnSupport;
39+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
3940
import org.hibernate.dialect.pagination.LimitHandler;
4041
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
4142
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
@@ -914,8 +915,8 @@ public GenerationType getNativeValueGenerationStrategy() {
914915
}
915916

916917
@Override
917-
public boolean supportsOuterJoinForUpdate() {
918-
return false;
918+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
919+
return OuterJoinLockingLevel.UNSUPPORTED;
919920
}
920921

921922
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.dialect.lock.LockingStrategy;
2020
import org.hibernate.dialect.lock.PessimisticReadUpdateLockingStrategy;
2121
import org.hibernate.dialect.lock.PessimisticWriteUpdateLockingStrategy;
22+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2223
import org.hibernate.dialect.pagination.FetchLimitHandler;
2324
import org.hibernate.dialect.pagination.LimitHandler;
2425
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -346,14 +347,13 @@ public boolean supportsCascadeDelete() {
346347
}
347348

348349
/**
349-
* Currently, RDMS-JDBC does not support ForUpdate.
350-
* Need to review this in the future when support is provided.
351-
* <p>
352-
* {@inheritDoc}
350+
* Currently, RDMS-JDBC does not support {@code for update}.
351+
*
352+
* @todo Need to review this in the future when support is provided.
353353
*/
354354
@Override
355-
public boolean supportsOuterJoinForUpdate() {
356-
return false;
355+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
356+
return OuterJoinLockingLevel.UNSUPPORTED;
357357
}
358358

359359
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.dialect.Replacer;
2020
import org.hibernate.dialect.function.CommonFunctionFactory;
2121
import org.hibernate.dialect.identity.IdentityColumnSupport;
22+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2223
import org.hibernate.dialect.pagination.LimitHandler;
2324
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
2425
import org.hibernate.dialect.unique.AlterTableUniqueDelegate;
@@ -410,8 +411,8 @@ public String getForUpdateString() {
410411
}
411412

412413
@Override
413-
public boolean supportsOuterJoinForUpdate() {
414-
return false;
414+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
415+
return OuterJoinLockingLevel.UNSUPPORTED;
415416
}
416417

417418
@Override

hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.dialect.function.PostgreSQLTruncFunction;
2222
import org.hibernate.dialect.identity.CockroachDBIdentityColumnSupport;
2323
import org.hibernate.dialect.identity.IdentityColumnSupport;
24+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2425
import org.hibernate.dialect.pagination.LimitHandler;
2526
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
2627
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
@@ -994,8 +995,8 @@ public String getForUpdateSkipLockedString(String aliases) {
994995
}
995996

996997
@Override
997-
public boolean supportsOuterJoinForUpdate() {
998-
return false;
998+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
999+
return OuterJoinLockingLevel.UNSUPPORTED;
9991000
}
10001001

10011002
@Override

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.dialect.function.TrimFunction;
2121
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
2222
import org.hibernate.dialect.identity.IdentityColumnSupport;
23+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2324
import org.hibernate.dialect.pagination.DB2LimitHandler;
2425
import org.hibernate.dialect.pagination.LegacyDB2LimitHandler;
2526
import org.hibernate.dialect.pagination.LimitHandler;
@@ -892,8 +893,8 @@ public String getReadLockString(int timeout) {
892893
}
893894

894895
@Override
895-
public boolean supportsOuterJoinForUpdate() {
896-
return false;
896+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
897+
return OuterJoinLockingLevel.UNSUPPORTED;
897898
}
898899

899900
@Override

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy;
5050
import org.hibernate.dialect.lock.SelectLockingStrategy;
5151
import org.hibernate.dialect.lock.internal.SqlAstBasedLockingStrategy;
52+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
5253
import org.hibernate.dialect.pagination.LimitHandler;
5354
import org.hibernate.dialect.sequence.NoSequenceSupport;
5455
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -2547,7 +2548,11 @@ public String getReadLockString(String aliases, int timeout) {
25472548
* @return True if outer-joined rows can be locked via {@code FOR UPDATE}.
25482549
*/
25492550
public boolean supportsOuterJoinForUpdate() {
2550-
return true;
2551+
return getOuterJoinLockingLevel() == OuterJoinLockingLevel.FULL;
2552+
}
2553+
2554+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
2555+
return OuterJoinLockingLevel.FULL;
25512556
}
25522557

25532558
/**

hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.dialect.function.CommonFunctionFactory;
2424
import org.hibernate.dialect.identity.H2FinalTableIdentityColumnSupport;
2525
import org.hibernate.dialect.identity.IdentityColumnSupport;
26+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2627
import org.hibernate.dialect.pagination.LimitHandler;
2728
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
2829
import org.hibernate.dialect.sequence.H2V1SequenceSupport;
@@ -664,6 +665,11 @@ public LimitHandler getLimitHandler() {
664665
return OffsetFetchLimitHandler.INSTANCE;
665666
}
666667

668+
@Override
669+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
670+
return OuterJoinLockingLevel.IGNORED;
671+
}
672+
667673
@Override
668674
public boolean supportsDistinctFromPredicate() {
669675
return true;

hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.dialect.function.TrimFunction;
1313
import org.hibernate.dialect.identity.HSQLIdentityColumnSupport;
1414
import org.hibernate.dialect.identity.IdentityColumnSupport;
15+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
1516
import org.hibernate.dialect.pagination.LimitHandler;
1617
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
1718
import org.hibernate.dialect.sequence.HSQLSequenceSupport;
@@ -413,6 +414,11 @@ public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockO
413414
return super.getLockingClauseStrategy( querySpec, lockOptions );
414415
}
415416

417+
@Override
418+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
419+
return OuterJoinLockingLevel.IGNORED;
420+
}
421+
416422
@Override
417423
public boolean supportsLockTimeouts() {
418424
return false;

hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.dialect.function.PostgreSQLTruncRoundFunction;
2424
import org.hibernate.dialect.identity.IdentityColumnSupport;
2525
import org.hibernate.dialect.identity.PostgreSQLIdentityColumnSupport;
26+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2627
import org.hibernate.dialect.pagination.LimitHandler;
2728
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
2829
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
@@ -888,8 +889,8 @@ public GenerationType getNativeValueGenerationStrategy() {
888889
}
889890

890891
@Override
891-
public boolean supportsOuterJoinForUpdate() {
892-
return false;
892+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
893+
return OuterJoinLockingLevel.UNSUPPORTED;
893894
}
894895

895896
@Override

hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.dialect.function.FormatFunction;
1919
import org.hibernate.dialect.lock.LockingStrategy;
2020
import org.hibernate.dialect.lock.LockingStrategyException;
21+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2122
import org.hibernate.dialect.pagination.LimitHandler;
2223
import org.hibernate.dialect.pagination.LimitOffsetLimitHandler;
2324
import org.hibernate.dialect.sql.ast.SpannerSqlAstTranslator;
@@ -793,8 +794,8 @@ public String getReadLockString(String aliases, int timeout) {
793794
}
794795

795796
@Override
796-
public boolean supportsOuterJoinForUpdate() {
797-
return false;
797+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
798+
return OuterJoinLockingLevel.UNSUPPORTED;
798799
}
799800

800801
@Override

0 commit comments

Comments
 (0)