com.alibaba.simpleEL.dialect.ql.QLEvalService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SimpleEL Show documentation
Show all versions of SimpleEL Show documentation
simple expression language implementation
The newest version!
package com.alibaba.simpleEL.dialect.ql;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.simpleEL.Expr;
import com.alibaba.simpleEL.ExprCacheProvider;
import com.alibaba.simpleEL.JavaSource;
import com.alibaba.simpleEL.JavaSourceCompiler;
import com.alibaba.simpleEL.compile.JdkCompiler;
import com.alibaba.simpleEL.eval.DefaultExprCacheProvider;
import com.alibaba.simpleEL.eval.DefaultExpressEvalService;
public class QLEvalService extends DefaultExpressEvalService {
public QLEvalService(){
super(new QLPreprocessor());
}
public void setPreprocessor(QLPreprocessor preprocessor) {
this.preprocessor = preprocessor;
}
public void select(Class clazz, Collection srcCollection, Collection destCollection, String ql,
Map context) throws Exception {
Expr compiledExpr = getExpr(Collections. singletonMap("class", clazz), ql);
Map evalContext = new HashMap();
evalContext.put("_src_", srcCollection);
evalContext.put("_dest_", destCollection);
evalContext.putAll(context);
compiledExpr.eval(evalContext);
}
public Expr getExpr(Map compileContext, String expr) throws InstantiationException,
IllegalAccessException {
Expr cachedExpr = null;
if (cacheProvider != null) {
cachedExpr = cacheProvider.get(compileContext, expr);
}
if (cachedExpr != null) {
return cachedExpr;
}
JavaSource source = preprocessor.handle(compileContext, expr);
System.out.println(source.getSource());
Class extends Expr> exprClass = compiler.compile(source);
Expr compiledExpr = exprClass.newInstance();
cacheProvider.putIfAbsent(compileContext, expr, compiledExpr);
cachedExpr = cacheProvider.get(compileContext, expr);
return cachedExpr;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy