diff --git a/dynamic-datasource-spring-boot-starter/build.gradle b/dynamic-datasource-spring-boot-starter/build.gradle index 97f26dc0..1f9721b3 100644 --- a/dynamic-datasource-spring-boot-starter/build.gradle +++ b/dynamic-datasource-spring-boot-starter/build.gradle @@ -22,6 +22,7 @@ dependencies { compileOnly("org.springframework.boot:spring-boot-configuration-processor") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") + testImplementation(project(":dynamic-datasource-test-common")) testImplementation("com.h2database:h2:${h2Version}") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-starter-web") diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/controller/UserController.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java similarity index 87% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/controller/UserController.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java index e8ae82a8..0f88deb4 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/controller/UserController.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.controller; +package com.baomidou.dynamic.datasource.common.controller; -import com.baomidou.dynamic.datasource.fixture.v1.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v1.service.spel.UserService; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/AddRemoveDatasourceTest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/AddRemoveDatasourceTest.java similarity index 95% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/AddRemoveDatasourceTest.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/AddRemoveDatasourceTest.java index 5204f256..7c09b1cb 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/AddRemoveDatasourceTest.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/AddRemoveDatasourceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1; +package com.baomidou.dynamic.datasource.common.v1; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -67,7 +67,7 @@ void testAddAndRemoveDataSource() { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class AddRemoveDatasourceApplication { public static void main(String[] args) { SpringApplication.run(AddRemoveDatasourceApplication.class, args); diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/DsTransactionalTest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/DsTransactionalTest.java similarity index 96% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/DsTransactionalTest.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/DsTransactionalTest.java index 77efb795..4b4c8188 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/DsTransactionalTest.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/DsTransactionalTest.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3; +package com.baomidou.dynamic.datasource.common.v1; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v3.service.tx.*; +import com.baomidou.dynamic.datasource.common.service.tx.*; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -95,7 +95,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class DsTransactionalApplication { public static void main(String[] args) { SpringApplication.run(DsTransactionalApplication.class, args); diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/LoadDatasourceFromJDBCTest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/LoadDatasourceFromJDBCTest.java similarity index 97% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/LoadDatasourceFromJDBCTest.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/LoadDatasourceFromJDBCTest.java index 5acec254..13a4e1fc 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/LoadDatasourceFromJDBCTest.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/LoadDatasourceFromJDBCTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1; +package com.baomidou.dynamic.datasource.common.v1; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -52,7 +52,7 @@ void testExistDataSource() { } @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class LoadDatasourceFromJDBCApplication { public static void main(String[] args) { diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/NestDataSourceTest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/NestDataSourceTest.java similarity index 89% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/NestDataSourceTest.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/NestDataSourceTest.java index 19a04b8f..684490bf 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/NestDataSourceTest.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/NestDataSourceTest.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1; +package com.baomidou.dynamic.datasource.common.v1; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v1.service.nest.SchoolService; -import com.baomidou.dynamic.datasource.fixture.v1.service.nest.Student; -import com.baomidou.dynamic.datasource.fixture.v1.service.nest.StudentService; -import com.baomidou.dynamic.datasource.fixture.v1.service.nest.TeacherService; +import com.baomidou.dynamic.datasource.common.service.nest.SchoolService; +import com.baomidou.dynamic.datasource.common.service.nest.Student; +import com.baomidou.dynamic.datasource.common.service.nest.StudentService; +import com.baomidou.dynamic.datasource.common.service.nest.TeacherService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -83,7 +83,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class NestApplication { public static void main(String[] args) { SpringApplication.run(NestApplication.class, args); diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/SPELTest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/SPELTest.java similarity index 95% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/SPELTest.java rename to dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/SPELTest.java index 8f8d05b5..98abb031 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/SPELTest.java +++ b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/common/v1/SPELTest.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1; +package com.baomidou.dynamic.datasource.common.v1; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v1.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v1.service.spel.UserService; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -104,7 +104,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class SPELApplication { public static void main(String[] args) { SpringApplication.run(SPELApplication.class, args); diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/StudentService.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/StudentService.java deleted file mode 100644 index 9fc590bf..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/StudentService.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.nest; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) -@Service -@DS("student") -public class StudentService { - private final DataSource dataSource; - - public StudentService(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Transactional - public int addStudentWithTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into student (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public int addStudentNoTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into student (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectStudents() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM student"); - while (resultSet.next()) { - result.add(new Student(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/TeacherService.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/TeacherService.java deleted file mode 100644 index f6abe777..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/TeacherService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.nest; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlNoDataSourceInspection", "SqlDialectInspection"}) -@Service -@DS("teacher") -public class TeacherService { - private final DataSource dataSource; - - public TeacherService(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Transactional - public int addTeacherWithTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into teacher (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - - public int addTeacherNoTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into teacher (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectTeachers() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM student"); - while (resultSet.next()) { - result.add(new Teacher(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Account.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Account.java deleted file mode 100644 index 34cd48a9..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Account.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Account { - private Integer id; - - /** - * 余额 - */ - private Double balance; -} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/AccountService.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/AccountService.java deleted file mode 100644 index 6d5a7601..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/AccountService.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import javax.sql.DataSource; -import java.sql.*; - - -@Service -@DS("account") -public class AccountService { - private final DataSource dataSource; - - public AccountService(DataSource dataSource) { - this.dataSource = dataSource; - } - - public void reduceBalance(Integer userId, Double price) { - try (Connection connection = dataSource.getConnection()) { - PreparedStatement preparedStatement = connection.prepareStatement("select * from account where id=?"); - preparedStatement.setInt(1, userId); - ResultSet resultSet = preparedStatement.executeQuery(); - Account account = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double balance = resultSet.getObject(2, Double.class); - account = new Account(id, balance); - } - Assert.notNull(account, "用户不存在"); - Double balance = account.getBalance(); - if (balance < price) { - throw new RuntimeException("余额不足"); - } - double currentBalance = account.getBalance() - price; - String sql = "update account set balance=? where id=?"; - PreparedStatement updateStatement = connection.prepareStatement(sql); - updateStatement.setDouble(1, currentBalance); - updateStatement.setInt(2, userId); - updateStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public Account selectAccount() { - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM account where id=1"); - Account account = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double balance = resultSet.getObject(2, Double.class); - account = new Account(id, balance); - } - return account; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Order.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Order.java deleted file mode 100644 index 603dc00c..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Order.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Order { - private Integer id; - - /** - * 用户ID - */ - private Integer userId; - /** - * 商品ID - */ - private Integer productId; - /** - * 数量 - */ - private Integer amount; - - /** - * 总金额 - */ - private Double totalPrice; -} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderService.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderService.java deleted file mode 100644 index 4998555e..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderService.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import com.baomidou.dynamic.datasource.tx.TransactionContext; -import org.springframework.stereotype.Service; -import org.springframework.transaction.support.TransactionSynchronization; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - - -@Service -@DS("order") -public class OrderService { - private final AccountService accountService; - private final ProductService productService; - private final DataSource dataSource; - - public OrderService(AccountService accountService, ProductService productService, DataSource dataSource) { - this.accountService = accountService; - this.productService = productService; - this.dataSource = dataSource; - } - - @DSTransactional - public int placeOrder(PlaceOrderRequest request) { - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCompletion(int status) { - if (status == STATUS_ROLLED_BACK) { - request.setOrderStatus(OrderStatus.FAIL); - } - } - }); - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCompletion(int status) { - if (status == STATUS_ROLLED_BACK) { - request.setOrderStatus(OrderStatus.FAIL); - } - } - }); - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCommit() { - request.setOrderStatus(OrderStatus.SUCCESS); - } - }); - - try (Connection connection = dataSource.getConnection()) { - Integer userId = request.getUserId(); - Integer productId = request.getProductId(); - Integer amount = request.getAmount(); - String sql = "insert into p_order(user_id,product_id,amount) values (?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setInt(1, userId); - preparedStatement.setInt(2, productId); - preparedStatement.setInt(3, amount); - preparedStatement.executeUpdate(); - // 扣减库存并计算总价 - Double totalPrice = productService.reduceStock(productId, amount); - // 扣减余额 - accountService.reduceBalance(userId, totalPrice); - String updateSql = "update p_order set total_price=? where user_id=? and product_id=?"; - PreparedStatement updateStatement = connection.prepareStatement(updateSql); - updateStatement.setDouble(1, totalPrice); - updateStatement.setInt(2, userId); - updateStatement.setInt(3, productId); - updateStatement.executeUpdate(); - return request.getOrderStatus(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectOrders() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM p_order"); - while (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Integer userId = resultSet.getObject(2, Integer.class); - Integer productId = resultSet.getObject(3, Integer.class); - Integer amount = resultSet.getObject(4, Integer.class); - Double totalPrice = resultSet.getObject(5, Double.class); - Order order = new Order(id, userId, productId, amount, totalPrice); - result.add(order); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/PlaceOrderRequest.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/PlaceOrderRequest.java deleted file mode 100644 index ad87a061..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/PlaceOrderRequest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class PlaceOrderRequest { - private Integer userId; - - private Integer productId; - - private Integer amount; - - private Integer orderStatus; -} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/ProductService.java b/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/ProductService.java deleted file mode 100644 index d9a64e4c..00000000 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/ProductService.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import javax.sql.DataSource; -import java.sql.*; - -@Service -@DS("product") -public class ProductService { - private final DataSource dataSource; - - public ProductService(DataSource dataSource) { - this.dataSource = dataSource; - } - - public Double reduceStock(Integer productId, Integer amount) { - try (Connection connection = dataSource.getConnection()) { - PreparedStatement preparedStatement = connection.prepareStatement("select * from product where id=?"); - preparedStatement.setInt(1, productId); - ResultSet resultSet = preparedStatement.executeQuery(); - Product product = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double price = resultSet.getObject(2, Double.class); - Integer stock = resultSet.getObject(3, Integer.class); - product = new Product(id, price, stock); - } - Assert.notNull(product, "商品不存在"); - Integer stock = product.getStock(); - if (stock < amount) { - throw new RuntimeException("库存不足"); - } - int currentStock = stock - amount; - String sql = "update product set stock=? where id=?"; - PreparedStatement updateStatement = connection.prepareStatement(sql); - updateStatement.setInt(1, currentStock); - updateStatement.setInt(2, productId); - updateStatement.executeUpdate(); - return product.getPrice() * amount; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public Product selectProduct() { - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM product where id=1"); - Product product = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double price = resultSet.getObject(2, Double.class); - Integer stock = resultSet.getObject(3, Integer.class); - product = new Product(id, price, stock); - } - return product; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot3-starter/build.gradle b/dynamic-datasource-spring-boot3-starter/build.gradle index 2c8f2d30..1dff08c2 100644 --- a/dynamic-datasource-spring-boot3-starter/build.gradle +++ b/dynamic-datasource-spring-boot3-starter/build.gradle @@ -29,6 +29,7 @@ dependencies { compileOnly("org.springframework.boot:spring-boot-configuration-processor") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") + testImplementation(project(":dynamic-datasource-test-common")) testImplementation("com.h2database:h2:${h2Version}") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-starter-web") diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/controller/UserController.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java similarity index 78% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/controller/UserController.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java index 82358d73..fb91cbee 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/controller/UserController.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java @@ -13,26 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.controller; +package com.baomidou.dynamic.datasource.common.controller; -import com.baomidou.dynamic.datasource.fixture.v4.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v4.service.spel.UserService; -import jakarta.servlet.http.HttpServletRequest; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import jakarta.servlet.http.HttpServletRequest; import java.util.List; @RequestMapping("/users") @RestController public class UserController { - private final UserService userService; - - public UserController(UserService userService) { - this.userService = userService; - } + @Autowired + private UserService userService; @GetMapping("/session") public List session(HttpServletRequest request) { diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/AddRemoveDatasourceTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/AddRemoveDatasourceTest.java similarity index 95% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/AddRemoveDatasourceTest.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/AddRemoveDatasourceTest.java index 302fc176..2dacaa6c 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/AddRemoveDatasourceTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/AddRemoveDatasourceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3; +package com.baomidou.dynamic.datasource.common.v3; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -67,7 +67,7 @@ void testAddAndRemoveDataSource() { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class AddRemoveDatasourceApplication { public static void main(String[] args) { SpringApplication.run(AddRemoveDatasourceApplication.class, args); diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/DsTransactionalTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/DsTransactionalTest.java similarity index 96% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/DsTransactionalTest.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/DsTransactionalTest.java index 211301cf..ead12456 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/DsTransactionalTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/DsTransactionalTest.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1; +package com.baomidou.dynamic.datasource.common.v3; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v1.service.tx.*; +import com.baomidou.dynamic.datasource.common.service.tx.*; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -95,7 +95,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class DsTransactionalApplication { public static void main(String[] args) { SpringApplication.run(DsTransactionalApplication.class, args); diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/LoadDatasourceFromJDBCTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/LoadDatasourceFromJDBCTest.java similarity index 97% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/LoadDatasourceFromJDBCTest.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/LoadDatasourceFromJDBCTest.java index a3778d90..7688bafa 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/LoadDatasourceFromJDBCTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/LoadDatasourceFromJDBCTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3; +package com.baomidou.dynamic.datasource.common.v3; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -52,7 +52,7 @@ void testExistDataSource() { } @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class LoadDatasourceFromJDBCApplication { public static void main(String[] args) { diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/NestDataSourceTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/NestDataSourceTest.java similarity index 89% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/NestDataSourceTest.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/NestDataSourceTest.java index dbdc0668..9348a491 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/NestDataSourceTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/NestDataSourceTest.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3; +package com.baomidou.dynamic.datasource.common.v3; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v3.service.nest.SchoolService; -import com.baomidou.dynamic.datasource.fixture.v3.service.nest.Student; -import com.baomidou.dynamic.datasource.fixture.v3.service.nest.StudentService; -import com.baomidou.dynamic.datasource.fixture.v3.service.nest.TeacherService; +import com.baomidou.dynamic.datasource.common.service.nest.SchoolService; +import com.baomidou.dynamic.datasource.common.service.nest.Student; +import com.baomidou.dynamic.datasource.common.service.nest.StudentService; +import com.baomidou.dynamic.datasource.common.service.nest.TeacherService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -82,7 +82,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class NestApplication { public static void main(String[] args) { SpringApplication.run(NestApplication.class, args); diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/SPELTest.java similarity index 95% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java rename to dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/SPELTest.java index c74f45b2..6c53070c 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/v3/SPELTest.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3; +package com.baomidou.dynamic.datasource.common.v3; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v3.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledInNativeImage; @@ -111,7 +111,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class SPELApplication { public static void main(String[] args) { SpringApplication.run(SPELApplication.class, args); diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/SchoolService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/SchoolService.java deleted file mode 100644 index 93e8aaf5..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/SchoolService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.nest; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class SchoolService { - - private final TeacherService teacherService; - private final StudentService studentService; - - public SchoolService(TeacherService teacherService, StudentService studentService) { - this.teacherService = teacherService; - this.studentService = studentService; - } - - @Transactional - public int addTeacherAndStudentWithTx() { - int aa = teacherService.addTeacherNoTx("aa", 3); - int bb = studentService.addStudentNoTx("bb", 4); - return aa + bb; - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Student.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Student.java deleted file mode 100644 index 47cba3c3..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Student.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.nest; - -public record Student(Integer id, String name, Integer age) { -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/StudentService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/StudentService.java deleted file mode 100644 index c08ba040..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/StudentService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.nest; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) -@Service -@DS("student") -public class StudentService { - - private final DataSource dataSource; - - public StudentService(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Transactional - public int addStudentWithTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into student (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public int addStudentNoTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into student (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectStudents() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM student"); - while (resultSet.next()) { - result.add(new Student(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Teacher.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Teacher.java deleted file mode 100644 index dcb431a9..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/Teacher.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.nest; - -public record Teacher(Integer id, String name, Integer age) { -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/TeacherService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/TeacherService.java deleted file mode 100644 index 6031ca08..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/nest/TeacherService.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.nest; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlNoDataSourceInspection", "SqlDialectInspection"}) -@Service -@DS("teacher") -public class TeacherService { - - private final DataSource dataSource; - - public TeacherService(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Transactional - public int addTeacherWithTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into teacher (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - - public int addTeacherNoTx(String name, Integer age) { - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("insert into teacher (`name`,age) values (?,?)")) { - preparedStatement.setString(1, name); - preparedStatement.setInt(2, age); - return preparedStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectTeachers() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM student"); - while (resultSet.next()) { - result.add(new Teacher(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/User.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/User.java deleted file mode 100644 index cfa7062d..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/User.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.spel; - -public record User(Integer id, String name, Integer age, String tenantName) { - public User(String tenantName) { - this(null, null, null, tenantName); - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/UserService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/UserService.java deleted file mode 100644 index 1b3affb3..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/spel/UserService.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.spel; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; -import org.springframework.stereotype.Service; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection", "UnusedReturnValue", "unused"}) -@Service -@DS("slave") -public class UserService { - - private final DataSource dataSource; - - public UserService(DataSource dataSource) { - this.dataSource = dataSource; - } - - - @DS("#session.tenantName") - public List selectSpelBySession() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("select * from t_user"); - while (resultSet.next()) { - result.add(new User(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3), resultSet.getString(4))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @DS("#header.tenantName") - public List selectSpelByHeader() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("select * from t_user"); - while (resultSet.next()) { - result.add(new User(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3), resultSet.getString(4))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @DS("#tenantName") - public String selectSpelByKey(String tenantName) { - return DynamicDataSourceContextHolder.peek(); - - } - - @DS("#user.tenantName") - public String selecSpelByTenant(User user) { - return DynamicDataSourceContextHolder.peek(); - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/AccountService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/AccountService.java deleted file mode 100644 index b5c91c4e..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/AccountService.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import javax.sql.DataSource; -import java.sql.*; - - -@Service -@DS("account") -public class AccountService { - private final DataSource dataSource; - - public AccountService(DataSource dataSource) { - this.dataSource = dataSource; - } - - public void reduceBalance(Integer userId, Double price) { - try (Connection connection = dataSource.getConnection()) { - PreparedStatement preparedStatement = connection.prepareStatement("select * from account where id=?"); - preparedStatement.setInt(1, userId); - ResultSet resultSet = preparedStatement.executeQuery(); - Account account = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double balance = resultSet.getObject(2, Double.class); - account = new Account(id, balance); - } - Assert.notNull(account, "用户不存在"); - Double balance = account.getBalance(); - if (balance < price) { - throw new RuntimeException("余额不足"); - } - double currentBalance = account.getBalance() - price; - String sql = "update account set balance=? where id=?"; - PreparedStatement updateStatement = connection.prepareStatement(sql); - updateStatement.setDouble(1, currentBalance); - updateStatement.setInt(2, userId); - updateStatement.executeUpdate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public Account selectAccount() { - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM account where id=1"); - Account account = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double balance = resultSet.getObject(2, Double.class); - account = new Account(id, balance); - } - return account; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Order.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Order.java deleted file mode 100644 index 03760ae3..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Order.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Order { - private Integer id; - - /** - * 用户ID - */ - private Integer userId; - /** - * 商品ID - */ - private Integer productId; - /** - * 数量 - */ - private Integer amount; - - /** - * 总金额 - */ - private Double totalPrice; -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderStatus.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderStatus.java deleted file mode 100644 index 470b8d8b..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -public class OrderStatus { - /** - * INIT - */ - public static final Integer INIT = 0; - /** - * SUCCESS - */ - public static final Integer SUCCESS = 1; - /** - * FAIL - */ - public static final Integer FAIL = 2; -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/PlaceOrderRequest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/PlaceOrderRequest.java deleted file mode 100644 index 43b83dde..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/PlaceOrderRequest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class PlaceOrderRequest { - private Integer userId; - - private Integer productId; - - private Integer amount; - - private Integer orderStatus; -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Product.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Product.java deleted file mode 100644 index 1c32c029..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Product.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Product { - private Integer id; - /** - * 价格 - */ - private Double price; - /** - * 库存 - */ - private Integer stock; -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/ProductService.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/ProductService.java deleted file mode 100644 index 39d3a2bf..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/ProductService.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import javax.sql.DataSource; -import java.sql.*; - -@Service -@DS("product") -public class ProductService { - private final DataSource dataSource; - - public ProductService(DataSource dataSource) { - this.dataSource = dataSource; - } - - public Double reduceStock(Integer productId, Integer amount) { - try (Connection connection = dataSource.getConnection()) { - PreparedStatement preparedStatement = connection.prepareStatement("select * from product where id=?"); - preparedStatement.setInt(1, productId); - ResultSet resultSet = preparedStatement.executeQuery(); - Product product = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double price = resultSet.getObject(2, Double.class); - Integer stock = resultSet.getObject(3, Integer.class); - product = new Product(id, price, stock); - } - Assert.notNull(product, "商品不存在"); - Integer stock = product.getStock(); - if (stock < amount) { - throw new RuntimeException("库存不足"); - } - int currentStock = stock - amount; - String sql = "update product set stock=? where id=?"; - PreparedStatement updateStatement = connection.prepareStatement(sql); - updateStatement.setInt(1, currentStock); - updateStatement.setInt(2, productId); - updateStatement.executeUpdate(); - return product.getPrice() * amount; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public Product selectProduct() { - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM product where id=1"); - Product product = null; - if (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Double price = resultSet.getObject(2, Double.class); - Integer stock = resultSet.getObject(3, Integer.class); - product = new Product(id, price, stock); - } - return product; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json b/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json deleted file mode 100644 index 1d039f96..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "resources":{ - "includes":[{ - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.fixture.v3.NestDataSourceTest"}, - "pattern":"\\Qdb/add-remove-datasource.sql\\E" - },{ - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.fixture.v3.DsTransactionalTest"}, - "pattern":"\\Qdb/ds-with-transactional.sql\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/druid-driver.properties\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/druid-filter.properties\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/services/com.alibaba.druid.filter.Filter\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\QMETA-INF/services/java.sql.Driver\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\Qorg/h2/util/data.zip\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"jdk.jfr:\\Qjdk/jfr/internal/query/view.ini\\E" - }]}, - "bundles":[] -} diff --git a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/add-remove-datasource.sql b/dynamic-datasource-spring-boot3-starter/src/test/resources/db/add-remove-datasource.sql deleted file mode 100644 index 63713626..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/add-remove-datasource.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE IF NOT EXISTS teacher -( - `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS student -( - `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); diff --git a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/ds-with-transactional.sql b/dynamic-datasource-spring-boot3-starter/src/test/resources/db/ds-with-transactional.sql deleted file mode 100644 index 9256f5f5..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/ds-with-transactional.sql +++ /dev/null @@ -1,27 +0,0 @@ -CREATE TABLE IF NOT EXISTS p_order -( - id INT NOT NULL AUTO_INCREMENT, - user_id INT DEFAULT NULL, - product_id INT DEFAULT NULL, - amount INT DEFAULT NULL, - total_price DOUBLE DEFAULT NULL, - PRIMARY KEY (id) -); - - -CREATE TABLE IF NOT EXISTS account -( - id INT NOT NULL AUTO_INCREMENT, - balance DOUBLE DEFAULT NULL, - PRIMARY KEY (id) -); -insert into account (id, balance) VALUES (1, 50.0); - -CREATE TABLE IF NOT EXISTS product -( - id INT NOT NULL AUTO_INCREMENT, - price DOUBLE DEFAULT NULL, - stock INT DEFAULT NULL, - PRIMARY KEY (id) -); -insert into product (id, price, stock) VALUES (1, 10.0, 20); \ No newline at end of file diff --git a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/spring-expression-language.sql b/dynamic-datasource-spring-boot3-starter/src/test/resources/db/spring-expression-language.sql deleted file mode 100644 index ea7ad1d5..00000000 --- a/dynamic-datasource-spring-boot3-starter/src/test/resources/db/spring-expression-language.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE IF NOT EXISTS t_user -( - id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); diff --git a/dynamic-datasource-spring-boot4-starter/build.gradle b/dynamic-datasource-spring-boot4-starter/build.gradle index 103e7f8c..76d1fec6 100644 --- a/dynamic-datasource-spring-boot4-starter/build.gradle +++ b/dynamic-datasource-spring-boot4-starter/build.gradle @@ -28,6 +28,7 @@ dependencies { compileOnly("org.springframework.boot:spring-boot-configuration-processor") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") + testImplementation(project(":dynamic-datasource-test-common")) testImplementation("com.h2database:h2:${h2Version}") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-starter-web") diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/controller/UserController.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java similarity index 78% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/controller/UserController.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java index 031ae7ae..fb91cbee 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/controller/UserController.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java @@ -13,26 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3.controller; +package com.baomidou.dynamic.datasource.common.controller; -import com.baomidou.dynamic.datasource.fixture.v3.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService; -import jakarta.servlet.http.HttpServletRequest; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import jakarta.servlet.http.HttpServletRequest; import java.util.List; @RequestMapping("/users") @RestController public class UserController { - private final UserService userService; - - public UserController(UserService userService) { - this.userService = userService; - } + @Autowired + private UserService userService; @GetMapping("/session") public List session(HttpServletRequest request) { diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/AddRemoveDatasourceTest.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/AddRemoveDatasourceTest.java similarity index 95% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/AddRemoveDatasourceTest.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/AddRemoveDatasourceTest.java index 0bd3cbeb..edb99d5f 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/AddRemoveDatasourceTest.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/AddRemoveDatasourceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4; +package com.baomidou.dynamic.datasource.common.v4; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -67,7 +67,7 @@ void testAddAndRemoveDataSource() { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class AddRemoveDatasourceApplication { public static void main(String[] args) { SpringApplication.run(AddRemoveDatasourceApplication.class, args); diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/DsTransactionalTest.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/DsTransactionalTest.java similarity index 96% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/DsTransactionalTest.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/DsTransactionalTest.java index d9888e17..59d66690 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/DsTransactionalTest.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/DsTransactionalTest.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4; +package com.baomidou.dynamic.datasource.common.v4; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v4.service.tx.*; +import com.baomidou.dynamic.datasource.common.service.tx.*; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -95,7 +95,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class DsTransactionalApplication { public static void main(String[] args) { SpringApplication.run(DsTransactionalApplication.class, args); diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/LoadDatasourceFromJDBCTest.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/LoadDatasourceFromJDBCTest.java similarity index 97% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/LoadDatasourceFromJDBCTest.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/LoadDatasourceFromJDBCTest.java index 44f8c4a6..f3c05a56 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/LoadDatasourceFromJDBCTest.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/LoadDatasourceFromJDBCTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4; +package com.baomidou.dynamic.datasource.common.v4; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; @@ -52,7 +52,7 @@ void testExistDataSource() { } @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class LoadDatasourceFromJDBCApplication { public static void main(String[] args) { diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/NestDataSourceTest.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/NestDataSourceTest.java similarity index 89% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/NestDataSourceTest.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/NestDataSourceTest.java index 7a82b6ac..cc4e5a93 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/NestDataSourceTest.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/NestDataSourceTest.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4; +package com.baomidou.dynamic.datasource.common.v4; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v4.service.nest.SchoolService; -import com.baomidou.dynamic.datasource.fixture.v4.service.nest.Student; -import com.baomidou.dynamic.datasource.fixture.v4.service.nest.StudentService; -import com.baomidou.dynamic.datasource.fixture.v4.service.nest.TeacherService; +import com.baomidou.dynamic.datasource.common.service.nest.SchoolService; +import com.baomidou.dynamic.datasource.common.service.nest.Student; +import com.baomidou.dynamic.datasource.common.service.nest.StudentService; +import com.baomidou.dynamic.datasource.common.service.nest.TeacherService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -82,7 +82,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class NestApplication { public static void main(String[] args) { SpringApplication.run(NestApplication.class, args); diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/SPELTest.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/SPELTest.java similarity index 95% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/SPELTest.java rename to dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/SPELTest.java index 8878611d..14d1f8f0 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/SPELTest.java +++ b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/v4/SPELTest.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4; +package com.baomidou.dynamic.datasource.common.v4; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; -import com.baomidou.dynamic.datasource.fixture.v4.service.spel.User; -import com.baomidou.dynamic.datasource.fixture.v4.service.spel.UserService; +import com.baomidou.dynamic.datasource.common.service.spel.User; +import com.baomidou.dynamic.datasource.common.service.spel.UserService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledInNativeImage; @@ -111,7 +111,7 @@ private DataSourceProperty createDataSourceProperty(String poolName) { } } -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.baomidou.dynamic.datasource.common") class SPELApplication { public static void main(String[] args) { SpringApplication.run(SPELApplication.class, args); diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/SchoolService.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/SchoolService.java deleted file mode 100644 index daefdeea..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/SchoolService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.nest; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class SchoolService { - - private final TeacherService teacherService; - private final StudentService studentService; - - public SchoolService(TeacherService teacherService, StudentService studentService) { - this.teacherService = teacherService; - this.studentService = studentService; - } - - @Transactional - public int addTeacherAndStudentWithTx() { - int aa = teacherService.addTeacherNoTx("aa", 3); - int bb = studentService.addStudentNoTx("bb", 4); - return aa + bb; - } -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Student.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Student.java deleted file mode 100644 index adc20415..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Student.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.nest; - -public record Student(Integer id, String name, Integer age) { -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Teacher.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Teacher.java deleted file mode 100644 index 56d61cb2..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/Teacher.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.nest; - -public record Teacher(Integer id, String name, Integer age) { -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/User.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/User.java deleted file mode 100644 index 3117bb37..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/User.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.spel; - -public record User(Integer id, String name, Integer age, String tenantName) { - public User(String tenantName) { - this(null, null, null, tenantName); - } -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/UserService.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/UserService.java deleted file mode 100644 index 95b97d24..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/spel/UserService.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.spel; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; -import org.springframework.stereotype.Service; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.LinkedList; -import java.util.List; - -@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection", "UnusedReturnValue", "unused"}) -@Service -@DS("slave") -public class UserService { - - private final DataSource dataSource; - - public UserService(DataSource dataSource) { - this.dataSource = dataSource; - } - - - @DS("#session.tenantName") - public List selectSpelBySession() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("select * from t_user"); - while (resultSet.next()) { - result.add(new User(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3), resultSet.getString(4))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @DS("#header.tenantName") - public List selectSpelByHeader() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("select * from t_user"); - while (resultSet.next()) { - result.add(new User(resultSet.getInt(1), resultSet.getString(2), resultSet.getInt(3), resultSet.getString(4))); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @DS("#tenantName") - public String selectSpelByKey(String tenantName) { - return DynamicDataSourceContextHolder.peek(); - - } - - @DS("#user.tenantName") - public String selecSpelByTenant(User user) { - return DynamicDataSourceContextHolder.peek(); - } -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Account.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Account.java deleted file mode 100644 index 870d0261..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Account.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Account { - private Integer id; - - /** - * 余额 - */ - private Double balance; -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderService.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderService.java deleted file mode 100644 index f89dfaee..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderService.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; - -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import com.baomidou.dynamic.datasource.tx.TransactionContext; -import org.springframework.stereotype.Service; -import org.springframework.transaction.support.TransactionSynchronization; - -import javax.sql.DataSource; -import java.sql.*; -import java.util.LinkedList; -import java.util.List; - - -@Service -@DS("order") -public class OrderService { - private final AccountService accountService; - private final ProductService productService; - private final DataSource dataSource; - - public OrderService(AccountService accountService, ProductService productService, DataSource dataSource) { - this.accountService = accountService; - this.productService = productService; - this.dataSource = dataSource; - } - - @DSTransactional - public int placeOrder(PlaceOrderRequest request) { - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCompletion(int status) { - if (status == STATUS_ROLLED_BACK) { - request.setOrderStatus(OrderStatus.FAIL); - } - } - }); - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCompletion(int status) { - if (status == STATUS_ROLLED_BACK) { - request.setOrderStatus(OrderStatus.FAIL); - } - } - }); - TransactionContext.registerSynchronization(new TransactionSynchronization() { - @Override - public void afterCommit() { - request.setOrderStatus(OrderStatus.SUCCESS); - } - }); - - try (Connection connection = dataSource.getConnection()) { - Integer userId = request.getUserId(); - Integer productId = request.getProductId(); - Integer amount = request.getAmount(); - String sql = "insert into p_order(user_id,product_id,amount) values (?,?,?)"; - PreparedStatement preparedStatement = connection.prepareStatement(sql); - preparedStatement.setInt(1, userId); - preparedStatement.setInt(2, productId); - preparedStatement.setInt(3, amount); - preparedStatement.executeUpdate(); - // 扣减库存并计算总价 - Double totalPrice = productService.reduceStock(productId, amount); - // 扣减余额 - accountService.reduceBalance(userId, totalPrice); - String updateSql = "update p_order set total_price=? where user_id=? and product_id=?"; - PreparedStatement updateStatement = connection.prepareStatement(updateSql); - updateStatement.setDouble(1, totalPrice); - updateStatement.setInt(2, userId); - updateStatement.setInt(3, productId); - updateStatement.executeUpdate(); - return request.getOrderStatus(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public List selectOrders() { - List result = new LinkedList<>(); - try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { - ResultSet resultSet = statement.executeQuery("SELECT * FROM p_order"); - while (resultSet.next()) { - Integer id = resultSet.getObject(1, Integer.class); - Integer userId = resultSet.getObject(2, Integer.class); - Integer productId = resultSet.getObject(3, Integer.class); - Integer amount = resultSet.getObject(4, Integer.class); - Double totalPrice = resultSet.getObject(5, Double.class); - Order order = new Order(id, userId, productId, amount, totalPrice); - result.add(order); - } - return result; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderStatus.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderStatus.java deleted file mode 100644 index df794c46..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/OrderStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; - -public class OrderStatus { - /** - * INIT - */ - public static final Integer INIT = 0; - /** - * SUCCESS - */ - public static final Integer SUCCESS = 1; - /** - * FAIL - */ - public static final Integer FAIL = 2; -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Product.java b/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Product.java deleted file mode 100644 index cb797c51..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Product.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2018 organization baomidou - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; - -import lombok.AllArgsConstructor; -import lombok.Data; - - -@Data -@AllArgsConstructor -public class Product { - private Integer id; - /** - * 价格 - */ - private Double price; - /** - * 库存 - */ - private Integer stock; -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json b/dynamic-datasource-spring-boot4-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json deleted file mode 100644 index 1d039f96..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/resources/META-INF/native-image/dynamic-datasource-spring-boot3-starter-test-metadata/resource-config.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "resources":{ - "includes":[{ - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.fixture.v3.NestDataSourceTest"}, - "pattern":"\\Qdb/add-remove-datasource.sql\\E" - },{ - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.fixture.v3.DsTransactionalTest"}, - "pattern":"\\Qdb/ds-with-transactional.sql\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/druid-driver.properties\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/druid-filter.properties\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.creator.druid.DruidDataSourceCreator"}, - "pattern":"\\QMETA-INF/services/com.alibaba.druid.filter.Filter\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\QMETA-INF/services/java.sql.Driver\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"\\Qorg/h2/util/data.zip\\E" - }, { - "condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"}, - "pattern":"jdk.jfr:\\Qjdk/jfr/internal/query/view.ini\\E" - }]}, - "bundles":[] -} diff --git a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/add-remove-datasource.sql b/dynamic-datasource-spring-boot4-starter/src/test/resources/db/add-remove-datasource.sql deleted file mode 100644 index 63713626..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/add-remove-datasource.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE IF NOT EXISTS teacher -( - `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS student -( - `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); diff --git a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/ds-with-transactional.sql b/dynamic-datasource-spring-boot4-starter/src/test/resources/db/ds-with-transactional.sql deleted file mode 100644 index 9256f5f5..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/ds-with-transactional.sql +++ /dev/null @@ -1,27 +0,0 @@ -CREATE TABLE IF NOT EXISTS p_order -( - id INT NOT NULL AUTO_INCREMENT, - user_id INT DEFAULT NULL, - product_id INT DEFAULT NULL, - amount INT DEFAULT NULL, - total_price DOUBLE DEFAULT NULL, - PRIMARY KEY (id) -); - - -CREATE TABLE IF NOT EXISTS account -( - id INT NOT NULL AUTO_INCREMENT, - balance DOUBLE DEFAULT NULL, - PRIMARY KEY (id) -); -insert into account (id, balance) VALUES (1, 50.0); - -CREATE TABLE IF NOT EXISTS product -( - id INT NOT NULL AUTO_INCREMENT, - price DOUBLE DEFAULT NULL, - stock INT DEFAULT NULL, - PRIMARY KEY (id) -); -insert into product (id, price, stock) VALUES (1, 10.0, 20); \ No newline at end of file diff --git a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/spring-expression-language.sql b/dynamic-datasource-spring-boot4-starter/src/test/resources/db/spring-expression-language.sql deleted file mode 100644 index ea7ad1d5..00000000 --- a/dynamic-datasource-spring-boot4-starter/src/test/resources/db/spring-expression-language.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE IF NOT EXISTS t_user -( - id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(30) NULL DEFAULT NULL, - age INT NULL DEFAULT NULL -); diff --git a/dynamic-datasource-test-common/build.gradle b/dynamic-datasource-test-common/build.gradle new file mode 100644 index 00000000..919aedfe --- /dev/null +++ b/dynamic-datasource-test-common/build.gradle @@ -0,0 +1,30 @@ +// Test Common Module - NOT published +// This module contains shared test code for all starter modules +apply plugin: 'io.spring.dependency-management' + +// Do not publish this module - disable all publishing tasks +if (JavaVersion.current() >= JavaVersion.VERSION_11) { + tasks.withType(PublishToMavenRepository).configureEach { + enabled = false + } + tasks.withType(PublishToMavenLocal).configureEach { + enabled = false + } + // Skip signing for this module + tasks.withType(Sign).configureEach { + enabled = false + } +} + +dependencyManagement { + imports { + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBoot2Version}" + } +} + +dependencies { + api project(":dynamic-datasource-spring-boot-common") + + compileOnly("org.springframework:spring-web") + compileOnly("org.springframework:spring-tx") +} diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/SchoolService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/SchoolService.java similarity index 95% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/SchoolService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/SchoolService.java index 516d87f3..46764309 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/SchoolService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/SchoolService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.nest; +package com.baomidou.dynamic.datasource.common.service.nest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Student.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Student.java similarity index 92% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Student.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Student.java index ba220300..dd5a93ff 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Student.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Student.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.nest; +package com.baomidou.dynamic.datasource.common.service.nest; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/StudentService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/StudentService.java similarity index 97% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/StudentService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/StudentService.java index c32b16f8..7a7571da 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/StudentService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/StudentService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.nest; +package com.baomidou.dynamic.datasource.common.service.nest; import com.baomidou.dynamic.datasource.annotation.DS; import org.springframework.stereotype.Service; @@ -28,7 +28,6 @@ @Service @DS("student") public class StudentService { - private final DataSource dataSource; public StudentService(DataSource dataSource) { diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Teacher.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Teacher.java similarity index 92% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Teacher.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Teacher.java index 4e871d9f..79525359 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/nest/Teacher.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/Teacher.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.nest; +package com.baomidou.dynamic.datasource.common.service.nest; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/TeacherService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/TeacherService.java similarity index 97% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/TeacherService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/TeacherService.java index 5511727e..d918f7d5 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/nest/TeacherService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/nest/TeacherService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.nest; +package com.baomidou.dynamic.datasource.common.service.nest; import com.baomidou.dynamic.datasource.annotation.DS; import org.springframework.stereotype.Service; @@ -28,7 +28,6 @@ @Service @DS("teacher") public class TeacherService { - private final DataSource dataSource; public TeacherService(DataSource dataSource) { diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/User.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/User.java similarity index 93% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/User.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/User.java index 1c88c098..e3ecd14e 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/User.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/User.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.spel; +package com.baomidou.dynamic.datasource.common.service.spel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/UserService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/UserService.java similarity index 97% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/UserService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/UserService.java index 1daa95fc..3a4f6cab 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/spel/UserService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/spel/UserService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.spel; +package com.baomidou.dynamic.datasource.common.service.spel; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Account.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Account.java similarity index 92% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Account.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Account.java index c1882fcc..60b335c8 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/Account.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Account.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/AccountService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/AccountService.java similarity index 97% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/AccountService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/AccountService.java index 5a174673..6a809bd0 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/AccountService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/AccountService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import com.baomidou.dynamic.datasource.annotation.DS; import org.springframework.stereotype.Service; diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Order.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Order.java similarity index 93% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Order.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Order.java index 68aefcdd..8c6e5652 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/Order.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Order.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderService.java similarity index 98% rename from dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderService.java index 75cc21ad..303be0b4 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/service/tx/OrderService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v3.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DSTransactional; diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderStatus.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderStatus.java similarity index 93% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderStatus.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderStatus.java index 38500863..724e01f9 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/OrderStatus.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/OrderStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; public class OrderStatus { /** diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/PlaceOrderRequest.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/PlaceOrderRequest.java similarity index 93% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/PlaceOrderRequest.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/PlaceOrderRequest.java index e1214245..75c451dc 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/PlaceOrderRequest.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/PlaceOrderRequest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Product.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Product.java similarity index 93% rename from dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Product.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Product.java index e2d2f9cc..98e1e05e 100644 --- a/dynamic-datasource-spring-boot-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v1/service/tx/Product.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/Product.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v1.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/ProductService.java b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/ProductService.java similarity index 98% rename from dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/ProductService.java rename to dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/ProductService.java index b9f1a028..a9a7a993 100644 --- a/dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v4/service/tx/ProductService.java +++ b/dynamic-datasource-test-common/src/main/java/com/baomidou/dynamic/datasource/common/service/tx/ProductService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.baomidou.dynamic.datasource.fixture.v4.service.tx; +package com.baomidou.dynamic.datasource.common.service.tx; import com.baomidou.dynamic.datasource.annotation.DS; import org.springframework.stereotype.Service; diff --git a/dynamic-datasource-spring-boot-starter/src/test/resources/db/add-remove-datasource.sql b/dynamic-datasource-test-common/src/main/resources/db/add-remove-datasource.sql similarity index 100% rename from dynamic-datasource-spring-boot-starter/src/test/resources/db/add-remove-datasource.sql rename to dynamic-datasource-test-common/src/main/resources/db/add-remove-datasource.sql diff --git a/dynamic-datasource-spring-boot-starter/src/test/resources/db/ds-with-transactional.sql b/dynamic-datasource-test-common/src/main/resources/db/ds-with-transactional.sql similarity index 100% rename from dynamic-datasource-spring-boot-starter/src/test/resources/db/ds-with-transactional.sql rename to dynamic-datasource-test-common/src/main/resources/db/ds-with-transactional.sql diff --git a/dynamic-datasource-spring-boot-starter/src/test/resources/db/spring-expression-language.sql b/dynamic-datasource-test-common/src/main/resources/db/spring-expression-language.sql similarity index 100% rename from dynamic-datasource-spring-boot-starter/src/test/resources/db/spring-expression-language.sql rename to dynamic-datasource-test-common/src/main/resources/db/spring-expression-language.sql diff --git a/settings.gradle b/settings.gradle index e75d76b3..1439337e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,5 +6,6 @@ include( "dynamic-datasource-spring-boot-common", "dynamic-datasource-spring-boot-starter", "dynamic-datasource-spring-boot3-starter", - "dynamic-datasource-spring-boot4-starter" + "dynamic-datasource-spring-boot4-starter", + "dynamic-datasource-test-common" )