TableDao { public List<T> queryBySample(T sample, Hints...hints) throws SQLException { return client.queryBySample(sample, hints); } TableDao(String logicDbName, Class<T> entityType); T queryByPk(T pk, Hints...hints); List<T> queryBySample(T sample, Hints...hints); List<T> queryBySample(T sample, PageRange range, Hints...hints); long countBySample(T sample, Hints...hints); int insert(T entity, Hints...hints); int insert(List<T> entities, Hints...hints); int[] batchInsert(List<T> entities, Hints...hints); int deleteByPk(T pk, Hints...hints); int deleteBySample(T sample, Hints...hints); int[] batchDelete(List<T> entities, Hints...hints); int update(T entity, Hints...hints); int[] batchUpdate(List<T> entities, Hints...hints);  }
@Test public void testQueryBySample() throws Exception { for(int j = 0; j < TABLE_MODE;j++) { Person pk = new Person(); pk.setName("test"); List<Person> plist = dao.queryBySample(pk); assertNotNull(plist); assertEquals(4, plist.size()); assertEquals("test", pk.getName()); } }
@Test public void testQueryBySamplePage() throws Exception { for(int j = 0; j < TABLE_MODE;j++) { List<Person> plist; Person pk = new Person(); pk.setName("test"); plist = dao.queryBySample(pk, PageRange.atPage(1, 10, p.PeopleID)); assertList(4, plist); plist = dao.queryBySample(pk, PageRange.atPage(2, 2, p.CityID, p.CountryID)); assertList(2, plist); if(dbCategory == DatabaseCategory.MySql) { plist = dao.queryBySample(pk, PageRange.atPage(3, 2)); assertList(0, plist); } plist = dao.queryBySample(pk, PageRange.atPage(1, 10, p.PeopleID.asc())); assertList(4, plist); assertOrder(plist, true); plist = dao.queryBySample(pk, PageRange.atPage(1, 10, p.PeopleID.desc())); assertList(4, plist); assertOrder(plist, false); plist = dao.queryBySample(pk, PageRange.atPage(1, 10, p.PeopleID.asc(), p.CityID.desc())); assertList(4, plist); assertOrder(plist, true); } }