Skip to content

Commit 6fe0553

Browse files
committed
HHH-18540 remove Session.LockRequest
Signed-off-by: Gavin King <[email protected]>
1 parent bbbaf51 commit 6fe0553

File tree

8 files changed

+5
-223
lines changed

8 files changed

+5
-223
lines changed

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

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import jakarta.persistence.EntityManager;
2323
import jakarta.persistence.FlushModeType;
2424
import jakarta.persistence.LockModeType;
25-
import jakarta.persistence.PessimisticLockScope;
2625
import jakarta.persistence.TypedQueryReference;
2726
import jakarta.persistence.criteria.CriteriaDelete;
2827
import jakarta.persistence.criteria.CriteriaQuery;
@@ -635,31 +634,6 @@ public interface Session extends SharedSessionContract, EntityManager {
635634
@Deprecated(since = "6.2")
636635
void lock(String entityName, Object object, LockMode lockMode);
637636

638-
/**
639-
* Build a new {@linkplain LockRequest lock request} that specifies:
640-
* <ul>
641-
* <li>the {@link LockMode} to use,
642-
* <li>the {@linkplain LockRequest#setTimeOut(int) pessimistic lock timeout},
643-
* and
644-
* <li>the {@linkplain LockRequest#setLockScope(PessimisticLockScope) scope}
645-
* that is, whether the lock extends to rows of owned collections.
646-
* </ul>
647-
* <p>
648-
* Timeout and scope are ignored if the specified {@code LockMode} represents
649-
* a flavor of {@linkplain LockMode#OPTIMISTIC optimistic} locking.
650-
* <p>
651-
* Call {@link LockRequest#lock(Object)} to actually obtain the requested lock
652-
* on a managed entity instance.
653-
*
654-
* @param lockOptions contains the lock level
655-
*
656-
* @return a {@link LockRequest} that can be used to lock any given object.
657-
*
658-
* @deprecated use {@link #lock(Object, LockOptions)}
659-
*/
660-
@Deprecated(since = "6.2")
661-
LockRequest buildLockRequest(LockOptions lockOptions);
662-
663637
/**
664638
* Reread the state of the given managed instance associated with this session
665639
* from the underlying database. This may be useful:
@@ -1157,125 +1131,6 @@ public interface Session extends SharedSessionContract, EntityManager {
11571131
*/
11581132
SharedSessionBuilder sessionWithOptions();
11591133

1160-
/**
1161-
* A set of {@linkplain LockOptions locking options} attached
1162-
* to the session.
1163-
*
1164-
* @deprecated simply construct a {@link LockOptions} and pass
1165-
* it to {@link #lock(Object, LockOptions)}.
1166-
*/
1167-
@Deprecated(since = "6.2")
1168-
interface LockRequest {
1169-
/**
1170-
* A timeout value indicating that the database should not
1171-
* wait at all to acquire a pessimistic lock which is not
1172-
* immediately available. This has the same effect as
1173-
* {@link LockMode#UPGRADE_NOWAIT}.
1174-
*/
1175-
int PESSIMISTIC_NO_WAIT = LockOptions.NO_WAIT;
1176-
1177-
/**
1178-
* A timeout value indicating that attempting to acquire
1179-
* that there is no timeout for the lock acquisition.
1180-
*/
1181-
int PESSIMISTIC_WAIT_FOREVER = LockOptions.WAIT_FOREVER;
1182-
1183-
/**
1184-
* Get the lock mode.
1185-
*
1186-
* @return the lock mode.
1187-
*/
1188-
LockMode getLockMode();
1189-
1190-
/**
1191-
* Specify the {@link LockMode} to be used. The default is {@link LockMode#NONE}.
1192-
*
1193-
* @param lockMode the lock mode to use for this request
1194-
*
1195-
* @return this {@code LockRequest} instance for operation chaining.
1196-
*/
1197-
LockRequest setLockMode(LockMode lockMode);
1198-
1199-
/**
1200-
* Get the timeout setting.
1201-
*
1202-
* @return timeout in milliseconds, -1 for indefinite wait and 0 for no wait.
1203-
*/
1204-
int getTimeOut();
1205-
1206-
/**
1207-
* Specify the pessimistic lock timeout. The default pessimistic lock
1208-
* behavior is to wait forever for the lock. Lock timeout support is
1209-
* not available in every {@link org.hibernate.dialect.Dialect dialect}
1210-
* of SQL.
1211-
*
1212-
* @param timeout is time in milliseconds to wait for lock.
1213-
* -1 means wait forever and 0 means no wait.
1214-
*
1215-
* @return this {@code LockRequest} instance for operation chaining.
1216-
*/
1217-
LockRequest setTimeOut(int timeout);
1218-
1219-
/**
1220-
* Check if locking extends to owned collections and associated entities.
1221-
*
1222-
* @return true if locking will be extended to owned collections and associated entities
1223-
*
1224-
* @deprecated use {@link #getLockScope()}
1225-
*/
1226-
@Deprecated(since = "6.2")
1227-
boolean getScope();
1228-
1229-
/**
1230-
* Obtain the {@link PessimisticLockScope}, which determines if locking
1231-
* extends to owned collections and associated entities.
1232-
*/
1233-
default PessimisticLockScope getLockScope() {
1234-
return getScope() ? PessimisticLockScope.EXTENDED : PessimisticLockScope.NORMAL;
1235-
}
1236-
1237-
/**
1238-
* Specify whether the {@link LockMode} should extend to owned collections
1239-
* and associated entities. An association must be mapped with
1240-
* {@link org.hibernate.annotations.CascadeType#LOCK} for this setting to
1241-
* have any effect.
1242-
*
1243-
* @param scope {@code true} to cascade locks; {@code false} to not.
1244-
*
1245-
* @return {@code this}, for method chaining
1246-
*
1247-
* @deprecated use {@link #setLockScope(PessimisticLockScope)}
1248-
*/
1249-
@Deprecated(since = "6.2")
1250-
LockRequest setScope(boolean scope);
1251-
1252-
/**
1253-
* Set the {@link PessimisticLockScope}, which determines if locking
1254-
* extends to owned collections and associated entities.
1255-
*/
1256-
default LockRequest setLockScope(PessimisticLockScope scope) {
1257-
return setScope( scope == PessimisticLockScope.EXTENDED );
1258-
}
1259-
1260-
/**
1261-
* Perform the requested locking.
1262-
*
1263-
* @param entityName the name of the entity to lock
1264-
* @param object the instance of the entity to lock
1265-
*
1266-
* @deprecated use {@link #lock(Object)}
1267-
*/
1268-
@Deprecated(since = "6.2")
1269-
void lock(String entityName, Object object);
1270-
1271-
/**
1272-
* Perform the requested locking.
1273-
*
1274-
* @param object the instance of the entity to lock
1275-
*/
1276-
void lock(Object object);
1277-
}
1278-
12791134
/**
12801135
* Add one or more listeners to the Session
12811136
*

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,6 @@ public void lock(Object object, LockOptions lockOptions) {
910910
delegate.lock( object, lockOptions );
911911
}
912912

913-
@Override @Deprecated
914-
public LockRequest buildLockRequest(LockOptions lockOptions) {
915-
return delegate.buildLockRequest( lockOptions );
916-
}
917-
918913
@Override
919914
public void refresh(Object object) {
920915
delegate.refresh( object );

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,6 @@ public void lock(Object object, LockOptions lockOptions) {
238238
this.lazySession.get().lock( object, lockOptions );
239239
}
240240

241-
@Override
242-
@Deprecated
243-
public LockRequest buildLockRequest(LockOptions lockOptions) {
244-
return this.lazySession.get().buildLockRequest( lockOptions );
245-
}
246-
247241
@Override
248242
public void refresh(Object object) {
249243
this.lazySession.get().refresh( object );

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

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,11 @@ public void lock(String entityName, Object object, LockMode lockMode) throws Hib
652652
fireLock( new LockEvent( entityName, object, lockMode, this ) );
653653
}
654654

655-
@Override @Deprecated
656-
public LockRequest buildLockRequest(LockOptions lockOptions) {
657-
return new LockRequestImpl( lockOptions );
658-
}
659-
660655
@Override
661656
public void lock(Object object, LockMode lockMode) throws HibernateException {
662657
fireLock( new LockEvent( object, lockMode, this ) );
663658
}
664659

665-
private void fireLock(String entityName, Object object, LockOptions options) {
666-
fireLock( new LockEvent( entityName, object, options, this ) );
667-
}
668-
669660
private void fireLock(Object object, LockOptions options) {
670661
fireLock( new LockEvent( object, options, this ) );
671662
}
@@ -2164,59 +2155,6 @@ public ActionQueue.TransactionCompletionProcesses getTransactionCompletionProces
21642155
}
21652156
}
21662157

2167-
@Deprecated
2168-
private class LockRequestImpl implements LockRequest {
2169-
private final LockOptions lockOptions;
2170-
2171-
private LockRequestImpl(LockOptions lockOptions) {
2172-
this.lockOptions = new LockOptions();
2173-
LockOptions.copy( lockOptions, this.lockOptions );
2174-
}
2175-
2176-
@Override
2177-
public LockMode getLockMode() {
2178-
return lockOptions.getLockMode();
2179-
}
2180-
2181-
@Override
2182-
public LockRequest setLockMode(LockMode lockMode) {
2183-
lockOptions.setLockMode( lockMode );
2184-
return this;
2185-
}
2186-
2187-
@Override
2188-
public int getTimeOut() {
2189-
return lockOptions.getTimeOut();
2190-
}
2191-
2192-
@Override
2193-
public LockRequest setTimeOut(int timeout) {
2194-
lockOptions.setTimeOut( timeout );
2195-
return this;
2196-
}
2197-
2198-
@Override @Deprecated @SuppressWarnings("deprecation")
2199-
public boolean getScope() {
2200-
return lockOptions.getScope();
2201-
}
2202-
2203-
@Override @Deprecated @SuppressWarnings("deprecation")
2204-
public LockRequest setScope(boolean scope) {
2205-
lockOptions.setScope( scope );
2206-
return this;
2207-
}
2208-
2209-
@Override @Deprecated @SuppressWarnings("deprecation")
2210-
public void lock(String entityName, Object object) throws HibernateException {
2211-
fireLock( entityName, object, lockOptions );
2212-
}
2213-
2214-
@Override
2215-
public void lock(Object object) throws HibernateException {
2216-
fireLock( object, lockOptions );
2217-
}
2218-
}
2219-
22202158
@Override
22212159
protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) {
22222160
transactionObserver = new TransactionObserver() {
@@ -2586,7 +2524,7 @@ public void lock(Object entity, LockModeType lockModeType, Map<String, Object> p
25862524

25872525
final LockOptions lockOptions = buildLockOptions( lockModeType, properties );
25882526
try {
2589-
buildLockRequest( lockOptions ).lock( entity );
2527+
fireLock( entity, lockOptions );
25902528
}
25912529
catch (RuntimeException e) {
25922530
throw getExceptionConverter().convert( e, lockOptions );

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public void testLockNowaitSqlServer() throws Exception {
368368
long start = System.currentTimeMillis();
369369
thread.start();
370370
try {
371-
s2.buildLockRequest( opt ).lock( kit2 );
371+
s2.lock( kit2, opt );
372372
}
373373
catch ( PessimisticEntityLockException e ) {
374374
assertTrue( e.getCause() instanceof LockTimeoutException );

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/MutableNaturalIdTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void testReattachmentUnmodifiedNaturalIdCheck(SessionFactoryScope scope)
148148
scope.inTransaction(
149149
(session) -> {
150150
try {
151-
session.buildLockRequest( LockOptions.NONE ).lock( created );
151+
session.lock( created, LockOptions.NONE );
152152

153153
name.set( created, "Gavin" );
154154
final User loaded = session

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/cached/CachedMutableNaturalIdTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void testReattachUnmodifiedInstance(SessionFactoryScope scope) {
295295
scope.inTransaction(
296296
(session) -> {
297297
// HHH-7513 failure during reattachment
298-
session.buildLockRequest( LockOptions.NONE ).lock( created );
298+
session.lock( created, LockOptions.NONE );
299299
session.remove( created.assA );
300300
session.remove( created );
301301
}

hibernate-core/src/test/java/org/hibernate/orm/test/proxy/ProxyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public void testLockUninitializedProxy() {
593593

594594
dp = s.load( DataPoint.class, dp.getId());
595595
assertFalse( Hibernate.isInitialized( dp ) );
596-
s.buildLockRequest( LockOptions.UPGRADE ).lock( dp );
596+
s.lock( dp, LockOptions.UPGRADE );
597597
assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) );
598598

599599
s.remove( dp );

0 commit comments

Comments
 (0)