Search in sources :

Example 6 with Pager

use of org.nutz.dao.pager.Pager in project nutz by nutzam.

the class Sqlserver2005JdbcExpert method formatQuery.

public void formatQuery(Pojo pojo) {
    Pager pager = pojo.getContext().getPager();
    if (null != pager && pager.getPageNumber() > 0) {
        // -----------------------------------------------------
        // TODO XXX 这个写法灰常暴力!!But , it works!!!! 期待更好的写法
        PItem pi = pojo.getItem(0);
        StringBuilder sb = new StringBuilder();
        pi.joinSql(pojo.getEntity(), sb);
        String str = sb.toString();
        if (str.trim().toLowerCase().startsWith("select")) {
            pojo.setItem(0, Pojos.Items.wrap(str.substring(6)));
        } else
            // 以免出错.
            return;
        pojo.insertFirst(Pojos.Items.wrapf("select * from(select row_number()over(order by __tc__)__rn__,* from(select top %d 0 __tc__, ", pager.getOffset() + pager.getPageSize()));
        pojo.append(Pojos.Items.wrapf(")t)tt where __rn__ > %d order by __rn__", pager.getOffset()));
    }
}
Also used : Pager(org.nutz.dao.pager.Pager) PItem(org.nutz.dao.sql.PItem)

Example 7 with Pager

use of org.nutz.dao.pager.Pager in project nutz by nutzam.

the class OracleJdbcExpert method formatQuery.

public void formatQuery(Pojo pojo) {
    Pager pager = pojo.getContext().getPager();
    // 需要进行分页
    if (null != pager && pager.getPageNumber() > 0) {
        pojo.insertFirst(Pojos.Items.wrap("SELECT * FROM (SELECT T.*, ROWNUM RN FROM ("));
        pojo.append(Pojos.Items.wrapf(") T WHERE ROWNUM <= %d) WHERE RN > %d", pager.getOffset() + pager.getPageSize(), pager.getOffset()));
    }
}
Also used : Pager(org.nutz.dao.pager.Pager)

Example 8 with Pager

use of org.nutz.dao.pager.Pager in project nutz by nutzam.

the class OracleJdbcExpert method formatQuery.

@Override
public void formatQuery(Sql sql) {
    Pager pager = sql.getContext().getPager();
    // 需要进行分页
    if (null != pager && pager.getPageNumber() > 0) {
        String pre = "SELECT * FROM (SELECT T.*, ROWNUM RN FROM (";
        String last = String.format(") T WHERE ROWNUM <= %d) WHERE RN > %d", pager.getOffset() + pager.getPageSize(), pager.getOffset());
        sql.setSourceSql(pre + sql.getSourceSql() + last);
    }
}
Also used : Pager(org.nutz.dao.pager.Pager)

Example 9 with Pager

use of org.nutz.dao.pager.Pager in project nutz by nutzam.

the class Db2JdbcExpert method formatQuery.

public void formatQuery(Sql sql) {
    Pager pager = sql.getContext().getPager();
    if (null != pager && pager.getPageNumber() > 0) {
        String pre = "SELECT * FROM (SELECT ROW_NUMBER() OVER() AS ROWNUM, T.* FROM (";
        String last = String.format(") T) AS A WHERE ROWNUM BETWEEN %d AND %d", pager.getOffset() + 1, pager.getOffset() + pager.getPageSize());
        sql.setSourceSql(pre + sql.getSourceSql() + last);
    }
}
Also used : Pager(org.nutz.dao.pager.Pager)

Example 10 with Pager

use of org.nutz.dao.pager.Pager in project nutz by nutzam.

the class SimpleCriteria method setPager.

public void setPager(int pageNumber, int pageSize) {
    pager = new Pager();
    pager.setPageNumber(pageNumber);
    pager.setPageSize(pageSize);
}
Also used : Pager(org.nutz.dao.pager.Pager)

Aggregations

Pager (org.nutz.dao.pager.Pager)11 Test (org.junit.Test)2 Sql (org.nutz.dao.sql.Sql)2 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 NutSql (org.nutz.dao.impl.sql.NutSql)1 ValueAdaptor (org.nutz.dao.jdbc.ValueAdaptor)1 DaoStatement (org.nutz.dao.sql.DaoStatement)1 PItem (org.nutz.dao.sql.PItem)1 Pet (org.nutz.dao.test.meta.Pet)1 PojoSql (org.nutz.dao.test.meta.issue1074.PojoSql)1 Issue1163Pet (org.nutz.dao.test.meta.issue1163.Issue1163Pet)1