diff --git a/mybatis-flex-test/mybatis-flex-seata-test/mybatis-flex.config b/mybatis-flex-test/mybatis-flex-seata-test/mybatis-flex.config
new file mode 100644
index 00000000..f6050f8b
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-seata-test/mybatis-flex.config
@@ -0,0 +1 @@
+processor.mapper.generateEnable=true
diff --git a/mybatis-flex-test/mybatis-flex-seata-test/pom.xml b/mybatis-flex-test/mybatis-flex-seata-test/pom.xml
new file mode 100644
index 00000000..af3998bc
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-seata-test/pom.xml
@@ -0,0 +1,67 @@
+
+
+ * 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.mybatisflex.test; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("com.mybatisflex.test.mapper") +public class MybatisFlexSpringBootSeataApplication { + + public static void main(String[] args) { + SpringApplication.run(MybatisFlexSpringBootSeataApplication.class, args); + } + +} diff --git a/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/controller/TestController.java b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/controller/TestController.java new file mode 100644 index 00000000..77b093d1 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/controller/TestController.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test.controller; + +import com.mybatisflex.core.audit.AuditManager; +import com.mybatisflex.core.audit.ConsoleMessageCollector; +import com.mybatisflex.core.audit.MessageCollector; +import com.mybatisflex.test.service.TestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class TestController { + + + @Autowired + TestService testService; + + @RequestMapping("buy") + public String buy() { + //开启审计功能 + AuditManager.setAuditEnable(true); + //设置 SQL 审计收集器 + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + return String.valueOf(testService.buy()); + } + +} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/AccountTbl.java b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/AccountTbl.java similarity index 54% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/AccountTbl.java rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/AccountTbl.java index ee716d42..d2629d81 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/AccountTbl.java +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/AccountTbl.java @@ -1,13 +1,26 @@ -package com.mybatisfle.test.mybatisflexspringbootseata.entity; +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test.entity; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; + import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; /** * 实体类。 diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/OrderTbl.java b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/OrderTbl.java similarity index 63% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/OrderTbl.java rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/OrderTbl.java index 8f5b7c2f..d9f32725 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/OrderTbl.java +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/OrderTbl.java @@ -1,13 +1,26 @@ -package com.mybatisfle.test.mybatisflexspringbootseata.entity; +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test.entity; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; + import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; /** * 实体类。 diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/StockTbl.java b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/StockTbl.java similarity index 56% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/StockTbl.java rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/StockTbl.java index f452cdec..e38e090f 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/entity/StockTbl.java +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/entity/StockTbl.java @@ -1,13 +1,26 @@ -package com.mybatisfle.test.mybatisflexspringbootseata.entity; +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test.entity; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; + import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; /** * 实体类。 diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/service/TestService.java b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/service/TestService.java similarity index 58% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/service/TestService.java rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/service/TestService.java index 77a811e5..15acd016 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/java/com/mybatisfle/test/mybatisflexspringbootseata/service/TestService.java +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/java/com/mybatisflex/test/service/TestService.java @@ -1,23 +1,37 @@ -package com.mybatisfle.test.mybatisflexspringbootseata.service; +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test.service; -import com.mybatisfle.test.mybatisflexspringbootseata.entity.AccountTbl; -import com.mybatisfle.test.mybatisflexspringbootseata.entity.OrderTbl; -import com.mybatisfle.test.mybatisflexspringbootseata.entity.StockTbl; -import com.mybatisfle.test.mybatisflexspringbootseata.entity.table.AccountTblTableDef; -import com.mybatisfle.test.mybatisflexspringbootseata.mapper.AccountTblMapper; -import com.mybatisfle.test.mybatisflexspringbootseata.mapper.OrderTblMapper; -import com.mybatisfle.test.mybatisflexspringbootseata.mapper.StockTblMapper; import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.test.entity.AccountTbl; +import com.mybatisflex.test.entity.OrderTbl; +import com.mybatisflex.test.entity.StockTbl; +import com.mybatisflex.test.entity.table.AccountTblTableDef; +import com.mybatisflex.test.mapper.AccountTblMapper; +import com.mybatisflex.test.mapper.OrderTblMapper; +import com.mybatisflex.test.mapper.StockTblMapper; import io.seata.core.context.RootContext; import io.seata.spring.annotation.GlobalTransactional; import org.mybatis.logging.Logger; import org.mybatis.logging.LoggerFactory; -import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service public class TestService { @@ -33,12 +47,12 @@ public class TestService { @Autowired StockTblMapper stockTblMapper; -// @Transactional + // @Transactional @GlobalTransactional public boolean buy() { // DataSourceKey.use("accountdb"); - LOGGER.warn(() -> "xid:"+RootContext.getXID()); - QueryWrapper account =new QueryWrapper(); + LOGGER.warn(() -> "xid:" + RootContext.getXID()); + QueryWrapper account = new QueryWrapper(); account.where(AccountTblTableDef.ACCOUNT_TBL.USER_ID.eq("1001")); AccountTbl accountTbl = accountTblMapper.selectOneByQuery(account); accountTbl.setMoney(accountTbl.getMoney() - 5); @@ -59,4 +73,5 @@ public class TestService { orderTblMapper.insert(orderTbl); return true; } + } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml b/mybatis-flex-test/mybatis-flex-seata-test/src/main/resources/application.yml similarity index 99% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/resources/application.yml index 2000304f..97c7b42c 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/application.yml +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/main/resources/application.yml @@ -1,4 +1,3 @@ - mybatis-flex: seata-config: enable: true #启动seata diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/db/all_in_one.sql b/mybatis-flex-test/mybatis-flex-seata-test/src/main/resources/db/all_in_one.sql similarity index 100% rename from mybatis-flex-test/mybatis-flex-spring-boot-seata/src/main/resources/db/all_in_one.sql rename to mybatis-flex-test/mybatis-flex-seata-test/src/main/resources/db/all_in_one.sql diff --git a/mybatis-flex-test/mybatis-flex-seata-test/src/test/java/com/mybatisflex/test/MybatisFlexSpringBootSeataApplicationTests.java b/mybatis-flex-test/mybatis-flex-seata-test/src/test/java/com/mybatisflex/test/MybatisFlexSpringBootSeataApplicationTests.java new file mode 100644 index 00000000..812410b1 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-seata-test/src/test/java/com/mybatisflex/test/MybatisFlexSpringBootSeataApplicationTests.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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.mybatisflex.test;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class MybatisFlexSpringBootSeataApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}
diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-seata/pom.xml b/mybatis-flex-test/mybatis-flex-spring-boot-seata/pom.xml
deleted file mode 100644
index e7fd6f34..00000000
--- a/mybatis-flex-test/mybatis-flex-spring-boot-seata/pom.xml
+++ /dev/null
@@ -1,155 +0,0 @@
-
-