Close Database to reset Connection's auto commit property

Previously, LiquibaseEndpoint closed the JdbcConnection but did not
close the Database. When using a connection pool, this could leave the
underlying SQL Connection with its auto commit property set to false.

This commit updates LiquibaseEndpoint to close the Database. This
ensures that it resets that Connection's auto commit property to the
value that it had when the Database was configured to use the
Connection.

See gh-13559
This commit is contained in:
dmsergeevp44 2018-06-23 13:31:22 -05:00 committed by Andy Wilkinson
parent f32c66d0e1
commit 3498a91259
1 changed files with 6 additions and 3 deletions

View File

@ -38,6 +38,7 @@ import org.springframework.util.StringUtils;
* {@link Endpoint} to expose liquibase info.
*
* @author Eddú Meléndez
* @author Dmitrii Sergeev
* @since 1.3.0
*/
@ConfigurationProperties(prefix = "endpoints.liquibase")
@ -65,9 +66,9 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
DataSource dataSource = entry.getValue().getDataSource();
JdbcConnection connection = new JdbcConnection(
dataSource.getConnection());
Database database = null;
try {
Database database = factory
.findCorrectDatabaseImplementation(connection);
database = factory.findCorrectDatabaseImplementation(connection);
String defaultSchema = entry.getValue().getDefaultSchema();
if (StringUtils.hasText(defaultSchema)) {
database.setDefaultSchemaName(defaultSchema);
@ -76,7 +77,9 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
service.queryDatabaseChangeLogTable(database)));
}
finally {
connection.close();
if (database != null) {
database.close();
}
}
}
catch (Exception ex) {