Merge branch '1.4.x' into 1.5.x

pull/9259/head
Phillip Webb 8 years ago
commit 440d03bf9e

@ -115,18 +115,14 @@ public class LiquibaseAutoConfiguration {
} }
private SpringLiquibase createSpringLiquibase() { private SpringLiquibase createSpringLiquibase() {
SpringLiquibase liquibase; DataSource liquibaseDataSource = getDataSource();
DataSource dataSourceToUse = getDataSource(); if (liquibaseDataSource != null) {
if (dataSourceToUse == null) { SpringLiquibase liquibase = new SpringLiquibase();
dataSourceToUse = DataSourceBuilder.create().url(this.properties.getUrl()) liquibase.setDataSource(liquibaseDataSource);
.username(this.properties.getUser()) return liquibase;
.password(this.properties.getPassword()).build();
liquibase = new DataSourceClosingSpringLiquibase();
} }
else { SpringLiquibase liquibase = new DataSourceClosingSpringLiquibase();
liquibase = new SpringLiquibase(); liquibase.setDataSource(createNewDataSource());
}
liquibase.setDataSource(dataSourceToUse);
return liquibase; return liquibase;
} }
@ -134,12 +130,18 @@ public class LiquibaseAutoConfiguration {
if (this.liquibaseDataSource != null) { if (this.liquibaseDataSource != null) {
return this.liquibaseDataSource; return this.liquibaseDataSource;
} }
else if (this.properties.getUrl() == null) { if (this.properties.getUrl() == null) {
return this.dataSource; return this.dataSource;
} }
return null; return null;
} }
private DataSource createNewDataSource() {
return DataSourceBuilder.create().url(this.properties.getUrl())
.username(this.properties.getUser())
.password(this.properties.getPassword()).build();
}
} }
/** /**
@ -171,8 +173,8 @@ public class LiquibaseAutoConfiguration {
} }
private void closeDataSource() { private void closeDataSource() {
Method closeMethod = ReflectionUtils.findMethod(getDataSource().getClass(), Class<?> dataSourceClass = getDataSource().getClass();
"close"); Method closeMethod = ReflectionUtils.findMethod(dataSourceClass, "close");
if (closeMethod != null) { if (closeMethod != null) {
ReflectionUtils.invokeMethod(closeMethod, getDataSource()); ReflectionUtils.invokeMethod(closeMethod, getDataSource());
} }

Loading…
Cancel
Save