Skip to content

HHH-19667 Support H2 2.2.220 for update clause enhancements #10668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ public LimitHandler getLimitHandler() {

@Override
public LockingSupport getLockingSupport() {
return H2LockingSupport.H2_LOCKING_SUPPORT;
return getVersion().isSameOrAfter( 2, 2, 220 ) ? H2LockingSupport.INSTANCE : H2LockingSupport.LEGACY_INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public LimitHandler getLimitHandler() {

@Override
public LockingSupport getLockingSupport() {
return H2LockingSupport.H2_LOCKING_SUPPORT;
return getVersion().isSameOrAfter( 2, 2, 220 ) ? H2LockingSupport.INSTANCE : H2LockingSupport.LEGACY_INSTANCE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@
*/
package org.hibernate.dialect.lock.internal;

import jakarta.persistence.Timeout;
import org.hibernate.Timeouts;
import org.hibernate.dialect.lock.spi.ConnectionLockTimeoutStrategy;
import org.hibernate.dialect.lock.spi.LockTimeoutType;
import org.hibernate.dialect.lock.spi.LockingSupport;
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;

import static org.hibernate.Timeouts.NO_WAIT_MILLI;
import static org.hibernate.Timeouts.SKIP_LOCKED_MILLI;
import static org.hibernate.dialect.lock.spi.LockTimeoutType.QUERY;

/**
* LockingSupport for H2Dialect
*
* @author Steve Ebersole
*/
public class H2LockingSupport implements LockingSupport, LockingSupport.Metadata {
public static final H2LockingSupport H2_LOCKING_SUPPORT = new H2LockingSupport();
public static final H2LockingSupport LEGACY_INSTANCE = new H2LockingSupport( false );
public static final H2LockingSupport INSTANCE = new H2LockingSupport( true );

private final boolean supportsForUpdateOptions;

private H2LockingSupport(boolean supportsForUpdateOptions) {
this.supportsForUpdateOptions = supportsForUpdateOptions;
}

@Override
public Metadata getMetadata() {
Expand All @@ -26,6 +40,16 @@ public OuterJoinLockingType getOuterJoinLockingType() {
return OuterJoinLockingType.IGNORED;
}

@Override
public LockTimeoutType getLockTimeoutType(Timeout timeout) {
return switch ( timeout.milliseconds() ) {
case NO_WAIT_MILLI -> supportsForUpdateOptions ? QUERY : LockTimeoutType.NONE;
case SKIP_LOCKED_MILLI -> supportsForUpdateOptions ? QUERY : LockTimeoutType.NONE;
case Timeouts.WAIT_FOREVER_MILLI -> LockTimeoutType.QUERY;
default -> LockTimeoutType.NONE;
};
}

@Override
public ConnectionLockTimeoutStrategy getConnectionLockTimeoutStrategy() {
// while we can set the `LOCK_TIMEOUT` setting, there seems to be
Expand Down