Skip to content

Commit

Permalink
fixes #712
Browse files Browse the repository at this point in the history
  • Loading branch information
caochengxiang committed Sep 13, 2023
1 parent 84ea265 commit 2aeb814
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jcommon/docean-plugin/docean-plugin-mybatis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>docean-plugin-mybatis</artifactId>
<version>1.4.7-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>

<dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class MybatisPlugin implements IPlugin {

private boolean serverLess = false;

private static SqlSessionFactory sqlSessionFactory;

private static String mapperName = "_mapperName_";


@SneakyThrows
@Override
Expand Down Expand Up @@ -118,6 +122,7 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one
Thread.currentThread().setContextClassLoader(ioc.getClassLoader());
}
SqlSessionFactory factory = bean.buildSqlSessionFactory();
MybatisPlugin.sqlSessionFactory = factory;
ioc.putBean("mybatis_" + beanName + config.getName(), factory);
if (System.getenv("mybatis_mapper_annotation") != null) {
factory.getConfiguration().addMappers(System.getenv("mybatis_mapper_annotation"));
Expand All @@ -134,10 +139,12 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one
new SqlSessionInterceptor(factory)));
if (one) {
ioc.putBean(it.getName(), proxy);
ioc.putBean(mapperName + it.getName(), it.getName());
} else {
String name = it.getSimpleName() + ":" + config.getName();
log.info("mybatis dao name:{} add", name);
ioc.putBean(name, proxy);
ioc.putBean(mapperName + name, it.getName());
}
});
} finally {
Expand All @@ -149,6 +156,14 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one
}
}

public static SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}

public static String getMapperName() {
return mapperName;
}

@Override
public String version() {
return "0.0.1:2022-03-29:[email protected]";
Expand Down

0 comments on commit 2aeb814

Please sign in to comment.