-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84ea265
commit 2aeb814
Showing
2 changed files
with
16 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ public class MybatisPlugin implements IPlugin { | |
|
||
private boolean serverLess = false; | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
private static String mapperName = "_mapperName_"; | ||
|
||
|
||
@SneakyThrows | ||
@Override | ||
|
@@ -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")); | ||
|
@@ -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 { | ||
|
@@ -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]"; | ||
|