From 3498a91259f0b417674e5fe392f3c831fc2ce9b4 Mon Sep 17 00:00:00 2001 From: dmsergeevp44 Date: Sat, 23 Jun 2018 13:31:22 -0500 Subject: [PATCH 1/2] 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 --- .../boot/actuate/endpoint/LiquibaseEndpoint.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java index 11b086f6647..6136a09862d 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java @@ -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> { 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> { service.queryDatabaseChangeLogTable(database))); } finally { - connection.close(); + if (database != null) { + database.close(); + } } } catch (Exception ex) { From 24d5209738246b4585be5bfc30f2767a1d773535 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 25 Jun 2018 11:02:31 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Polish=20=E2=80=9CClose=20Database=20to=20r?= =?UTF-8?q?eset=20Connection's=20auto=20commit=20property=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes gh-13559 --- .../actuate/endpoint/LiquibaseEndpoint.java | 5 ++- .../endpoint/LiquibaseEndpointTests.java | 42 +++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java index 6136a09862d..0c6a3ead12a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -80,6 +80,9 @@ public class LiquibaseEndpoint extends AbstractEndpoint> { if (database != null) { database.close(); } + else { + connection.close(); + } } } catch (Exception ex) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java index 2380079842c..4379cb14706 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -16,11 +16,15 @@ package org.springframework.boot.actuate.endpoint; +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + import liquibase.integration.spring.SpringLiquibase; import org.junit.Test; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -44,7 +48,20 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests