|
@@ -38,7 +38,12 @@ import org.springframework.util.ResourceUtils;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -83,7 +88,7 @@ public class MybatisMapperRefresh implements Runnable {
|
|
|
private static Map<String, List<Resource>> jarMapper = new HashMap<String, List<Resource>>();
|
|
|
|
|
|
public MybatisMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
|
|
|
- int sleepSeconds, boolean enabled) {
|
|
|
+ int sleepSeconds, boolean enabled) {
|
|
|
this.mapperLocations = mapperLocations;
|
|
|
this.sqlSessionFactory = sqlSessionFactory;
|
|
|
this.delaySeconds = delaySeconds;
|
|
@@ -102,7 +107,7 @@ public class MybatisMapperRefresh implements Runnable {
|
|
|
}
|
|
|
|
|
|
public void run() {
|
|
|
- final GlobalConfiguration mybatisGlobalCache = GlobalConfiguration.GlobalConfig(configuration);
|
|
|
+ final GlobalConfiguration globalConfig = GlobalConfiguration.GlobalConfig(configuration);
|
|
|
/*
|
|
|
* 启动 XML 热加载
|
|
|
*/
|
|
@@ -145,7 +150,7 @@ public class MybatisMapperRefresh implements Runnable {
|
|
|
for (String filePath : fileSet) {
|
|
|
File file = new File(filePath);
|
|
|
if (file != null && file.isFile() && file.lastModified() > beforeTime) {
|
|
|
- mybatisGlobalCache.setRefresh(true);
|
|
|
+ globalConfig.setRefresh(true);
|
|
|
List<Resource> removeList = jarMapper.get(filePath);
|
|
|
if (removeList != null && !removeList.isEmpty()) {// 如果是jar包中的xml,将刷新jar包中存在的所有xml,后期再修改加载jar中修改过后的xml
|
|
|
for (Resource resource : removeList) {
|
|
@@ -156,10 +161,10 @@ public class MybatisMapperRefresh implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (mybatisGlobalCache.isRefresh()) {
|
|
|
+ if (globalConfig.isRefresh()) {
|
|
|
beforeTime = SystemClock.now();
|
|
|
}
|
|
|
- mybatisGlobalCache.setRefresh(true);
|
|
|
+ globalConfig.setRefresh(true);
|
|
|
} catch (Exception exception) {
|
|
|
exception.printStackTrace();
|
|
|
}
|
|
@@ -239,20 +244,21 @@ public class MybatisMapperRefresh implements Runnable {
|
|
|
String id = resultMapNode.getStringAttribute("id", resultMapNode.getValueBasedIdentifier());
|
|
|
configuration.getResultMapNames().remove(id);
|
|
|
configuration.getResultMapNames().remove(namespace + "." + id);
|
|
|
- clearResultMap(resultMapNode,namespace);
|
|
|
+ clearResultMap(resultMapNode, namespace);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void clearResultMap(XNode xNode,String namespace){
|
|
|
+ private void clearResultMap(XNode xNode, String namespace) {
|
|
|
for (XNode resultChild : xNode.getChildren()) {
|
|
|
- if ("association".equals(resultChild.getName())
|
|
|
- || "collection".equals(resultChild.getName())
|
|
|
+ if ("association".equals(resultChild.getName()) || "collection".equals(resultChild.getName())
|
|
|
|| "case".equals(resultChild.getName())) {
|
|
|
if (resultChild.getStringAttribute("select") == null) {
|
|
|
- configuration.getResultMapNames().remove(resultChild.getStringAttribute("id",resultChild.getValueBasedIdentifier()));
|
|
|
- configuration.getResultMapNames().remove(namespace+"."+resultChild.getStringAttribute("id",resultChild.getValueBasedIdentifier()));
|
|
|
- if(resultChild.getChildren()!=null&&!resultChild.getChildren().isEmpty()){
|
|
|
- clearResultMap(resultChild,namespace);
|
|
|
+ configuration.getResultMapNames().remove(
|
|
|
+ resultChild.getStringAttribute("id", resultChild.getValueBasedIdentifier()));
|
|
|
+ configuration.getResultMapNames().remove(
|
|
|
+ namespace + "." + resultChild.getStringAttribute("id", resultChild.getValueBasedIdentifier()));
|
|
|
+ if (resultChild.getChildren() != null && !resultChild.getChildren().isEmpty()) {
|
|
|
+ clearResultMap(resultChild, namespace);
|
|
|
}
|
|
|
}
|
|
|
}
|