Skip to content

Commit a56b7e0

Browse files
committed
HHH-19551 - Address deficiencies in pessimistic locking
1 parent 00f0c68 commit a56b7e0

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ protected boolean supportsAliasLocks() {
291291
return false;
292292
}
293293

294+
@Override
295+
protected boolean supportsForShare() {
296+
//only supported on MySQL
297+
return false;
298+
}
299+
294300
/**
295301
* @return {@code true} for 10.5 and above because Maria supports
296302
* {@code insert ... returning} even though MySQL does not

hibernate-core/src/main/java/org/hibernate/dialect/lock/internal/MariaDBLockingSupport.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,36 @@
55
package org.hibernate.dialect.lock.internal;
66

77
import jakarta.persistence.Timeout;
8-
import org.hibernate.Timeouts;
98
import org.hibernate.dialect.DatabaseVersion;
109
import org.hibernate.dialect.lock.spi.ConnectionLockTimeoutStrategy;
1110
import org.hibernate.dialect.lock.spi.LockTimeoutType;
1211
import org.hibernate.dialect.lock.spi.LockingSupport;
1312
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
1413

14+
import static org.hibernate.Timeouts.NO_WAIT_MILLI;
15+
import static org.hibernate.Timeouts.SKIP_LOCKED_MILLI;
16+
import static org.hibernate.Timeouts.WAIT_FOREVER_MILLI;
1517
import static org.hibernate.dialect.lock.internal.MySQLLockingSupport.MYSQL_CONN_LOCK_TIMEOUT_STRATEGY;
18+
import static org.hibernate.dialect.lock.spi.LockTimeoutType.NONE;
19+
import static org.hibernate.dialect.lock.spi.LockTimeoutType.QUERY;
1620

1721
/**
1822
* LockingSupport for MariaDBDialect
1923
*
2024
* @author Steve Ebersole
2125
*/
2226
public class MariaDBLockingSupport implements LockingSupport, LockingSupport.Metadata {
23-
private final boolean supportsSkipLocked;
24-
private final boolean supportsNoWait;
25-
private final boolean supportsWait;
27+
private final LockTimeoutType skipLockedType;
28+
private final LockTimeoutType noWaitType;
29+
private final LockTimeoutType waitType;
2630

2731
public MariaDBLockingSupport(boolean supportsSkipLocked, boolean supportsNoWait, boolean supportsWait) {
28-
this.supportsSkipLocked = supportsSkipLocked;
29-
this.supportsNoWait = supportsNoWait;
30-
this.supportsWait = supportsWait;
32+
this.skipLockedType = supportsSkipLocked ? QUERY : NONE;
33+
this.noWaitType = supportsNoWait ? QUERY : NONE;
34+
// Real lock timeouts need to be applied on the Connection
35+
// todo (db-locking) : integrate connection-based lock timeouts. for now report NONE
36+
//this.waitType = supportsWait ? CONNECTION : NONE;
37+
this.waitType = NONE;
3138
}
3239

3340
public MariaDBLockingSupport(boolean supportsSkipLocked, boolean supportsWait) {
@@ -48,11 +55,12 @@ public Metadata getMetadata() {
4855

4956
@Override
5057
public LockTimeoutType getLockTimeoutType(Timeout timeout) {
51-
// MariaDB supports wait and no-wait, and skip-locked after 10.6
52-
if ( timeout.milliseconds() == Timeouts.SKIP_LOCKED_MILLI && !supportsSkipLocked ) {
53-
return LockTimeoutType.NONE;
54-
}
55-
return LockTimeoutType.QUERY;
58+
return switch ( timeout.milliseconds() ) {
59+
case NO_WAIT_MILLI -> noWaitType;
60+
case SKIP_LOCKED_MILLI -> skipLockedType;
61+
case WAIT_FOREVER_MILLI -> NONE;
62+
default -> waitType;
63+
};
5664
}
5765

5866
@Override

hibernate-core/src/main/java/org/hibernate/dialect/lock/internal/MySQLLockingSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public LockTimeoutType getLockTimeoutType(Timeout timeout) {
5454
case SKIP_LOCKED_MILLI, NO_WAIT_MILLI -> laterThanVersion8 ? QUERY : NONE;
5555
case WAIT_FOREVER_MILLI -> NONE;
5656
// For MySQL real lock timeouts need to be applied on the Connection
57-
default -> CONNECTION;
57+
//default -> CONNECTION;
58+
// todo (db-locking) : however, I have not yet integrated that stuff - so report NONE
59+
default -> NONE;
5860
};
5961
}
6062

0 commit comments

Comments
 (0)