Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
optional("org.codehaus.groovy:groovy-templates")
optional("com.github.ben-manes.caffeine:caffeine")
optional("com.github.mxab.thymeleaf.extras:thymeleaf-extras-data-attribute")
optional("com.oracle.ojdbc:ucp")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized I used the old groupId for Oracle. It would be better replace "com.oracle.ojdbc" with "com.oracle.database.jdbc".

optional("com.sendgrid:sendgrid-java")
optional("com.unboundid:unboundid-ldapsdk")
optional("com.zaxxer:HikariCP")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @author Phillip Webb
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @author Fabio Grassi
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
Expand All @@ -69,8 +70,8 @@ protected static class EmbeddedDatabaseConfiguration {
@Conditional(PooledDataSourceCondition.class)
@ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
@Import({ DataSourceConfiguration.Hikari.class, DataSourceConfiguration.Tomcat.class,
DataSourceConfiguration.Dbcp2.class, DataSourceConfiguration.Generic.class,
DataSourceJmxConfiguration.class })
DataSourceConfiguration.Dbcp2.class, DataSourceConfiguration.Ucp.class,
DataSourceConfiguration.Generic.class, DataSourceJmxConfiguration.class })
protected static class PooledDataSourceConfiguration {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package org.springframework.boot.autoconfigure.jdbc;

import java.sql.SQLException;

import javax.sql.DataSource;

import com.zaxxer.hikari.HikariDataSource;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceImpl;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -27,6 +31,7 @@
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.util.StringUtils;

/**
Expand All @@ -35,6 +40,7 @@
* @author Dave Syer
* @author Phillip Webb
* @author Stephane Nicoll
* @author Fabio Grassi
*/
abstract class DataSourceConfiguration {

Expand Down Expand Up @@ -109,6 +115,33 @@ org.apache.commons.dbcp2.BasicDataSource dataSource(DataSourceProperties propert

}

/**
* UCP DataSource configuration.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(PoolDataSource.class)
@ConditionalOnMissingBean(DataSource.class)
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "oracle.ucp.jdbc.PoolDataSource",
matchIfMissing = true)
static class Ucp {

@Bean
@ConfigurationProperties(prefix = "spring.datasource.ucp")
PoolDataSource dataSource(DataSourceProperties properties) {
PoolDataSource dataSource = createDataSource(properties, PoolDataSourceImpl.class);
if (StringUtils.hasText(properties.getName())) {
try {
dataSource.setConnectionPoolName(properties.getName());
}
catch (SQLException e) {
throw new InvalidDataAccessApiUsageException("Error setting property connectionPoolName", e);
}
}
return dataSource;
}

}

/**
* Generic DataSource configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.jdbc.metadata;

import com.zaxxer.hikari.HikariDataSource;
import oracle.ucp.jdbc.PoolDataSource;
import org.apache.commons.dbcp2.BasicDataSource;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -25,6 +26,7 @@
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.boot.jdbc.metadata.HikariDataSourcePoolMetadata;
import org.springframework.boot.jdbc.metadata.TomcatDataSourcePoolMetadata;
import org.springframework.boot.jdbc.metadata.UcpDataSourcePoolMetadata;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -33,6 +35,7 @@
* sources.
*
* @author Stephane Nicoll
* @author Fabio Grassi
* @since 1.2.0
*/
@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -90,4 +93,21 @@ DataSourcePoolMetadataProvider commonsDbcp2PoolDataSourceMetadataProvider() {

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(PoolDataSource.class)
static class UcpPoolDataSourceMetadataProviderConfiguration {

@Bean
DataSourcePoolMetadataProvider UcpPoolDataSourceMetadataProvider() {
return (dataSource) -> {
PoolDataSource ucpDataSource = DataSourceUnwrapper.unwrap(dataSource, PoolDataSource.class);
if (ucpDataSource != null) {
return new UcpDataSourcePoolMetadata(ucpDataSource);
}
return null;
};
}

}

}
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
optional("com.atomikos:transactions-jta")
optional("com.fasterxml.jackson.core:jackson-databind")
optional("com.google.code.gson:gson")
optional("com.oracle.ojdbc:ucp")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized I used the old groupId for Oracle. It would be better replace "com.oracle.ojdbc" with "com.oracle.database.jdbc".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PR is usually created off a branch so that's a bit unfortunate now but if you add an extra commit on your fork of master and push, this will update this PR automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

optional("com.samskivert:jmustache")
optional("com.zaxxer:HikariCP")
optional("io.netty:netty-tcnative-boringssl-static")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@

/**
* Convenience class for building a {@link DataSource} with common implementations and
* properties. If HikariCP, Tomcat or Commons DBCP are on the classpath one of them will
* be selected (in that order with Hikari first). In the interest of a uniform interface,
* and so that there can be a fallback to an embedded database if one can be detected on
* the classpath, only a small set of common configuration properties are supported. To
* inject additional properties into the result you can downcast it, or use
* properties. If HikariCP, Tomcat, Commons DBCP or Oracle UCP are on the classpath one of
* them will be selected (in that order with Hikari first). In the interest of a uniform
* interface, and so that there can be a fallback to an embedded database if one can be
* detected on the classpath, only a small set of common configuration properties are
* supported. To inject additional properties into the result you can downcast it, or use
* {@code @ConfigurationProperties}.
*
* @param <T> type of DataSource produced by the builder
* @author Dave Syer
* @author Madhura Bhave
* @author Fabio Grassi
* @since 2.0.0
*/
public final class DataSourceBuilder<T extends DataSource> {

private static final String[] DATA_SOURCE_TYPE_NAMES = new String[] { "com.zaxxer.hikari.HikariDataSource",
"org.apache.tomcat.jdbc.pool.DataSource", "org.apache.commons.dbcp2.BasicDataSource" };
"org.apache.tomcat.jdbc.pool.DataSource", "org.apache.commons.dbcp2.BasicDataSource",
"oracle.ucp.jdbc.PoolDataSourceImpl" };

private Class<? extends DataSource> type;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.jdbc.metadata;

import java.sql.SQLException;

import javax.sql.DataSource;

import oracle.ucp.jdbc.PoolDataSource;

import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.util.StringUtils;

/**
* {@link DataSourcePoolMetadata} for a Oracle UCP {@link DataSource}.
*
* @author Fabio Grassi
* @since 2.3.4
*/
public class UcpDataSourcePoolMetadata extends AbstractDataSourcePoolMetadata<PoolDataSource> {

public UcpDataSourcePoolMetadata(PoolDataSource dataSource) {
super(dataSource);
}

@Override
public Integer getActive() {
try {
return getDataSource().getBorrowedConnectionsCount();
}
catch (SQLException e) {
throw new InvalidDataAccessApiUsageException("Error while reading property borrowedConnectionsCount", e);
}
}

@Override
public Integer getIdle() {
try {
return getDataSource().getAvailableConnectionsCount();
}
catch (SQLException e) {
throw new InvalidDataAccessApiUsageException("Error while reading property availableConnectionsCount", e);
}
}

@Override
public Integer getMax() {
return getDataSource().getMaxPoolSize();
}

@Override
public Integer getMin() {
return getDataSource().getMinPoolSize();
}

@Override
public String getValidationQuery() {
return getDataSource().getSQLForValidateConnection();
}

@Override
public Boolean getDefaultAutoCommit() {
String ac = getDataSource().getConnectionProperties().getProperty("AutoCommit");
return StringUtils.hasText(ac) ? Boolean.valueOf(ac) : null;
}

}