Commit 15375fdf authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.4.x'

Closes gh-25342
parents 274a985e 5d1bb302
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -196,6 +196,8 @@ public final class DataSourceBuilder<T extends DataSource> { ...@@ -196,6 +196,8 @@ public final class DataSourceBuilder<T extends DataSource> {
(aliases) -> aliases.addAliases("driver-class-name", "driver-class")))); (aliases) -> aliases.addAliases("driver-class-name", "driver-class"))));
addIfAvailable(this.allDataSourceSettings, addIfAvailable(this.allDataSourceSettings,
create(classLoader, "oracle.jdbc.datasource.OracleDataSource", OracleDataSourceSettings::new)); create(classLoader, "oracle.jdbc.datasource.OracleDataSource", OracleDataSourceSettings::new));
addIfAvailable(this.allDataSourceSettings, create(classLoader, "org.h2.jdbcx.JdbcDataSource",
(type) -> new DataSourceSettings(type, (aliases) -> aliases.addAliases("username", "user"))));
} }
private static List<DataSourceSettings> resolveAvailableDataSourceSettings(ClassLoader classLoader) { private static List<DataSourceSettings> resolveAvailableDataSourceSettings(ClassLoader classLoader) {
......
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -30,6 +30,7 @@ import oracle.jdbc.pool.OracleDataSource; ...@@ -30,6 +30,7 @@ import oracle.jdbc.pool.OracleDataSource;
import oracle.ucp.jdbc.PoolDataSourceImpl; import oracle.ucp.jdbc.PoolDataSourceImpl;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import org.h2.Driver; import org.h2.Driver;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -119,6 +120,15 @@ class DataSourceBuilderTests { ...@@ -119,6 +120,15 @@ class DataSourceBuilderTests {
assertThat(upcDataSource.getUser()).isEqualTo("test"); assertThat(upcDataSource.getUser()).isEqualTo("test");
} }
@Test
void dataSourceCanBeCreatedWithH2JdbcDataSource() {
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(JdbcDataSource.class).username("test")
.build();
assertThat(this.dataSource).isInstanceOf(JdbcDataSource.class);
JdbcDataSource h2DataSource = (JdbcDataSource) this.dataSource;
assertThat(h2DataSource.getUser()).isEqualTo("test");
}
@Test @Test
void dataSourceAliasesAreOnlyAppliedToRelevantDataSource() { void dataSourceAliasesAreOnlyAppliedToRelevantDataSource() {
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(TestDataSource.class).username("test") this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(TestDataSource.class).username("test")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment