-
Notifications
You must be signed in to change notification settings - Fork 44
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
Showing
8 changed files
with
148 additions
and
144 deletions.
There are no files selected for viewing
74 changes: 38 additions & 36 deletions
74
src/main/java/org/nebula/contrib/ngbatis/binding/beetl/functions/IncludeFn.java
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 |
---|---|---|
@@ -1,51 +1,53 @@ | ||
package org.nebula.contrib.ngbatis.binding.beetl.functions; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import org.beetl.core.Template; | ||
import org.nebula.contrib.ngbatis.models.ClassModel; | ||
import org.nebula.contrib.ngbatis.models.MapperContext; | ||
import org.springframework.util.CollectionUtils; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* TODO | ||
* 2023-9-6 14:28 lyw. | ||
*/ | ||
public class IncludeFn extends AbstractFunction<String,Map<String,Object>,Void,Void,Void,Void>{ | ||
public class IncludeFn extends | ||
AbstractFunction<String, Map<String, Object>, Void, Void, Void, Void> { | ||
|
||
@Override | ||
public Object call(String ngql,Map<String,Object> args) { | ||
if(StringUtils.isEmpty(ngql)){ | ||
throw new RuntimeException("未指定nGQL片段"); | ||
} | ||
int idx = ngql.lastIndexOf("."); | ||
ClassModel classModel; | ||
String ngqlId; | ||
if(idx < 0){ | ||
ngqlId = ngql; | ||
classModel = (ClassModel) ctx.globalVar.get("ng_cm"); | ||
}else{ | ||
String namespace = ngql.substring(0,idx); | ||
ngqlId = ngql.substring(idx + 1); | ||
classModel = MapperContext.newInstance().getInterfaces().get(namespace + ClassModel.PROXY_SUFFIX); | ||
} | ||
if(CollectionUtils.isEmpty(classModel.getNgqls()) || StringUtils.isEmpty(classModel.getNgqls().get(ngqlId))){ | ||
throw new RuntimeException("未找到 nGQL(" + ngql + ") 的定义"); | ||
} | ||
Map<String,Object> param; | ||
if(!CollectionUtils.isEmpty(args)){ | ||
//防止同名的 子片段参数 覆盖 父片段参数,导致渲染结果与预期不一致。 | ||
param = new LinkedHashMap<>(ctx.globalVar); | ||
param.putAll(args); | ||
}else{ | ||
param = ctx.globalVar; | ||
} | ||
String text = classModel.getNgqls().get(ngqlId).getText(); | ||
Template template = ctx.gt.getTemplate(text); | ||
template.fastBinding(param); | ||
template.renderTo(ctx.byteWriter); | ||
return null; | ||
@Override | ||
public Object call(String ngql, Map<String, Object> args) { | ||
if (StringUtils.isEmpty(ngql)) { | ||
throw new RuntimeException("未指定nGQL片段"); | ||
} | ||
int idx = ngql.lastIndexOf("."); | ||
ClassModel classModel; | ||
String ngqlId; | ||
if (idx < 0) { | ||
ngqlId = ngql; | ||
classModel = (ClassModel) ctx.globalVar.get("ng_cm"); | ||
} else { | ||
String namespace = ngql.substring(0, idx); | ||
ngqlId = ngql.substring(idx + 1); | ||
classModel = MapperContext.newInstance().getInterfaces() | ||
.get(namespace + ClassModel.PROXY_SUFFIX); | ||
} | ||
if (CollectionUtils.isEmpty(classModel.getNgqls()) || StringUtils.isEmpty( | ||
classModel.getNgqls().get(ngqlId))) { | ||
throw new RuntimeException("未找到 nGQL(" + ngql + ") 的定义"); | ||
} | ||
Map<String, Object> param; | ||
if (!CollectionUtils.isEmpty(args)) { | ||
//防止同名的 子片段参数 覆盖 父片段参数,导致渲染结果与预期不一致。 | ||
param = new LinkedHashMap<>(ctx.globalVar); | ||
param.putAll(args); | ||
} else { | ||
param = ctx.globalVar; | ||
} | ||
String text = classModel.getNgqls().get(ngqlId).getText(); | ||
Template template = ctx.gt.getTemplate(text); | ||
template.fastBinding(param); | ||
template.renderTo(ctx.byteWriter); | ||
return null; | ||
} | ||
} |
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
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
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
Oops, something went wrong.