Skip to content

Commit 9a4a205

Browse files
committed
Polish
1 parent 198093c commit 9a4a205

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,33 @@ public SpringLiquibase liquibase() {
116116
}
117117

118118
private SpringLiquibase createSpringLiquibase() {
119-
SpringLiquibase liquibase;
120-
DataSource dataSourceToUse = getDataSource();
121-
if (dataSourceToUse == null) {
122-
dataSourceToUse = DataSourceBuilder.create().url(this.properties.getUrl())
123-
.username(this.properties.getUser())
124-
.password(this.properties.getPassword()).build();
125-
liquibase = new DataSourceClosingSpringLiquibase();
119+
DataSource liquibaseDataSource = getDataSource();
120+
if (liquibaseDataSource != null) {
121+
SpringLiquibase liquibase = new SpringLiquibase();
122+
liquibase.setDataSource(liquibaseDataSource);
123+
return liquibase;
126124
}
127-
else {
128-
liquibase = new SpringLiquibase();
129-
}
130-
liquibase.setDataSource(dataSourceToUse);
125+
SpringLiquibase liquibase = new DataSourceClosingSpringLiquibase();
126+
liquibase.setDataSource(createNewDataSource());
131127
return liquibase;
132128
}
133129

134130
private DataSource getDataSource() {
135131
if (this.liquibaseDataSource != null) {
136132
return this.liquibaseDataSource;
137133
}
138-
else if (this.properties.getUrl() == null) {
134+
if (this.properties.getUrl() == null) {
139135
return this.dataSource;
140136
}
141137
return null;
142138
}
143139

140+
private DataSource createNewDataSource() {
141+
return DataSourceBuilder.create().url(this.properties.getUrl())
142+
.username(this.properties.getUser())
143+
.password(this.properties.getPassword()).build();
144+
}
145+
144146
}
145147

146148
/**
@@ -172,8 +174,8 @@ public void afterPropertiesSet() throws LiquibaseException {
172174
}
173175

174176
private void closeDataSource() {
175-
Method closeMethod = ReflectionUtils.findMethod(getDataSource().getClass(),
176-
"close");
177+
Class<?> dataSourceClass = getDataSource().getClass();
178+
Method closeMethod = ReflectionUtils.findMethod(dataSourceClass, "close");
177179
if (closeMethod != null) {
178180
ReflectionUtils.invokeMethod(closeMethod, getDataSource());
179181
}

0 commit comments

Comments
 (0)