Skip to content

Commit

Permalink
support multiple mapper-locations
Browse files Browse the repository at this point in the history
  • Loading branch information
charle004 committed Sep 5, 2024
1 parent e8140c7 commit fb6eafb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private ParseCfgProps readParseCfgProps(ConfigurableEnvironment environment) {
.setLogShow(environment.getProperty("cql.parser.log-show"))
.setMapper(environment.getProperty("cql.parser.mapper"))
.setNamespace(environment.getProperty("cql.parser.namespace"))
.setMapperLocations(environment.getProperty("cql.parser.mapper-locations"))
.setMapperLocations(environment.getProperty("cql.parser.mapper-locations", String[].class))
.setMapperTplLocation(environment.getProperty("cql.parser.mapper-tpl-location"))
.setResultType(environment.getProperty("cql.parser.result-type"))
.setParameterType(environment.getProperty("cql.parser.parameter-type"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ParseCfgProps {

private String mapperTplLocation = "NebulaDaoBasic.xml";

private String mapperLocations = "mapper/**/*.xml";
private String[] mapperLocations = {"mapper/**/*.xml"};

private String id = "id";

Expand Down Expand Up @@ -75,7 +75,7 @@ public ParseCfgProps setMapperTplLocation(String mapperTplLocation) {
* <p>获取开发者业务dao对应xml所存放的路径。</p>
* @return 开发者业务dao对应xml所存放的路径
*/
public String getMapperLocations() {
public String[] getMapperLocations() {
return mapperLocations;
}

Expand All @@ -84,8 +84,8 @@ public String getMapperLocations() {
* @param mapperLocations 业务dao对应xml所存放的路径
* @return 解析配置(本应是 void,为支持链式调用而改)
*/
public ParseCfgProps setMapperLocations(String mapperLocations) {
if (isBlank(mapperLocations)) {
public ParseCfgProps setMapperLocations(String[] mapperLocations) {
if (isEmpty(mapperLocations)) {
return this;
}
this.mapperLocations = mapperLocations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public MapperResourceLoader(ParseCfgProps parseConfig,ApplicationContext applica
@TimeLog(name = "xml-load", explain = "mappers xml load completed : {} ms")
public Map<String, ClassModel> load() {
Map<String, ClassModel> resultClassModel = new HashMap<>();
String mapperLocations = parseConfig.getMapperLocations();
String[] mapperLocations = parseConfig.getMapperLocations();
try {
Resource[] resources = getResources(mapperLocations);
for (Resource resource : resources) {
resultClassModel.putAll(parseClassModel(resource));
for (String mapperLocation : mapperLocations) {
Resource[] resources = getResources(mapperLocation);
for (Resource resource : resources) {
resultClassModel.putAll(parseClassModel(resource));
}
}
} catch (FileNotFoundException ffe) {
log.warn("No mapper files were found in path pattern '{}', please add", mapperLocations);
Expand Down

0 comments on commit fb6eafb

Please sign in to comment.