package com.app.query.dao; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * sql参数 * @author tanxiang * * @param */ public class SQLParameter { public final static int DEFAULT_PAG = 1; public final static int DEFAULT_PAGESIZE = 10000; /** * 页码 */ private int page = DEFAULT_PAG; /** * 页大小 */ private int pageSize = DEFAULT_PAGESIZE; public SQLParameter() { } public static SQLParameter newInstance() { return new SQLParameter(); } public static SQLParameter newInstance(Class cls) { return new SQLParameter(); } public SQLParameter clear() { list.clear(); return this; } public SQLParameter reset() { this.page = DEFAULT_PAG; this.pageSize = DEFAULT_PAGESIZE; list.clear(); return this; } private List list = new ArrayList(); public SQLParameter add(T param) { list.add(param); return this; } public List toList() { return list; } public T[] toArray(T[] a) { return list.toArray(a); } public Map toMap() { Map map = new HashMap(); Parameter p; for (T t : list) { if(t instanceof Parameter) { p = (Parameter) t; map.put(p.getName(), p.getValue()); continue; } throw new IllegalArgumentException("Occurs Exception: "+t.getClass().getName() + "is not instanceof com.unind.base.dbconnection.query.Parameter"); } return map; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getStartIndex() { return (page-1) * pageSize; } }