Skip to content

Commit d44b7eb

Browse files
committed
When closing, look for the close method in proxy targets. Fixes #1253
1 parent 8b429fd commit d44b7eb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/jdbc/connections/DataSourceConnectionSource.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.grails.datastore.mapping.core.connections.DefaultConnectionSource;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
6+
import org.springframework.jdbc.datasource.DelegatingDataSource;
67
import org.springframework.util.ReflectionUtils;
78

89
import javax.sql.DataSource;
@@ -26,10 +27,18 @@ public DataSourceConnectionSource(String name, DataSource source, DataSourceSett
2627
public void close() throws IOException {
2728
super.close();
2829
if(!closed) {
29-
Method closeMethod = ReflectionUtils.findMethod(getSource().getClass(), "close");
30+
31+
DataSource source = getSource();
32+
Method closeMethod = ReflectionUtils.findMethod(source.getClass(), "close");
33+
34+
while (closeMethod == null && source instanceof DelegatingDataSource) {
35+
source = ((DelegatingDataSource) source).getTargetDataSource();
36+
closeMethod = ReflectionUtils.findMethod(source.getClass(), "close");
37+
}
38+
3039
if(closeMethod != null) {
3140
try {
32-
ReflectionUtils.invokeMethod(closeMethod, getSource());
41+
ReflectionUtils.invokeMethod(closeMethod, source);
3342
this.closed = true;
3443
} catch (Throwable e) {
3544
LOG.warn("Error closing JDBC connection [{}]: {}", getName(), e.getMessage());

0 commit comments

Comments
 (0)