public IList <T> Get(OnCriteria onCriteria, QueryDel qd, int pageSize, int pageNum) { IList <T> retVal = null; ISession s = null; ITransaction trans = null; try { s = hibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); ICriteria criteria = s.CreateCriteria(type); if (qd == QueryDel.Del) { ICriterion criterion = Restrictions.Eq("Del", true); criteria.Add(criterion); } else if (qd == QueryDel.UnDel) { ICriterion criterion = Restrictions.Eq("Del", false); criteria.Add(criterion); } //如果要触发事件 if (onCriteria != null) { onCriteria(this, criteria); } // criteria.SetResultTransformer(new AliasToBeanResultTransformer(type)); if (pageNum > 0 && pageSize > 0) { criteria.SetFirstResult((pageNum - 1) * pageSize); criteria.SetMaxResults(pageSize); } criteria.SetCacheable(true); retVal = criteria.List <T>(); trans.Commit(); } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } finally { // hibernateOper.Close(s); } return(retVal); }
public int GetPageCount(OnCriteria onCriteria, QueryDel qd, int pageSize) { int retVal = 0; ISession s = null; ITransaction trans = null; try { s = hibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); ICriteria criteria = s.CreateCriteria(type); if (qd == QueryDel.Del) { ICriterion criterion = Restrictions.Eq("Del", true); criteria.Add(criterion); } else if (qd == QueryDel.UnDel) { ICriterion criterion = Restrictions.Eq("Del", false); criteria.Add(criterion); } //如果要触发事件 if (onCriteria != null) { onCriteria(this, criteria); } //统计 criteria.SetProjection( Projections.ProjectionList() .Add(Projections.Count("Id")) ); criteria.SetCacheable(true); int count = (int)criteria.UniqueResult(); if (pageSize > 0) { retVal = count / pageSize; if (count % pageSize > 0) { retVal++; } } else { retVal = 1; } trans.Commit(); } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } finally { // hibernateOper.Close(s); } return(retVal); }
public int GetPageCount(OnCriteria onCriteria, int pageSize) { return(GetPageCount(onCriteria, QueryDel.UnDel, pageSize)); }
public int GetPageCount(OnCriteria onCriteria, QueryDel qd) { return(GetPageCount(onCriteria, qd, 0)); }
public int GetPageCount(OnCriteria onCriteria) { return(GetPageCount(onCriteria, QueryDel.UnDel)); }
public IList <T> Get(OnCriteria onCriteria, int pageSize, int pageNum) { return(Get(onCriteria, QueryDel.UnDel, pageSize, pageNum)); }
public IList <T> Get(OnCriteria onCriteria) { return(Get(onCriteria, QueryDel.UnDel, 0, 0)); }