Skip to content

Commit bf11c9b

Browse files
committed
HHH-19440 - Deprecate exposing of LockOptions
1 parent 2867b99 commit bf11c9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+850
-516
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import jakarta.persistence.EntityGraph;
1010

11+
import jakarta.persistence.PessimisticLockScope;
12+
import jakarta.persistence.Timeout;
1113
import org.hibernate.graph.GraphSemantic;
1214

1315
/**
@@ -44,14 +46,51 @@
4446
* @see Session#byId(Class)
4547
*/
4648
public interface IdentifierLoadAccess<T> {
49+
50+
/**
51+
* Specify the {@linkplain LockMode lock mode} to use when
52+
* querying the database.
53+
*
54+
* @param lockMode The lock mode to apply
55+
* @return {@code this}, for method chaining
56+
*/
57+
default IdentifierLoadAccess<T> with(LockMode lockMode) {
58+
return with( lockMode, PessimisticLockScope.NORMAL );
59+
}
60+
61+
/**
62+
* Specify the {@linkplain LockMode lock mode} to use when
63+
* querying the database.
64+
*
65+
* @param lockMode The lock mode to apply
66+
*
67+
* @return {@code this}, for method chaining
68+
*/
69+
IdentifierLoadAccess<T> with(LockMode lockMode, PessimisticLockScope lockScope);
70+
71+
/**
72+
* Specify the {@linkplain Timeout timeout} to use when
73+
* querying the database.
74+
*
75+
* @param timeout The timeout to apply to the database operation
76+
*
77+
* @return {@code this}, for method chaining
78+
*/
79+
IdentifierLoadAccess<T> with(Timeout timeout);
80+
4781
/**
4882
* Specify the {@linkplain LockOptions lock options} to use when
4983
* querying the database.
5084
*
5185
* @param lockOptions The lock options to use
5286
*
5387
* @return {@code this}, for method chaining
88+
*
89+
* @deprecated Use one of {@linkplain #with(LockMode)},
90+
* {@linkplain #with(LockMode, PessimisticLockScope)}
91+
* and/or {@linkplain #with(Timeout)} instead.
5492
*/
93+
@Deprecated(since = "7.0", forRemoval = true)
5594
IdentifierLoadAccess<T> with(LockOptions lockOptions);
5695

5796
/**

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,22 @@ public class LockOptions implements FindOption, RefreshOption, Serializable {
109109
public static final LockOptions UPGRADE = PESSIMISTIC_WRITE;
110110

111111
/**
112-
* Indicates that the database should not wait at all to acquire
113-
* a pessimistic lock which is not immediately available. This
114-
* has the same effect as {@link LockMode#UPGRADE_NOWAIT}.
115-
*
112+
* @see Timeouts#NO_WAIT_MILLI
113+
* @see Timeouts#NO_WAIT
116114
* @see #getTimeOut
117115
*/
118-
public static final int NO_WAIT = 0;
116+
public static final int NO_WAIT = Timeouts.NO_WAIT_MILLI;
119117

120118
/**
121-
* Indicates that there is no timeout for the lock acquisition,
122-
* that is, that the database should in principle wait forever
123-
* to obtain the lock.
124-
*
119+
* @see Timeouts#WAIT_FOREVER_MILLI
120+
* @see Timeouts#WAIT_FOREVER
125121
* @see #getTimeOut
126122
*/
127-
public static final int WAIT_FOREVER = -1;
123+
public static final int WAIT_FOREVER = Timeouts.WAIT_FOREVER_MILLI;
128124

129125
/**
130-
* Indicates that rows which are already locked should be skipped.
131-
*
126+
* @see Timeouts#SKIP_LOCKED_MILLI
127+
* @see Timeouts#SKIP_LOCKED
132128
* @see #getTimeOut()
133129
* @deprecated use {@link LockMode#UPGRADE_SKIPLOCKED}
134130
*/

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import jakarta.persistence.EntityGraph;
1010

11+
import jakarta.persistence.PessimisticLockScope;
12+
import jakarta.persistence.Timeout;
1113
import org.hibernate.graph.GraphSemantic;
1214

1315
/**
@@ -31,14 +33,51 @@
3133
* @author Steve Ebersole
3234
*/
3335
public interface MultiIdentifierLoadAccess<T> {
36+
37+
/**
38+
* Specify the {@linkplain LockMode lock mode} to use when
39+
* querying the database.
40+
*
41+
* @param lockMode The lock mode to apply
42+
* @return {@code this}, for method chaining
43+
*/
44+
default MultiIdentifierLoadAccess<T> with(LockMode lockMode) {
45+
return with( lockMode, PessimisticLockScope.NORMAL );
46+
}
47+
48+
/**
49+
* Specify the {@linkplain LockMode lock mode} to use when
50+
* querying the database.
51+
*
52+
* @param lockMode The lock mode to apply
53+
*
54+
* @return {@code this}, for method chaining
55+
*/
56+
MultiIdentifierLoadAccess<T> with(LockMode lockMode, PessimisticLockScope lockScope);
57+
58+
/**
59+
* Specify the {@linkplain Timeout timeout} to use when
60+
* querying the database.
61+
*
62+
* @param timeout The timeout to apply to the database operation
63+
*
64+
* @return {@code this}, for method chaining
65+
*/
66+
MultiIdentifierLoadAccess<T> with(Timeout timeout);
67+
3468
/**
3569
* Specify the {@linkplain LockOptions lock options} to use when
3670
* querying the database.
3771
*
3872
* @param lockOptions The lock options to use
3973
*
4074
* @return {@code this}, for method chaining
75+
*
76+
* @deprecated Use one of {@linkplain #with(LockMode)},
77+
* {@linkplain #with(LockMode, PessimisticLockScope)}
78+
* and/or {@linkplain #with(Timeout)} instead.
4179
*/
80+
@Deprecated(since = "7.0", forRemoval = true)
4281
MultiIdentifierLoadAccess<T> with(LockOptions lockOptions);
4382

4483
/**

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import jakarta.persistence.EntityGraph;
88

9+
import jakarta.persistence.PessimisticLockScope;
10+
import jakarta.persistence.Timeout;
911
import jakarta.persistence.metamodel.SingularAttribute;
1012
import org.hibernate.graph.GraphSemantic;
1113

@@ -35,14 +37,51 @@
3537
* @see SimpleNaturalIdLoadAccess
3638
*/
3739
public interface NaturalIdLoadAccess<T> {
40+
41+
/**
42+
* Specify the {@linkplain LockMode lock mode} to use when
43+
* querying the database.
44+
*
45+
* @param lockMode The lock mode to apply
46+
* @return {@code this}, for method chaining
47+
*/
48+
default NaturalIdLoadAccess<T> with(LockMode lockMode) {
49+
return with( lockMode, PessimisticLockScope.NORMAL );
50+
}
51+
52+
/**
53+
* Specify the {@linkplain LockMode lock mode} to use when
54+
* querying the database.
55+
*
56+
* @param lockMode The lock mode to apply
57+
*
58+
* @return {@code this}, for method chaining
59+
*/
60+
NaturalIdLoadAccess<T> with(LockMode lockMode, PessimisticLockScope lockScope);
61+
62+
/**
63+
* Specify the {@linkplain Timeout timeout} to use when
64+
* querying the database.
65+
*
66+
* @param timeout The timeout to apply to the database operation
67+
*
68+
* @return {@code this}, for method chaining
69+
*/
70+
NaturalIdLoadAccess<T> with(Timeout timeout);
71+
3872
/**
3973
* Specify the {@linkplain LockOptions lock options} to use when
4074
* querying the database.
4175
*
4276
* @param lockOptions The lock options to use.
4377
*
4478
* @return {@code this}, for method chaining
79+
*
80+
* @deprecated Use one of {@linkplain #with(LockMode)},
81+
* {@linkplain #with(LockMode, PessimisticLockScope)}
82+
* and/or {@linkplain #with(Timeout)} instead.
4583
*/
84+
@Deprecated(since = "7.0", forRemoval = true)
4685
NaturalIdLoadAccess<T> with(LockOptions lockOptions);
4786

4887
/**

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import jakarta.persistence.EntityGraph;
88

9+
import jakarta.persistence.PessimisticLockScope;
10+
import jakarta.persistence.Timeout;
911
import org.hibernate.graph.GraphSemantic;
1012

1113
import java.util.List;
@@ -36,14 +38,51 @@
3638
* @see org.hibernate.annotations.NaturalId
3739
*/
3840
public interface NaturalIdMultiLoadAccess<T> {
41+
42+
/**
43+
* Specify the {@linkplain LockMode lock mode} to use when
44+
* querying the database.
45+
*
46+
* @param lockMode The lock mode to apply
47+
* @return {@code this}, for method chaining
48+
*/
49+
default NaturalIdMultiLoadAccess<T> with(LockMode lockMode) {
50+
return with( lockMode, PessimisticLockScope.NORMAL );
51+
}
52+
53+
/**
54+
* Specify the {@linkplain LockMode lock mode} to use when
55+
* querying the database.
56+
*
57+
* @param lockMode The lock mode to apply
58+
*
59+
* @return {@code this}, for method chaining
60+
*/
61+
NaturalIdMultiLoadAccess<T> with(LockMode lockMode, PessimisticLockScope lockScope);
62+
63+
/**
64+
* Specify the {@linkplain Timeout timeout} to use when
65+
* querying the database.
66+
*
67+
* @param timeout The timeout to apply to the database operation
68+
*
69+
* @return {@code this}, for method chaining
70+
*/
71+
NaturalIdMultiLoadAccess<T> with(Timeout timeout);
72+
3973
/**
4074
* Specify the {@linkplain LockOptions lock options} to use when
4175
* querying the database.
4276
*
4377
* @param lockOptions The lock options to use
4478
*
4579
* @return {@code this}, for method chaining
80+
*
81+
* @deprecated Use one of {@linkplain #with(LockMode)},
82+
* {@linkplain #with(LockMode, PessimisticLockScope)}
83+
* and/or {@linkplain #with(Timeout)} instead.
4684
*/
85+
@Deprecated(since = "7.0", forRemoval = true)
4786
NaturalIdMultiLoadAccess<T> with(LockOptions lockOptions);
4887

4988
/**

0 commit comments

Comments
 (0)