From c65a3608f8c7cb43eb5d95f72548f60eac68b51b Mon Sep 17 00:00:00 2001 From: pbnoyz <11922388+pbnoyz@users.noreply.github.com> Date: Tue, 26 Aug 2025 22:34:28 +0800 Subject: [PATCH 1/2] fix: use ${project.version} for module deps --- mybatis-flex-codegen/pom.xml | 6 +++--- mybatis-flex-core/pom.xml | 11 ++--------- mybatis-flex-dependencies/pom.xml | 17 ++++++++--------- mybatis-flex-loveqq-starter/pom.xml | 2 +- mybatis-flex-processor/pom.xml | 4 +--- mybatis-flex-solon-plugin/pom.xml | 2 +- mybatis-flex-spring-boot-starter/pom.xml | 4 ++-- mybatis-flex-spring-boot3-starter/pom.xml | 2 +- mybatis-flex-spring/pom.xml | 2 +- .../mybatis-flex-loveqq-test/pom.xml | 2 +- .../mybatis-flex-native-test/pom.xml | 2 +- .../mybatis-flex-seata-test/pom.xml | 2 +- .../mybatis-flex-solon-test/pom.xml | 4 ++-- .../mybatis-flex-spring-boot-test/pom.xml | 2 +- .../mybatis-flex-spring-cloud-test/pom.xml | 5 +++-- .../mybatis-flex-spring-test/pom.xml | 4 ++-- mybatis-flex-test/pom.xml | 2 +- pom.xml | 3 +++ 18 files changed, 35 insertions(+), 41 deletions(-) diff --git a/mybatis-flex-codegen/pom.xml b/mybatis-flex-codegen/pom.xml index d08a5a86..f8ad97f9 100644 --- a/mybatis-flex-codegen/pom.xml +++ b/mybatis-flex-codegen/pom.xml @@ -25,7 +25,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} com.mybatis-flex @@ -122,7 +122,7 @@ com.mybatis-flex mybatis-flex-spring - ${revision} + ${project.version} com.mybatis-flex @@ -136,7 +136,7 @@ com.mybatis-flex mybatis-flex-solon-plugin - ${revision} + ${project.version} com.mybatis-flex diff --git a/mybatis-flex-core/pom.xml b/mybatis-flex-core/pom.xml index 0f27f41b..65c88295 100644 --- a/mybatis-flex-core/pom.xml +++ b/mybatis-flex-core/pom.xml @@ -25,13 +25,13 @@ com.mybatis-flex mybatis-flex-annotation - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-processor - ${revision} + ${project.version} @@ -100,13 +100,6 @@ test - - com.mybatis-flex - mybatis-flex-annotation - ${revision} - compile - - diff --git a/mybatis-flex-dependencies/pom.xml b/mybatis-flex-dependencies/pom.xml index 868735ed..cb069fe5 100644 --- a/mybatis-flex-dependencies/pom.xml +++ b/mybatis-flex-dependencies/pom.xml @@ -12,7 +12,6 @@ mybatis-flex-dependencies - ${revision} pom @@ -61,42 +60,42 @@ com.mybatis-flex mybatis-flex-annotation - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-codegen - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-processor - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-solon-plugin - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-spring - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-spring-boot-starter - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-spring-boot3-starter - ${revision} + ${project.version} diff --git a/mybatis-flex-loveqq-starter/pom.xml b/mybatis-flex-loveqq-starter/pom.xml index 7e085a97..445e288f 100644 --- a/mybatis-flex-loveqq-starter/pom.xml +++ b/mybatis-flex-loveqq-starter/pom.xml @@ -35,7 +35,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} diff --git a/mybatis-flex-processor/pom.xml b/mybatis-flex-processor/pom.xml index 991ddc7d..384bdb14 100644 --- a/mybatis-flex-processor/pom.xml +++ b/mybatis-flex-processor/pom.xml @@ -13,8 +13,6 @@ mybatis-flex-processor mybatis-flex-processor jar - ${revision} - 8 @@ -25,7 +23,7 @@ com.mybatis-flex mybatis-flex-annotation - ${revision} + ${project.version} diff --git a/mybatis-flex-solon-plugin/pom.xml b/mybatis-flex-solon-plugin/pom.xml index 4cb22020..bf5bd253 100644 --- a/mybatis-flex-solon-plugin/pom.xml +++ b/mybatis-flex-solon-plugin/pom.xml @@ -30,7 +30,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} diff --git a/mybatis-flex-spring-boot-starter/pom.xml b/mybatis-flex-spring-boot-starter/pom.xml index cabe91f9..16dd2373 100644 --- a/mybatis-flex-spring-boot-starter/pom.xml +++ b/mybatis-flex-spring-boot-starter/pom.xml @@ -25,7 +25,7 @@ com.mybatis-flex mybatis-flex-spring - ${revision} + ${project.version} @@ -106,7 +106,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} diff --git a/mybatis-flex-spring-boot3-starter/pom.xml b/mybatis-flex-spring-boot3-starter/pom.xml index ec9dde32..d4d42b1c 100644 --- a/mybatis-flex-spring-boot3-starter/pom.xml +++ b/mybatis-flex-spring-boot3-starter/pom.xml @@ -22,7 +22,7 @@ com.mybatis-flex mybatis-flex-spring-boot-starter - ${revision} + ${project.version} org.mybatis diff --git a/mybatis-flex-spring/pom.xml b/mybatis-flex-spring/pom.xml index 87b5fb62..f324950f 100644 --- a/mybatis-flex-spring/pom.xml +++ b/mybatis-flex-spring/pom.xml @@ -24,7 +24,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} diff --git a/mybatis-flex-test/mybatis-flex-loveqq-test/pom.xml b/mybatis-flex-test/mybatis-flex-loveqq-test/pom.xml index 7210a83a..cddb515e 100644 --- a/mybatis-flex-test/mybatis-flex-loveqq-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-loveqq-test/pom.xml @@ -29,7 +29,7 @@ com.mybatis-flex mybatis-flex-loveqq-starter - ${revision} + ${project.version diff --git a/mybatis-flex-test/mybatis-flex-native-test/pom.xml b/mybatis-flex-test/mybatis-flex-native-test/pom.xml index 55385a7a..d2235abc 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-native-test/pom.xml @@ -24,7 +24,7 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} diff --git a/mybatis-flex-test/mybatis-flex-seata-test/pom.xml b/mybatis-flex-test/mybatis-flex-seata-test/pom.xml index 0f5f2e5a..e94e917c 100644 --- a/mybatis-flex-test/mybatis-flex-seata-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-seata-test/pom.xml @@ -22,7 +22,7 @@ com.mybatis-flex mybatis-flex-spring-boot-starter - ${revision} + ${project.version diff --git a/mybatis-flex-test/mybatis-flex-solon-test/pom.xml b/mybatis-flex-test/mybatis-flex-solon-test/pom.xml index 8b623c2c..9120d4dd 100644 --- a/mybatis-flex-test/mybatis-flex-solon-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-solon-test/pom.xml @@ -26,7 +26,7 @@ com.mybatis-flex mybatis-flex-solon-plugin - ${revision} + ${project.version @@ -97,7 +97,7 @@ com.mybatis-flex mybatis-flex-processor - ${revision} + ${project.version} diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml b/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml index 2ba2cc11..ef7c510d 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml @@ -24,7 +24,7 @@ com.mybatis-flex mybatis-flex-spring-boot-starter - ${revision} + ${project.version} diff --git a/mybatis-flex-test/mybatis-flex-spring-cloud-test/pom.xml b/mybatis-flex-test/mybatis-flex-spring-cloud-test/pom.xml index e428c967..21bbabfa 100644 --- a/mybatis-flex-test/mybatis-flex-spring-cloud-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-spring-cloud-test/pom.xml @@ -58,7 +58,7 @@ com.mybatis-flex mybatis-flex-spring-boot-starter - ${revision} + ${project.version} @@ -85,7 +85,7 @@ com.mybatis-flex mybatis-flex-spring-test - ${revision} + ${project.version} compile @@ -95,6 +95,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} diff --git a/mybatis-flex-test/mybatis-flex-spring-test/pom.xml b/mybatis-flex-test/mybatis-flex-spring-test/pom.xml index d86eb7ac..ef9bdba5 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-spring-test/pom.xml @@ -24,13 +24,13 @@ com.mybatis-flex mybatis-flex-core - ${revision} + ${project.version} com.mybatis-flex mybatis-flex-spring - ${revision} + ${project.version} diff --git a/mybatis-flex-test/pom.xml b/mybatis-flex-test/pom.xml index bae5c207..312737cf 100644 --- a/mybatis-flex-test/pom.xml +++ b/mybatis-flex-test/pom.xml @@ -77,7 +77,7 @@ com.mybatis-flex mybatis-flex-processor - ${revision} + ${project.version} diff --git a/pom.xml b/pom.xml index 78ac0ced..e4d1666e 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,9 @@ + UTF-8 + UTF-8 + UTF-8 8 8 From 9afcb9514dd6037de2b1cf53c40008c9eaf3f589 Mon Sep 17 00:00:00 2001 From: pbnoyz <11922388+pbnoyz@users.noreply.github.com> Date: Tue, 26 Aug 2025 22:36:36 +0800 Subject: [PATCH 2/2] feat: add stmtId for AuditMessage --- .../mybatisflex/core/audit/AuditManager.java | 3 +- .../mybatisflex/core/audit/AuditMessage.java | 14 ++++++ .../core/mybatis/FlexStatementHandler.java | 10 ++-- .../test/mapper/AccountMapper.java | 6 +++ .../java/com/mybatisflex/test/AuditTest.java | 49 +++++++++++++++++++ 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AuditTest.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java index b4d21fc8..658bc415 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditManager.java @@ -97,11 +97,12 @@ public class AuditManager { } @SuppressWarnings("rawtypes") - public static T startAudit(AuditRunnable supplier, Statement statement, BoundSql boundSql, Configuration configuration) throws SQLException { + public static T startAudit(AuditRunnable supplier, String stmtId, Statement statement, BoundSql boundSql, Configuration configuration) throws SQLException { AuditMessage auditMessage = messageFactory.create(); if (auditMessage == null) { return supplier.execute(); } + auditMessage.setStmtId(stmtId); String key = DataSourceKey.get(); if (StringUtil.noText(key)) { key = FlexGlobalConfig.getDefaultConfig() diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java index 11aa6920..392e91e4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/AuditMessage.java @@ -95,6 +95,11 @@ public class AuditMessage implements Serializable { */ private long elapsedTime; + /** + * MappedStatement ID + */ + private String stmtId; + /** * 数据库名称。 */ @@ -270,6 +275,14 @@ public class AuditMessage implements Serializable { metas.put(key, value); } + public String getStmtId() { + return stmtId; + } + + public void setStmtId(String stmtId) { + this.stmtId = stmtId; + } + public String getDsName() { return dsName; } @@ -293,6 +306,7 @@ public class AuditMessage implements Serializable { ", queryCount=" + queryCount + ", queryTime=" + queryTime + ", elapsedTime=" + elapsedTime + + ", stmtId=" + stmtId + ", dsName=" + dsName + ", metas=" + metas + '}'; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java index b3c4f9d0..a149aac1 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexStatementHandler.java @@ -46,9 +46,11 @@ public class FlexStatementHandler implements StatementHandler { private final BoundSql boundSql; private final boolean auditEnable = AuditManager.isAuditEnable(); private final Configuration configuration; + private final String stmtId; public FlexStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { configuration = ms.getConfiguration(); + stmtId = ms.getId(); switch (ms.getStatementType()) { case STATEMENT: delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); @@ -83,7 +85,7 @@ public class FlexStatementHandler implements StatementHandler { AuditManager.startAudit(() -> { delegate.batch(statement); return null; - }, statement, boundSql, configuration); + }, stmtId, statement, boundSql, configuration); } else { delegate.batch(statement); } @@ -91,19 +93,19 @@ public class FlexStatementHandler implements StatementHandler { @Override public int update(Statement statement) throws SQLException { - return auditEnable ? AuditManager.startAudit(() -> delegate.update(statement), statement, boundSql, configuration) + return auditEnable ? AuditManager.startAudit(() -> delegate.update(statement), stmtId, statement, boundSql, configuration) : delegate.update(statement); } @Override public List query(Statement statement, ResultHandler resultHandler) throws SQLException { - return auditEnable ? AuditManager.startAudit(() -> delegate.query(statement, resultHandler), statement, boundSql, configuration) + return auditEnable ? AuditManager.startAudit(() -> delegate.query(statement, resultHandler), stmtId, statement, boundSql, configuration) : delegate.query(statement, resultHandler); } @Override public Cursor queryCursor(Statement statement) throws SQLException { - return auditEnable ? AuditManager.startAudit(() -> delegate.queryCursor(statement), statement, boundSql, configuration) + return auditEnable ? AuditManager.startAudit(() -> delegate.queryCursor(statement), stmtId, statement, boundSql, configuration) : delegate.queryCursor(statement); } diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java index 2c812405..a2642fbb 100644 --- a/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/main/java/com/mybatisflex/test/mapper/AccountMapper.java @@ -18,6 +18,9 @@ package com.mybatisflex.test.mapper; import com.mybatisflex.core.BaseMapper; import com.mybatisflex.test.model.Account; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * @author 王帅 @@ -25,4 +28,7 @@ import com.mybatisflex.test.model.Account; */ public interface AccountMapper extends BaseMapper { + @Select("select * from tb_account") + List selectAccounts(); + } diff --git a/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AuditTest.java b/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AuditTest.java new file mode 100644 index 00000000..4b8c3148 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-test/src/test/java/com/mybatisflex/test/AuditTest.java @@ -0,0 +1,49 @@ +package com.mybatisflex.test; + +import com.mybatisflex.core.audit.AuditManager; +import com.mybatisflex.core.audit.AuditMessage; +import com.mybatisflex.core.audit.MessageCollector; +import com.mybatisflex.test.mapper.AccountMapper; +import com.mybatisflex.test.mapper.TbClassMapper; +import lombok.Getter; +import org.assertj.core.api.WithAssertions; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = AppConfig.class) +public class AuditTest implements WithAssertions { + @Autowired + AccountMapper accountMapper; + @Autowired + TbClassMapper tbClassMapper; + + @Test + public void test() { + TestMsgCollector collector = new TestMsgCollector(); + AuditManager.setMessageCollector(collector); + AuditManager.setAuditEnable(true); + accountMapper.selectAccounts(); + tbClassMapper.selectAll(); + List messages = collector.getMessages(); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).getStmtId()).isEqualTo("com.mybatisflex.test.mapper.AccountMapper.selectAccounts"); + assertThat(messages.get(1).getStmtId()).isEqualTo("com.mybatisflex.test.mapper.TbClassMapper.selectListByQuery"); + } + + static class TestMsgCollector implements MessageCollector { + @Getter + private final List messages = new ArrayList<>(); + + @Override + public void collect(AuditMessage message) { + messages.add(message); + } + } +}