List of usage examples for org.hibernate.criterion Projections rowCount
public static Projection rowCount()
From source file:com.algoTrader.PropertySearch.java
/** * Gets the total possible count of objects returned in this search. * @return totalCount/*from ww w . ja va 2s. c o m*/ */ public int getTotalCount() { int count; if (this.search.isUseSqlLimiting()) { // Remove first result requirement this.getConfiguration().setFirstResult(new Integer(0)); this.getRootCriteria().setProjection(Projections.projectionList().add(Projections.rowCount())); count = ((Integer) this.executeAsList().iterator().next()).intValue(); } else { count = this.totalCount; } return count; }
From source file:com.allinfinance.commquery.dao.CommQueryDAO.java
License:Open Source License
/** * // w ww . jav a2 s . c o m * * @param clazz * @return */ public int getTotalNum(DetachedCriteria detachedCriteria) { // ,hibernate?select count(id) from xxx.... detachedCriteria.setProjection(Projections.rowCount()); @SuppressWarnings("unchecked") List<Object> countList = this.getHibernateTemplate().findByCriteria(detachedCriteria); if (countList != null && countList.size() > 0) { int total = (Integer) countList.get(0); return total; } else return 0; }
From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java
License:Open Source License
@Override public StorageResults visit(Count count) { projectionList.add(Projections.rowCount()); return null; }
From source file:com.app.gpo.dao.OrderItemDAO.java
License:Open Source License
public boolean isInDbByOrderNumber(String orderNumber) { Criteria criteria = getSession().createCriteria(OrderItem.class); criteria.add(Restrictions.like("orderNumber", orderNumber + "%")); criteria.setProjection(Projections.rowCount()); long count = (Long) criteria.uniqueResult(); logger.info("DB count " + count + " for order items with order number " + orderNumber); if (count != 0) { logger.info("In DB exist" + count + " order items with order number " + orderNumber); return true; } else {/* w w w . j a v a 2s. c om*/ logger.info("In DB no exist order items with order number " + orderNumber); return false; } }
From source file:com.apress.progwt.server.dao.hibernate.SchoolDAOHibernateImpl.java
License:Apache License
/** * get the total number of rows without actually returning all rows * NOTE: important to set the start row here, otherwise when we start * paging, this criteria will be affected and we won't get the first * row./* w w w . j a v a2s. co m*/ * * @param criteria * @return */ private int getRowCount(DetachedCriteria criteria) { criteria.setProjection(Projections.rowCount()); return ((Integer) getHibernateTemplate().findByCriteria(criteria, 0, 1).get(0)).intValue(); }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@SuppressWarnings("unchecked") @Override//from w w w .ja v a 2s . com public List<Chart> getVentaVendedores(int idVendedor) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartVenta = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria facturas = getSession().createCriteria(Factura.class); facturas.add(Restrictions.like("estado", "CONFIRMADO")); facturas.add(Restrictions.between("fechaCreacion", fromDate, toDate)); Criteria vendedorFactura = facturas.createCriteria("idVendedor"); vendedorFactura.add(Restrictions.eq("idUsuario", idVendedor)); vendedorFactura.setProjection(Projections.rowCount()); Long counter = (Long) facturas.uniqueResult(); chart.setValue(counter.intValue()); chart.setDate(fromDate); chartVenta.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartVenta; }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@Override public List<Chart> getVentaMedioPago(int idMedioPago) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartMedioPago = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria metodo = getSession().createCriteria(MetodoPagoFactura.class); metodo.add(Restrictions.eq("estado", true)); Criteria planPago = metodo.createCriteria("planPago"); Criteria tarjeta = planPago.createCriteria("tarjeta"); Criteria medioPago = tarjeta.createCriteria("medioPago"); medioPago.add(Restrictions.eq("idMedioPago", idMedioPago)); metodo.add(Restrictions.between("fechaCreacion", fromDate, toDate)); metodo.setProjection(Projections.rowCount()); Long counter = (Long) metodo.uniqueResult(); if (counter != null) { chart.setValue(counter.intValue()); } else {//from w w w . jav a 2 s.co m chart.setValue(0); } chart.setDate(fromDate); chartMedioPago.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartMedioPago; }
From source file:com.askme.dao.AnswerDAOImpl.java
@Override public Long countAll() { return (Long) sessionFactory.getCurrentSession().createCriteria(Answer.class) .setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.askme.dao.CategoryDAOImpl.java
@Override public Long countAll() { return (Long) sessionFactory.getCurrentSession().createCriteria(Category.class) .setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.askme.dao.QuestionDAOImpl.java
@Override public Long countAll() { return (Long) sessionFactory.getCurrentSession().createCriteria(Question.class) .setProjection(Projections.rowCount()).uniqueResult(); }