From 5faacd5a3dd131ea2bef1b77f99805e7d42ef331 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 16 May 2014 15:08:09 +0200 Subject: [PATCH] JmsResourceHolder checks for nested DataSource transactions as well (for Oracle AQ compatibility) Issue: SPR-11791 --- .../jms/connection/JmsResourceHolder.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java index c215b689952..98c4b60a5e9 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -191,10 +191,20 @@ public class JmsResourceHolder extends ResourceHolderSupport { try { Method getDataSourceMethod = this.connectionFactory.getClass().getMethod("getDataSource"); Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory); - if (ds != null && TransactionSynchronizationManager.hasResource(ds)) { - // IllegalStateException from sharing the underlying JDBC Connection - // which typically gets committed first, e.g. with Oracle AQ --> ignore - return; + while (ds != null) { + if (TransactionSynchronizationManager.hasResource(ds)) { + // IllegalStateException from sharing the underlying JDBC Connection + // which typically gets committed first, e.g. with Oracle AQ --> ignore + return; + } + try { + // Check for decorated DataSource a la Spring's DelegatingDataSource + Method getTargetDataSourceMethod = ds.getClass().getMethod("getTargetDataSource"); + ds = ReflectionUtils.invokeMethod(getTargetDataSourceMethod, ds); + } + catch (NoSuchMethodException nsme) { + ds = null; + } } } catch (Throwable ex2) {