com.mybaits.jpa.service.QueryWrapperFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-jpa Show documentation
Show all versions of mybatis-jpa Show documentation
Mybaits JPA: a convenient development tool for mybatis puls
package com.mybaits.jpa.service;
import com.mybaits.jpa.sql.wrapper.MyQueryWrapper;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
* Created by Administrator on 2019/12/24 0024.
*/
public class QueryWrapperFactory {
private static Map map;
public QueryWrapperFactory(){
map=new HashMap<>();
}
// public MyQueryWrapper getQueryWrapper(StackTraceElement stackTraceElement, Object...params){
// String methodName = stackTraceElement.getMethodName();
// String className=stackTraceElement.getClassName();
// MyQueryWrapper queryWrapper=map.get(className+"."+methodName);
// if(queryWrapper==null){
// return null;
// }
// MyQueryWrapper queryWrapperOut=setQueryWrapperParam(new ObjcetUtils().cloneObject(queryWrapper),params);
// return queryWrapperOut;
// }
// public MyQueryWrapper getQueryWrapper(StackTraceElement stackTraceElement,MyQueryWrapper myQueryWrapper, Object...params){
// String methodName = stackTraceElement.getMethodName();
// String className=stackTraceElement.getClassName();
// MyQueryWrapper queryWrapper=map.get(className+"."+methodName);
// if(queryWrapper==null){
// return null;
// }
// MyQueryWrapper queryWrapperOut=setQueryWrapperParam(new ObjcetUtils().cloneObject(queryWrapper),params);
// return queryWrapperOut;
// }
public void putQueryWrapper(StackTraceElement stackTraceElement,MyQueryWrapper queryWrapper){
String methodName = stackTraceElement.getMethodName();
String className=stackTraceElement.getClassName();
map.put(className+"."+methodName,queryWrapper);
}
private MyQueryWrapper setQueryWrapperParam(MyQueryWrapper queryWrapper,Object...params){
Set set=queryWrapper.getParamNameValuePairs().keySet();
Set sortSet = new TreeSet((o1, o2) -> o1.compareTo(o2));
sortSet.addAll(set);
if(params.length<0){
return queryWrapper;
}
int index=0;
for (String key : sortSet) {
if(params.length>index){
queryWrapper.getParamNameValuePairs().put(key,params[index]);
}
}
return queryWrapper;
}
}