avoid use of deprecated methods

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-09-01 16:32:50 +02:00
parent f95182e736
commit 335f7bea9c
7 changed files with 26 additions and 22 deletions

View File

@ -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<String, LockMode> 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);
}
}

View File

@ -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() {

View File

@ -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() {

View File

@ -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;
}
}

View File

@ -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 );

View File

@ -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<R>
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() );
}

View File

@ -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(