-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for `com.baomidou:dynamic-datasource-spring-boot-starter:…
…3.6.1`
- Loading branch information
1 parent
657d207
commit cd7b25c
Showing
29 changed files
with
732 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
"jni-config.json", | ||
"proxy-config.json", | ||
"reflect-config.json", | ||
"resource-config.json", | ||
"serialization-config.json" | ||
] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/jni-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/proxy-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/reflect-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/resource-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/serialization-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"lambdaCapturingTypes": [], | ||
"types": [] | ||
} |
10 changes: 10 additions & 0 deletions
10
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"latest": true, | ||
"metadata-version": "3.6.1", | ||
"module": "com.baomidou:dynamic-datasource-spring-boot-starter", | ||
"tested-versions": [ | ||
"3.6.1" | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gradlew.bat | ||
gradlew | ||
gradle/ | ||
build/ |
44 changes: 44 additions & 0 deletions
44
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
|
||
plugins { | ||
id "org.graalvm.internal.tck" | ||
id 'org.springframework.boot' version '3.0.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
} | ||
|
||
String libraryVersion = tck.testedLibraryVersion.get() | ||
|
||
dependencies { | ||
testImplementation "com.baomidou:dynamic-datasource-spring-boot-starter:$libraryVersion" | ||
testImplementation 'org.assertj:assertj-core:3.22.0' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-web' | ||
testRuntimeOnly 'com.h2database:h2:2.1.214' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
group 'com_baomidou.dynamic_datasource_spring_boot_starter' | ||
|
||
springBoot { | ||
mainClass = 'com_baomidou.dynamic_datasource_spring_boot_starter.AddRemoveDatasourceApplication' | ||
} | ||
|
||
graalvmNative { | ||
agent { | ||
defaultMode = "conditional" | ||
modes { | ||
conditional { | ||
userCodeFilterPath = "user-code-filter.json" | ||
} | ||
} | ||
metadataCopy { | ||
mergeWithExisting = true | ||
inputTaskNames.add("test") | ||
outputDirectories.add("src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot-starter") | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
library.version = 3.6.1 | ||
metadata.dir = com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/ |
13 changes: 13 additions & 0 deletions
13
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pluginManagement { | ||
def tckPath = Objects.requireNonNullElse( | ||
System.getenv("GVM_TCK_TCKDIR"), | ||
"../../../../tck-build-logic" | ||
) | ||
includeBuild(tckPath) | ||
} | ||
|
||
plugins { | ||
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT" | ||
} | ||
|
||
rootProject.name = 'com.baomidou.dynamic-datasource-spring-boot-starter_tests' |
51 changes: 51 additions & 0 deletions
51
...est/java/com_baomidou/dynamic_datasource_spring_boot_starter/AddRemoveDatasourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.hikari.HikariCpConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = AddRemoveDatasourceApplication.class, webEnvironment = RANDOM_PORT) | ||
public class AddRemoveDatasourceTest { | ||
@Autowired | ||
DataSource dataSource; | ||
@Autowired | ||
DefaultDataSourceCreator dataSourceCreator; | ||
|
||
@Test | ||
void testAddAndRemoveDataSource() { | ||
HikariCpConfig hikariCpConfig = new HikariCpConfig(); | ||
hikariCpConfig.setConnectionTestQuery("select 1"); | ||
DataSourceProperty dataSourceProperty = new DataSourceProperty() | ||
.setPoolName("slave_1").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test1;MODE=MySQL") | ||
.setUsername("sa").setPassword("").setHikari(hikariCpConfig); | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
ds.addDataSource(dataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(dataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("slave_1"); | ||
ds.removeDataSource("slave_1"); | ||
assertThat(ds.getDataSources().keySet()).doesNotContain("slave_1"); | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
class AddRemoveDatasourceApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(AddRemoveDatasourceApplication.class, args); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
.../java/com_baomidou/dynamic_datasource_spring_boot_starter/LoadDatasourceFromJDBCTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider; | ||
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = LoadDatasourceFromJDBCApplication.class, webEnvironment = RANDOM_PORT) | ||
public class LoadDatasourceFromJDBCTest { | ||
@Autowired | ||
DataSource dataSource; | ||
|
||
@Test | ||
void testExistDataSource() { | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
assertThat(ds.getDataSources().keySet()).contains("master", "db1", "db2", "db3"); | ||
} | ||
} | ||
|
||
@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) | ||
@SpringBootApplication | ||
class LoadDatasourceFromJDBCApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(LoadDatasourceFromJDBCApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public DynamicDataSourceProvider dynamicDataSourceProvider() { | ||
return new AbstractJdbcDataSourceProvider("org.h2.Driver", "jdbc:h2:mem:test;MODE=MySQL", "sa", "") { | ||
@Override | ||
protected Map<String, DataSourceProperty> executeStmt(Statement statement) throws SQLException { | ||
statement.execute(""" | ||
CREATE TABLE IF NOT EXISTS `DB` | ||
( | ||
`name` VARCHAR(30) NULL DEFAULT NULL, | ||
`username` VARCHAR(30) NULL DEFAULT NULL, | ||
`password` VARCHAR(30) NULL DEFAULT NULL, | ||
`url` VARCHAR(30) NULL DEFAULT NULL, | ||
`driver` VARCHAR(30) NULL DEFAULT NULL | ||
)"""); | ||
statement.executeUpdate("insert into DB values ('master','sa','','jdbc:h2:mem:test;MODE=MySQL','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db1','sa','','jdbc:h2:mem:test2','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db2','sa','','jdbc:h2:mem:test3','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db3','sa','','jdbc:h2:mem:test4','org.h2.Driver')"); | ||
Map<String, DataSourceProperty> map = new HashMap<>(); | ||
ResultSet rs = statement.executeQuery("select * from DB"); | ||
while (rs.next()) { | ||
map.put(rs.getString("name"), new DataSourceProperty() | ||
.setUsername(rs.getString("username")).setPassword(rs.getString("password")) | ||
.setUrl(rs.getString("url")).setDriverClassName(rs.getString("driver"))); | ||
} | ||
return map; | ||
} | ||
}; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...src/test/java/com_baomidou/dynamic_datasource_spring_boot_starter/NestDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import com_baomidou.dynamic_datasource_spring_boot_starter.service.nest.*; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = NestApplication.class, webEnvironment = RANDOM_PORT) | ||
public class NestDataSourceTest { | ||
@Autowired | ||
DataSource dataSource; | ||
@Autowired | ||
DefaultDataSourceCreator dataSourceCreator; | ||
@Autowired | ||
private TeacherService teacherService; | ||
@Autowired | ||
private StudentService studentService; | ||
@Autowired | ||
private SchoolService schoolService; | ||
|
||
@Test | ||
void testNest() { | ||
DataSourceProperty masterDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("master").setDriverClassName("org.h2.Driver") | ||
.setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:db/add-remove-datasource.sql'") | ||
.setUsername("sa").setPassword(""); | ||
DataSourceProperty teacherDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("teacher").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE") | ||
.setUsername("sa").setPassword(""); | ||
DataSourceProperty studentDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("student").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE") | ||
.setUsername("sa").setPassword(""); | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
ds.addDataSource(masterDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(masterDataSourceProperty)); | ||
ds.addDataSource(teacherDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(teacherDataSourceProperty)); | ||
ds.addDataSource(studentDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(studentDataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("master", "teacher", "student"); | ||
assertThat(teacherService.addTeacherWithTx("ss", 1)).isEqualTo(1); | ||
assertThat(studentService.addStudentWithTx("tt", 2)).isEqualTo(1); | ||
assertThat(teacherService.selectTeachers()).isEqualTo(List.of(new Teacher(1, "tt", 2))); | ||
assertThat(studentService.selectStudents()).isEqualTo(List.of(new Student(1, "tt", 2))); | ||
assertThat(schoolService.addTeacherAndStudentWithTx()).isEqualTo(2); | ||
assertThat(teacherService.selectTeachers()).isEqualTo(List.of(new Teacher(1, "tt", 2), new Teacher(2, "bb", 4))); | ||
assertThat(studentService.selectStudents()).isEqualTo(List.of(new Student(1, "tt", 2), new Student(2, "bb", 4))); | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
class NestApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(NestApplication.class, args); | ||
} | ||
} |
Oops, something went wrong.