44 */
55package org .hibernate .dialect .lock .internal ;
66
7+ import jakarta .persistence .Timeout ;
8+ import org .hibernate .Timeouts ;
79import org .hibernate .dialect .lock .spi .ConnectionLockTimeoutStrategy ;
10+ import org .hibernate .dialect .lock .spi .LockTimeoutType ;
811import org .hibernate .dialect .lock .spi .LockingSupport ;
912import org .hibernate .dialect .lock .spi .OuterJoinLockingType ;
1013
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+
1118/**
1219 * LockingSupport for H2Dialect
1320 *
1421 * @author Steve Ebersole
1522 */
1623public 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+ }
1832
1933 @ Override
2034 public Metadata getMetadata () {
@@ -26,6 +40,16 @@ public OuterJoinLockingType getOuterJoinLockingType() {
2640 return OuterJoinLockingType .IGNORED ;
2741 }
2842
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+
2953 @ Override
3054 public ConnectionLockTimeoutStrategy getConnectionLockTimeoutStrategy () {
3155 // while we can set the `LOCK_TIMEOUT` setting, there seems to be
0 commit comments