Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
24d52097
Commit
24d52097
authored
Jun 25, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish “Close Database to reset Connection's auto commit property”
Closes gh-13559
parent
3498a912
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
22 deletions
+25
-22
LiquibaseEndpoint.java
...ingframework/boot/actuate/endpoint/LiquibaseEndpoint.java
+4
-1
LiquibaseEndpointTests.java
...amework/boot/actuate/endpoint/LiquibaseEndpointTests.java
+21
-21
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java
View file @
24d52097
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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>> {
...
@@ -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
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java
View file @
24d52097
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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 @@
...
@@ -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
...
@@ -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
...
@@ -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
(
C
ustomSchemaC
onfig
.
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
({
EmbeddedDataSource
Configuration
.
class
,
LiquibaseAutoConfiguration
.
class
})
@Import
({
DataSourceAuto
Configuration
.
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
...
@@ -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
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment