Add support for Vibur DBCP connection pool to DataSourceBuilder

Closes gh-42903
This commit is contained in:
Stéphane Nicoll 2024-11-04 08:09:08 +09:00
parent 0a95b229e0
commit 9f6f244370
7 changed files with 48 additions and 3 deletions

View File

@ -2484,6 +2484,14 @@ bom {
releaseNotes("https://github.com/mojohaus/versions/releases/tag/{version}")
}
}
library("Vibur", "25.0") {
group("org.vibur") {
modules = [
"vibur-dbcp",
"vibur-object-pool"
]
}
}
library("WebJars Locator Lite", "1.0.1") {
group("org.webjars") {
modules = [

View File

@ -142,6 +142,7 @@ The following connection pools are supported by javadoc:org.springframework.boot
* H2 javadoc:org.h2.jdbcx.JdbcDataSource[]
* PostgreSQL javadoc:org.postgresql.ds.PGSimpleDataSource[]
* C3P0
* Vibur

View File

@ -96,6 +96,7 @@ dependencies {
exclude group: "org.eclipse.jetty", module: "jetty-servlet"
exclude group: "jakarta.mail", module: "jakarta.mail-api"
}
optional("org.vibur:vibur-dbcp")
optional("org.yaml:snakeyaml")
optional("org.jetbrains.kotlin:kotlin-reflect")
optional("org.jetbrains.kotlin:kotlin-stdlib")

View File

@ -36,6 +36,7 @@ import oracle.ucp.jdbc.PoolDataSourceImpl;
import org.apache.commons.dbcp2.BasicDataSource;
import org.h2.jdbcx.JdbcDataSource;
import org.postgresql.ds.PGSimpleDataSource;
import org.vibur.dbcp.ViburDBCPDataSource;
import org.springframework.beans.BeanUtils;
import org.springframework.core.ResolvableType;
@ -60,6 +61,7 @@ import org.springframework.util.StringUtils;
* <li>Apache DBCP2 ({@code org.apache.commons.dbcp2.BasicDataSource})</li>
* <li>Oracle UCP ({@code oracle.ucp.jdbc.PoolDataSourceImpl})</li>
* <li>C3P0 ({@code com.mchange.v2.c3p0.ComboPooledDataSource})</li>
* <li>Vibur {@code org.vibur.dbcp.ViburDBCPDataSource}</li>
* </ul>
* <p>
* The following non-pooling {@link DataSource} implementations can be used when
@ -412,6 +414,8 @@ public final class DataSourceBuilder<T extends DataSource> {
OraclePoolDataSourceProperties::new, "oracle.jdbc.OracleConnection");
result = lookup(classLoader, type, result, "com.mchange.v2.c3p0.ComboPooledDataSource",
ComboPooledDataSourceProperties::new);
result = lookup(classLoader, type, result, "org.vibur.dbcp.ViburDBCPDataSource",
ViburDataSourceProperties::new);
return result;
}
@ -694,6 +698,18 @@ public final class DataSourceBuilder<T extends DataSource> {
}
private static class ViburDataSourceProperties extends MappedDataSourceProperties<ViburDBCPDataSource> {
ViburDataSourceProperties() {
add(DataSourceProperty.URL, ViburDBCPDataSource::getJdbcUrl, ViburDBCPDataSource::setJdbcUrl);
add(DataSourceProperty.DRIVER_CLASS_NAME, ViburDBCPDataSource::getDriverClassName,
ViburDBCPDataSource::setDriverClassName);
add(DataSourceProperty.USERNAME, ViburDBCPDataSource::getUsername, ViburDBCPDataSource::setUsername);
add(DataSourceProperty.PASSWORD, ViburDBCPDataSource::getPassword, ViburDBCPDataSource::setPassword);
}
}
/**
* {@link DataSourceProperties} for Spring's {@link SimpleDriverDataSource}.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@ -43,6 +43,7 @@ class DataSourceBuilderRuntimeHints implements RuntimeHintsRegistrar {
typeNames.add("org.apache.commons.dbcp2.BasicDataSource");
typeNames.add("oracle.jdbc.datasource.OracleDataSource");
typeNames.add("oracle.ucp.jdbc.PoolDataSource");
typeNames.add("org.vibur.dbcp.ViburDBCPDataSource");
typeNames.add("org.postgresql.ds.PGSimpleDataSource");
typeNames.add("org.springframework.jdbc.datasource.SimpleDriverDataSource");
typeNames.add("org.apache.tomcat.jdbc.pool.DataSource");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@ -42,7 +42,7 @@ class DataSourceBuilderRuntimeHintsTests {
.of(com.mchange.v2.c3p0.ComboPooledDataSource.class, org.h2.jdbcx.JdbcDataSource.class,
com.zaxxer.hikari.HikariDataSource.class, org.apache.commons.dbcp2.BasicDataSource.class,
oracle.jdbc.datasource.OracleDataSource.class, oracle.ucp.jdbc.PoolDataSource.class,
org.postgresql.ds.PGSimpleDataSource.class,
org.vibur.dbcp.ViburDBCPDataSource.class, org.postgresql.ds.PGSimpleDataSource.class,
org.springframework.jdbc.datasource.SimpleDriverDataSource.class,
org.apache.tomcat.jdbc.pool.DataSource.class)
.forEach((dataSourceType) -> {

View File

@ -42,6 +42,7 @@ import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.postgresql.ds.PGSimpleDataSource;
import org.vibur.dbcp.ViburDBCPDataSource;
import org.springframework.jdbc.datasource.AbstractDataSource;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
@ -504,6 +505,23 @@ class DataSourceBuilderTests {
assertThat(c3p0DataSource.getDriverClass()).isEqualTo("com.example.Driver");
}
@Test // gh-42903
void buildWhenViburTypeSpecifiedReturnsExpectedDataSource() {
this.dataSource = DataSourceBuilder.create()
.url("jdbc:postgresql://localhost:5432/postgres")
.type(ViburDBCPDataSource.class)
.username("test")
.password("secret")
.driverClassName("com.example.Driver")
.build();
assertThat(this.dataSource).isInstanceOf(ViburDBCPDataSource.class);
ViburDBCPDataSource viburDataSource = (ViburDBCPDataSource) this.dataSource;
assertThat(viburDataSource.getJdbcUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
assertThat(viburDataSource.getUsername()).isEqualTo("test");
assertThat(viburDataSource.getPassword()).isEqualTo("secret");
assertThat(viburDataSource.getDriverClassName()).isEqualTo("com.example.Driver");
}
private DataSource wrap(DataSource target) {
return new DataSourceWrapper(target);
}