From d46c1f600a97e41307e96225223d780b0e9c49f7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 11 Nov 2009 18:19:16 +0000 Subject: [PATCH] TransactionAwareDataSourceProxy processes isClosed explicitly in order to avoid potential leaks (SPR-5780) --- .../jdbc/datasource/LazyConnectionDataSourceProxy.java | 5 ++--- .../jdbc/datasource/SingleConnectionDataSource.java | 4 ++-- .../jdbc/datasource/TransactionAwareDataSourceProxy.java | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java index f27a2692e5a..34c7401d853 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -22,7 +22,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.SQLException; - import javax.sql.DataSource; import org.apache.commons.logging.Log; @@ -346,7 +345,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { return null; } else if (method.getName().equals("isClosed")) { - return (this.closed); + return this.closed; } else if (method.getName().equals("close")) { // Ignore: no target connection yet. diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java index e98676fbacd..4ad4fddbeba 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -61,7 +61,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource /** Create a close-suppressing proxy? */ private boolean suppressClose; - /** Override AutoCommit? */ + /** Override auto-commit state? */ private Boolean autoCommit; /** Wrapped Connection */ diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java index 768bbb55ddb..2409693a29f 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -23,7 +23,6 @@ import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; - import javax.sql.DataSource; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -196,6 +195,9 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource { sb.append(" from DataSource [").append(this.targetDataSource).append("]"); } } + else if (method.getName().equals("isClosed")) { + return this.closed; + } else if (method.getName().equals("close")) { // Handle close method: only close if not within a transaction. DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource);