com.kukababy.plus.utils.HoldUtil Maven / Gradle / Ivy
The newest version!
/**
*
*/
package com.kukababy.plus.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.kukababy.plus.exception.PlusRuntimeException;
import com.kukababy.plus.pager.CustSqlInfo;
import com.kukababy.plus.pager.SqlFilter;
import com.kukababy.plus.pager.SqlInfo;
import com.kukababy.plus.pager.SqlWhere;
import com.kukababy.plus.pojo.P;
/**
*
*
*
*
* 描述:Sql的占位符处理,最终的SQL语句和?对应的值
*
*
*
*
* @author [email protected]
* @date 2019年3月5日 下午10:48:48
*/
public class HoldUtil {
/**
* sql语句占位符规则 sql=select * from a where id=:id
*/
// private static Pattern holdP = Pattern.compile(":[a-zA-Z-_]{1,}");
private static Pattern holdP = Pattern.compile("#\\{[a-zA-Z-_]{1,}\\}");
/**
*
* 描述:最终sql和对应的值
*
*
* @param sql
* @param sqlFilter
* @return
*/
public static SqlInfo getSqlAndVals(String sql, SqlFilter sqlFilter) {
Map holdMap = getHoldValsSql(sql, sqlFilter.getHoldName2ValMap());
return getSqlAndVals(sql, holdMap, sqlFilter);
}
/**
*
* 描述:最终sql语句与对应的值
*
*
* @param sql
* @param holdWhereColVals
* @return
*/
public static SqlInfo getSqlAndVals(String sql, P... holdWhereColVals) {
List holdWheres = new ArrayList();
for (P p : holdWhereColVals) {
holdWheres.add(p);
}
Map holdValMap = new HashMap();
for (P p : holdWhereColVals) {
holdValMap.put(p.getCol(), p.getVal());
}
Map holdMap = getHoldValsSql(sql, holdValMap);
SqlFilter sqlFilter = SqlUtil.list2SqlFilter(holdWheres);
return getSqlAndVals(sql, holdMap, sqlFilter);
}
public static CustSqlInfo getCustSqlAndVals(String sql, List params) {
Map holdValMap = new HashMap();
for (P p : params) {
holdValMap.put(p.getCol(), p.getVal());
}
Map holdMap = getHoldValsSql(sql, holdValMap);
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy