Skip to content

Commit

Permalink
Hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Nov 3, 2024
1 parent fdf24c6 commit af45053
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
8 changes: 8 additions & 0 deletions spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,14 @@ bom {
]
}
}
library("Vibur", "25.0") {
group("org.vibur") {
modules = [
"vibur-dbcp",
"vibur-object-pool"
]
}
}
library("WebJars Locator Lite", "1.0.0") {
group("org.webjars") {
modules = [
Expand Down
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 @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -411,6 +412,8 @@ private static <T extends DataSource> MappedDataSourceProperties<T> lookupPooled
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;
}

Expand Down Expand Up @@ -693,6 +696,18 @@ private void setDriverClass(ComboPooledDataSource dataSource, String driverClass

}

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}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,7 +42,7 @@ void shouldRegisterDataSourceConstructors() {
.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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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;
Expand Down Expand Up @@ -504,6 +505,23 @@ void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource() {
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);
}
Expand Down

0 comments on commit af45053

Please sign in to comment.