Skip to content

Commit fb396ea

Browse files
committed
HHH-19551 - Address deficiencies in pessimistic locking
1 parent 7013473 commit fb396ea

File tree

68 files changed

+1659
-758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1659
-758
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.sql.DatabaseMetaData;
8-
import java.sql.SQLException;
9-
import java.sql.Types;
10-
import java.time.temporal.TemporalAccessor;
11-
import java.util.Date;
12-
import java.util.TimeZone;
13-
7+
import jakarta.persistence.TemporalType;
148
import org.hibernate.boot.model.FunctionContributions;
159
import org.hibernate.boot.model.TypeContributions;
1610
import org.hibernate.community.dialect.pagination.AltibaseLimitHandler;
@@ -25,7 +19,8 @@
2519
import org.hibernate.dialect.OracleDialect;
2620
import org.hibernate.dialect.function.CommonFunctionFactory;
2721
import org.hibernate.dialect.function.OracleTruncFunction;
28-
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
22+
import org.hibernate.dialect.lock.internal.NoLockingSupport;
23+
import org.hibernate.dialect.lock.spi.LockingSupport;
2924
import org.hibernate.dialect.pagination.LimitHandler;
3025
import org.hibernate.dialect.sequence.SequenceSupport;
3126
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -37,9 +32,9 @@
3732
import org.hibernate.exception.LockTimeoutException;
3833
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
3934
import org.hibernate.internal.util.JdbcExceptionHelper;
35+
import org.hibernate.query.common.TemporalUnit;
4036
import org.hibernate.query.sqm.CastType;
4137
import org.hibernate.query.sqm.IntervalType;
42-
import org.hibernate.query.common.TemporalUnit;
4338
import org.hibernate.query.sqm.TrimSpec;
4439
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
4540
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
@@ -57,7 +52,12 @@
5752
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
5853
import org.hibernate.type.spi.TypeConfiguration;
5954

60-
import jakarta.persistence.TemporalType;
55+
import java.sql.DatabaseMetaData;
56+
import java.sql.SQLException;
57+
import java.sql.Types;
58+
import java.time.temporal.TemporalAccessor;
59+
import java.util.Date;
60+
import java.util.TimeZone;
6161

6262
import static org.hibernate.type.SqlTypes.BINARY;
6363
import static org.hibernate.type.SqlTypes.BIT;
@@ -586,9 +586,8 @@ public boolean supportsFromClauseInUpdate() {
586586
}
587587

