|
7 | 7 | import java.io.Serializable;
|
8 | 8 | import java.sql.SQLException;
|
9 | 9 |
|
| 10 | +import org.hibernate.AssertionFailure; |
10 | 11 | import org.hibernate.HibernateException;
|
11 | 12 | import org.hibernate.JDBCException;
|
12 | 13 | import org.hibernate.LockOptions;
|
@@ -80,18 +81,18 @@ public RuntimeException convert(HibernateException exception, LockOptions lockOp
|
80 | 81 | rollbackIfNecessary( converted );
|
81 | 82 | return converted;
|
82 | 83 | }
|
83 |
| - else if ( exception instanceof LockAcquisitionException ) { |
84 |
| - final PersistenceException converted = wrapLockException( exception, lockOptions ); |
| 84 | + else if ( exception instanceof LockAcquisitionException lockAcquisitionException ) { |
| 85 | + final PersistenceException converted = wrapLockException( lockAcquisitionException, lockOptions ); |
85 | 86 | rollbackIfNecessary( converted );
|
86 | 87 | return converted;
|
87 | 88 | }
|
88 |
| - else if ( exception instanceof LockingStrategyException ) { |
89 |
| - final PersistenceException converted = wrapLockException( exception, lockOptions ); |
| 89 | + else if ( exception instanceof LockingStrategyException lockingStrategyException ) { |
| 90 | + final PersistenceException converted = wrapLockException( lockingStrategyException, lockOptions ); |
90 | 91 | rollbackIfNecessary( converted );
|
91 | 92 | return converted;
|
92 | 93 | }
|
93 |
| - else if ( exception instanceof org.hibernate.PessimisticLockException ) { |
94 |
| - final PersistenceException converted = wrapLockException( exception, lockOptions ); |
| 94 | + else if ( exception instanceof org.hibernate.PessimisticLockException pessimisticLockException ) { |
| 95 | + final PersistenceException converted = wrapLockException( pessimisticLockException, lockOptions ); |
95 | 96 | rollbackIfNecessary( converted );
|
96 | 97 | return converted;
|
97 | 98 | }
|
@@ -202,30 +203,37 @@ protected PersistenceException wrapStaleStateException(StaleStateException excep
|
202 | 203 | return new OptimisticLockException( exception.getMessage(), exception );
|
203 | 204 | }
|
204 | 205 |
|
205 |
| - protected PersistenceException wrapLockException(HibernateException exception, LockOptions lockOptions) { |
| 206 | + protected PersistenceException wrapLockException(LockAcquisitionException exception, LockOptions lockOptions) { |
| 207 | + if ( exception instanceof org.hibernate.exception.LockTimeoutException ) { |
| 208 | + return new LockTimeoutException( exception.getMessage(), exception ); |
| 209 | + } |
| 210 | + else { |
| 211 | + throw new PessimisticLockException( exception.getMessage(), exception ); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + protected PersistenceException wrapLockException(LockingStrategyException exception, LockOptions lockOptions) { |
206 | 216 | if ( exception instanceof OptimisticEntityLockException lockException ) {
|
207 | 217 | return new OptimisticLockException( lockException.getMessage(), lockException, lockException.getEntity() );
|
208 | 218 | }
|
209 |
| - else if ( exception instanceof org.hibernate.exception.LockTimeoutException ) { |
210 |
| - return new LockTimeoutException( exception.getMessage(), exception, null ); |
211 |
| - } |
212 | 219 | else if ( exception instanceof PessimisticEntityLockException lockException ) {
|
213 | 220 | // assume lock timeout occurred if a timeout or NO WAIT was specified
|
214 | 221 | return lockOptions != null && lockOptions.getTimeOut() > -1
|
215 | 222 | ? new LockTimeoutException( lockException.getMessage(), lockException, lockException.getEntity() )
|
216 | 223 | : new PessimisticLockException( lockException.getMessage(), lockException, lockException.getEntity() );
|
217 | 224 | }
|
218 |
| - else if ( exception instanceof org.hibernate.PessimisticLockException lockException ) { |
219 |
| - // assume lock timeout occurred if a timeout or NO WAIT was specified |
220 |
| - return lockOptions != null && lockOptions.getTimeOut() > -1 |
221 |
| - ? new LockTimeoutException( lockException.getMessage(), lockException, null ) |
222 |
| - : new PessimisticLockException( lockException.getMessage(), lockException, null ); |
223 |
| - } |
224 | 225 | else {
|
225 |
| - return new OptimisticLockException( exception ); |
| 226 | + throw new AssertionFailure( "Unrecognized exception type" ); |
226 | 227 | }
|
227 | 228 | }
|
228 | 229 |
|
| 230 | + protected PersistenceException wrapLockException(org.hibernate.PessimisticLockException exception, LockOptions lockOptions) { |
| 231 | + // assume lock timeout occurred if a timeout or NO WAIT was specified |
| 232 | + return lockOptions != null && lockOptions.getTimeOut() > -1 |
| 233 | + ? new LockTimeoutException( exception.getMessage(), exception ) |
| 234 | + : new PessimisticLockException( exception.getMessage(), exception ); |
| 235 | + } |
| 236 | + |
229 | 237 | private void rollbackIfNecessary(PersistenceException persistenceException) {
|
230 | 238 | if ( !isNonRollbackException( persistenceException ) ) {
|
231 | 239 | try {
|
|
0 commit comments