|
1 | 1 | /* |
2 | | - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 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. |
|
16 | 16 |
|
17 | 17 | package org.springframework.jms.connection; |
18 | 18 |
|
| 19 | +import java.lang.reflect.Method; |
19 | 20 | import java.util.HashMap; |
20 | 21 | import java.util.LinkedList; |
21 | 22 | import java.util.List; |
|
30 | 31 | import org.apache.commons.logging.LogFactory; |
31 | 32 |
|
32 | 33 | import org.springframework.transaction.support.ResourceHolderSupport; |
| 34 | +import org.springframework.transaction.support.TransactionSynchronizationManager; |
33 | 35 | import org.springframework.util.Assert; |
34 | 36 | import org.springframework.util.CollectionUtils; |
| 37 | +import org.springframework.util.ReflectionUtils; |
35 | 38 |
|
36 | 39 | /** |
37 | 40 | * JMS resource holder, wrapping a JMS Connection and a JMS Session. |
@@ -183,7 +186,26 @@ public void commitAll() throws JMSException { |
183 | 186 | catch (TransactionInProgressException ex) { |
184 | 187 | // Ignore -> can only happen in case of a JTA transaction. |
185 | 188 | } |
186 | | - // Let IllegalStateException through: It might point out an unexpectedly closed session. |
| 189 | + catch (javax.jms.IllegalStateException ex) { |
| 190 | + if (this.connectionFactory != null) { |
| 191 | + try { |
| 192 | + Method getDataSourceMethod = this.connectionFactory.getClass().getMethod("getDataSource"); |
| 193 | + Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory); |
| 194 | + if (ds != null && TransactionSynchronizationManager.hasResource(ds)) { |
| 195 | + // IllegalStateException from sharing the underlying JDBC Connection |
| 196 | + // which typically gets committed first, e.g. with Oracle AQ --> ignore |
| 197 | + return; |
| 198 | + } |
| 199 | + } |
| 200 | + catch (Throwable ex2) { |
| 201 | + if (logger.isDebugEnabled()) { |
| 202 | + logger.debug("No working getDataSource method found on ConnectionFactory: " + ex2); |
| 203 | + } |
| 204 | + // No working getDataSource method - cannot perform DataSource transaction check |
| 205 | + } |
| 206 | + } |
| 207 | + throw ex; |
| 208 | + } |
187 | 209 | } |
188 | 210 | } |
189 | 211 |
|
|
0 commit comments