RESOLVED - issue SPR-6668: Small Connection leak in DataSourceInitializer

http://jira.springframework.org/browse/SPR-6668
This commit is contained in:
David Syer
2010-01-13 11:00:41 +00:00
parent e195c39d3c
commit e4d8651aa9
3 changed files with 42 additions and 2 deletions

View File

@@ -15,9 +15,13 @@
*/
package org.springframework.jdbc.datasource.init;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.util.Assert;
/**
@@ -66,7 +70,23 @@ public class DataSourceInitializer implements InitializingBean {
if (enabled) {
Assert.state(dataSource != null, "DataSource must be provided");
Assert.state(databasePopulator != null, "DatabasePopulator must be provided");
databasePopulator.populate(dataSource.getConnection());
try {
Connection connection = this.dataSource.getConnection();
try {
this.databasePopulator.populate(connection);
}
finally {
try {
connection.close();
}
catch (SQLException ex) {
// ignore
}
}
}
catch (SQLException ex) {
throw new DataAccessResourceFailureException("Failed to populate database", ex);
}
}
}
}