org.onetwo.common.db.filequery.ParserContextFunctionSet Maven / Gradle / Ivy
The newest version!
package org.onetwo.common.db.filequery;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Date;
import org.onetwo.common.date.DateUtils;
import org.onetwo.common.db.SqlUtils;
import org.onetwo.common.db.spi.QueryContextVariable;
import org.onetwo.common.utils.Assert;
import org.onetwo.common.utils.LangUtils;
import org.onetwo.common.utils.StringUtils;
public class ParserContextFunctionSet implements QueryContextVariable {
public static final String CONTEXT_KEY = "_func";//helper
private static final ParserContextFunctionSet instance = new ParserContextFunctionSet();
public static ParserContextFunctionSet getInstance() {
return instance;
}
@Override
public String varName() {
return CONTEXT_KEY;
}
public boolean isEmpty(Object obj){
return LangUtils.size(obj)==0;
}
public boolean isBlank(Object obj){
if(String.class.isInstance(obj))
return StringUtils.isBlank(obj.toString());
return LangUtils.size(obj)==0;
}
public String check(String sqlValue){
return SqlUtils.checkSqlValue(sqlValue);
}
/****
* spring named sql supported List value
* ${_func.paramIn('dptcode', dptcodeList)}
* @param name
* @param inValue
* @return
*/
public String paramIn(String name, Object inValue){
int size = 0;
if(Collection.class.isInstance(inValue)){
size = ((Collection>)inValue).size();
}else if(inValue!=null && inValue.getClass().isArray()){
size = Array.getLength(inValue);
}else{
throw new IllegalArgumentException("only supported array or collection: " + inValue);
}
StringBuilder str = new StringBuilder();
str.append("(");
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy