This is an automated email from the ASF dual-hosted git repository. jgallimore pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomee.git
commit 255e2842fe310e172aa7f314c9bab39b39221ae5 Author: Jonathan Gallimore <j...@jrg.me.uk> AuthorDate: Wed Jul 3 01:14:47 2019 +0100 TOMEE-2557 add debug logging for ManagedConnection --- .../jdbc/managed/local/ManagedConnection.java | 63 ++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/managed/local/ManagedConnection.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/managed/local/ManagedConnection.java index 45ef356..9445a30 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/managed/local/ManagedConnection.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/managed/local/ManagedConnection.java @@ -39,9 +39,13 @@ import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.SQLException; import java.sql.Wrapper; +import java.util.Arrays; import java.util.Objects; public class ManagedConnection implements InvocationHandler { + + private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB_RESOURCE_JDBC, ManagedConnection.class); + private final TransactionManager transactionManager; private final Key key; private final TransactionSynchronizationRegistry registry; @@ -50,6 +54,7 @@ public class ManagedConnection implements InvocationHandler { protected XAConnection xaConnection; private Transaction currentTransaction; private boolean closed; + private StackTraceElement[] createdAt; public ManagedConnection(final CommonDataSource ds, final TransactionManager txMgr, @@ -59,6 +64,10 @@ public class ManagedConnection implements InvocationHandler { registry = txRegistry; closed = false; key = new Key(ds, user, password); + + if (LOGGER.isDebugEnabled()) { + createdAt = new Throwable().getStackTrace(); + } } public XAResource getXAResource() throws SQLException { @@ -151,11 +160,11 @@ public class ManagedConnection implements InvocationHandler { setAutoCommit(false); } catch (final SQLException xae) { // we are alreay in a transaction so this can't be called from a user perspective - some XA DataSource prevents it in their code final String message = "Can't set auto commit to false cause the XA datasource doesn't support it, this is likely an issue"; - final Logger logger = Logger.getInstance(LogCategory.OPENEJB_RESOURCE_JDBC, ManagedConnection.class); - if (logger.isDebugEnabled()) { // we don't want to print the exception by default - logger.warning(message, xae); + + if (LOGGER.isDebugEnabled()) { // we don't want to print the exception by default + LOGGER.warning(message, xae); } else { - logger.warning(message); + LOGGER.warning(message); } } } @@ -206,6 +215,21 @@ public class ManagedConnection implements InvocationHandler { delegate = Connection.class.cast(connection); xaResource = new LocalXAResource(delegate); } + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Created new " + + ((XAConnection.class.isInstance(connection)) ? "XAConnection" : "Connection") + + " xaConnection = " + + ((xaConnection == null) ? "null" : xaConnection.toString()) + + " delegate = " + + ((delegate == null) ? "null" : delegate.toString()) + ); + } + + if (LOGGER.isDebugEnabled()) { + this.createdAt = new Throwable().getStackTrace(); + } + return connection; } @@ -270,13 +294,30 @@ public class ManagedConnection implements InvocationHandler { } private void closeConnection(final boolean force) { + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Closing connection " + this.toString() + ", force = " + force + ", closed = " + this.closed); + if (createdAt != null) { + LOGGER.debug("Connection created at: " + Arrays.toString(createdAt)); + } + + LOGGER.debug("Connection closed at: " + Arrays.toString(new Throwable().getStackTrace())); + } + if (!force && closed) { return; } try { if (xaConnection != null) { // handles the underlying connection + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Closing XAConnection " + xaConnection); + } xaConnection.close(); } else if (delegate != null && !delegate.isClosed()) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Closing delegate " + delegate); + } + delegate.close(); } } catch (final SQLException e) { @@ -286,6 +327,20 @@ public class ManagedConnection implements InvocationHandler { } } + @Override + public String toString() { + return "ManagedConnection{" + + "transactionManager=" + transactionManager + + ", key=" + key + + ", registry=" + registry + + ", xaResource=" + xaResource + + ", delegate=" + delegate + + ", xaConnection=" + xaConnection + + ", currentTransaction=" + currentTransaction + + ", closed=" + closed + + '}'; + } + private static final class Key { private final CommonDataSource ds; private final String user;