Skip to content

Commit 98f06d4

Browse files
committed
remove deprecated operations of LockOptions
1 parent 71fe3ec commit 98f06d4

File tree

1 file changed

+18
-53
lines changed

1 file changed

+18
-53
lines changed

hibernate-core/src/main/java/org/hibernate/LockOptions.java

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.query.Query;
1919
import org.hibernate.query.spi.QueryOptions;
2020

21+
import static jakarta.persistence.PessimisticLockScope.NORMAL;
2122
import static java.util.Collections.emptySet;
2223
import static java.util.Collections.unmodifiableSet;
2324

@@ -138,7 +139,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable {
138139
private final boolean immutable;
139140
private LockMode lockMode;
140141
private int timeout;
141-
private boolean extendedScope;
142+
private PessimisticLockScope pessimisticLockScope;
142143
private Boolean followOnLocking;
143144
private Map<String, LockMode> aliasSpecificLockModes;
144145

@@ -150,6 +151,7 @@ public LockOptions() {
150151
immutable = false;
151152
lockMode = LockMode.NONE;
152153
timeout = WAIT_FOREVER;
154+
pessimisticLockScope = NORMAL;
153155
}
154156

155157
/**
@@ -162,6 +164,7 @@ public LockOptions(LockMode lockMode) {
162164
immutable = false;
163165
this.lockMode = lockMode;
164166
timeout = WAIT_FOREVER;
167+
pessimisticLockScope = NORMAL;
165168
}
166169

167170
/**
@@ -175,6 +178,7 @@ public LockOptions(LockMode lockMode, int timeout) {
175178
immutable = false;
176179
this.lockMode = lockMode;
177180
this.timeout = timeout;
181+
pessimisticLockScope = NORMAL;
178182
}
179183

180184
/**
@@ -189,7 +193,7 @@ public LockOptions(LockMode lockMode, int timeout, PessimisticLockScope scope) {
189193
immutable = false;
190194
this.lockMode = lockMode;
191195
this.timeout = timeout;
192-
this.extendedScope = scope == PessimisticLockScope.EXTENDED;
196+
this.pessimisticLockScope = scope;
193197
}
194198

195199
/**
@@ -199,6 +203,7 @@ private LockOptions(boolean immutable, LockMode lockMode) {
199203
this.immutable = immutable;
200204
this.lockMode = lockMode;
201205
timeout = WAIT_FOREVER;
206+
pessimisticLockScope = NORMAL;
202207
}
203208
/**
204209
* Determine of the lock options are empty.
@@ -210,7 +215,7 @@ public boolean isEmpty() {
210215
return lockMode == LockMode.NONE
211216
&& timeout == WAIT_FOREVER
212217
&& followOnLocking == null
213-
&& !extendedScope
218+
&& pessimisticLockScope == NORMAL
214219
&& !hasAliasSpecificLockModes();
215220
}
216221

@@ -232,7 +237,7 @@ public LockMode getLockMode() {
232237
*/
233238
public LockOptions setLockMode(LockMode lockMode) {
234239
if ( immutable ) {
235-
throw new UnsupportedOperationException("immutable global instance of LockMode");
240+
throw new UnsupportedOperationException("immutable global instance of LockOptions");
236241
}
237242
this.lockMode = lockMode;
238243
return this;
@@ -249,7 +254,7 @@ public LockOptions setLockMode(LockMode lockMode) {
249254
*/
250255
public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
251256
if ( immutable ) {
252-
throw new UnsupportedOperationException("immutable global instance of LockMode");
257+
throw new UnsupportedOperationException("immutable global instance of LockOptions");
253258
}
254259
if ( aliasSpecificLockModes == null ) {
255260
aliasSpecificLockModes = new LinkedHashMap<>();
@@ -413,7 +418,7 @@ public LockOptions setTimeOut(int timeout) {
413418
* @return the current {@link PessimisticLockScope}
414419
*/
415420
public PessimisticLockScope getLockScope() {
416-
return extendedScope ? PessimisticLockScope.EXTENDED : PessimisticLockScope.NORMAL;
421+
return pessimisticLockScope;
417422
}
418423

419424
/**
@@ -430,49 +435,9 @@ public PessimisticLockScope getLockScope() {
430435
*/
431436
public LockOptions setLockScope(PessimisticLockScope scope) {
432437
if ( immutable ) {
433-
throw new UnsupportedOperationException("immutable global instance of LockMode");
434-
}
435-
return setScope(scope==PessimisticLockScope.EXTENDED);
436-
}
437-
438-
/**
439-
* The current lock scope setting:
440-
* <ul>
441-
* <li>{@code true} means the lock extends to rows of owned
442-
* collections, but
443-
* <li>{@code false} means only the entity table and secondary
444-
* tables are locked.
445-
* </ul>
446-
*
447-
* @return {@code true} if the lock extends to owned associations
448-
*
449-
* @deprecated use {@link #getLockScope()}
450-
*/
451-
@Deprecated(since = "6.2", forRemoval = true)
452-
public boolean getScope() {
453-
return extendedScope;
454-
}
455-
456-
/**
457-
* Set the lock scope setting:
458-
* <ul>
459-
* <li>{@code true} means the lock extends to rows of owned
460-
* collections, but
461-
* <li>{@code false} means only the entity table and secondary
462-
* tables are locked.
463-
* </ul>
464-
*
465-
* @param scope the new scope setting
466-
* @return {@code this} for method chaining
467-
*
468-
* @deprecated use {@link #setLockScope(PessimisticLockScope)}
469-
*/
470-
@Deprecated(since = "6.2", forRemoval = true)
471-
public LockOptions setScope(boolean scope) {
472-
if ( immutable ) {
473-
throw new UnsupportedOperationException("immutable global instance of LockMode");
438+
throw new UnsupportedOperationException("immutable global instance of LockOptions");
474439
}
475-
this.extendedScope = scope;
440+
pessimisticLockScope = scope;
476441
return this;
477442
}
478443

@@ -505,7 +470,7 @@ public Boolean getFollowOnLocking() {
505470
*/
506471
public LockOptions setFollowOnLocking(Boolean followOnLocking) {
507472
if ( immutable ) {
508-
throw new UnsupportedOperationException("immutable global instance of LockMode");
473+
throw new UnsupportedOperationException("immutable global instance of LockOptions");
509474
}
510475
this.followOnLocking = followOnLocking;
511476
return this;
@@ -544,7 +509,7 @@ public LockOptions makeDefensiveCopy() {
544509
*/
545510
public void overlay(LockOptions lockOptions) {
546511
setLockMode( lockOptions.getLockMode() );
547-
setScope( lockOptions.getScope() );
512+
setLockScope( lockOptions.getLockScope() );
548513
setTimeOut( lockOptions.getTimeOut() );
549514
if ( lockOptions.aliasSpecificLockModes != null ) {
550515
lockOptions.aliasSpecificLockModes.forEach(this::setAliasSpecificLockMode);
@@ -563,7 +528,7 @@ public void overlay(LockOptions lockOptions) {
563528
*/
564529
public static LockOptions copy(LockOptions source, LockOptions destination) {
565530
destination.setLockMode( source.getLockMode() );
566-
destination.setScope( source.getScope() );
531+
destination.setLockScope( source.getLockScope() );
567532
destination.setTimeOut( source.getTimeOut() );
568533
if ( source.aliasSpecificLockModes != null ) {
569534
destination.aliasSpecificLockModes = new HashMap<>( source.aliasSpecificLockModes );
@@ -582,7 +547,7 @@ else if ( !(object instanceof LockOptions that) ) {
582547
}
583548
else {
584549
return timeout == that.timeout
585-
&& extendedScope == that.extendedScope
550+
&& pessimisticLockScope == that.pessimisticLockScope
586551
&& lockMode == that.lockMode
587552
&& Objects.equals( aliasSpecificLockModes, that.aliasSpecificLockModes )
588553
&& Objects.equals( followOnLocking, that.followOnLocking );
@@ -591,6 +556,6 @@ else if ( !(object instanceof LockOptions that) ) {
591556

592557
@Override
593558
public int hashCode() {
594-
return Objects.hash( lockMode, timeout, aliasSpecificLockModes, followOnLocking, extendedScope);
559+
return Objects.hash( lockMode, timeout, aliasSpecificLockModes, followOnLocking, pessimisticLockScope );
595560
}
596561
}

0 commit comments

Comments
 (0)