Polish “Close Database to reset Connection's auto commit property”
Closes gh-13559
This commit is contained in:
parent
3498a91259
commit
24d5209738
|
@ -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");
|
* 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.
|
||||||
|
@ -80,6 +80,9 @@ public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -16,11 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint;
|
package org.springframework.boot.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import liquibase.integration.spring.SpringLiquibase;
|
import liquibase.integration.spring.SpringLiquibase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
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.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
@ -44,7 +48,20 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invoke() throws Exception {
|
public void invoke() throws Exception {
|
||||||
|
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||||
|
assertThat(getAutoCommit(dataSource)).isTrue();
|
||||||
assertThat(getEndpointBean().invoke()).hasSize(1);
|
assertThat(getEndpointBean().invoke()).hasSize(1);
|
||||||
|
assertThat(getAutoCommit(dataSource)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getAutoCommit(DataSource dataSource) throws SQLException {
|
||||||
|
Connection connection = dataSource.getConnection();
|
||||||
|
try {
|
||||||
|
return connection.getAutoCommit();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,13 +72,13 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
||||||
"liquibase.default-schema=CUSTOMSCHEMA",
|
"liquibase.default-schema=CUSTOMSCHEMA",
|
||||||
"spring.datasource.generate-unique-name=true",
|
"spring.datasource.generate-unique-name=true",
|
||||||
"spring.datasource.schema=classpath:/db/create-custom-schema.sql");
|
"spring.datasource.schema=classpath:/db/create-custom-schema.sql");
|
||||||
this.context.register(CustomSchemaConfig.class);
|
this.context.register(Config.class);
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
assertThat(getEndpointBean().invoke()).hasSize(1);
|
assertThat(getEndpointBean().invoke()).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class })
|
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
|
||||||
public static class Config {
|
public static class Config {
|
||||||
|
|
||||||
private final SpringLiquibase liquibase;
|
private final SpringLiquibase liquibase;
|
||||||
|
@ -77,21 +94,4 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
|
|
||||||
public static class CustomSchemaConfig {
|
|
||||||
|
|
||||||
private final SpringLiquibase liquibase;
|
|
||||||
|
|
||||||
public CustomSchemaConfig(SpringLiquibase liquibase) {
|
|
||||||
this.liquibase = liquibase;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public LiquibaseEndpoint endpoint() {
|
|
||||||
return new LiquibaseEndpoint(this.liquibase);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue