List of usage examples for org.hibernate.criterion Projections rowCount
public static Projection rowCount()
From source file:com.jeroensteenbeeke.hyperion.data.HibernateDAO.java
License:Open Source License
/** * @return The total number of items of this type *//*w w w. jav a2 s .c o m*/ public long countAll() { Criteria crit = getSession().createCriteria(domainClass); crit.setProjection(Projections.rowCount()); return ((Number) crit.uniqueResult()).longValue(); }
From source file:com.jeroensteenbeeke.hyperion.data.HibernateDAO.java
License:Open Source License
@Override public long countByFilter(SearchFilter<T> filter) { Criteria crit = createCriteria(filter); if (crit != null) { crit.setProjection(Projections.rowCount()); return ((Number) crit.uniqueResult()).longValue(); }/*from ww w . jav a2s. co m*/ return 0; }
From source file:com.jscompany.ebsystem.lazymodels.BaseLazyDataModel.java
@Override public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { List result = null;/* w ww .j av a2 s. c o m*/ Criteria cq, dcq; try { cq = EntityManagerServices.getCurrentSession().createCriteria(this.getEntity(), "entity"); this.criteriaFilterSetup(cq, filters); cq.setProjection(Projections.projectionList().add(Projections.rowCount())); dcq = EntityManagerServices.getCurrentSession().createCriteria(this.getEntity(), "entity1"); this.criteriaFilterSetup(dcq, filters); this.criteriaSortSetup(dcq, sortField, sortOrder); this.criteriaPageSetup(dcq, first, pageSize); rowCount = 0; rowCount = ((Long) cq.uniqueResult()).intValue(); this.setRowCount(rowCount); result = dcq.list(); Hibernate.initialize(result); } catch (Exception ex) { Logger.getLogger(BaseLazyDataModel.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long fetchEntitySize(String fromDate, String toDate, String type) { System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()"); Long size = 0l;// ww w . j a v a 2 s. com switch (type) { case "Total": System.out.println("*****Case - Total"); session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Busy": System.out.println("*****Case - Busy"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "busy", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Failed": System.out.println("*****Case - Failed"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "failed", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "NoAnswer": System.out.println("*****Case - NoAnswer"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("Status", "no-answer", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "RequestedCallBack": System.out.println("*****Case - RequestedCallBack"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "requested for callback", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "GreetingsHangUp": System.out.println("*****Case - GreetingsHangUp"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("CallType", "trans", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("Status", "completed", MatchMode.ANYWHERE)); criteria.add(Restrictions.isNull("TrackStatus")); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "HangUpOnConnect": System.out.println("*****Case - HangUpOnConnect"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "client-hangup", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "MissCall": System.out.println("*****Case - MissCall"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "incomplete", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Spoke": System.out.println("*****Case - Spoke"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate), Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead"))); criteria.add(Restrictions.like("TrackStatus", "spoke", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; } return size; }
From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long fetchEntitySize(String date, String type) { System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()"); Long size = 0l;/*from ww w. j ava 2 s. c om*/ switch (type) { case "Total": System.out.println("*****Case - Total"); session = getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Busy": System.out.println("*****Case - Busy"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "busy", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Failed": System.out.println("*****Case - Failed"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "failed", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "NoAnswer": System.out.println("*****Case - NoAnswer"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("Status", "no-answer", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "RequestedCallBack": System.out.println("*****Case - RequestedCallBack"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "requested for callback", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "GreetingsHangUp": System.out.println("*****Case - GreetingsHangUp"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("CallType", "trans", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("Status", "completed", MatchMode.ANYWHERE)); criteria.add(Restrictions.isNull("TrackStatus")); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "HangUpOnConnect": System.out.println("*****Case - HangUpOnConnect"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "client-hangup", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "MissCall": System.out.println("*****Case - MissCall"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE)); criteria.add(Restrictions.like("CallType", "incomplete", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; case "Spoke": System.out.println("*****Case - Spoke"); session = getSessionFactory().getCurrentSession(); criteria = session.createCriteria(Call.class, "call"); criteria.setReadOnly(true); criteria.add(Restrictions.like("DateCreated", date, MatchMode.START)); criteria.add(Restrictions.like("TrackStatus", "spoke", MatchMode.ANYWHERE)); criteria.setProjection(Projections.rowCount()); size = (Long) criteria.uniqueResult(); break; } return size; }
From source file:com.klistret.cmdb.dao.ElementDAOImpl.java
License:Open Source License
/** * Query count of XPath expressions/* w ww. j a va 2 s . co m*/ */ public Integer count(List<String> expressions) { try { logger.debug("Query count of XPath expressions [session: {}]", getSession().hashCode()); if (expressions == null) throw new ApplicationException("Expressions parameter is null", new IllegalArgumentException()); Criteria hcriteria = new XPathCriteria(expressions, getSession()).getCriteria(); hcriteria.setProjection(Projections.rowCount()); return ((Long) hcriteria.list().get(0)).intValue(); } catch (StaleStateException e) { throw new ApplicationException( "Element(s) counted are stale which means newer version exists (Hibernate)."); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.klistret.cmdb.dao.RelationDAOImpl.java
License:Open Source License
/** * Query count of XPath expressions//from ww w .j a v a 2 s . c om */ public Integer count(List<String> expressions) { try { logger.debug("Query count of XPath expressions"); if (expressions == null) throw new ApplicationException("Expressions parameter is null", new IllegalArgumentException()); Criteria hcriteria = new XPathCriteria(expressions, getSession()).getCriteria(); hcriteria.setProjection(Projections.rowCount()); return ((Long) hcriteria.list().get(0)).intValue(); } catch (StaleStateException e) { throw new ApplicationException( "Relation(s) counted are stale which means newer version exists (Hibernate)."); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.kodemore.hibernate.criteria.KmCriteria.java
License:Open Source License
public void selectRowCount() { Projection e; e = Projections.rowCount(); addProjection(e); }
From source file:com.koylubaevnt.library.db.DataHelper.java
private void runCountCriteria() { Criteria criteria = booksCountCriteria.getExecutableCriteria(getSession()); Object o = criteria.setProjection(Projections.rowCount()).uniqueResult(); Integer total = 0;//w w w . j av a2 s. co m if (o != null) { total = Integer.valueOf(o.toString()); } pager.setTotalBooksCount(total); }
From source file:com.kunckle.jetpower.core.base.search.SearchAdapter.java
License:Apache License
/** * Criteria/*from w w w .j a v a2 s . c o m*/ * * @param criteria Session?Criteria * @return ?Criteria */ public Criteria getCountCriteria(Criteria criteria) { if (criterions != null) { for (Criterion criterion : criterions) { criteria.add(criterion); } } criteria.setProjection(Projections.rowCount()); return criteria; }