public static long demSoLuongTaiKhoanTheoTuKhoa(TaiKhoan tk, String strDaXoa, String strDaBan) { long result = 0; Session session = HibernateUtil.getSessionFactory().openSession(); try { Criteria crit = session.createCriteria(TaiKhoan.class); ganThuocTinhTimKiem(crit, tk, strDaXoa, strDaBan); crit.setProjection(Projections.rowCount()); result = (long) crit.uniqueResult(); } catch (HibernateException ex) { // Log the exception System.err.println(ex); } finally { session.close(); } return result; }
@SuppressWarnings("unchecked") public static List<TaiKhoan> layDanhSachTaiKhoanTheoTuKhoa( int page, int nRecordsPerPage, TaiKhoan tk, String strDaXoa, String strDaBan) { List<TaiKhoan> ds = null; Session session = HibernateUtil.getSessionFactory().openSession(); try { Criteria crit = session.createCriteria(TaiKhoan.class); crit.addOrder(Order.asc("maTaiKhoan")); ganThuocTinhTimKiem(crit, tk, strDaXoa, strDaBan); crit.setFirstResult((page - 1) * nRecordsPerPage); crit.setMaxResults(nRecordsPerPage); ds = crit.list(); } catch (HibernateException ex) { // Log the exception System.err.println(ex); } finally { session.close(); } return ds; }