Skip to content

Commit 610743a

Browse files
committed
HHH-19440 put back a method which was accidentally removed
- and fix some javadoc - and use a switch expression
1 parent f330a19 commit 610743a

File tree

6 files changed

+57
-21
lines changed

6 files changed

+57
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public enum LockMode implements FindOption, RefreshOption {
103103
* <p>
104104
* This lock mode is for internal use only and is not a legal
105105
* argument to {@link Session#get(Class, Object, LockMode)},
106-
* {@link Session#refresh(Object, LockMode)}, or
106+
* {@link Session#refresh(Object, RefreshOption...)}, or
107107
* {@link Session#lock(Object, LockMode)}. These methods throw
108108
* an exception if {@code WRITE} is given as an argument.
109109
* <p>

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
* behavior is appropriate for programs which use optimistic locking.
103103
* <ul>
104104
* <li>A different lock level may be obtained by explicitly specifying the mode using
105-
* {@link #get(Class, Object, LockMode)}, {@link #find(Class, Object, LockModeType)},
106-
* {@link #refresh(Object, LockMode)}, {@link #refresh(Object, LockModeType)}, or
107-
* {@link org.hibernate.query.SelectionQuery#setLockMode(LockModeType)}.
105+
* {@link #find(Class,Object,LockModeType)}, {@link #find(Class,Object,FindOption...)},
106+
* {@link #refresh(Object,LockModeType)}, {@link #refresh(Object,RefreshOption...)},
107+
* or {@link org.hibernate.query.SelectionQuery#setLockMode(LockModeType)}.
108108
* <li>The lock level of a managed instance already held by the session may be upgraded
109109
* to a more restrictive lock level by calling {@link #lock(Object, LockMode)} or
110110
* {@link #lock(Object, LockModeType)}.
@@ -802,7 +802,8 @@ public interface Session extends SharedSessionContract, EntityManager {
802802
* with {@link jakarta.persistence.CascadeType#REFRESH}.
803803
* <p>
804804
* This operation requests {@link LockMode#READ}. To obtain a stronger lock,
805-
* call {@link #refresh(Object, LockMode)}.
805+
* call {@link #refresh(Object, RefreshOption...)}, passing the appropriate
806+
* {@link LockMode} as an option.
806807
*
807808
* @param object a persistent instance associated with this session
808809
*/
@@ -938,6 +939,24 @@ public interface Session extends SharedSessionContract, EntityManager {
938939
@Deprecated(since = "7.0", forRemoval = true)
939940
Object get(String entityName, Object id, LockMode lockMode);
940941

942+
/**
943+
* Return the persistent instance of the given entity class with the given identifier,
944+
* or null if there is no such persistent instance. If the instance is already associated
945+
* with the session, return that instance. This method never returns an uninitialized
946+
* instance. Obtain the specified lock mode if the instance exists.
947+
*
948+
* @param entityType the entity type
949+
* @param id an identifier
950+
* @param lockOptions the lock mode
951+
*
952+
* @return a persistent instance or null
953+
*
954+
* @deprecated This method will be removed.
955+
* Use {@link #find(Class, Object, FindOption...)} instead.
956+
*/
957+
@Deprecated(since = "7.0", forRemoval = true)
958+
<T> T get(Class<T> entityType, Object id, LockOptions lockOptions);
959+
941960
/**
942961
* Return the persistent instance of the given entity class with the given identifier,
943962
* or null if there is no such persistent instance. If the instance is already associated
@@ -950,7 +969,11 @@ public interface Session extends SharedSessionContract, EntityManager {
950969
*
951970
* @return a persistent instance or null
952971
*
953-
* @deprecated Use {@linkplain #find(Class, Object, FindOption...)} instead
972+
* @deprecated This method will be removed.
973+
* Use {@link SessionFactory#createGraphForDynamicEntity(String)}
974+
* together with {@link #find(EntityGraph, Object, FindOption...)}
975+
* to load {@link org.hibernate.metamodel.RepresentationMode#MAP
976+
* dynamic entities}.
954977
*/
955978
@Deprecated(since = "7.0", forRemoval = true)
956979
Object get(String entityName, Object id, LockOptions lockOptions);
@@ -967,7 +990,8 @@ public interface Session extends SharedSessionContract, EntityManager {
967990
*
968991
* @since 6.2
969992
*
970-
* @deprecated Use {@linkplain #lock(Object, LockModeType, LockOption...)} instead
993+
* @deprecated This method will be removed.
994+
* Use {@linkplain #lock(Object, LockModeType, LockOption...)} instead
971995
*/
972996
@Deprecated(since = "7.0", forRemoval = true)
973997
void lock(Object object, LockOptions lockOptions);
@@ -979,7 +1003,8 @@ public interface Session extends SharedSessionContract, EntityManager {
9791003
* @param object a persistent instance associated with this session
9801004
* @param lockOptions contains the lock mode to use
9811005
*
982-
* @deprecated Use {@linkplain #refresh(Object, RefreshOption...)} instead
1006+
* @deprecated This method will be removed.
1007+
* Use {@linkplain #refresh(Object, RefreshOption...)} instead
9831008
*/
9841009
@Deprecated(since = "7.0", forRemoval = true)
9851010
void refresh(Object object, LockOptions lockOptions);

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ public interface Timeouts {
6565
* the "magic values".
6666
*/
6767
static Timeout interpretMilliSeconds(int timeoutInMilliseconds) {
68-
if ( timeoutInMilliseconds == NO_WAIT_MILLI ) {
69-
return NO_WAIT;
70-
}
71-
else if ( timeoutInMilliseconds == WAIT_FOREVER_MILLI ) {
72-
return WAIT_FOREVER;
73-
}
74-
else if ( timeoutInMilliseconds == SKIP_LOCKED_MILLI ) {
75-
return SKIP_LOCKED;
76-
}
77-
return Timeout.milliseconds( timeoutInMilliseconds );
68+
return switch ( timeoutInMilliseconds ) {
69+
case NO_WAIT_MILLI -> NO_WAIT;
70+
case WAIT_FOREVER_MILLI -> WAIT_FOREVER;
71+
case SKIP_LOCKED_MILLI -> SKIP_LOCKED;
72+
default -> Timeout.milliseconds( timeoutInMilliseconds );
73+
};
7874
}
7975

8076
/**

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,11 @@ public Object get(String entityName, Object id, LockMode lockMode) {
982982
return delegate.get( entityName, id, lockMode );
983983
}
984984

985+
@Override
986+
public <T> T get(Class<T> entityType, Object id, LockOptions lockOptions) {
987+
return delegate.get( entityType, id, lockOptions );
988+
}
989+
985990
@Override
986991
public Object get(String entityName, Object id, LockOptions lockOptions) {
987992
return delegate.get( entityName, id, lockOptions );

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ public Object get(String entityName, Object id, LockMode lockMode) {
296296
return this.lazySession.get().get( entityName, id, lockMode );
297297
}
298298

299+
@Override
300+
public <T> T get(Class<T> entityType, Object id, LockOptions lockOptions) {
301+
return this.lazySession.get().get( entityType, id, lockOptions );
302+
}
303+
299304
@Override
300305
public Object get(String entityName, Object id, LockOptions lockOptions) {
301306
return this.lazySession.get().get( entityName, id, lockOptions );

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,17 +1174,22 @@ protected void releaseLoadEvent(LoadEvent event) {
11741174
}
11751175
}
11761176

1177-
@Override
1177+
@Override @Deprecated
11781178
public <T> T get(Class<T> entityClass, Object id, LockMode lockMode) {
11791179
return this.byId( entityClass ).with( new LockOptions( lockMode ) ).load( id );
11801180
}
11811181

1182-
@Override
1182+
@Override @Deprecated
11831183
public Object get(String entityName, Object id, LockMode lockMode) {
11841184
return this.byId( entityName ).with( new LockOptions( lockMode ) ).load( id );
11851185
}
11861186

1187-
@Override
1187+
@Override @Deprecated
1188+
public <T> T get(Class<T> entityClass, Object id, LockOptions lockOptions) {
1189+
return this.byId( entityClass ).with( lockOptions ).load( id );
1190+
}
1191+
1192+
@Override @Deprecated
11881193
public Object get(String entityName, Object id, LockOptions lockOptions) {
11891194
return this.byId( entityName ).with( lockOptions ).load( id );
11901195
}

0 commit comments

Comments
 (0)