Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Executor;

import javax.sql.DataSource;

Expand Down Expand Up @@ -86,6 +88,7 @@
*
* @author Juergen Hoeller
* @author Sam Brannen
* @author Chengang Guan
* @since 1.1.4
* @see DataSourceTransactionManager
* @see #setTargetDataSource
Expand Down Expand Up @@ -311,6 +314,12 @@ private class LazyConnectionInvocationHandler implements InvocationHandler {

private @Nullable Boolean autoCommit;

private @Nullable Executor networkTimeoutExecutor;

private @Nullable Integer networkTimeout;

private @Nullable Map<String, String> clientInfo;

private boolean closed = false;

private @Nullable Connection target;
Expand Down Expand Up @@ -434,6 +443,24 @@ public LazyConnectionInvocationHandler(String username, String password) {
// Ignore: no warnings to expose yet.
return null;
}
case "setNetworkTimeout" -> {
this.networkTimeoutExecutor = (Executor) args[0];
this.networkTimeout = (Integer) args[1];
return null;
}
case "getNetworkTimeout" -> {
return this.networkTimeout == null ? 0 : this.networkTimeout;
Comment thread
sbrannen marked this conversation as resolved.
Outdated
}
case "setClientInfo" -> {
if (args.length == 2) {
if (this.clientInfo == null) {
this.clientInfo = new LinkedHashMap<>();
}
this.clientInfo.put((String) args[0], (String) args[1]);
return null;
}
// setClientInfo(Properties) will fall-through
}
case "close" -> {
// Ignore: no target connection yet.
this.closed = true;
Expand Down Expand Up @@ -530,6 +557,14 @@ private Connection getTargetConnection(Method operation) throws Throwable {
if (this.autoCommit != null && this.autoCommit != defaultAutoCommit()) {
target.setAutoCommit(this.autoCommit);
}
if (this.networkTimeout != null) {
target.setNetworkTimeout(this.networkTimeoutExecutor, this.networkTimeout);
}
if (this.clientInfo != null) {
for (Map.Entry<String, String> entry: this.clientInfo.entrySet()) {
target.setClientInfo(entry.getKey(), entry.getValue());
}
}
}
catch (Throwable settingsEx) {
logger.debug("Failed to apply transaction settings to JDBC Connection", settingsEx);
Expand Down
Loading
Loading