Package org.hibernate
Class LockOptions
java.lang.Object
org.hibernate.LockOptions
- All Implemented Interfaces:
Serializable
@Deprecated(since="7.0",
forRemoval=true)
public class LockOptions
extends Object
implements Serializable
Deprecated, for removal: This API element is subject to removal in a future version.
Contains a set of options describing how a row of a database table
mapped by an entity should be locked. For
Session.lock(Object, LockOptions),
Session.get(Class, Object, LockOptions), or
Session.refresh(Object, LockOptions), the relevant options
are:
- the lock mode,
- the pessimistic lock timeout, and
- the lock scope, that is, whether the lock extends to rows of owned collections.
Timeout and lock scope are ignored if the specified LockMode
represents a flavor of optimistic
locking.
In HQL and criteria queries, lock modes can be defined in an even more granular fashion, with the option to specify a lock mode that applies only to a certain query alias.
Finally, the use of follow-on locking may be force enabled or disabled,
overriding the default behavior of the SQL dialect by passing a non-null argument
to setFollowOnLocking(Boolean).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated, for removal: This API element is subject to removal in a future version.static final LockOptionsDeprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.NONE, to which timeout and scope are not applicable.static final LockOptionsDeprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.READ, to which timeout and scope are not applicable.static final intDeprecated, for removal: This API element is subject to removal in a future version.static final LockOptionsDeprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.PESSIMISTIC_WRITEwith no timeout, and no extension of the lock to owned collections.static final intDeprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Construct an instance with modeLockMode.NONEand no timeout.protectedLockOptions(boolean immutable, LockMode lockMode) Deprecated, for removal: This API element is subject to removal in a future version.Internal operation used to create immutable global instances.LockOptions(LockMode lockMode) Deprecated, for removal: This API element is subject to removal in a future version.Construct an instance with the given mode and no timeout.LockOptions(LockMode lockMode, int timeout) Deprecated.Use LockOptions(LockMode, Timeout) insteadLockOptions(LockMode lockMode, int timeout, PessimisticLockScope scope) Deprecated.LockOptions(LockMode lockMode, Timeout timeout) Deprecated, for removal: This API element is subject to removal in a future version.Construct an instance with the given mode and timeout.LockOptions(LockMode lockMode, Timeout timeout, PessimisticLockScope scope) -
Method Summary
Modifier and TypeMethodDescriptionstatic LockOptionscopy(LockOptions source, LockOptions destination) Deprecated, for removal: This API element is subject to removal in a future version.Copy the options in the first given instance ofLockOptionsto the second given instance.booleanDeprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Currently needed for follow-on locking.intDeprecated, for removal: This API element is subject to removal in a future version.The number of aliases that have alias-specific lock modes specified.Deprecated.getAliasSpecificLockMode(String alias) Deprecated, for removal: This API element is subject to removal in a future version.Get theLockModeexplicitly specified for the given alias viasetAliasSpecificLockMode(String, LockMode).Deprecated, for removal: This API element is subject to removal in a future version.getEffectiveLockMode(String alias) Deprecated, for removal: This API element is subject to removal in a future version.Determine theLockModeto apply to the given alias.Deprecated, for removal: This API element is subject to removal in a future version.Returns a value indicating if follow-on locking was force enabled or disabled, overriding the default behavior of the SQL dialect.Deprecated, for removal: This API element is subject to removal in a future version.Retrieve the overall lock mode in effect for this set of options.Deprecated, for removal: This API element is subject to removal in a future version.The current lock scope:PessimisticLockScope.EXTENDEDmeans the lock extends to rows of owned collections, butPessimisticLockScope.NORMALmeans only the entity table and secondary tables are locked.Deprecated, for removal: This API element is subject to removal in a future version.The timeout associated withthisoptions, defining a maximum amount of time that the database should wait to obtain a pessimistic lock before returning an error to the client.intDeprecated, for removal: This API element is subject to removal in a future version.The timeout, in milliseconds, associated withthisoptions.booleanDeprecated, for removal: This API element is subject to removal in a future version.Whether thisLockOptionsinstance defines alias-specific lock-modesinthashCode()Deprecated, for removal: This API element is subject to removal in a future version.booleanisEmpty()Deprecated, for removal: This API element is subject to removal in a future version.Whether thisLockOptionsinstance is "empty", meaning it has any non-default values set (which is the same asmakeCopy()Deprecated, for removal: This API element is subject to removal in a future version.Make a copy.Deprecated, for removal: This API element is subject to removal in a future version.Make a copy, unless this is an immutable instance.voidoverlay(LockOptions lockOptions) Deprecated, for removal: This API element is subject to removal in a future version.Copy the given lock options into this instance, merging the alias-specific lock modes.setAliasSpecificLockMode(String alias, LockMode lockMode) Deprecated, for removal: This API element is subject to removal in a future version.Specify theLockModeto be used for the given query alias.setFollowOnLocking(Boolean followOnLocking) Deprecated, for removal: This API element is subject to removal in a future version.Force enable or disable the use of follow-on locking, overriding the default behavior of the SQL dialect.setLockMode(LockMode lockMode) Deprecated, for removal: This API element is subject to removal in a future version.Set the overall lock mode.setLockScope(PessimisticLockScope scope) Deprecated, for removal: This API element is subject to removal in a future version.Set the lock scope:PessimisticLockScope.EXTENDEDmeans the lock extends to rows of owned collections, butPessimisticLockScope.NORMALmeans only the entity table and secondary tables are locked.setTimeout(Timeout timeout) Deprecated, for removal: This API element is subject to removal in a future version.Set the timeout associated withthisoptions.setTimeOut(int timeout) Deprecated, for removal: This API element is subject to removal in a future version.Set the timeout, in milliseconds, associated withthisoptions.
-
Field Details
-
NONE
Deprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.NONE, to which timeout and scope are not applicable. -
READ
Deprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.READ, to which timeout and scope are not applicable. -
UPGRADE
Deprecated, for removal: This API element is subject to removal in a future version.RepresentsLockMode.PESSIMISTIC_WRITEwith no timeout, and no extension of the lock to owned collections. -
NO_WAIT
public static final int NO_WAITDeprecated, for removal: This API element is subject to removal in a future version. -
WAIT_FOREVER
public static final int WAIT_FOREVERDeprecated, for removal: This API element is subject to removal in a future version. -
SKIP_LOCKED
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
LockOptions
public LockOptions()Deprecated, for removal: This API element is subject to removal in a future version.Construct an instance with modeLockMode.NONEand no timeout.- See Also:
-
LockOptions
Deprecated, for removal: This API element is subject to removal in a future version.Construct an instance with the given mode and no timeout.- Parameters:
lockMode- The initial lock mode- See Also:
-
LockOptions
Deprecated, for removal: This API element is subject to removal in a future version.Construct an instance with the given mode and timeout.- Parameters:
lockMode- The initial lock modetimeout- The initial timeout, in milliseconds
-
LockOptions
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
lockMode- The initial lock modetimeout- The initial timeoutscope- The initial lock scope
-
LockOptions
Deprecated, for removal: This API element is subject to removal in a future version.Internal operation used to create immutable global instances. -
LockOptions
Deprecated.Use LockOptions(LockMode, Timeout) insteadConstruct an instance with the given mode and timeout.- Parameters:
lockMode- The initial lock modetimeout- The initial timeout, in milliseconds
-
LockOptions
@Deprecated(since="7.0") public LockOptions(LockMode lockMode, int timeout, PessimisticLockScope scope) Deprecated.- Parameters:
lockMode- The initial lock modetimeout- The initial timeout, in millisecondsscope- The initial lock scope
-
-
Method Details
-
isEmpty
public boolean isEmpty()Deprecated, for removal: This API element is subject to removal in a future version.Whether thisLockOptionsinstance is "empty", meaning it has any non-default values set (which is the same as- Returns:
trueif the lock options are equivalent toNONE.
-
getLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve the overall lock mode in effect for this set of options.- Returns:
- the overall lock mode
-
setLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Set the overall lock mode. The default isLockMode.NONE, that is, no locking at all.- Parameters:
lockMode- the new overall lock mode- Returns:
thisfor method chaining
-
getAliasSpecificLocks
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- an iterable with the
Map.Entrys
-
setAliasSpecificLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Specify theLockModeto be used for the given query alias.- Parameters:
alias- the query alias to which the lock mode applieslockMode- the lock mode to apply to the given alias- Returns:
thisfor method chaining- See Also:
-
getAliasLockCount
public int getAliasLockCount()Deprecated, for removal: This API element is subject to removal in a future version.The number of aliases that have alias-specific lock modes specified.- Returns:
- the number of explicitly defined alias lock modes.
-
hasAliasSpecificLockModes
public boolean hasAliasSpecificLockModes()Deprecated, for removal: This API element is subject to removal in a future version.Whether thisLockOptionsinstance defines alias-specific lock-modes- Returns:
trueif this object defines alias-specific lock modes;falseotherwise.
-
getAliasSpecificLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Get theLockModeexplicitly specified for the given alias viasetAliasSpecificLockMode(String, LockMode).Differs from
getEffectiveLockMode(String)in that here we only return an explicitly specified alias-specific lock mode.- Parameters:
alias- The alias for which to locate the explicit lock mode.- Returns:
- The explicit lock mode for that alias.
-
getAliasLockIterator
Deprecated.- Returns:
- an iterator over the
Map.Entrys
-
getEffectiveLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Determine theLockModeto apply to the given alias. If no mode was explicitly set, the overall mode is returned. If the overall lock mode is alsonull,LockMode.NONEis returned.Differs from
getAliasSpecificLockMode(String)in that here we fall back to only returning the overall lock mode.- Parameters:
alias- The alias for which to locate the effective lock mode.- Returns:
- The effective lock mode.
-
findGreatestLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Currently needed for follow-on locking.- Returns:
- The greatest of all requested lock modes.
-
getTimeout
Deprecated, for removal: This API element is subject to removal in a future version.The timeout associated withthisoptions, defining a maximum amount of time that the database should wait to obtain a pessimistic lock before returning an error to the client. -
setTimeout
Deprecated, for removal: This API element is subject to removal in a future version.Set the timeout associated withthisoptions.- Returns:
thisfor method chaining- See Also:
-
getTimeOut
public int getTimeOut()Deprecated, for removal: This API element is subject to removal in a future version.The timeout, in milliseconds, associated withthisoptions.NO_WAIT,WAIT_FOREVER, orSKIP_LOCKEDrepresent 3 "magic" values.- Returns:
- a timeout in milliseconds,
NO_WAIT,WAIT_FOREVER, orSKIP_LOCKED
-
setTimeOut
Deprecated, for removal: This API element is subject to removal in a future version.Set the timeout, in milliseconds, associated withthisoptions.NO_WAIT,WAIT_FOREVER, orSKIP_LOCKEDrepresent 3 "magic" values.- Returns:
thisfor method chaining- See Also:
-
getLockScope
Deprecated, for removal: This API element is subject to removal in a future version.The current lock scope:PessimisticLockScope.EXTENDEDmeans the lock extends to rows of owned collections, butPessimisticLockScope.NORMALmeans only the entity table and secondary tables are locked.
- Returns:
- the current
PessimisticLockScope
-
setLockScope
Deprecated, for removal: This API element is subject to removal in a future version.Set the lock scope:PessimisticLockScope.EXTENDEDmeans the lock extends to rows of owned collections, butPessimisticLockScope.NORMALmeans only the entity table and secondary tables are locked.
- Parameters:
scope- the newPessimisticLockScope- Returns:
thisfor method chaining
-
getFollowOnLocking
Deprecated, for removal: This API element is subject to removal in a future version.Returns a value indicating if follow-on locking was force enabled or disabled, overriding the default behavior of the SQL dialect.- Returns:
trueif follow-on locking was force enabled,falseif follow-on locking was force disabled, ornullif the default behavior of the dialect has not been overridden.- See Also:
-
setFollowOnLocking
Deprecated, for removal: This API element is subject to removal in a future version.Force enable or disable the use of follow-on locking, overriding the default behavior of the SQL dialect.- Parameters:
followOnLocking- The new follow-on locking setting- Returns:
thisfor method chaining- See Also:
-
makeCopy
Deprecated, for removal: This API element is subject to removal in a future version.Make a copy. The new copy will be mutable even if the original wasn't.- Returns:
- The copy
-
makeDefensiveCopy
Deprecated, for removal: This API element is subject to removal in a future version.Make a copy, unless this is an immutable instance.- Returns:
- The copy, or this if it was immutable.
-
overlay
Deprecated, for removal: This API element is subject to removal in a future version.Copy the given lock options into this instance, merging the alias-specific lock modes. -
copy
Deprecated, for removal: This API element is subject to removal in a future version.Copy the options in the first given instance ofLockOptionsto the second given instance.- Parameters:
source- Source for the copy (copied from)destination- Destination for the copy (copied to)- Returns:
- destination
-
equals
Deprecated, for removal: This API element is subject to removal in a future version. -
hashCode
public int hashCode()Deprecated, for removal: This API element is subject to removal in a future version.
-
LockMode,Timeout, orPessimisticLockScopemay be passed directly as an option tofind(),refresh(), orlock(). Therefore, this class is obsolete as an API and will be moved to an SPI package.For HQL/JPQL queries, locking should be controlled via operations of the
SelectionQueryinterface:- A timeout may be set via
- The
- Alias-specific lock modes may be specified using
- Use of follow-on locking may be enabled via
The interfaceCommonQueryContract.setTimeout(Timeout)PessimisticLockScopemay be set usingSelectionQuery.setLockScope(PessimisticLockScope)SelectionQuery.setLockMode(String, LockMode)SelectionQuery.setFollowOnLocking(boolean)Timeoutsprovides several operations to simplify migration.