Skip to content

Commit e25fe49

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 bddaac5 commit e25fe49

File tree

9 files changed

+43
-21
lines changed

9 files changed

+43
-21
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
db=h2
1+
db=db2_ci
22

33
# Keep all these properties in sync unless you know what you are doing!
44
# We set '-Dlog4j2.disableJmx=true' to prevent classloader leaks triggered by the logger.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.dialect.TimeZoneSupport;
1919
import org.hibernate.dialect.function.CommonFunctionFactory;
2020
import org.hibernate.dialect.identity.IdentityColumnSupport;
21+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2122
import org.hibernate.dialect.pagination.LimitHandler;
2223
import org.hibernate.dialect.sequence.ANSISequenceSupport;
2324
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -420,6 +421,11 @@ public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockO
420421
return NON_CLAUSE_STRATEGY;
421422
}
422423

424+
@Override
425+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
426+
return OuterJoinLockingLevel.UNSUPPORTED;
427+
}
428+
423429
/**
424430
* {@code FOR UPDATE} only supported for cursors
425431
*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.dialect.identity.AbstractTransactSQLIdentityColumnSupport;
1515
import org.hibernate.dialect.identity.IdentityColumnSupport;
1616
import org.hibernate.dialect.lock.PessimisticLockStyle;
17+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
1718
import org.hibernate.dialect.temptable.TemporaryTable;
1819
import org.hibernate.dialect.temptable.TemporaryTableKind;
1920
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -204,6 +205,11 @@ public PessimisticLockStyle getPessimisticLockStyle() {
204205
return PessimisticLockStyle.TABLE_HINT;
205206
}
206207

208+
@Override
209+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
210+
return OuterJoinLockingLevel.IDENTIFIED;
211+
}
212+
207213
@Override
208214
public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockOptions lockOptions) {
209215
// T-SQL uses table-based lock hints and thus does not support FOR UPDATE clause

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
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;
2423
import org.hibernate.dialect.pagination.DB2LimitHandler;
2524
import org.hibernate.dialect.pagination.LegacyDB2LimitHandler;
2625
import org.hibernate.dialect.pagination.LimitHandler;
@@ -892,11 +891,6 @@ public String getReadLockString(int timeout) {
892891
: FOR_SHARE_SQL;
893892
}
894893

895-
@Override
896-
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
897-
return OuterJoinLockingLevel.UNSUPPORTED;
898-
}
899-
900894
@Override
901895
public boolean supportsExistsInSelect() {
902896
return false;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.dialect.function.IntegralTimestampaddFunction;
2222
import org.hibernate.dialect.identity.HANAIdentityColumnSupport;
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.LimitOffsetLimitHandler;
2627
import org.hibernate.dialect.sequence.HANASequenceSupport;
@@ -653,6 +654,11 @@ public RowLockStrategy getWriteRowLockStrategy() {
653654
return RowLockStrategy.COLUMN;
654655
}
655656

657+
@Override
658+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
659+
return OuterJoinLockingLevel.IDENTIFIED;
660+
}
661+
656662
@Override
657663
public String getCreateTableString() {
658664
return isDefaultTableTypeColumn() ? "create column table" : "create row table";

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.dialect.function.CommonFunctionFactory;
2020
import org.hibernate.dialect.identity.IdentityColumnSupport;
2121
import org.hibernate.dialect.identity.MySQLIdentityColumnSupport;
22+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2223
import org.hibernate.dialect.pagination.LimitHandler;
2324
import org.hibernate.dialect.pagination.LimitLimitHandler;
2425
import org.hibernate.dialect.sequence.NoSequenceSupport;
@@ -1581,6 +1582,11 @@ public RowLockStrategy getWriteRowLockStrategy() {
15811582
return supportsAliasLocks() ? RowLockStrategy.TABLE : RowLockStrategy.NONE;
15821583
}
15831584

1585+
@Override
1586+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
1587+
return supportsAliasLocks() ? OuterJoinLockingLevel.IDENTIFIED : OuterJoinLockingLevel.FULL;
1588+
}
1589+
15841590
@Override
15851591
protected void registerDefaultKeywords() {
15861592
super.registerDefaultKeywords();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.dialect.function.OracleTruncFunction;
2020
import org.hibernate.dialect.identity.IdentityColumnSupport;
2121
import org.hibernate.dialect.identity.Oracle12cIdentityColumnSupport;
22+
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
2223
import org.hibernate.dialect.pagination.LimitHandler;
2324
import org.hibernate.dialect.pagination.Oracle12LimitHandler;
2425
import org.hibernate.dialect.sequence.OracleSequenceSupport;
@@ -1436,6 +1437,11 @@ public boolean supportsSkipLocked() {
14361437
return true;
14371438
}
14381439

1440+
@Override
1441+
public OuterJoinLockingLevel getOuterJoinLockingLevel() {
1442+
return OuterJoinLockingLevel.IDENTIFIED;
1443+
}
1444+
14391445
@Override
14401446
public RowLockStrategy getWriteRowLockStrategy() {
14411447
return RowLockStrategy.COLUMN;

hibernate-core/src/main/java/org/hibernate/dialect/lock/spi/OuterJoinLockingLevel.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,15 @@ public enum OuterJoinLockingLevel {
4040
* Applying locks to joins is fully supported, acquiring locks
4141
* on all tables.
4242
*/
43-
FULL
43+
FULL,
44+
45+
/**
46+
* The joined rows to lock can be controlled per table reference,
47+
* generally via one of:<ul>
48+
* <li>{@linkplain org.hibernate.dialect.RowLockStrategy#TABLE}
49+
* <li>{@linkplain org.hibernate.dialect.RowLockStrategy#COLUMN}
50+
* <li>{@linkplain org.hibernate.dialect.lock.PessimisticLockStyle#TABLE_HINT}
51+
* </ul>
52+
*/
53+
IDENTIFIED
4454
}

hibernate-core/src/test/java/org/hibernate/orm/test/locking/options/ScopeTests.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.hibernate.dialect.Dialect;
1414
import org.hibernate.dialect.H2Dialect;
1515
import org.hibernate.dialect.HSQLDialect;
16-
import org.hibernate.dialect.RowLockStrategy;
1716
import org.hibernate.dialect.lock.PessimisticLockStyle;
1817
import org.hibernate.dialect.lock.spi.OuterJoinLockingLevel;
1918
import org.hibernate.testing.jdbc.SQLStatementInspector;
@@ -263,18 +262,7 @@ private boolean willAggressivelyLockJoinedTables(Dialect dialect) {
263262
//
264263
// todo : this is something we should consider and disallow the situation
265264

266-
final OuterJoinLockingLevel outerJoinLockingLevel = dialect.getOuterJoinLockingLevel();
267-
if ( outerJoinLockingLevel == OuterJoinLockingLevel.FULL ) {
268-
// there will be a join with some form of locking
269-
final PessimisticLockStyle pessimisticLockStyle = dialect.getPessimisticLockStyle();
270-
if ( pessimisticLockStyle == PessimisticLockStyle.CLAUSE ) {
271-
final RowLockStrategy rowLockStrategy = dialect.getWriteRowLockStrategy();
272-
if ( rowLockStrategy == RowLockStrategy.NONE ) {
273-
return true;
274-
}
275-
}
276-
}
277-
return false;
265+
return dialect.getOuterJoinLockingLevel() == OuterJoinLockingLevel.FULL;
278266
}
279267

280268
@Test

0 commit comments

Comments
 (0)