Skip to content

Commit 091be3c

Browse files
yangfuhaigitee-org
authored andcommitted
!493 添加 solon 适配事务支持
Merge pull request !493 from 西东/main
2 parents 6ffc669 + d04192c commit 091be3c

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/FlexDataSource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
202202
}
203203

204204

205-
private DataSource getDataSource() {
205+
protected DataSource getDataSource() {
206206
DataSource dataSource = defaultDataSource;
207207
if (dataSourceMap.size() > 1) {
208208
String dataSourceKey = DataSourceKey.get();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.mybatisflex.solon.integration;
2+
3+
import com.mybatisflex.core.datasource.FlexDataSource;
4+
import org.noear.solon.data.datasource.RoutingDataSource;
5+
6+
import javax.sql.DataSource;
7+
8+
/**
9+
* 用与 solon 的事务对接
10+
*
11+
* @author noear
12+
* @since 2.8
13+
*/
14+
public class FlexRoutingDataSource extends FlexDataSource implements RoutingDataSource {
15+
public FlexRoutingDataSource(String dataSourceKey, DataSource dataSource) {
16+
super(dataSourceKey, dataSource);
17+
}
18+
19+
public FlexRoutingDataSource(String dataSourceKey, DataSource dataSource, boolean needDecryptDataSource) {
20+
super(dataSourceKey, dataSource, needDecryptDataSource);
21+
}
22+
23+
@Override
24+
public DataSource determineCurrentTarget() {
25+
return getDataSource();
26+
}
27+
}

mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFlex.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.mybatisflex.solon.integration;
1818

1919
import com.mybatisflex.core.FlexGlobalConfig;
20-
import com.mybatisflex.core.datasource.FlexDataSource;
2120
import com.mybatisflex.core.mybatis.FlexConfiguration;
2221
import com.mybatisflex.core.mybatis.FlexSqlSessionFactoryBuilder;
2322
import com.mybatisflex.core.row.RowMapperInvoker;
@@ -39,12 +38,9 @@
3938
* @since 2.2
4039
*/
4140
public class MybatisAdapterFlex extends MybatisAdapterDefault {
42-
43-
FlexSqlSessionFactoryBuilder factoryBuilderPlus;
44-
45-
FlexGlobalConfig globalConfig;
46-
47-
RowMapperInvoker rowMapperInvoker;
41+
private FlexSqlSessionFactoryBuilder factoryBuilderPlus;
42+
private FlexGlobalConfig globalConfig;
43+
private RowMapperInvoker rowMapperInvoker;
4844

4945
protected MybatisAdapterFlex(BeanWrap dsWrap) {
5046
super(dsWrap);
@@ -66,7 +62,7 @@ protected void initAfter(BeanWrap dsWrap) {
6662

6763
@Override
6864
protected DataSource getDataSource() {
69-
return new FlexDataSource(dsWrap.name(), dsWrap.raw());
65+
return new FlexRoutingDataSource(dsWrap.name(), dsWrap.raw());
7066
}
7167

7268
@Override
@@ -94,7 +90,7 @@ protected void initConfiguration(Environment environment) {
9490
FlexGlobalConfig.setConfig(environment.getId(), globalConfig, false);
9591

9692
//增加事件扩展机制
97-
EventBus.push(globalConfig);
93+
EventBus.publish(globalConfig);
9894

9995

10096
if (dsWrap.typed()) {

mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/XPluginImpl.java

-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.mybatisflex.solon.integration;
1818

1919
import org.apache.ibatis.solon.integration.MybatisAdapterManager;
20-
import org.noear.solon.core.AopContext;
2120
import org.noear.solon.core.AppContext;
2221
import org.noear.solon.core.Plugin;
2322

@@ -28,15 +27,6 @@
2827
* @since 2.2
2928
*/
3029
public class XPluginImpl implements Plugin {
31-
32-
//兼容 2.5 以下版本
33-
@Override
34-
public void start(AopContext context) throws Throwable {
35-
// 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值
36-
MybatisAdapterManager.setAdapterFactory(new MybatisAdapterFactoryFlex());
37-
}
38-
39-
//兼容 2.5 以上版本
4030
@Override
4131
public void start(AppContext context) throws Throwable {
4232
// 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
<spring.version>5.3.27</spring.version>
7070
<spring-boot.version>2.7.11</spring-boot.version>
71-
<solon.version>2.5.3</solon.version>
71+
<solon.version>2.9.3</solon.version>
7272

7373
<junit.version>4.13.2</junit.version>
7474
<testcontainers.version>1.19.3</testcontainers.version>

0 commit comments

Comments
 (0)