4
4
*/
5
5
package org .hibernate .dialect .lock .internal ;
6
6
7
+ import jakarta .persistence .Timeout ;
8
+ import org .hibernate .Timeouts ;
7
9
import org .hibernate .dialect .lock .spi .ConnectionLockTimeoutStrategy ;
10
+ import org .hibernate .dialect .lock .spi .LockTimeoutType ;
8
11
import org .hibernate .dialect .lock .spi .LockingSupport ;
9
12
import org .hibernate .dialect .lock .spi .OuterJoinLockingType ;
10
13
14
+ import static org .hibernate .Timeouts .NO_WAIT_MILLI ;
15
+ import static org .hibernate .Timeouts .SKIP_LOCKED_MILLI ;
16
+ import static org .hibernate .dialect .lock .spi .LockTimeoutType .QUERY ;
17
+
11
18
/**
12
19
* LockingSupport for H2Dialect
13
20
*
14
21
* @author Steve Ebersole
15
22
*/
16
23
public class H2LockingSupport implements LockingSupport , LockingSupport .Metadata {
17
- public static final H2LockingSupport H2_LOCKING_SUPPORT = new H2LockingSupport ();
24
+ public static final H2LockingSupport LEGACY_INSTANCE = new H2LockingSupport ( false );
25
+ public static final H2LockingSupport INSTANCE = new H2LockingSupport ( true );
26
+
27
+ private final boolean supportsForUpdateOptions ;
28
+
29
+ private H2LockingSupport (boolean supportsForUpdateOptions ) {
30
+ this .supportsForUpdateOptions = supportsForUpdateOptions ;
31
+ }
18
32
19
33
@ Override
20
34
public Metadata getMetadata () {
@@ -26,6 +40,16 @@ public OuterJoinLockingType getOuterJoinLockingType() {
26
40
return OuterJoinLockingType .IGNORED ;
27
41
}
28
42
43
+ @ Override
44
+ public LockTimeoutType getLockTimeoutType (Timeout timeout ) {
45
+ return switch ( timeout .milliseconds () ) {
46
+ case NO_WAIT_MILLI -> supportsForUpdateOptions ? QUERY : LockTimeoutType .NONE ;
47
+ case SKIP_LOCKED_MILLI -> supportsForUpdateOptions ? QUERY : LockTimeoutType .NONE ;
48
+ case Timeouts .WAIT_FOREVER_MILLI -> LockTimeoutType .QUERY ;
49
+ default -> LockTimeoutType .NONE ;
50
+ };
51
+ }
52
+
29
53
@ Override
30
54
public ConnectionLockTimeoutStrategy getConnectionLockTimeoutStrategy () {
31
55
// while we can set the `LOCK_TIMEOUT` setting, there seems to be
0 commit comments