Skip to content

Commit 9f6f244

Browse files
committed
Add support for Vibur DBCP connection pool to DataSourceBuilder
Closes gh-42903
1 parent 0a95b22 commit 9f6f244

File tree

7 files changed

+48
-3
lines changed

7 files changed

+48
-3
lines changed

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,14 @@ bom {
24842484
releaseNotes("https://github.com/mojohaus/versions/releases/tag/{version}")
24852485
}
24862486
}
2487+
library("Vibur", "25.0") {
2488+
group("org.vibur") {
2489+
modules = [
2490+
"vibur-dbcp",
2491+
"vibur-object-pool"
2492+
]
2493+
}
2494+
}
24872495
library("WebJars Locator Lite", "1.0.1") {
24882496
group("org.webjars") {
24892497
modules = [

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/data/sql.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ The following connection pools are supported by javadoc:org.springframework.boot
142142
* H2 javadoc:org.h2.jdbcx.JdbcDataSource[]
143143
* PostgreSQL javadoc:org.postgresql.ds.PGSimpleDataSource[]
144144
* C3P0
145+
* Vibur
145146

146147

147148

spring-boot-project/spring-boot/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ dependencies {
9696
exclude group: "org.eclipse.jetty", module: "jetty-servlet"
9797
exclude group: "jakarta.mail", module: "jakarta.mail-api"
9898
}
99+
optional("org.vibur:vibur-dbcp")
99100
optional("org.yaml:snakeyaml")
100101
optional("org.jetbrains.kotlin:kotlin-reflect")
101102
optional("org.jetbrains.kotlin:kotlin-stdlib")

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.commons.dbcp2.BasicDataSource;
3737
import org.h2.jdbcx.JdbcDataSource;
3838
import org.postgresql.ds.PGSimpleDataSource;
39+
import org.vibur.dbcp.ViburDBCPDataSource;
3940

4041
import org.springframework.beans.BeanUtils;
4142
import org.springframework.core.ResolvableType;
@@ -60,6 +61,7 @@
6061
* <li>Apache DBCP2 ({@code org.apache.commons.dbcp2.BasicDataSource})</li>
6162
* <li>Oracle UCP ({@code oracle.ucp.jdbc.PoolDataSourceImpl})</li>
6263
* <li>C3P0 ({@code com.mchange.v2.c3p0.ComboPooledDataSource})</li>
64+
* <li>Vibur {@code org.vibur.dbcp.ViburDBCPDataSource}</li>
6365
* </ul>
6466
* <p>
6567
* The following non-pooling {@link DataSource} implementations can be used when
@@ -412,6 +414,8 @@ private static <T extends DataSource> MappedDataSourceProperties<T> lookupPooled
412414
OraclePoolDataSourceProperties::new, "oracle.jdbc.OracleConnection");
413415
result = lookup(classLoader, type, result, "com.mchange.v2.c3p0.ComboPooledDataSource",
414416
ComboPooledDataSourceProperties::new);
417+
result = lookup(classLoader, type, result, "org.vibur.dbcp.ViburDBCPDataSource",
418+
ViburDataSourceProperties::new);
415419
return result;
416420
}
417421

@@ -694,6 +698,18 @@ private void setDriverClass(ComboPooledDataSource dataSource, String driverClass
694698

695699
}
696700

701+
private static class ViburDataSourceProperties extends MappedDataSourceProperties<ViburDBCPDataSource> {
702+
703+
ViburDataSourceProperties() {
704+
add(DataSourceProperty.URL, ViburDBCPDataSource::getJdbcUrl, ViburDBCPDataSource::setJdbcUrl);
705+
add(DataSourceProperty.DRIVER_CLASS_NAME, ViburDBCPDataSource::getDriverClassName,
706+
ViburDBCPDataSource::setDriverClassName);
707+
add(DataSourceProperty.USERNAME, ViburDBCPDataSource::getUsername, ViburDBCPDataSource::setUsername);
708+
add(DataSourceProperty.PASSWORD, ViburDBCPDataSource::getPassword, ViburDBCPDataSource::setPassword);
709+
}
710+
711+
}
712+
697713
/**
698714
* {@link DataSourceProperties} for Spring's {@link SimpleDriverDataSource}.
699715
*/

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilderRuntimeHints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ class DataSourceBuilderRuntimeHints implements RuntimeHintsRegistrar {
4343
typeNames.add("org.apache.commons.dbcp2.BasicDataSource");
4444
typeNames.add("oracle.jdbc.datasource.OracleDataSource");
4545
typeNames.add("oracle.ucp.jdbc.PoolDataSource");
46+
typeNames.add("org.vibur.dbcp.ViburDBCPDataSource");
4647
typeNames.add("org.postgresql.ds.PGSimpleDataSource");
4748
typeNames.add("org.springframework.jdbc.datasource.SimpleDriverDataSource");
4849
typeNames.add("org.apache.tomcat.jdbc.pool.DataSource");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderRuntimeHintsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ void shouldRegisterDataSourceConstructors() {
4242
.of(com.mchange.v2.c3p0.ComboPooledDataSource.class, org.h2.jdbcx.JdbcDataSource.class,
4343
com.zaxxer.hikari.HikariDataSource.class, org.apache.commons.dbcp2.BasicDataSource.class,
4444
oracle.jdbc.datasource.OracleDataSource.class, oracle.ucp.jdbc.PoolDataSource.class,
45-
org.postgresql.ds.PGSimpleDataSource.class,
45+
org.vibur.dbcp.ViburDBCPDataSource.class, org.postgresql.ds.PGSimpleDataSource.class,
4646
org.springframework.jdbc.datasource.SimpleDriverDataSource.class,
4747
org.apache.tomcat.jdbc.pool.DataSource.class)
4848
.forEach((dataSourceType) -> {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.junit.jupiter.api.AfterEach;
4343
import org.junit.jupiter.api.Test;
4444
import org.postgresql.ds.PGSimpleDataSource;
45+
import org.vibur.dbcp.ViburDBCPDataSource;
4546

4647
import org.springframework.jdbc.datasource.AbstractDataSource;
4748
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
@@ -504,6 +505,23 @@ void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource() {
504505
assertThat(c3p0DataSource.getDriverClass()).isEqualTo("com.example.Driver");
505506
}
506507

508+
@Test // gh-42903
509+
void buildWhenViburTypeSpecifiedReturnsExpectedDataSource() {
510+
this.dataSource = DataSourceBuilder.create()
511+
.url("jdbc:postgresql://localhost:5432/postgres")
512+
.type(ViburDBCPDataSource.class)
513+
.username("test")
514+
.password("secret")
515+
.driverClassName("com.example.Driver")
516+
.build();
517+
assertThat(this.dataSource).isInstanceOf(ViburDBCPDataSource.class);
518+
ViburDBCPDataSource viburDataSource = (ViburDBCPDataSource) this.dataSource;
519+
assertThat(viburDataSource.getJdbcUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
520+
assertThat(viburDataSource.getUsername()).isEqualTo("test");
521+
assertThat(viburDataSource.getPassword()).isEqualTo("secret");
522+
assertThat(viburDataSource.getDriverClassName()).isEqualTo("com.example.Driver");
523+
}
524+
507525
private DataSource wrap(DataSource target) {
508526
return new DataSourceWrapper(target);
509527
}

0 commit comments

Comments
 (0)