diff --git a/sqlhelper-examples/sqlhelper-examples-db/src/main/resources/test.h2.db b/sqlhelper-examples/sqlhelper-examples-db/src/main/resources/test.h2.db index 183204b94..903205941 100644 Binary files a/sqlhelper-examples/sqlhelper-examples-db/src/main/resources/test.h2.db and b/sqlhelper-examples/sqlhelper-examples-db/src/main/resources/test.h2.db differ diff --git a/sqlhelper-mybatis-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatis/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java b/sqlhelper-mybatis-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatis/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java index e0d5427bb..d4562efd4 100644 --- a/sqlhelper-mybatis-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatis/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java +++ b/sqlhelper-mybatis-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatis/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java @@ -36,15 +36,20 @@ public class DynamicDataSourceTransactionFactoryCustomizer implements Configurat public void customize(Configuration configuration) { Environment oldEnv = configuration.getEnvironment(); if (oldEnv != null) { - String id = oldEnv.getId(); - DataSource dataSource = oldEnv.getDataSource(); - if (dataSource instanceof NamedDataSource) { - id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); - } - TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); - Environment newEnv = new Environment(id, transactionFactory, dataSource); - configuration.setEnvironment(newEnv); + boolean replaceIt = oldEnv.getTransactionFactory() == null || !(oldEnv.getTransactionFactory() instanceof DynamicDataSourceManagedTransactionFactory); + if (replaceIt) { + + String id = oldEnv.getId(); + DataSource dataSource = oldEnv.getDataSource(); + if (dataSource instanceof NamedDataSource) { + id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); + } + + TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); + Environment newEnv = new Environment(id, transactionFactory, dataSource); + configuration.setEnvironment(newEnv); + } } } } diff --git a/sqlhelper-mybatisplus-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java b/sqlhelper-mybatisplus-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java index 2a58d2dc1..a1f110991 100644 --- a/sqlhelper-mybatisplus-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java +++ b/sqlhelper-mybatisplus-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java @@ -39,15 +39,18 @@ public class DynamicDataSourceTransactionFactoryCustomizer implements Configurat public void customize(MybatisConfiguration configuration) { Environment oldEnv = configuration.getEnvironment(); if (oldEnv != null) { - String id = oldEnv.getId(); - DataSource dataSource = oldEnv.getDataSource(); - if (dataSource instanceof NamedDataSource) { - id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); - } + boolean replaceIt = oldEnv.getTransactionFactory() == null || !(oldEnv.getTransactionFactory() instanceof DynamicDataSourceManagedTransactionFactory); + if(replaceIt) { + String id = oldEnv.getId(); + DataSource dataSource = oldEnv.getDataSource(); + if (dataSource instanceof NamedDataSource) { + id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); + } - TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); - Environment newEnv = new Environment(id, transactionFactory, dataSource); - configuration.setEnvironment(newEnv); + TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); + Environment newEnv = new Environment(id, transactionFactory, dataSource); + configuration.setEnvironment(newEnv); + } } } } diff --git a/sqlhelper-mybatisplus_2x-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus2x/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java b/sqlhelper-mybatisplus_2x-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus2x/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java index 8bc900e2c..af2536c8f 100644 --- a/sqlhelper-mybatisplus_2x-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus2x/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java +++ b/sqlhelper-mybatisplus_2x-spring-boot-starter/src/main/java/com/jn/sqlhelper/mybatisplus2x/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java @@ -39,15 +39,18 @@ public class DynamicDataSourceTransactionFactoryCustomizer implements Configurat public void customize(Configuration configuration) { Environment oldEnv = configuration.getEnvironment(); if (oldEnv != null) { - String id = oldEnv.getId(); - DataSource dataSource = oldEnv.getDataSource(); - if (dataSource instanceof NamedDataSource) { - id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); - } + boolean replaceIt = oldEnv.getTransactionFactory() == null || !(oldEnv.getTransactionFactory() instanceof DynamicDataSourceManagedTransactionFactory); + if(replaceIt) { + String id = oldEnv.getId(); + DataSource dataSource = oldEnv.getDataSource(); + if (dataSource instanceof NamedDataSource) { + id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); + } - TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); - Environment newEnv = new Environment(id, transactionFactory, dataSource); - configuration.setEnvironment(newEnv); + TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); + Environment newEnv = new Environment(id, transactionFactory, dataSource); + configuration.setEnvironment(newEnv); + } } } } diff --git a/sqlhelper-tkmapper-spring-boot-starter/src/main/java/com/jn/sqlhelper/tkmapper/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java b/sqlhelper-tkmapper-spring-boot-starter/src/main/java/com/jn/sqlhelper/tkmapper/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java index fc25b86e9..f090e0724 100644 --- a/sqlhelper-tkmapper-spring-boot-starter/src/main/java/com/jn/sqlhelper/tkmapper/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java +++ b/sqlhelper-tkmapper-spring-boot-starter/src/main/java/com/jn/sqlhelper/tkmapper/spring/boot/autoconfigure/DynamicDataSourceTransactionFactoryCustomizer.java @@ -40,15 +40,18 @@ public class DynamicDataSourceTransactionFactoryCustomizer implements Configurat public void customize(Configuration configuration) { Environment oldEnv = configuration.getEnvironment(); if (oldEnv != null) { - String id = oldEnv.getId(); - DataSource dataSource = oldEnv.getDataSource(); - if (dataSource instanceof NamedDataSource) { - id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); - } + boolean replaceIt = oldEnv.getTransactionFactory() == null || !(oldEnv.getTransactionFactory() instanceof DynamicDataSourceManagedTransactionFactory); + if (replaceIt) { + String id = oldEnv.getId(); + DataSource dataSource = oldEnv.getDataSource(); + if (dataSource instanceof NamedDataSource) { + id = ((NamedDataSource) dataSource).getDataSourceKey().getId(); + } - TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); - Environment newEnv = new Environment(id, transactionFactory, dataSource); - configuration.setEnvironment(newEnv); + TransactionFactory transactionFactory = new DynamicDataSourceManagedTransactionFactory(); + Environment newEnv = new Environment(id, transactionFactory, dataSource); + configuration.setEnvironment(newEnv); + } } } }