588588
@Override
589-
public OuterJoinLockingType getOuterJoinLockingType() {
590-
// "SELECT FOR UPDATE can only be used with a single-table SELECT statement"
591-
return OuterJoinLockingType.UNSUPPORTED;
589+
public LockingSupport getLockingSupport() {
590+
return NoLockingSupport.NO_LOCKING_SUPPORT;
592591
}
593592

594593
@Override

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.hibernate.dialect.TimeZoneSupport;
1818
import org.hibernate.dialect.function.CommonFunctionFactory;
1919
import org.hibernate.dialect.identity.IdentityColumnSupport;
20+
import org.hibernate.dialect.lock.internal.LockingSupportSimple;
21+
import org.hibernate.dialect.lock.spi.LockingSupport;
2022
import org.hibernate.dialect.pagination.LimitHandler;
2123
import org.hibernate.dialect.pagination.LimitLimitHandler;
2224
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -316,6 +318,11 @@ public char closeQuote() {
316318
return ']';
317319
}
318320

321+
@Override
322+
public LockingSupport getLockingSupport() {
323+
return LockingSupportSimple.STANDARD_SUPPORT;
324+
}
325+
319326
@Override
320327
public String getForUpdateString() {
321328
return "";

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
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.OuterJoinLockingType;
24+
import org.hibernate.dialect.lock.internal.NoLockingSupport;
25+
import org.hibernate.dialect.lock.spi.LockingSupport;
2526
import org.hibernate.dialect.pagination.LimitHandler;
2627
import org.hibernate.dialect.pagination.TopLimitHandler;
2728
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -309,15 +310,15 @@ public String getQuerySequencesString() {
309310

310311
// lock acquisition support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311312

313+
312314
@Override
313-
public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockOptions lockOptions) {
314-
return NON_CLAUSE_STRATEGY;
315+
public LockingSupport getLockingSupport() {
316+
return NoLockingSupport.NO_LOCKING_SUPPORT;
315317
}
316318

317319
@Override
318-
public OuterJoinLockingType getOuterJoinLockingType() {
319-
// InterSystems Cache' does not current support "SELECT ... FOR UPDATE" syntax at all
320-
return OuterJoinLockingType.UNSUPPORTED;
320+
public LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockOptions lockOptions) {
321+
return NON_CLAUSE_STRATEGY;
321322
}
322323

323324
@Override

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
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.OuterJoinLockingType;
37+
import org.hibernate.dialect.lock.internal.LockingSupportSimple;
38+
import org.hibernate.dialect.lock.spi.LockingSupport;
3839
import org.hibernate.dialect.pagination.LimitHandler;
3940
import org.hibernate.dialect.pagination.OffsetFetchLimitHandler;
4041
import org.hibernate.dialect.sequence.PostgreSQLSequenceSupport;
@@ -1085,8 +1086,8 @@ public String getForUpdateSkipLockedString(String aliases) {
10851086
}
10861087

10871088
@Override
1088-
public OuterJoinLockingType getOuterJoinLockingType() {
1089-
return OuterJoinLockingType.UNSUPPORTED;
1089+
public LockingSupport getLockingSupport() {
1090+
return LockingSupportSimple.NO_OUTER_JOIN;
10901091
}
10911092

10921093
@Override

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
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.LockTimeoutStyle;
31-
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
30+
import org.hibernate.dialect.lock.internal.NoLockingSupport;
31+
import org.hibernate.dialect.lock.spi.LockingSupport;
3232
import org.hibernate.dialect.pagination.DB2LimitHandler;
3333
import org.hibernate.dialect.pagination.LegacyDB2LimitHandler;
3434
import org.hibernate.dialect.pagination.LimitHandler;
@@ -812,21 +812,15 @@ public String getReadLockString(int timeout) {
812812
}
813813

814814
@Override
815-
public OuterJoinLockingType getOuterJoinLockingType() {
816-
return OuterJoinLockingType.UNSUPPORTED;
815+
public LockingSupport getLockingSupport() {
816+
return NoLockingSupport.NO_LOCKING_SUPPORT;
817817
}
818818

819819
@Override
820820
public boolean supportsExistsInSelect() {
821821
return false;
822822
}
823823

824-
@Override
825-
public LockTimeoutStyle getLockTimeoutStyle(Timeout timeout) {
826-
//as far as I know, DB2 doesn't support this
827-
return LockTimeoutStyle.NONE;
828-
}
829-
830824
@Override
831825
public boolean requiresCastForConcatenatingNonStrings() {
832826
return true;

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.sql.DatabaseMetaData;
8-
import java.sql.SQLException;
9-
import java.sql.Types;
10-
import java.util.Locale;
11-
7+
import jakarta.persistence.TemporalType;
128
import jakarta.persistence.Timeout;
139
import org.hibernate.Locking;
1410
import org.hibernate.boot.model.FunctionContributions;
1511
import org.hibernate.boot.model.TypeContributions;
12+
import org.hibernate.community.dialect.function.DerbyLpadEmulation;
13+
import org.hibernate.community.dialect.function.DerbyRpadEmulation;
14+
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
15+
import org.hibernate.community.dialect.sequence.DerbySequenceSupport;
16+
import org.hibernate.community.dialect.sequence.SequenceInformationExtractorDerbyDatabaseImpl;
1617
import org.hibernate.dialect.DB2Dialect;
1718
import org.hibernate.dialect.DatabaseVersion;
1819
import org.hibernate.dialect.Dialect;
@@ -24,16 +25,12 @@
2425
import org.hibernate.dialect.function.ChrLiteralEmulation;
2526
import org.hibernate.dialect.function.CommonFunctionFactory;
2627
import org.hibernate.dialect.function.CountFunction;
27-
import org.hibernate.community.dialect.function.DerbyLpadEmulation;
28-
import org.hibernate.community.dialect.function.DerbyRpadEmulation;
2928
import org.hibernate.dialect.function.InsertSubstringOverlayEmulation;
3029
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
3130
import org.hibernate.dialect.identity.IdentityColumnSupport;
32-
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
33-
import org.hibernate.dialect.lock.spi.LockTimeoutStyle;
34-
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
31+
import org.hibernate.dialect.lock.internal.NoLockingSupport;
32+
import org.hibernate.dialect.lock.spi.LockingSupport;
3533
import org.hibernate.dialect.pagination.LimitHandler;
36-
import org.hibernate.community.dialect.sequence.DerbySequenceSupport;
3734
import org.hibernate.dialect.sequence.SequenceSupport;
3835
import org.hibernate.dialect.temptable.TemporaryTable;
3936
import org.hibernate.dialect.temptable.TemporaryTableKind;
@@ -52,13 +49,13 @@
5249
import org.hibernate.internal.util.JdbcExceptionHelper;
5350
import org.hibernate.metamodel.mapping.EntityMappingType;
5451
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
52+
import org.hibernate.query.common.TemporalUnit;
5553
import org.hibernate.query.sqm.CastType;
5654
import org.hibernate.query.sqm.IntervalType;
57-
import org.hibernate.query.common.TemporalUnit;
58-
import org.hibernate.query.sqm.mutation.spi.BeforeUseAction;
5955
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableMutationStrategy;
6056
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableInsertStrategy;
6157
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
58+
import org.hibernate.query.sqm.mutation.spi.BeforeUseAction;
6259
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
6360
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
6461
import org.hibernate.service.ServiceRegistry;
@@ -71,7 +68,6 @@
7168
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
7269
import org.hibernate.sql.ast.tree.Statement;
7370
import org.hibernate.sql.exec.spi.JdbcOperation;
74-
import org.hibernate.community.dialect.sequence.SequenceInformationExtractorDerbyDatabaseImpl;
7571
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
7672
import org.hibernate.type.BasicType;
7773
import org.hibernate.type.BasicTypeRegistry;
@@ -85,7 +81,10 @@
8581
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
8682
import org.hibernate.type.spi.TypeConfiguration;
8783

88-
import jakarta.persistence.TemporalType;
84+
import java.sql.DatabaseMetaData;
85+
import java.sql.SQLException;
86+
import java.sql.Types;
87+
import java.util.Locale;
8988

9089
import static org.hibernate.type.SqlTypes.BINARY;
9190
import static org.hibernate.type.SqlTypes.BLOB;
@@ -573,6 +572,11 @@ public boolean supportsCommentOn() {
573572
return false;
574573
}
575574

575+
@Override
576+
public LockingSupport getLockingSupport() {
577+
return NoLockingSupport.NO_LOCKING_SUPPORT;
578+
}
579+
576580
@Override
577581
protected LockingClauseStrategy buildLockingClauseStrategy(PessimisticLockKind lockKind, RowLockStrategy rowLockStrategy, Locking.Scope lockScope, int timeout) {
578582
return new DerbyLockingClauseStrategy( this, lockKind, rowLockStrategy, lockScope, timeout );
@@ -608,26 +612,12 @@ public String getReadLockString(int timeout) {
608612
return " for read only with rs";
609613
}
610614

611-
@Override
612-
public OuterJoinLockingType getOuterJoinLockingType() {
613-
//TODO: check this!
614-
return OuterJoinLockingType.UNSUPPORTED;
615-
}
616-
617615
@Override
618616
public boolean supportsExistsInSelect() {
619617
//TODO: check this!
620618
return false;
621619
}
622620

623-
@Override
624-
public LockTimeoutStyle getLockTimeoutStyle(Timeout timeout) {
625-
// To enable the lock timeout, we need a dedicated call
626-
// 'call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.locks.waitTimeout', '3')'
627-
// Even supporting that at the CONNECTION level would be tough
628-
return LockTimeoutStyle.NONE;
629-
}
630-
631621
@Override
632622
public boolean supportsCurrentTimestampSelection() {
633623
return true;

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.sql.DatabaseMetaData;
8-
import java.sql.SQLException;
9-
import java.sql.Types;
10-
7+
import jakarta.persistence.TemporalType;
118
import jakarta.persistence.Timeout;
129
import org.hibernate.Locking;
1310
import org.hibernate.boot.model.FunctionContributions;
1411
import org.hibernate.boot.model.TypeContributions;
12+
import org.hibernate.community.dialect.function.DerbyLpadEmulation;
13+
import org.hibernate.community.dialect.function.DerbyRpadEmulation;
14+
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
15+
import org.hibernate.community.dialect.sequence.DerbySequenceSupport;
16+
import org.hibernate.community.dialect.sequence.SequenceInformationExtractorDerbyDatabaseImpl;
1517
import org.hibernate.dialect.DB2Dialect;
1618
import org.hibernate.dialect.DatabaseVersion;
1719
import org.hibernate.dialect.Dialect;
@@ -23,17 +25,13 @@
2325
import org.hibernate.dialect.function.ChrLiteralEmulation;
2426
import org.hibernate.dialect.function.CommonFunctionFactory;
2527
import org.hibernate.dialect.function.CountFunction;
26-
import org.hibernate.community.dialect.function.DerbyLpadEmulation;
27-
import org.hibernate.community.dialect.function.DerbyRpadEmulation;
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.LockTimeoutStyle;
32-
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
31+
import org.hibernate.dialect.lock.internal.NoLockingSupport;
32+
import org.hibernate.dialect.lock.spi.LockingSupport;
3333
import org.hibernate.dialect.pagination.AbstractLimitHandler;
34-
import org.hibernate.community.dialect.pagination.DerbyLimitHandler;
3534
import org.hibernate.dialect.pagination.LimitHandler;
36-
import org.hibernate.community.dialect.sequence.DerbySequenceSupport;
3735
import org.hibernate.dialect.sequence.SequenceSupport;
3836
import org.hibernate.dialect.temptable.TemporaryTable;
3937
import org.hibernate.dialect.temptable.TemporaryTableKind;
@@ -50,13 +48,13 @@
5048
import org.hibernate.internal.util.JdbcExceptionHelper;
5149
import org.hibernate.metamodel.mapping.EntityMappingType;
5250
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
51+
import org.hibernate.query.common.TemporalUnit;
5352
import org.hibernate.query.sqm.CastType;
5453
import org.hibernate.query.sqm.IntervalType;
55-
import org.hibernate.query.common.TemporalUnit;
56-
import org.hibernate.query.sqm.mutation.spi.BeforeUseAction;
5754
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableMutationStrategy;
5855
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableInsertStrategy;
5956
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy;
57+
import org.hibernate.query.sqm.mutation.spi.BeforeUseAction;
6058
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
6159
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
6260
import org.hibernate.service.ServiceRegistry;
@@ -69,7 +67,6 @@
6967
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
7068
import org.hibernate.sql.ast.tree.Statement;
7169
import org.hibernate.sql.exec.spi.JdbcOperation;
72-
import org.hibernate.community.dialect.sequence.SequenceInformationExtractorDerbyDatabaseImpl;
7370
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
7471
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
7572
import org.hibernate.type.BasicType;
@@ -85,7 +82,9 @@
8582
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
8683
import org.hibernate.type.spi.TypeConfiguration;
8784

88-
import jakarta.persistence.TemporalType;
85+
import java.sql.DatabaseMetaData;
86+
import java.sql.SQLException;
87+
import java.sql.Types;
8988

9089
import static org.hibernate.type.SqlTypes.BINARY;
9190
import static org.hibernate.type.SqlTypes.BLOB;
@@ -615,9 +614,8 @@ public String getReadLockString(int timeout) {
615614
}
616615

617616
@Override
618-
public OuterJoinLockingType getOuterJoinLockingType() {
619-
//TODO: check this!
620-
return OuterJoinLockingType.UNSUPPORTED;
617+
public LockingSupport getLockingSupport() {
618+
return NoLockingSupport.NO_LOCKING_SUPPORT;
621619
}
622620

623621
@Override
@@ -626,14 +624,6 @@ public boolean supportsExistsInSelect() {
626624
return false;
627625
}
628626

629-
@Override
630-
public LockTimeoutStyle getLockTimeoutStyle(Timeout timeout) {
631-
// To enable the lock timeout, we need a dedicated call
632-
// 'call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.locks.waitTimeout', '3')'
633-
// Even supporting that at the CONNECTION level would be tough
634-
return LockTimeoutStyle.NONE;
635-
}
636-
637627
@Override
638628
public boolean supportsCurrentTimestampSelection() {
639629
return true;

0 commit comments

Comments
 (0)