package com.github.wz2cool.dynamic;

/**
 * @author Frank
 */
public class NormPagingQuery<T> extends BaseDynamicQuery<T, NormPagingQuery<T>> {

    private final int pageNum;
    private final int pageSize;
    private final boolean calcTotal;
    private boolean autoBackIfEmpty;

    public int getPageNum() {
        return pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public boolean isCalcTotal() {
        return calcTotal;
    }

    public boolean isAutoBackIfEmpty() {
        return autoBackIfEmpty;
    }

    public void setAutoBackIfEmpty(boolean autoBackIfEmpty) {
        this.autoBackIfEmpty = autoBackIfEmpty;
    }

    private NormPagingQuery(Class<T> clazz, int pageNum, int pageSize, boolean autoBackIfEmpty, boolean calcTotal) {
        this.setEntityClass(clazz);
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.autoBackIfEmpty = autoBackIfEmpty;
        this.calcTotal = calcTotal;
    }

    public static <T> NormPagingQuery<T> createQuery(
            Class<T> clazz, int pageNum, int pageSize, boolean autoBackIfEmpty, boolean calcTotal) {
        return new NormPagingQuery<>(clazz, pageNum, pageSize, autoBackIfEmpty, calcTotal);
    }

    public static <T> NormPagingQuery<T> createQuery(
            Class<T> clazz, int pageNum, int pageSize, boolean autoBackIfEmpty) {
        return new NormPagingQuery<>(clazz, pageNum, pageSize, autoBackIfEmpty, true);
    }

    public DynamicQuery<T> getDynamicQuery() {
        DynamicQuery<T> dynamicQuery = DynamicQuery.createQuery(getEntityClass());
        dynamicQuery.addFilters(this.getFilters());
        dynamicQuery.addSorts(this.getSorts());
        dynamicQuery.setDistinct(this.isDistinct());
        dynamicQuery.setSelectedProperties(this.getSelectedProperties());
        dynamicQuery.setIgnoredProperties(this.getIgnoredProperties());
        return dynamicQuery;
    }
}

@@ -1451,32 +1451,214 @@
 , true);%0A    %7D%0A%0A
+    public static %3CT%3E NormPagingQuery%3CT%3E createQuery(Class%3CT%3E clazz, int pageNum, int pageSize) %7B%0A        return new NormPagingQuery%3C%3E(clazz, pageNum, pageSize, false, true);%0A    %7D%0A%0A
     public Dynam

change pageIndex to pageNum