|
|
@ -25,7 +25,6 @@ import oracle.jdbc.OracleConnection;
|
|
|
|
import oracle.ucp.jdbc.PoolDataSourceImpl;
|
|
|
|
import oracle.ucp.jdbc.PoolDataSourceImpl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
@ -48,20 +47,15 @@ import org.springframework.util.StringUtils;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
abstract class DataSourceConfiguration {
|
|
|
|
abstract class DataSourceConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
private static <T> T createDataSource(DataSourceProperties properties, Class<? extends DataSource> type) {
|
|
|
|
|
|
|
|
return (T) properties.initializeDataSourceBuilder().type(type).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private static <T> T createDataSource(JdbcConnectionDetails connectionDetails, Class<? extends DataSource> type,
|
|
|
|
private static <T> T createDataSource(JdbcConnectionDetails connectionDetails, Class<? extends DataSource> type,
|
|
|
|
ClassLoader classLoader) {
|
|
|
|
ClassLoader classLoader) {
|
|
|
|
return (T) DataSourceBuilder.create(classLoader)
|
|
|
|
return (T) DataSourceBuilder.create(classLoader)
|
|
|
|
|
|
|
|
.type(type)
|
|
|
|
|
|
|
|
.driverClassName(connectionDetails.getDriverClassName())
|
|
|
|
.url(connectionDetails.getJdbcUrl())
|
|
|
|
.url(connectionDetails.getJdbcUrl())
|
|
|
|
.username(connectionDetails.getUsername())
|
|
|
|
.username(connectionDetails.getUsername())
|
|
|
|
.password(connectionDetails.getPassword())
|
|
|
|
.password(connectionDetails.getPassword())
|
|
|
|
.driverClassName(connectionDetails.getDriverClassName())
|
|
|
|
|
|
|
|
.type(type)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -76,7 +70,7 @@ abstract class DataSourceConfiguration {
|
|
|
|
static class Tomcat {
|
|
|
|
static class Tomcat {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnBean(JdbcConnectionDetails.class)
|
|
|
|
@ConditionalOnMissingBean(PropertiesJdbcConnectionDetails.class)
|
|
|
|
static TomcatJdbcConnectionDetailsBeanPostProcessor tomcatJdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
static TomcatJdbcConnectionDetailsBeanPostProcessor tomcatJdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
return new TomcatJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
|
return new TomcatJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
@ -85,15 +79,12 @@ abstract class DataSourceConfiguration {
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.tomcat")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.tomcat")
|
|
|
|
org.apache.tomcat.jdbc.pool.DataSource dataSource(DataSourceProperties properties,
|
|
|
|
org.apache.tomcat.jdbc.pool.DataSource dataSource(DataSourceProperties properties,
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
JdbcConnectionDetails connectionDetails) {
|
|
|
|
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
|
|
|
|
|
|
|
|
Class<? extends DataSource> dataSourceType = org.apache.tomcat.jdbc.pool.DataSource.class;
|
|
|
|
Class<? extends DataSource> dataSourceType = org.apache.tomcat.jdbc.pool.DataSource.class;
|
|
|
|
org.apache.tomcat.jdbc.pool.DataSource dataSource = (connectionDetails != null)
|
|
|
|
org.apache.tomcat.jdbc.pool.DataSource dataSource = createDataSource(connectionDetails, dataSourceType,
|
|
|
|
? createDataSource(connectionDetails, dataSourceType, properties.getClassLoader())
|
|
|
|
properties.getClassLoader());
|
|
|
|
: createDataSource(properties, dataSourceType);
|
|
|
|
|
|
|
|
String validationQuery;
|
|
|
|
String validationQuery;
|
|
|
|
String url = (connectionDetails != null) ? connectionDetails.getJdbcUrl() : properties.determineUrl();
|
|
|
|
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(connectionDetails.getJdbcUrl());
|
|
|
|
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(url);
|
|
|
|
|
|
|
|
validationQuery = databaseDriver.getValidationQuery();
|
|
|
|
validationQuery = databaseDriver.getValidationQuery();
|
|
|
|
if (validationQuery != null) {
|
|
|
|
if (validationQuery != null) {
|
|
|
|
dataSource.setTestOnBorrow(true);
|
|
|
|
dataSource.setTestOnBorrow(true);
|
|
|
@ -115,7 +106,6 @@ abstract class DataSourceConfiguration {
|
|
|
|
static class Hikari {
|
|
|
|
static class Hikari {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnBean(JdbcConnectionDetails.class)
|
|
|
|
|
|
|
|
static HikariJdbcConnectionDetailsBeanPostProcessor jdbcConnectionDetailsHikariBeanPostProcessor(
|
|
|
|
static HikariJdbcConnectionDetailsBeanPostProcessor jdbcConnectionDetailsHikariBeanPostProcessor(
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
return new HikariJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
|
return new HikariJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
@ -123,12 +113,9 @@ abstract class DataSourceConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.hikari")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.hikari")
|
|
|
|
HikariDataSource dataSource(DataSourceProperties properties,
|
|
|
|
HikariDataSource dataSource(DataSourceProperties properties, JdbcConnectionDetails connectionDetails) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
HikariDataSource dataSource = createDataSource(connectionDetails, HikariDataSource.class,
|
|
|
|
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
|
|
|
|
properties.getClassLoader());
|
|
|
|
HikariDataSource dataSource = (connectionDetails != null)
|
|
|
|
|
|
|
|
? createDataSource(connectionDetails, HikariDataSource.class, properties.getClassLoader())
|
|
|
|
|
|
|
|
: createDataSource(properties, HikariDataSource.class);
|
|
|
|
|
|
|
|
if (StringUtils.hasText(properties.getName())) {
|
|
|
|
if (StringUtils.hasText(properties.getName())) {
|
|
|
|
dataSource.setPoolName(properties.getName());
|
|
|
|
dataSource.setPoolName(properties.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,7 +135,6 @@ abstract class DataSourceConfiguration {
|
|
|
|
static class Dbcp2 {
|
|
|
|
static class Dbcp2 {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnBean(JdbcConnectionDetails.class)
|
|
|
|
|
|
|
|
static Dbcp2JdbcConnectionDetailsBeanPostProcessor dbcp2JdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
static Dbcp2JdbcConnectionDetailsBeanPostProcessor dbcp2JdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
return new Dbcp2JdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
|
return new Dbcp2JdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
@ -157,12 +143,9 @@ abstract class DataSourceConfiguration {
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.dbcp2")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.dbcp2")
|
|
|
|
org.apache.commons.dbcp2.BasicDataSource dataSource(DataSourceProperties properties,
|
|
|
|
org.apache.commons.dbcp2.BasicDataSource dataSource(DataSourceProperties properties,
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
JdbcConnectionDetails connectionDetails) {
|
|
|
|
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
|
|
|
|
|
|
|
|
Class<? extends DataSource> dataSourceType = org.apache.commons.dbcp2.BasicDataSource.class;
|
|
|
|
Class<? extends DataSource> dataSourceType = org.apache.commons.dbcp2.BasicDataSource.class;
|
|
|
|
return (connectionDetails != null)
|
|
|
|
return createDataSource(connectionDetails, dataSourceType, properties.getClassLoader());
|
|
|
|
? createDataSource(connectionDetails, dataSourceType, properties.getClassLoader())
|
|
|
|
|
|
|
|
: createDataSource(properties, dataSourceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -178,7 +161,6 @@ abstract class DataSourceConfiguration {
|
|
|
|
static class OracleUcp {
|
|
|
|
static class OracleUcp {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnBean(JdbcConnectionDetails.class)
|
|
|
|
|
|
|
|
static OracleUcpJdbcConnectionDetailsBeanPostProcessor oracleUcpJdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
static OracleUcpJdbcConnectionDetailsBeanPostProcessor oracleUcpJdbcConnectionDetailsBeanPostProcessor(
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
return new OracleUcpJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
|
return new OracleUcpJdbcConnectionDetailsBeanPostProcessor(connectionDetailsProvider);
|
|
|
@ -186,12 +168,10 @@ abstract class DataSourceConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.oracleucp")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.oracleucp")
|
|
|
|
PoolDataSourceImpl dataSource(DataSourceProperties properties,
|
|
|
|
PoolDataSourceImpl dataSource(DataSourceProperties properties, JdbcConnectionDetails connectionDetails)
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) throws SQLException {
|
|
|
|
throws SQLException {
|
|
|
|
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
|
|
|
|
PoolDataSourceImpl dataSource = createDataSource(connectionDetails, PoolDataSourceImpl.class,
|
|
|
|
PoolDataSourceImpl dataSource = (connectionDetails != null)
|
|
|
|
properties.getClassLoader());
|
|
|
|
? createDataSource(connectionDetails, PoolDataSourceImpl.class, properties.getClassLoader())
|
|
|
|
|
|
|
|
: createDataSource(properties, PoolDataSourceImpl.class);
|
|
|
|
|
|
|
|
dataSource.setValidateConnectionOnBorrow(true);
|
|
|
|
dataSource.setValidateConnectionOnBorrow(true);
|
|
|
|
if (StringUtils.hasText(properties.getName())) {
|
|
|
|
if (StringUtils.hasText(properties.getName())) {
|
|
|
|
dataSource.setConnectionPoolName(properties.getName());
|
|
|
|
dataSource.setConnectionPoolName(properties.getName());
|
|
|
@ -210,13 +190,8 @@ abstract class DataSourceConfiguration {
|
|
|
|
static class Generic {
|
|
|
|
static class Generic {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
DataSource dataSource(DataSourceProperties properties,
|
|
|
|
DataSource dataSource(DataSourceProperties properties, JdbcConnectionDetails connectionDetails) {
|
|
|
|
ObjectProvider<JdbcConnectionDetails> connectionDetailsProvider) {
|
|
|
|
return createDataSource(connectionDetails, properties.getType(), properties.getClassLoader());
|
|
|
|
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
|
|
|
|
|
|
|
|
if (connectionDetails != null) {
|
|
|
|
|
|
|
|
return createDataSource(connectionDetails, properties.getType(), properties.getClassLoader());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.initializeDataSourceBuilder().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|