TOMEE-2257 fix test
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/540dd8f4 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/540dd8f4 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/540dd8f4 Branch: refs/heads/master Commit: 540dd8f4cf1695861bac8d0b6fdff85758f8ce87 Parents: 6f8d5dd Author: Jonathan Gallimore <[email protected]> Authored: Wed Oct 10 17:22:52 2018 +0100 Committer: Jonathan Gallimore <[email protected]> Committed: Wed Oct 10 17:25:25 2018 +0100 ---------------------------------------------------------------------- .../openejb/resource/AutoConnectionTracker.java | 72 ++++++++++---------- 1 file changed, 37 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/540dd8f4/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java index cd78a93..49f891e 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java @@ -104,51 +104,53 @@ public class AutoConnectionTracker implements ConnectionTracker { * @param reassociate should always be false */ public void handleObtained(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final boolean reassociate) throws ResourceException { - Transaction currentTx = null; - try { - currentTx = txMgr.getTransaction(); - } catch (SystemException e) { - //ignore - } - - if (currentTx != null) { - Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY); - if (txConnections == null) { - txConnections = new HashMap<ManagedConnectionInfo, Map<ConnectionInfo, Object>>(); - registry.putResource(KEY, txConnections); + if (txMgr != null && registry != null) { + Transaction currentTx = null; + try { + currentTx = txMgr.getTransaction(); + } catch (SystemException e) { + //ignore } - Map<ConnectionInfo, Object> connectionObjects = txConnections.get(connectionInfo.getManagedConnectionInfo()); - if (connectionObjects == null) { - connectionObjects = new HashMap<ConnectionInfo, Object>(); - txConnections.put(connectionInfo.getManagedConnectionInfo(), connectionObjects); - } + if (currentTx != null) { + Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY); + if (txConnections == null) { + txConnections = new HashMap<ManagedConnectionInfo, Map<ConnectionInfo, Object>>(); + registry.putResource(KEY, txConnections); + } - connectionObjects.put(connectionInfo, connectionInfo.getConnectionProxy()); + Map<ConnectionInfo, Object> connectionObjects = txConnections.get(connectionInfo.getManagedConnectionInfo()); + if (connectionObjects == null) { + connectionObjects = new HashMap<ConnectionInfo, Object>(); + txConnections.put(connectionInfo.getManagedConnectionInfo(), connectionObjects); + } - registry.registerInterposedSynchronization(new Synchronization() { - @Override - public void beforeCompletion() { - final Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY); - if (txConnections != null && txConnections.size() > 0) { + connectionObjects.put(connectionInfo, connectionInfo.getConnectionProxy()); - for (final ManagedConnectionInfo managedConnectionInfo : txConnections.keySet()) { - final StringBuilder sb = new StringBuilder(); - final Collection<ConnectionInfo> connectionInfos = txConnections.get(managedConnectionInfo).keySet(); - for (final ConnectionInfo connectionInfo : connectionInfos) { - sb.append("\n ").append("Connection handle opened at ").append(stackTraceToString(connectionInfo.getTrace().getStackTrace())); - } + registry.registerInterposedSynchronization(new Synchronization() { + @Override + public void beforeCompletion() { + final Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY); + if (txConnections != null && txConnections.size() > 0) { - logger.warning("Transaction complete, but connection still has handles associated: " + managedConnectionInfo + "\nAbandoned connection information: " + sb.toString()); + for (final ManagedConnectionInfo managedConnectionInfo : txConnections.keySet()) { + final StringBuilder sb = new StringBuilder(); + final Collection<ConnectionInfo> connectionInfos = txConnections.get(managedConnectionInfo).keySet(); + for (final ConnectionInfo connectionInfo : connectionInfos) { + sb.append("\n ").append("Connection handle opened at ").append(stackTraceToString(connectionInfo.getTrace().getStackTrace())); + } + + logger.warning("Transaction complete, but connection still has handles associated: " + managedConnectionInfo + "\nAbandoned connection information: " + sb.toString()); + } } } - } - @Override - public void afterCompletion(final int status) { + @Override + public void afterCompletion(final int status) { - } - }); + } + }); + } } if (! reassociate) {
