Skip to content

Commit 7bd857c

Browse files
committed
HHH-19440 - Deprecate exposing of LockOptions
1 parent d7c6c6a commit 7bd857c

File tree

2 files changed

+153
-102
lines changed

2 files changed

+153
-102
lines changed

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
* @author Gavin King
3939
*
4040
* @see Session#lock(Object, LockMode)
41+
* @see Session#lock(Object, LockMode, jakarta.persistence.LockOption...)
42+
* @see Session#find(Class, Object, FindOption...)
43+
* @see Session#refresh(Object, RefreshOption...)
4144
* @see LockModeType
42-
* @see LockOptions
4345
* @see org.hibernate.annotations.OptimisticLocking
4446
*/
4547
public enum LockMode implements FindOption, RefreshOption {
@@ -113,25 +115,6 @@ public enum LockMode implements FindOption, RefreshOption {
113115
@Internal
114116
WRITE,
115117

116-
/**
117-
* A pessimistic upgrade lock, obtained using an Oracle-style
118-
* {@code select for update nowait}. The semantics of this
119-
* lock mode, if the lock is successfully obtained, are the same
120-
* as {@link #PESSIMISTIC_WRITE}. If the lock is not immediately
121-
* available, an exception occurs.
122-
*/
123-
UPGRADE_NOWAIT,
124-
125-
/**
126-
* A pessimistic upgrade lock, obtained using an Oracle-style
127-
* {@code select for update skip locked}. The semantics of this
128-
* lock mode, if the lock is successfully obtained, are the same
129-
* as {@link #PESSIMISTIC_WRITE}. But if the lock is not
130-
* immediately available, no exception occurs, but the locked
131-
* row is not returned from the database.
132-
*/
133-
UPGRADE_SKIPLOCKED,
134-
135118
/**
136119
* A pessimistic shared lock, which prevents concurrent
137120
* transactions from writing the locked object. Obtained via
@@ -164,7 +147,34 @@ public enum LockMode implements FindOption, RefreshOption {
164147
*
165148
* @see LockModeType#PESSIMISTIC_FORCE_INCREMENT
166149
*/
167-
PESSIMISTIC_FORCE_INCREMENT;
150+
PESSIMISTIC_FORCE_INCREMENT,
151+
152+
/**
153+
* A pessimistic upgrade lock, obtained using an Oracle-style
154+
* {@code select for update nowait}. The semantics of this
155+
* lock mode, if the lock is successfully obtained, are the same
156+
* as {@link #PESSIMISTIC_WRITE}. If the lock is not immediately
157+
* available, an exception occurs.
158+
*
159+
* @apiNote To be removed in a future version. A different approach to
160+
* specifying handling for locked rows will be introduced.
161+
*/
162+
@Remove
163+
UPGRADE_NOWAIT,
164+
165+
/**
166+
* A pessimistic upgrade lock, obtained using an Oracle-style
167+
* {@code select for update skip locked}. The semantics of this
168+
* lock mode, if the lock is successfully obtained, are the same
169+
* as {@link #PESSIMISTIC_WRITE}. But if the lock is not
170+
* immediately available, no exception occurs, but the locked
171+
* row is not returned from the database.
172+
*
173+
* @apiNote To be removed in a future version. A different approach to
174+
* specifying handling for locked rows will be introduced.
175+
*/
176+
@Remove
177+
UPGRADE_SKIPLOCKED;
168178

169179
/**
170180
* @return an instance with the same semantics as the given JPA
@@ -273,9 +283,11 @@ public static LockMode fromExternalForm(String externalForm) {
273283
}
274284

275285
/**
276-
* @return an instance of {@link LockOptions} with this lock mode, and
277-
* all other settings defaulted.
286+
* @return an instance of {@link LockOptions} with this lock mode, and all other settings defaulted.
287+
*
288+
* @deprecated As LockOptions will become an SPI, this method will be removed with no replacement
278289
*/
290+
@Deprecated(since = "7", forRemoval = true)
279291
public LockOptions toLockOptions() {
280292
return switch (this) {
281293
case NONE -> LockOptions.NONE;

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

Lines changed: 118 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -76,86 +76,8 @@
7676
*
7777
* @author Scott Marlow
7878
*/
79-
@Deprecated(since = "7.0", forRemoval = true) // moving to an SPI package
79+
@Deprecated(since = "7", forRemoval = true) // moving to an SPI package
8080
public class LockOptions implements Serializable {
81-
/**
82-
* Represents {@link LockMode#NONE}, to which timeout and scope are
83-
* not applicable.
84-
*/
85-
public static final LockOptions NONE = new LockOptions( true, LockMode.NONE );
86-
87-
/**
88-
* Represents {@link LockMode#READ}, to which timeout and scope are
89-
* not applicable.
90-
*/
91-
public static final LockOptions READ = new LockOptions( true, LockMode.READ );
92-
93-
/**
94-
* Represents {@link LockMode#OPTIMISTIC}.
95-
*/
96-
static final LockOptions OPTIMISTIC = new LockOptions( true, LockMode.OPTIMISTIC );
97-
98-
/**
99-
* Represents {@link LockMode#OPTIMISTIC_FORCE_INCREMENT}, to which
100-
* timeout and scope are not applicable.
101-
*/
102-
static final LockOptions OPTIMISTIC_FORCE_INCREMENT = new LockOptions( true, LockMode.OPTIMISTIC_FORCE_INCREMENT );
103-
104-
/**
105-
* Represents {@link LockMode#PESSIMISTIC_READ}.
106-
*/
107-
static final LockOptions PESSIMISTIC_READ = new LockOptions( true, LockMode.PESSIMISTIC_READ );
108-
109-
/**
110-
* Represents {@link LockMode#PESSIMISTIC_WRITE}.
111-
*/
112-
static final LockOptions PESSIMISTIC_WRITE = new LockOptions( true, LockMode.PESSIMISTIC_WRITE );
113-
114-
/**
115-
* Represents {@link LockMode#PESSIMISTIC_FORCE_INCREMENT}.
116-
*/
117-
static final LockOptions PESSIMISTIC_FORCE_INCREMENT = new LockOptions( true, LockMode.PESSIMISTIC_FORCE_INCREMENT );
118-
119-
/**
120-
* Represents {@link LockMode#UPGRADE_NOWAIT}.
121-
*/
122-
static final LockOptions UPGRADE_NOWAIT = new LockOptions( true, LockMode.UPGRADE_NOWAIT );
123-
124-
/**
125-
* Represents {@link LockMode#UPGRADE_SKIPLOCKED}.
126-
*/
127-
static final LockOptions UPGRADE_SKIPLOCKED = new LockOptions( true, LockMode.UPGRADE_SKIPLOCKED );
128-
129-
/**
130-
* Represents {@link LockMode#PESSIMISTIC_WRITE} with
131-
* {@linkplain #WAIT_FOREVER no timeout}, and
132-
* {@linkplain PessimisticLockScope#NORMAL no extension of the
133-
* lock to owned collections}.
134-
*/
135-
public static final LockOptions UPGRADE = PESSIMISTIC_WRITE;
136-
137-
/**
138-
* @see Timeouts#NO_WAIT_MILLI
139-
* @see Timeouts#NO_WAIT
140-
* @see #getTimeOut
141-
*/
142-
public static final int NO_WAIT = Timeouts.NO_WAIT_MILLI;
143-
144-
/**
145-
* @see Timeouts#WAIT_FOREVER_MILLI
146-
* @see Timeouts#WAIT_FOREVER
147-
* @see #getTimeOut
148-
*/
149-
public static final int WAIT_FOREVER = Timeouts.WAIT_FOREVER_MILLI;
150-
151-
/**
152-
* @see Timeouts#SKIP_LOCKED_MILLI
153-
* @see Timeouts#SKIP_LOCKED
154-
* @see #getTimeOut()
155-
* @deprecated use {@link LockMode#UPGRADE_SKIPLOCKED}
156-
*/
157-
@Deprecated(since = "6.2", forRemoval = true)
158-
public static final int SKIP_LOCKED = -2;
15981

16082
private final boolean immutable;
16183
private LockMode lockMode;
@@ -662,4 +584,121 @@ public LockMode findGreatestLockMode() {
662584

663585
return lockModeToUse;
664586
}
587+
588+
589+
/**
590+
* Represents {@link LockMode#NONE}, to which timeout and scope are
591+
* not applicable.
592+
*
593+
* @deprecated This, and the other constants on this class, will be removed.
594+
*/
595+
@Deprecated(since = "7", forRemoval = true)
596+
public static final LockOptions NONE = new LockOptions( true, LockMode.NONE );
597+
598+
/**
599+
* Represents {@link LockMode#READ}, to which timeout and scope are
600+
* not applicable.
601+
*
602+
* @deprecated This, and the other constants on this class, will be removed.
603+
*/
604+
@Deprecated(since = "7", forRemoval = true)
605+
public static final LockOptions READ = new LockOptions( true, LockMode.READ );
606+
607+
/**
608+
* Represents {@link LockMode#OPTIMISTIC}.
609+
*
610+
* @deprecated This, and the other constants on this class, will be removed.
611+
*/
612+
@Deprecated(since = "7", forRemoval = true)
613+
static final LockOptions OPTIMISTIC = new LockOptions( true, LockMode.OPTIMISTIC );
614+
615+
/**
616+
* Represents {@link LockMode#OPTIMISTIC_FORCE_INCREMENT}, to which
617+
* timeout and scope are not applicable.
618+
*
619+
* @deprecated This, and the other constants on this class, will be removed.
620+
*/
621+
@Deprecated(since = "7", forRemoval = true)
622+
static final LockOptions OPTIMISTIC_FORCE_INCREMENT = new LockOptions( true, LockMode.OPTIMISTIC_FORCE_INCREMENT );
623+
624+
/**
625+
* Represents {@link LockMode#PESSIMISTIC_READ}.
626+
*
627+
* @deprecated This, and the other constants on this class, will be removed.
628+
*/
629+
@Deprecated(since = "7", forRemoval = true)
630+
static final LockOptions PESSIMISTIC_READ = new LockOptions( true, LockMode.PESSIMISTIC_READ );
631+
632+
/**
633+
* Represents {@link LockMode#PESSIMISTIC_WRITE}.
634+
*
635+
* @deprecated This, and the other constants on this class, will be removed.
636+
*/
637+
@Deprecated(since = "7", forRemoval = true)
638+
static final LockOptions PESSIMISTIC_WRITE = new LockOptions( true, LockMode.PESSIMISTIC_WRITE );
639+
640+
/**
641+
* Represents {@link LockMode#PESSIMISTIC_FORCE_INCREMENT}.
642+
*
643+
* @deprecated This, and the other constants on this class, will be removed.
644+
*/
645+
@Deprecated(since = "7", forRemoval = true)
646+
static final LockOptions PESSIMISTIC_FORCE_INCREMENT = new LockOptions( true, LockMode.PESSIMISTIC_FORCE_INCREMENT );
647+
648+
/**
649+
* Represents {@link LockMode#UPGRADE_NOWAIT}.
650+
*
651+
* @deprecated This, and the other constants on this class, will be removed.
652+
*/
653+
@Deprecated(since = "7", forRemoval = true)
654+
static final LockOptions UPGRADE_NOWAIT = new LockOptions( true, LockMode.UPGRADE_NOWAIT );
655+
656+
/**
657+
* Represents {@link LockMode#UPGRADE_SKIPLOCKED}.
658+
*
659+
* @deprecated This, and the other constants on this class, will be removed.
660+
*/
661+
@Deprecated(since = "7", forRemoval = true)
662+
static final LockOptions UPGRADE_SKIPLOCKED = new LockOptions( true, LockMode.UPGRADE_SKIPLOCKED );
663+
664+
/**
665+
* Represents {@link LockMode#PESSIMISTIC_WRITE} with
666+
* {@linkplain #WAIT_FOREVER no timeout}, and
667+
* {@linkplain PessimisticLockScope#NORMAL no extension of the
668+
* lock to owned collections}.
669+
*
670+
* @deprecated This, and the other constants on this class, will be removed.
671+
*/
672+
@Deprecated(since = "7", forRemoval = true)
673+
public static final LockOptions UPGRADE = PESSIMISTIC_WRITE;
674+
675+
/**
676+
* @see Timeouts#NO_WAIT_MILLI
677+
* @see Timeouts#NO_WAIT
678+
* @see #getTimeOut
679+
*
680+
* @deprecated This, and the other constants on this class, will be removed.
681+
*/
682+
@Deprecated(since = "7", forRemoval = true)
683+
public static final int NO_WAIT = Timeouts.NO_WAIT_MILLI;
684+
685+
/**
686+
* @see Timeouts#WAIT_FOREVER_MILLI
687+
* @see Timeouts#WAIT_FOREVER
688+
* @see #getTimeOut
689+
*
690+
* @deprecated This, and the other constants on this class, will be removed.
691+
*/
692+
@Deprecated(since = "7", forRemoval = true)
693+
public static final int WAIT_FOREVER = Timeouts.WAIT_FOREVER_MILLI;
694+
695+
/**
696+
* @see Timeouts#SKIP_LOCKED_MILLI
697+
* @see Timeouts#SKIP_LOCKED
698+
* @see #getTimeOut()
699+
*
700+
* @deprecated This, and the other constants on this class, will be removed.
701+
*/
702+
@Deprecated(since = "6.2", forRemoval = true)
703+
public static final int SKIP_LOCKED = -2;
665704
}

0 commit comments

Comments
 (0)