in wrapper/src/main/java/software/amazon/jdbc/plugin/DefaultConnectionPlugin.java [110:163]
public <T, E extends Exception> T execute(
final Class<T> resultClass,
final Class<E> exceptionClass,
final Object methodInvokeOn,
final String methodName,
final JdbcCallable<T, E> jdbcMethodFunc,
final Object[] jdbcMethodArgs)
throws E {
LOGGER.finest(
() -> Messages.get("DefaultConnectionPlugin.executingMethod", new Object[] {methodName}));
TelemetryFactory telemetryFactory = this.pluginService.getTelemetryFactory();
TelemetryContext telemetryContext = telemetryFactory.openTelemetryContext(
this.pluginService.getTargetName(), TelemetryTraceLevel.NESTED);
T result;
try {
result = jdbcMethodFunc.call();
} finally {
telemetryContext.closeContext();
}
final Connection currentConn = this.pluginService.getCurrentConnection();
final Connection boundConnection = WrapperUtils.getConnectionFromSqlObject(methodInvokeOn);
if (boundConnection != null && boundConnection != currentConn) {
// The method being invoked is using an old connection, so transaction/autocommit analysis should be skipped.
// ConnectionPluginManager#execute blocks all methods invoked using old connections except for close/abort.
return result;
}
if (sqlMethodAnalyzer.doesOpenTransaction(currentConn, methodName, jdbcMethodArgs)) {
this.pluginManagerService.setInTransaction(true);
} else if (
sqlMethodAnalyzer.doesCloseTransaction(currentConn, methodName, jdbcMethodArgs)
// According to the JDBC spec, transactions are committed if autocommit is switched from false to true.
|| sqlMethodAnalyzer.doesSwitchAutoCommitFalseTrue(currentConn, methodName,
jdbcMethodArgs)) {
this.pluginManagerService.setInTransaction(false);
}
if (sqlMethodAnalyzer.isStatementSettingAutoCommit(methodName, jdbcMethodArgs)) {
final Boolean autocommit = sqlMethodAnalyzer.getAutoCommitValueFromSqlStatement(jdbcMethodArgs);
if (autocommit != null) {
try {
currentConn.setAutoCommit(autocommit);
} catch (final SQLException e) {
// do nothing
}
}
}
return result;
}