|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
77 | 77 | * You will get the same effect with non-transactional reads, but lazy fetching
|
78 | 78 | * of JDBC Connections allows you to still perform reads in transactions.
|
79 | 79 | *
|
| 80 | + * <p>As of 6.2.6, this DataSource proxy also suppresses a rollback attempt |
| 81 | + * in case of a timeout where the connection has been closed in the meantime. |
| 82 | + * |
80 | 83 | * <p><b>NOTE:</b> This DataSource proxy needs to return wrapped Connections
|
81 | 84 | * (which implement the {@link ConnectionProxy} interface) in order to handle
|
82 | 85 | * lazy fetching of an actual JDBC Connection. Use {@link Connection#unwrap}
|
@@ -436,11 +439,19 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
|
436 | 439 | return null;
|
437 | 440 | }
|
438 | 441 |
|
439 |
| - // Target Connection already fetched, |
440 |
| - // or target Connection necessary for current operation -> |
441 |
| - // invoke method on target connection. |
| 442 | + |
| 443 | + // Target Connection already fetched, or target Connection necessary for current operation |
| 444 | + // -> invoke method on target connection. |
442 | 445 | try {
|
443 |
| - return method.invoke(getTargetConnection(method), args); |
| 446 | + Connection conToUse = getTargetConnection(method); |
| 447 | + |
| 448 | + if ("rollback".equals(method.getName()) && conToUse.isClosed()) { |
| 449 | + // Connection closed in the meantime, probably due to a resource timeout. Since a |
| 450 | + // rollback attempt typically happens right before close, we leniently suppress it. |
| 451 | + return null; |
| 452 | + } |
| 453 | + |
| 454 | + return method.invoke(conToUse, args); |
444 | 455 | }
|
445 | 456 | catch (InvocationTargetException ex) {
|
446 | 457 | throw ex.getTargetException();
|
|
0 commit comments