|
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}
|
@@ -425,11 +428,19 @@ public LazyConnectionInvocationHandler(String username, String password) {
|
425 | 428 | return null;
|
426 | 429 | }
|
427 | 430 |
|
428 |
| - // Target Connection already fetched, |
429 |
| - // or target Connection necessary for current operation -> |
430 |
| - // invoke method on target connection. |
| 431 | + |
| 432 | + // Target Connection already fetched, or target Connection necessary for current operation |
| 433 | + // -> invoke method on target connection. |
431 | 434 | try {
|
432 |
| - return method.invoke(getTargetConnection(method), args); |
| 435 | + Connection conToUse = getTargetConnection(method); |
| 436 | + |
| 437 | + if ("rollback".equals(method.getName()) && conToUse.isClosed()) { |
| 438 | + // Connection closed in the meantime, probably due to a resource timeout. Since a |
| 439 | + // rollback attempt typically happens right before close, we leniently suppress it. |
| 440 | + return null; |
| 441 | + } |
| 442 | + |
| 443 | + return method.invoke(conToUse, args); |
433 | 444 | }
|
434 | 445 | catch (InvocationTargetException ex) {
|
435 | 446 | throw ex.getTargetException();
|
|
0 commit comments