TransactionAwareDataSourceProxy processes isClosed explicitly in order to avoid potential leaks (SPR-5780)
This commit is contained in:
parent
2b962e7730
commit
d46c1f600a
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.lang.reflect.Proxy;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
@ -346,7 +345,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (method.getName().equals("isClosed")) {
|
else if (method.getName().equals("isClosed")) {
|
||||||
return (this.closed);
|
return this.closed;
|
||||||
}
|
}
|
||||||
else if (method.getName().equals("close")) {
|
else if (method.getName().equals("close")) {
|
||||||
// Ignore: no target connection yet.
|
// Ignore: no target connection yet.
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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? */
|
/** Create a close-suppressing proxy? */
|
||||||
private boolean suppressClose;
|
private boolean suppressClose;
|
||||||
|
|
||||||
/** Override AutoCommit? */
|
/** Override auto-commit state? */
|
||||||
private Boolean autoCommit;
|
private Boolean autoCommit;
|
||||||
|
|
||||||
/** Wrapped Connection */
|
/** Wrapped Connection */
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
@ -196,6 +195,9 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
|
||||||
sb.append(" from DataSource [").append(this.targetDataSource).append("]");
|
sb.append(" from DataSource [").append(this.targetDataSource).append("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (method.getName().equals("isClosed")) {
|
||||||
|
return this.closed;
|
||||||
|
}
|
||||||
else if (method.getName().equals("close")) {
|
else if (method.getName().equals("close")) {
|
||||||
// Handle close method: only close if not within a transaction.
|
// Handle close method: only close if not within a transaction.
|
||||||
DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource);
|
DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue