diff --git a/hibernate-core/src/main/java/org/hibernate/LockOptions.java b/hibernate-core/src/main/java/org/hibernate/LockOptions.java index f59ea5d16a..f85c526d28 100644 --- a/hibernate-core/src/main/java/org/hibernate/LockOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/LockOptions.java @@ -140,7 +140,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { private final boolean immutable; private LockMode lockMode; private int timeout; - private boolean scope; + private boolean extendedScope; private Boolean followOnLocking; private Map aliasSpecificLockModes; @@ -191,7 +191,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { immutable = false; this.lockMode = lockMode; this.timeout = timeout; - this.scope = scope == PessimisticLockScope.EXTENDED; + this.extendedScope = scope == PessimisticLockScope.EXTENDED; } /** @@ -212,7 +212,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { return lockMode == LockMode.NONE && timeout == WAIT_FOREVER && followOnLocking == null - && !scope + && !extendedScope && !hasAliasSpecificLockModes(); } @@ -415,7 +415,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { * @return the current {@link PessimisticLockScope} */ public PessimisticLockScope getLockScope() { - return scope ? PessimisticLockScope.EXTENDED : PessimisticLockScope.NORMAL; + return extendedScope ? PessimisticLockScope.EXTENDED : PessimisticLockScope.NORMAL; } /** @@ -450,9 +450,9 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { * * @deprecated use {@link #getLockScope()} */ - @Deprecated(since = "6.2") + @Deprecated(since = "6.2", forRemoval = true) public boolean getScope() { - return scope; + return extendedScope; } /** @@ -469,12 +469,12 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { * * @deprecated use {@link #setLockScope(PessimisticLockScope)} */ - @Deprecated(since = "6.2") + @Deprecated(since = "6.2", forRemoval = true) public LockOptions setScope(boolean scope) { if ( immutable ) { throw new UnsupportedOperationException("immutable global instance of LockMode"); } - this.scope = scope; + this.extendedScope = scope; return this; } @@ -579,13 +579,12 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { if ( this == object ) { return true; } - else if ( !(object instanceof LockOptions) ) { + else if ( !(object instanceof LockOptions that) ) { return false; } else { - final LockOptions that = (LockOptions) object; return timeout == that.timeout - && scope == that.scope + && extendedScope == that.extendedScope && lockMode == that.lockMode && Objects.equals( aliasSpecificLockModes, that.aliasSpecificLockModes ) && Objects.equals( followOnLocking, that.followOnLocking ); @@ -594,6 +593,6 @@ public class LockOptions implements FindOption, RefreshOption, Serializable { @Override public int hashCode() { - return Objects.hash( lockMode, timeout, aliasSpecificLockModes, followOnLocking, scope ); + return Objects.hash( lockMode, timeout, aliasSpecificLockModes, followOnLocking, extendedScope); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java b/hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java index da4ce3544a..e12370baf3 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java +++ b/hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java @@ -6,6 +6,7 @@ */ package org.hibernate.event.spi; +import jakarta.persistence.PessimisticLockScope; import org.hibernate.LockMode; import org.hibernate.LockOptions; @@ -130,11 +131,11 @@ public class LoadEvent extends AbstractEvent { } public int getLockTimeout() { - return this.lockOptions.getTimeOut(); + return lockOptions.getTimeOut(); } public boolean getLockScope() { - return this.lockOptions.getScope(); + return lockOptions.getLockScope() == PessimisticLockScope.EXTENDED; } public Object getResult() { diff --git a/hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java b/hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java index 367bc2f7ab..0ba58b5820 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java +++ b/hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java @@ -6,6 +6,7 @@ */ package org.hibernate.event.spi; +import jakarta.persistence.PessimisticLockScope; import org.hibernate.LockMode; import org.hibernate.LockOptions; @@ -63,7 +64,7 @@ public class LockEvent extends AbstractEvent { } public boolean getLockScope() { - return lockOptions.getScope(); + return lockOptions.getLockScope() == PessimisticLockScope.EXTENDED; } public String getEntityName() { diff --git a/hibernate-core/src/main/java/org/hibernate/event/spi/RefreshEvent.java b/hibernate-core/src/main/java/org/hibernate/event/spi/RefreshEvent.java index 0c0a20bbd1..109a2c3c10 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/spi/RefreshEvent.java +++ b/hibernate-core/src/main/java/org/hibernate/event/spi/RefreshEvent.java @@ -6,6 +6,7 @@ */ package org.hibernate.event.spi; +import jakarta.persistence.PessimisticLockScope; import org.hibernate.LockMode; import org.hibernate.LockOptions; @@ -80,10 +81,10 @@ public class RefreshEvent extends AbstractEvent { } public int getLockTimeout() { - return this.lockOptions.getTimeOut(); + return lockOptions.getTimeOut(); } public boolean getLockScope() { - return this.lockOptions.getScope(); + return lockOptions.getLockScope() == PessimisticLockScope.EXTENDED; } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/LockOptionsHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/LockOptionsHelper.java index 7cd7ac7e4e..11f04c530f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/LockOptionsHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/LockOptionsHelper.java @@ -14,6 +14,7 @@ import jakarta.persistence.PessimisticLockScope; import org.hibernate.LockOptions; import static jakarta.persistence.PessimisticLockScope.EXTENDED; +import static jakarta.persistence.PessimisticLockScope.NORMAL; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_SCOPE; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE; @@ -47,10 +48,10 @@ final class LockOptionsHelper { } if ( lockScope instanceof String string ) { - lockOptions.get().setScope( EXTENDED.name().equalsIgnoreCase( string ) ); + lockOptions.get().setLockScope( EXTENDED.name().equalsIgnoreCase( string ) ? EXTENDED : NORMAL ); } - else if ( lockScope instanceof PessimisticLockScope ) { - lockOptions.get().setScope( EXTENDED == lockScope ); + else if ( lockScope instanceof PessimisticLockScope pessimisticLockScope ) { + lockOptions.get().setLockScope( pessimisticLockScope ); } else if ( lockScope != null ) { throw new PersistenceException( "Unable to parse " + lockScopeHint + ": " + lockScope ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index ce56398383..7011442a30 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -22,6 +22,7 @@ import jakarta.persistence.EntityGraph; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; import jakarta.persistence.Parameter; +import jakarta.persistence.PessimisticLockScope; import jakarta.persistence.TemporalType; import org.hibernate.CacheMode; @@ -349,7 +350,7 @@ public abstract class AbstractQuery hints.put( HINT_JAVAEE_LOCK_TIMEOUT, getLockOptions().getTimeOut() ); } - if ( getLockOptions().getScope() ) { + if ( getLockOptions().getLockScope() == PessimisticLockScope.EXTENDED ) { hints.put( HINT_SPEC_LOCK_SCOPE, getLockOptions().getLockScope() ); hints.put( HINT_JAVAEE_LOCK_SCOPE, getLockOptions().getLockScope() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DeferredResultSetAccess.java b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DeferredResultSetAccess.java index 8965fb2603..cebd72306f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DeferredResultSetAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DeferredResultSetAccess.java @@ -113,7 +113,7 @@ public class DeferredResultSetAccess extends AbstractResultSetAccess { final LockOptions lockOptionsToUse = new LockOptions( lockMode ); lockOptionsToUse.setTimeOut( lockOptions.getTimeOut() ); - lockOptionsToUse.setScope( lockOptions.getScope() ); + lockOptionsToUse.setLockScope( lockOptions.getLockScope() ); executionContext.getCallback().registerAfterLoadAction( (entity, persister, session) -> session.asSessionImplementor().lock(