|
54 | 54 | import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
55 | 55 | import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
|
56 | 56 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
| 57 | +import org.springframework.util.StringUtils; |
57 | 58 |
|
58 | 59 | /**
|
59 | 60 | * {@link EnableAutoConfiguration Auto-configuration} for Liquibase.
|
@@ -148,20 +149,26 @@ private DataSource createNewDataSource(DataSourceProperties dataSourceProperties
|
148 | 149 | String url = getProperty(this.properties::getUrl, dataSourceProperties::determineUrl);
|
149 | 150 | String user = getProperty(this.properties::getUser, dataSourceProperties::determineUsername);
|
150 | 151 | String password = getProperty(this.properties::getPassword, dataSourceProperties::determinePassword);
|
| 152 | + String driverClassName = determineDriverClassName(dataSourceProperties, url); |
151 | 153 | return DataSourceBuilder.create().type(determineDataSourceType()).url(url).username(user).password(password)
|
152 |
| - .driverClassName(determineDriverClassName(url)).build(); |
| 154 | + .driverClassName(driverClassName).build(); |
| 155 | + } |
| 156 | + |
| 157 | + private String determineDriverClassName(DataSourceProperties dataSourceProperties, String url) { |
| 158 | + if (StringUtils.hasText(this.properties.getDriverClassName())) { |
| 159 | + return this.properties.getDriverClassName(); |
| 160 | + } |
| 161 | + if (StringUtils.hasText(dataSourceProperties.getDriverClassName())) { |
| 162 | + return dataSourceProperties.getDriverClassName(); |
| 163 | + } |
| 164 | + return StringUtils.hasText(url) ? DatabaseDriver.fromJdbcUrl(url).getDriverClassName() : null; |
153 | 165 | }
|
154 | 166 |
|
155 | 167 | private Class<? extends DataSource> determineDataSourceType() {
|
156 | 168 | Class<? extends DataSource> type = DataSourceBuilder.findType(null);
|
157 | 169 | return (type != null) ? type : SimpleDriverDataSource.class;
|
158 | 170 | }
|
159 | 171 |
|
160 |
| - private String determineDriverClassName(String url) { |
161 |
| - String driverClassName = this.properties.getDriverClassName(); |
162 |
| - return (driverClassName != null) ? driverClassName : DatabaseDriver.fromJdbcUrl(url).getDriverClassName(); |
163 |
| - } |
164 |
| - |
165 | 172 | private String getProperty(Supplier<String> property, Supplier<String> defaultValue) {
|
166 | 173 | String value = property.get();
|
167 | 174 | return (value != null) ? value : defaultValue.get();
|
|
0 commit comments