Search in sources :

Example 11 with Pager

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

the class SimpleDaoTest method test_sql_pager.

@Test
public void test_sql_pager() {
    dao.create(Pet.class, true);
    for (int i = 0; i < 100; i++) {
        dao.insert(Pet.class, Chain.make("name", "record" + i).add("nickName", "Time=" + System.currentTimeMillis()));
    }
    Pager pager = dao.createPager(5, 5);
    pager.setRecordCount(dao.count(Pet.class));
    Sql sql = Sqls.queryEntity("select * from t_pet");
    sql.setEntity(dao.getEntity(Pet.class));
    sql.setPager(pager);
    dao.execute(sql);
    List<Pet> pets = sql.getList(Pet.class);
    assertNotNull(pets);
    assertEquals(5, pets.size());
    assertEquals("record20", pets.get(0).getName());
    assertEquals("record21", pets.get(1).getName());
    assertEquals("record22", pets.get(2).getName());
    assertEquals("record23", pets.get(3).getName());
    assertEquals("record24", pets.get(4).getName());
}
Also used : Pager(org.nutz.dao.pager.Pager) Issue1163Pet(org.nutz.dao.test.meta.issue1163.Issue1163Pet) Pet(org.nutz.dao.test.meta.Pet) PojoSql(org.nutz.dao.test.meta.issue1074.PojoSql) Sql(org.nutz.dao.sql.Sql) Test(org.junit.Test)

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