org.hibernate.criterion.Projections.rowCount() - java examples

Here are the examples of the java api org.hibernate.criterion.Projections.rowCount() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

79 Examples 7

19 View Complete Implementation : HibernateCrudRepository.java
Copyright Educational Community License v2.0
Author : sakaiproject
@Override
public long count() {
    Object count = startCriteriaQuery().setProjection(Projections.rowCount()).uniqueResult();
    return ((Number) count).longValue();
}

19 View Complete Implementation : CriteriaQuery.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.hibernate.search.SearchQuery#resultSize()
 */
@Override
public long resultSize() {
    criteria.setProjection(Projections.rowCount());
    return ((Number) criteria.uniqueResult()).longValue();
}

19 View Complete Implementation : RetailerDao.java
Copyright Apache License 2.0
Author : qalingo
public Long countStore() {
    Criteria criteria = createDefaultCriteria(Store.clreplaced);
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

18 View Complete Implementation : DefaultDao.java
Copyright MIT License
Author : theonedev
@Sessional
@Override
public <T extends AbstractEnreplacedy> int count(EnreplacedyCriteria<T> enreplacedyCriteria) {
    Criteria criteria = enreplacedyCriteria.getExecutableCriteria(getSession());
    criteria.setProjection(Projections.rowCount());
    return ((Long) criteria.uniqueResult()).intValue();
}

18 View Complete Implementation : ProductService.java
Copyright GNU Affero General Public License v3.0
Author : SentinelDataHub
/**
 * Odata dedicated Services
 */
@Transactional(readOnly = true)
@Cacheable(value = "product_count", key = "{#criteria, #uuid}")
public int countProducts(DetachedCriteria criteria, String uuid) {
    if (criteria == null) {
        criteria = DetachedCriteria.forClreplaced(Product.clreplaced);
    }
    // count only processed products
    criteria.add(Restrictions.eq("processed", true));
    if (uuid != null) {
        List<Long> product_ids = collectionService.getProductIds(uuid);
        criteria.add(Restrictions.in("id", product_ids));
    }
    criteria.setProjection(Projections.rowCount());
    return productDao.count(criteria);
}

18 View Complete Implementation : BaseDao.java
Copyright Apache License 2.0
Author : grycap
public long getTotalPages(int offSet) throws DaoException {
    long resultado = 0;
    if (offSet >= 0) {
        try {
            Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(clazz);
            criteria.setProjection(Projections.rowCount());
            resultado = ((Integer) criteria.uniqueResult()) / offSet;
        } catch (Exception e) {
            resultado = 0;
            e = null;
        }
    }
    return resultado;
}

18 View Complete Implementation : JoinFetchTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testProjection() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.createCriteria(Item.clreplaced).setProjection(Projections.rowCount()).uniqueResult();
    s.createCriteria(Item.clreplaced).uniqueResult();
    t.commit();
    s.close();
}

18 View Complete Implementation : HibernateEncounterDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.EncounterDAO#getEncountersByVisitsAndPatientCount(org.openmrs.Patient,
 *      boolean, java.lang.String)
 */
@Override
public Integer getEncountersByVisitsAndPatientCount(Patient patient, boolean includeVoided, String query) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Visit.clreplaced);
    addEmptyVisitsByPatientCriteria(criteria, patient, includeVoided, query);
    criteria.setProjection(Projections.rowCount());
    Integer count = ((Number) criteria.uniqueResult()).intValue();
    criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.clreplaced);
    addEncountersByPatientCriteria(criteria, patient, includeVoided, query);
    criteria.setProjection(Projections.rowCount());
    count = count + ((Number) criteria.uniqueResult()).intValue();
    return count;
}

18 View Complete Implementation : SaveOrUpdateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testSaveOrUpdateGotWithMutableProp() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Node root = new Node("root");
    s.saveOrUpdate(root);
    tx.commit();
    s.close();
    replacedertInsertCount(1);
    replacedertUpdateCount(0);
    clearCounts();
    s = openSession();
    tx = s.beginTransaction();
    s.saveOrUpdate(root);
    tx.commit();
    s.close();
    replacedertInsertCount(0);
    replacedertUpdateCount(0);
    s = openSession();
    tx = s.beginTransaction();
    root = (Node) s.get(Node.clreplaced, "root");
    Hibernate.initialize(root.getChildren());
    tx.commit();
    s.close();
    clearCounts();
    s = openSession();
    tx = s.beginTransaction();
    Node child = new Node("child");
    root.addChild(child);
    s.saveOrUpdate(root);
    replacedertTrue(s.contains(child));
    tx.commit();
    replacedertInsertCount(1);
    // note: will fail here if no second-level cache
    replacedertUpdateCount(1);
    tx = s.beginTransaction();
    replacedertEquals(s.createCriteria(Node.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    s.delete(root);
    s.delete(child);
    tx.commit();
    s.close();
}

18 View Complete Implementation : AbstractDAS.java
Copyright GNU Affero General Public License v3.0
Author : mosabsalih
/**
 * Returns true if a persisted record exsits for the given id.
 *
 * @param id primary key of enreplacedy
 * @return true if enreplacedy exists for id, false if enreplacedy does not exist
 */
public boolean isIdPersisted(Serializable id) {
    Criteria criteria = getSession().createCriteria(getPersistentClreplaced()).add(Restrictions.idEq(id)).setProjection(Projections.rowCount());
    return (criteria.uniqueResult() != null && ((Integer) criteria.uniqueResult()) > 0);
}

18 View Complete Implementation : ECRFFieldValueDaoImpl.java
Copyright GNU Lesser General Public License v2.1
Author : phoenixctms
@Override
protected Collection<ECRFFieldValue> handleGetLog(Long trialId, Long probandListEntryId, Long ecrfId, boolean sort, PSFVO psf) throws Exception {
    org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
    org.hibernate.Criteria listEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
    if (trialId != null || probandListEntryId != null) {
        if (trialId != null) {
            listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
        }
        if (probandListEntryId != null) {
            listEntryCriteria.add(Restrictions.idEq(probandListEntryId.longValue()));
        }
    }
    org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
    if (ecrfId != null) {
        ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
    }
    DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, listEntryCriteria, probandListEntryId, null);
    subQuery.setProjection(Projections.rowCount());
    subQuery.add(Restrictions.or(Restrictions.isNull("index"), Restrictions.eqProperty("index", "ecrfFieldValue0" + ".index")));
    ecrfFieldValueCriteria.add(Subqueries.lt(1l, subQuery));
    SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldValue.clreplaced, ecrfFieldValueCriteria);
    criteriaMap.registerCriteria("listEntry", listEntryCriteria);
    criteriaMap.registerCriteria("ecrfField", ecrfFieldCriteria);
    CriteriaUtil.applyPSFVO(criteriaMap, psf);
    // if (sort) { // after applyPSFVO
    // ecrfFieldValueCriteria.addOrder(Order.asc("index"));
    // ecrfFieldValueCriteria.addOrder(Order.desc("id"));
    // }
    if (sort) {
        applySortOrders(listEntryCriteria, ecrfFieldCriteria, ecrfFieldValueCriteria);
    }
    return ecrfFieldValueCriteria.list();
// throw new Exception();
}

18 View Complete Implementation : SaveOrUpdateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testSaveOrUpdateGot() {
    boolean instrumented = FieldInterceptionHelper.isInstrumented(new NumberedNode());
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode("root");
    s.saveOrUpdate(root);
    tx.commit();
    s.close();
    replacedertInsertCount(1);
    replacedertUpdateCount(0);
    clearCounts();
    s = openSession();
    tx = s.beginTransaction();
    s.saveOrUpdate(root);
    tx.commit();
    s.close();
    replacedertInsertCount(0);
    replacedertUpdateCount(instrumented ? 0 : 1);
    s = openSession();
    tx = s.beginTransaction();
    root = (NumberedNode) s.get(NumberedNode.clreplaced, new Long(root.getId()));
    Hibernate.initialize(root.getChildren());
    tx.commit();
    s.close();
    clearCounts();
    s = openSession();
    tx = s.beginTransaction();
    NumberedNode child = new NumberedNode("child");
    root.addChild(child);
    s.saveOrUpdate(root);
    replacedertTrue(s.contains(child));
    tx.commit();
    replacedertInsertCount(1);
    replacedertUpdateCount(instrumented ? 0 : 1);
    tx = s.beginTransaction();
    replacedertEquals(s.createCriteria(NumberedNode.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    s.delete(root);
    s.delete(child);
    tx.commit();
    s.close();
}

18 View Complete Implementation : HibernateConfigItemDaoImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
/* (non-Javadoc)
     * @see org.sakaiproject.config.api.HibernateConfigItemDao#countByNodeAndName(java.lang.String, java.lang.String)
     */
@Override
public int countByNodeAndName(String node, String name) {
    if (node == null || name == null) {
        return -1;
    }
    Criteria criteria = currentSession().createCriteria(HibernateConfigItem.clreplaced).setProjection(Projections.rowCount()).add(Restrictions.eq("node", node)).add(Restrictions.eq("name", name));
    return ((Number) criteria.uniqueResult()).intValue();
}

18 View Complete Implementation : ECRFFieldValueDaoImpl.java
Copyright GNU Lesser General Public License v2.1
Author : phoenixctms
@Override
protected Collection<ECRFFieldValue> handleGetLog(Long trialId, Long probandListEntryId, Long ecrfId, String section, boolean sort, PSFVO psf) throws Exception {
    org.hibernate.Criteria ecrfFieldValueCriteria = createEcrfFieldValueCriteria("ecrfFieldValue0");
    org.hibernate.Criteria listEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0");
    if (trialId != null || probandListEntryId != null) {
        if (trialId != null) {
            listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
        }
        if (probandListEntryId != null) {
            listEntryCriteria.add(Restrictions.idEq(probandListEntryId.longValue()));
        }
    }
    org.hibernate.Criteria ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0");
    if (ecrfId != null) {
        ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
    }
    if (section != null && section.length() > 0) {
        ecrfFieldCriteria.add(Restrictions.eq("section", section));
    } else {
        ecrfFieldCriteria.add(Restrictions.or(Restrictions.eq("section", ""), Restrictions.isNull("section")));
    }
    DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, listEntryCriteria, probandListEntryId, null);
    subQuery.setProjection(Projections.rowCount());
    subQuery.add(Restrictions.or(Restrictions.isNull("index"), Restrictions.eqProperty("index", "ecrfFieldValue0" + ".index")));
    ecrfFieldValueCriteria.add(Subqueries.lt(1l, subQuery));
    SubCriteriaMap criteriaMap = new SubCriteriaMap(ECRFFieldValue.clreplaced, ecrfFieldValueCriteria);
    criteriaMap.registerCriteria("listEntry", listEntryCriteria);
    criteriaMap.registerCriteria("ecrfField", ecrfFieldCriteria);
    CriteriaUtil.applyPSFVO(criteriaMap, psf);
    // if (sort) { // after applyPSFVO
    // ecrfFieldValueCriteria.addOrder(Order.asc("index"));
    // ecrfFieldValueCriteria.addOrder(Order.desc("id"));
    // }
    if (sort) {
        applySortOrders(listEntryCriteria, ecrfFieldCriteria, ecrfFieldValueCriteria);
    }
    return ecrfFieldValueCriteria.list();
// throw new Exception();
}

18 View Complete Implementation : UserService.java
Copyright GNU Affero General Public License v3.0
Author : SentinelDataHub
/**
 * Counts corresponding users at the given criteria.
 *
 * @param criteria criteria contains filter of required collection.
 * @return number of corresponding users.
 */
@Transactional(readOnly = true)
public int countUsers(DetachedCriteria criteria) {
    if (criteria == null) {
        criteria = DetachedCriteria.forClreplaced(User.clreplaced);
    }
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENreplacedY);
    criteria.setProjection(Projections.rowCount());
    return userDao.count(criteria);
}

18 View Complete Implementation : BaseController.java
Copyright Apache License 2.0
Author : zhangdaiscott
/**
 * 分页公共方法(非easyui)
 *
 * @author Alexander
 * @date 20131022
 */
public List<?> pageBaseMethod(HttpServletRequest request, DetachedCriteria dc, CommonService commonService, int pageRow) {
    // 当前页
    // 总条数
    // 总页数
    int currentPage = 1;
    int totalRow = 0;
    int totalPage = 0;
    // 获取当前页
    String str_currentPage = request.getParameter("str_currentPage");
    currentPage = str_currentPage == null || "".equals(str_currentPage) ? 1 : Integer.parseInt(str_currentPage);
    // 获取每页的条数
    String str_pageRow = request.getParameter("str_pageRow");
    pageRow = str_pageRow == null || "".equals(str_pageRow) ? pageRow : Integer.parseInt(str_pageRow);
    // 统计的总行数
    dc.setProjection(Projections.rowCount());
    totalRow = Integer.parseInt(commonService.findByDetached(dc).get(0).toString());
    totalPage = (totalRow + pageRow - 1) / pageRow;
    currentPage = currentPage < 1 ? 1 : currentPage;
    currentPage = currentPage > totalPage ? totalPage : currentPage;
    // 清空统计函数
    dc.setProjection(null);
    // dc.setResultTransformer(dc.DISTINCT_ROOT_ENreplacedY);
    List<?> list = commonService.pageList(dc, (currentPage - 1) * pageRow, pageRow);
    request.setAttribute("currentPage", currentPage);
    request.setAttribute("pageRow", pageRow);
    request.setAttribute("totalRow", totalRow);
    request.setAttribute("totalPage", totalPage);
    return list;
}

18 View Complete Implementation : NotifyDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public int unread4Me(long ownId) {
    Criteria count = createCriteria();
    count.setProjection(Projections.rowCount());
    count.add(Restrictions.eq("ownId", ownId));
    count.add(Restrictions.eq("status", Consts.UNREAD));
    return NumberUtils.changeToInt(count.uniqueResult());
}

18 View Complete Implementation : GeolocDao.java
Copyright Apache License 2.0
Author : qalingo
public Long countGeolocAddressByFormatedAddress(String formatedAddress) {
    Criteria criteria = createDefaultCriteria(GeolocAddress.clreplaced);
    criteria.setProjection(Projections.rowCount());
    criteria.add(Restrictions.eq("formatedAddress", formatedAddress));
    Long rowCount = (Long) criteria.uniqueResult();
    return rowCount;
}

18 View Complete Implementation : SaveOrUpdateTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testSaveOrUpdateManaged() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode("root");
    s.saveOrUpdate(root);
    tx.commit();
    tx = s.beginTransaction();
    NumberedNode child = new NumberedNode("child");
    root.addChild(child);
    s.saveOrUpdate(root);
    replacedertFalse(s.contains(child));
    s.flush();
    replacedertTrue(s.contains(child));
    tx.commit();
    replacedertTrue(root.getChildren().contains(child));
    replacedertEquals(root.getChildren().size(), 1);
    tx = s.beginTransaction();
    replacedertEquals(s.createCriteria(NumberedNode.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    s.delete(root);
    s.delete(child);
    tx.commit();
    s.close();
}

18 View Complete Implementation : HibernateConfigItemDaoImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
/* (non-Javadoc)
     * @see org.sakaiproject.config.api.HibernateConfigItemDao#countByNode(java.lang.String)
     */
public int countByNode(String node) {
    if (node == null) {
        return -1;
    }
    Criteria criteria = currentSession().createCriteria(HibernateConfigItem.clreplaced).setProjection(Projections.rowCount()).add(Restrictions.eq("node", node));
    return ((Number) criteria.uniqueResult()).intValue();
}

17 View Complete Implementation : CreditBankDAOImpl.java
Copyright GNU General Public License v3.0
Author : uwol
@Override
public CreditBank findRandom(final Currency currency) {
    Criteria crit = getSession().createCriteria(CreditBankImpl.clreplaced);
    crit.add(Restrictions.eq("primaryCurrency", currency));
    crit.setProjection(Projections.rowCount());
    final int count = ((Number) crit.uniqueResult()).intValue();
    if (0 != count) {
        final int index = ApplicationContext.getInstance().getRandomNumberGenerator().nextInt(count);
        crit = getSession().createCriteria(CreditBankImpl.clreplaced);
        crit.add(Restrictions.eq("primaryCurrency", currency));
        return (CreditBankImpl) crit.setFirstResult(index).setMaxResults(1).uniqueResult();
    }
    return null;
}

17 View Complete Implementation : HibernateDAOImpl.java
Copyright GNU General Public License v3.0
Author : uwol
@Override
@SuppressWarnings("unchecked")
public T findRandom() {
    Criteria crit = getSession().createCriteria(persistentClreplaced);
    crit.setProjection(Projections.rowCount());
    final int count = ((Number) crit.uniqueResult()).intValue();
    if (0 != count) {
        final int index = ApplicationContext.getInstance().getRandomNumberGenerator().nextInt(count);
        crit = getSession().createCriteria(persistentClreplaced);
        final T enreplacedy = (T) crit.setFirstResult(index).setMaxResults(1).uniqueResult();
        return enreplacedy;
    }
    return null;
}

17 View Complete Implementation : HibernateGenericDao.java
Copyright Apache License 2.0
Author : xuhuisheng
/**
 * 获得总记录数.
 *
 * @param criteria
 *            条件
 * @return 总数
 */
@Transactional(readOnly = true)
public Integer getCount(Criteria criteria) {
    Object result = criteria.setProjection(Projections.rowCount()).uniqueResult();
    return HibernateUtils.getNumber(result);
}

17 View Complete Implementation : HibernateGridDataSource.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns the total number of rows for the configured enreplacedy type.
 */
@Override
public int getAvailableRows() {
    Criteria criteria = session.createCriteria(enreplacedyType);
    applyAdditionalConstraints(criteria);
    criteria.setProjection(Projections.rowCount());
    Number result = (Number) criteria.uniqueResult();
    return result.intValue();
}

17 View Complete Implementation : MergeTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testMergeManaged() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode("root");
    s.persist(root);
    tx.commit();
    clearCounts();
    tx = s.beginTransaction();
    NumberedNode child = new NumberedNode("child");
    root.addChild(child);
    replacedertSame(root, s.merge(root));
    Object mergedChild = root.getChildren().iterator().next();
    replacedertNotSame(mergedChild, child);
    replacedertTrue(s.contains(mergedChild));
    replacedertFalse(s.contains(child));
    replacedertEquals(root.getChildren().size(), 1);
    replacedertTrue(root.getChildren().contains(mergedChild));
    // replacedertNotSame( mergedChild, s.merge(child) ); //yucky :(
    tx.commit();
    replacedertInsertCount(1);
    replacedertUpdateCount(0);
    replacedertEquals(root.getChildren().size(), 1);
    replacedertTrue(root.getChildren().contains(mergedChild));
    tx = s.beginTransaction();
    replacedertEquals(s.createCriteria(NumberedNode.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(2));
    s.close();
    cleanup();
}

17 View Complete Implementation : HibernateDao.java
Copyright Apache License 2.0
Author : chelu
/**
 * Get Page, apply filter if any.
 * If Filter is a enreplacedy model, use Example to create a criteria.
 * else enable filter by name on session.
 * @param page with page definitions
 * @return page of results
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <K> Page<K> getPage(Page<K> page) {
    List data = null;
    // try named query
    Query query = getQuery(page);
    if (query != null) {
        data = query.list();
    } else {
        // try filter, example and criteria builders
        Criteria criteria = getCriteria(page);
        ResultTransformer rt = ((CriteriaImpl) criteria).getResultTransformer();
        criteria.setProjection(Projections.rowCount());
        page.setCount(((Long) criteria.uniqueResult()).intValue());
        // reset criteria
        criteria.setProjection(null);
        criteria.setResultTransformer(rt);
        // set start index and page size
        criteria.setFirstResult(page.getStartIndex()).setMaxResults(page.getPageSize());
        applyOrder(page, criteria);
        // run it
        criteria.setCacheable(cachePageQueries);
        data = criteria.list();
    }
    page.setData(data);
    return page;
}

17 View Complete Implementation : HibernateScheduledJobDao.java
Copyright Mozilla Public License 2.0
Author : secdec
@Override
public boolean checkSameDate(@Nonnull S scheduledJob) {
    if (scheduledJob.getDay() == null && scheduledJob.getFrequency() == null) {
        throw new IllegalArgumentException("Got scheduled job without day or frequency.");
    }
    Criteria criteria = getSession().createCriteria(getClreplacedReference());
    if (scheduledJob.getDay() != null) {
        criteria.add(Restrictions.eq("day", scheduledJob.getDay()));
    } else if (scheduledJob.getFrequency() != null) {
        criteria.add(Restrictions.eq("frequency", scheduledJob.getFrequency()));
    }
    criteria.add(Restrictions.eq("hour", scheduledJob.getHour()));
    criteria.add(Restrictions.eq("minute", scheduledJob.getMinute()));
    criteria.add(Restrictions.eq("period", scheduledJob.getPeriod()));
    criteria.setProjection(Projections.rowCount());
    Long count = (Long) criteria.uniqueResult();
    return (count > 0);
}

17 View Complete Implementation : HibernateCompleteDataSetRegistrationStore.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : dhis2
@Override
public int getCompleteDataSetCountLastUpdatedAfter(Date lastUpdated) {
    if (lastUpdated == null) {
        throw new IllegalArgumentException("lastUpdated parameter must be specified");
    }
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(CompleteDataSetRegistration.clreplaced).setProjection(Projections.rowCount());
    criteria.add(Restrictions.ge("lastUpdated", lastUpdated));
    Number rs = (Number) criteria.uniqueResult();
    return rs != null ? rs.intValue() : 0;
}

17 View Complete Implementation : CriterionDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
public int numberOfRelatedSatisfactions(Criterion criterion) {
    Criteria c = getSession().createCriteria(CriterionSatisfaction.clreplaced).add(Restrictions.eq("criterion", criterion)).setProjection(Projections.rowCount());
    return Integer.valueOf(c.uniqueResult().toString());
}

17 View Complete Implementation : CriterionDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
public int numberOfRelatedRequirements(Criterion criterion) {
    Criteria c = getSession().createCriteria(CriterionRequirement.clreplaced).add(Restrictions.eq("criterion", criterion)).setProjection(Projections.rowCount());
    return Integer.valueOf(c.uniqueResult().toString());
}

17 View Complete Implementation : TrialDaoImpl.java
Copyright GNU Lesser General Public License v2.1
Author : phoenixctms
@Override
protected Collection<Trial> handleFindByEcrfs(Long departmentId, boolean withChargeOnly, PSFVO psf) throws Exception {
    org.hibernate.Criteria trialCriteria = createTrialCriteria("trial0");
    SubCriteriaMap criteriaMap = new SubCriteriaMap(Trial.clreplaced, trialCriteria);
    if (departmentId != null) {
        trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue()));
    }
    // IMPL!!!!
    DetachedCriteria subQuery = DetachedCriteria.forClreplaced(ECRFImpl.clreplaced, "ecrf");
    subQuery.setProjection(Projections.rowCount());
    subQuery.add(Restrictions.eqProperty("trial.id", "trial0.id"));
    if (withChargeOnly) {
        subQuery.add(Restrictions.gt("charge", 0.0f));
    }
    trialCriteria.add(Subqueries.lt(0l, subQuery));
    CriteriaUtil.applyPSFVO(criteriaMap, psf);
    return trialCriteria.list();
}

17 View Complete Implementation : GoodsCommentDaoImpl.java
Copyright MIT License
Author : PowerDos
@Override
public int getCount() {
    DetachedCriteria criteria = DetachedCriteria.forClreplaced(GoodsComment.clreplaced);
    criteria.setProjection(Projections.rowCount());
    Object obj = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}

17 View Complete Implementation : CollectionLogRepositoryImpl.java
Copyright GNU Affero General Public License v3.0
Author : qcri-social
@SuppressWarnings("unchecked")
@Override
public CollectionLogDataResponse getPaginatedData(Integer start, Integer limit) {
    Criteria countCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.clreplaced);
    countCriteria.setProjection(Projections.rowCount());
    Long count = (Long) countCriteria.uniqueResult();
    if (count == 0) {
        return new CollectionLogDataResponse(Collections.<CollectionLog>emptyList(), count);
    }
    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.clreplaced);
    criteria.setFirstResult(start);
    criteria.setMaxResults(limit);
    criteria.addOrder(Order.desc("startDate"));
    return new CollectionLogDataResponse(criteria.list(), count);
}

17 View Complete Implementation : CollectionLogRepositoryImpl.java
Copyright GNU Affero General Public License v3.0
Author : qcri-social
@SuppressWarnings("unchecked")
@Override
public CollectionLogDataResponse getPaginatedDataForCollection(Integer start, Integer limit, Long collectionId) {
    Criteria countCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.clreplaced);
    countCriteria.add(Restrictions.eq("collectionId", collectionId));
    countCriteria.setProjection(Projections.rowCount());
    Long count = (Long) countCriteria.uniqueResult();
    if (count == 0) {
        return new CollectionLogDataResponse(Collections.<CollectionLog>emptyList(), count);
    }
    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.clreplaced);
    criteria.add(Restrictions.eq("collectionId", collectionId));
    criteria.setFirstResult(start);
    criteria.setMaxResults(limit);
    criteria.addOrder(Order.desc("startDate"));
    return new CollectionLogDataResponse(criteria.list(), count);
}

17 View Complete Implementation : DataModelImageExportDaoImpl.java
Copyright GNU Affero General Public License v3.0
Author : qcri-social
@Override
public Long getTotalImageCountForCollection(String collectionCode) {
    Criteria criteria = getCurrentSession().createCriteria(DataModelImageExport.clreplaced);
    criteria.setProjection(Projections.rowCount());
    criteria.add(Restrictions.eq("collectionCode", collectionCode));
    Long count = (Long) criteria.uniqueResult();
    return count;
}

16 View Complete Implementation : DaoActor.java
Copyright GNU Affero General Public License v3.0
Author : BloatIt
// ======================================================================
// HQL static requests.
// ======================================================================
/**
 * This method use a HQL request. If you intend to use "getByLogin" or
 * "getByName", "exist" is useless. (In that case you'd better test if
 * getByLogin != null, to minimize the number of HQL request).
 *
 * @param login the login we are looking for.
 * @return true if found.
 */
public static boolean loginExists(final String login) {
    if (login == null) {
        return false;
    }
    final Session session = SessionManager.getSessionFactory().getCurrentSession();
    final Criteria c = session.createCriteria(DaoActor.clreplaced).setProjection(Projections.rowCount()).add(Restrictions.like("login", login).ignoreCase());
    return ((Long) c.uniqueResult()) > 0;
}

16 View Complete Implementation : CriteriaBuilder.java
Copyright MIT License
Author : Breeze
/**
 * Apply the OData $inlinecount to the (already filtered) Criteria. Removes
 * $skip and $top and $orderby operations and adds a rowCount projection.
 *
 * @param crit
 *            a Criteria object. Should already contain only filters that
 *            affect the row count.
 * @return the same Criteria that was preplaceded in, with operations added.
 */
public Criteria applyInlineCount(Criteria crit) {
    crit.setMaxResults(0);
    crit.setFirstResult(0);
    CriteriaImpl impl = (CriteriaImpl) crit;
    Iterator<OrderEntry> iter = impl.iterateOrderings();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    crit.setProjection(Projections.rowCount());
    return crit;
}

16 View Complete Implementation : HibernateStorage.java
Copyright GNU General Public License v3.0
Author : LSIR
public long countStreamElement() throws GSNRuntimeException {
    Transaction tx = null;
    try {
        Session session = sf.getCurrentSession();
        tx = session.beginTransaction();
        Criteria criteria = session.createCriteria(identifier);
        criteria.setProjection(Projections.rowCount());
        List count = criteria.list();
        tx.commit();
        return (Long) count.get(0);
    } catch (RuntimeException e) {
        try {
            if (tx != null)
                tx.rollback();
        } catch (RuntimeException ex) {
            logger.error("Couldn't roll back transaction.");
        }
        throw e;
    }
}

16 View Complete Implementation : MassMailDaoImpl.java
Copyright GNU Lesser General Public License v2.1
Author : phoenixctms
@Override
protected long handleGetCount(Long trialId, Long probandListStatusTypeId, Boolean locked, Long resendProbandId) throws Exception {
    org.hibernate.Criteria mreplacedMailCriteria = createMreplacedMailCriteria("mreplacedMail0");
    if (trialId != null) {
        mreplacedMailCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
    }
    if (probandListStatusTypeId != null) {
        mreplacedMailCriteria.add(Restrictions.eq("probandListStatus.id", probandListStatusTypeId.longValue()));
    }
    if (locked != null) {
        mreplacedMailCriteria.createCriteria("status").add(Restrictions.eq("locked", locked.booleanValue()));
    }
    if (resendProbandId != null) {
        // IMPL!!!!
        DetachedCriteria recipientsSubQuery = DetachedCriteria.forClreplaced(MreplacedMailRecipientImpl.clreplaced, "mreplacedMailRecipient1");
        recipientsSubQuery.setProjection(Projections.rowCount());
        recipientsSubQuery.add(Restrictions.eq("proband.id", resendProbandId.longValue()));
        recipientsSubQuery.add(Restrictions.eqProperty("mreplacedMail.id", "mreplacedMail0.id"));
        mreplacedMailCriteria.add(Restrictions.or(Restrictions.eq("probandListStatusResend", true), Subqueries.eq(0l, recipientsSubQuery)));
    }
    return (Long) mreplacedMailCriteria.setProjection(Projections.rowCount()).uniqueResult();
}

16 View Complete Implementation : TriggerEventManagerHibernateImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
@Transactional(readOnly = true)
public int getTriggerEventsSize(Date after, Date before, List<String> jobs, String triggerName, TriggerEvent.TRIGGER_EVENT_TYPE[] types) {
    final Criteria criteria = buildCriteria(after, before, jobs, triggerName, types);
    criteria.setProjection(Projections.rowCount());
    return ((Long) criteria.list().get(0)).intValue();
}

16 View Complete Implementation : MessageBundleServiceImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
@Transactional(readOnly = true)
public int getSearchCount(String searchQuery, String module, String baseName, String locale) {
    Number count = 0;
    Criteria query = sessionFactory.getCurrentSession().createCriteria(MessageBundleProperty.clreplaced);
    try {
        if (StringUtils.isNotEmpty(searchQuery)) {
            query.add(Restrictions.disjunction().add(Restrictions.ilike("defaultValue", searchQuery, MatchMode.ANYWHERE)).add(Restrictions.ilike("value", searchQuery, MatchMode.ANYWHERE)).add(Restrictions.ilike("propertyName", searchQuery, MatchMode.ANYWHERE)));
        }
        if (StringUtils.isNotEmpty(module)) {
            query.add(Restrictions.eq("moduleName", module));
        }
        if (StringUtils.isNotEmpty(baseName)) {
            query.add(Restrictions.eq("baseName", baseName));
        }
        if (StringUtils.isNotEmpty(locale)) {
            query.add(Restrictions.eq("locale", locale));
        }
        query.setProjection(Projections.rowCount());
        try {
            count = (Number) query.uniqueResult();
        } catch (HibernateException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } catch (Exception e) {
        log.error("problem searching the message bundle data", e);
    }
    return count.intValue();
}

16 View Complete Implementation : SignupMeetingDaoImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
/**
 * {@inheritDoc}
 */
public int getAutoReminderTotalEventCounts(Date startDate, Date endDate) {
    DetachedCriteria criteria = DetachedCriteria.forClreplaced(SignupMeeting.clreplaced).setResultTransformer(Criteria.DISTINCT_ROOT_ENreplacedY).add(Restrictions.eq("autoReminder", true)).add(Restrictions.between("startTime", startDate, endDate)).setProjection(Projections.rowCount());
    List ls = getHibernateTemplate().findByCriteria(criteria);
    if (ls == null || ls.isEmpty())
        return 0;
    Integer rowCount = (Integer) ls.get(0);
    return rowCount != null ? rowCount.intValue() : 0;
}

16 View Complete Implementation : HibernateUserDao.java
Copyright Mozilla Public License 2.0
Author : secdec
@Override
public Long countUsers(String searchString) {
    Criteria criteria = getActiveUserCriteria().setProjection(Projections.rowCount());
    if (searchString != null) {
        criteria.add(Restrictions.or(Restrictions.like("name", "%" + searchString + "%"), Restrictions.like("displayName", "%" + searchString + "%")));
    }
    return (Long) criteria.uniqueResult();
}

15 View Complete Implementation : IdentifierPropertyReferencesTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testCriteriaIdPropertyReferences() {
    Session s = openSession();
    s.beginTransaction();
    Person p = new Person(new Long(1), "steve", 123);
    s.save(p);
    Order o = new Order(new Long(1), p);
    LineItem l = new LineItem(o, "my-product", 2);
    l.setId("456");
    s.save(o);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    Criteria crit = s.createCriteria(Person.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("id", new Integer(123)));
    long count = extractCount(crit);
    replacedertEquals("Person by id prop (non-identifier)", 1, count);
    crit = s.createCriteria(Person.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("pk", new Long(1)));
    count = extractCount(crit);
    replacedertEquals("Person by pk prop (identifier)", 1, count);
    crit = s.createCriteria(Order.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("number", new Long(1)));
    count = extractCount(crit);
    replacedertEquals("Order by number prop (named identifier)", 1, count);
    crit = s.createCriteria(Order.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("id", new Long(1)));
    count = extractCount(crit);
    replacedertEquals("Order by id prop (virtual identifier)", 1, count);
    crit = s.createCriteria(LineItem.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("id", "456"));
    count = extractCount(crit);
    replacedertEquals("LineItem by id prop (non-identifier", 1, count);
    if (getDialect().supportsRowValueConstructorSyntax()) {
        crit = s.createCriteria(LineItem.clreplaced);
        crit.setProjection(Projections.rowCount());
        crit.add(Restrictions.eq("pk", new LineItemPK(o, "my-product")));
        count = extractCount(crit);
        replacedertEquals("LineItem by pk prop (named composite identifier)", 1, count);
    }
    crit = s.createCriteria(Order.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.createAlias("orderee", "p").add(Restrictions.eq("p.id", new Integer(1)));
    count = extractCount(crit);
    replacedertEquals(0, count);
    crit = s.createCriteria(Order.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.createAlias("orderee", "p").add(Restrictions.eq("p.pk", new Long(1)));
    count = extractCount(crit);
    replacedertEquals(1, count);
    crit = s.createCriteria(Order.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.createAlias("orderee", "p").add(Restrictions.eq("p.id", new Integer(123)));
    count = extractCount(crit);
    replacedertEquals(1, count);
    crit = s.createCriteria(LineItem.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("pk.order.id", new Long(1)));
    count = extractCount(crit);
    replacedertEquals(1, count);
    crit = s.createCriteria(LineItem.clreplaced);
    crit.setProjection(Projections.rowCount());
    crit.add(Restrictions.eq("pk.order.number", new Long(1)));
    count = extractCount(crit);
    replacedertEquals(1, count);
    s.delete(o);
    s.delete(p);
    s.getTransaction().commit();
    s.close();
}

15 View Complete Implementation : ImmutableTest.java
Copyright GNU Lesser General Public License v2.1
Author : cacheonix
public void testImmutable() {
    Contract c = new Contract("gavin", "phone");
    ContractVariation cv1 = new ContractVariation(1, c);
    cv1.setText("expensive");
    ContractVariation cv2 = new ContractVariation(2, c);
    cv2.setText("more expensive");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.persist(c);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    c = (Contract) s.createCriteria(Contract.clreplaced).uniqueResult();
    c.setCustomerName("foo bar");
    c.getVariations().add(new ContractVariation(3, c));
    cv1 = (ContractVariation) c.getVariations().iterator().next();
    cv1.setText("blah blah");
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    c = (Contract) s.createCriteria(Contract.clreplaced).uniqueResult();
    replacedertEquals(c.getCustomerName(), "gavin");
    replacedertEquals(c.getVariations().size(), 2);
    cv1 = (ContractVariation) c.getVariations().iterator().next();
    replacedertEquals(cv1.getText(), "expensive");
    s.delete(c);
    replacedertEquals(s.createCriteria(Contract.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    replacedertEquals(s.createCriteria(ContractVariation.clreplaced).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0));
    t.commit();
    s.close();
}

15 View Complete Implementation : VaultDAOImpl.java
Copyright MIT License
Author : DataVault
@Override
public Long getTotalNumberOfVaults(String userId) {
    Session session = this.sessionFactory.openSession();
    SchoolPermissionCriteriaBuilder criteriaBuilder = createVaultCriteriaBuilder(userId, session, Permission.CAN_MANAGE_VAULTS);
    if (criteriaBuilder.hasNoAccess()) {
        return 0L;
    }
    Criteria criteria = criteriaBuilder.build();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENreplacedY);
    criteria.setProjection(Projections.rowCount());
    Long totalNumberOfVaults = (Long) criteria.uniqueResult();
    session.close();
    return totalNumberOfVaults;
}

15 View Complete Implementation : HibernateObsDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.ObsDAO#getObservationCount(List, List, List, List, List, List, Integer, Date, Date, List, boolean, String)
 */
@Override
public Long getObservationCount(List<Person> whom, List<Encounter> encounters, List<Concept> questions, List<Concept> answers, List<PERSON_TYPE> personTypes, List<Location> locations, Integer obsGroupId, Date fromDate, Date toDate, List<ConceptName> valueCodedNameAnswers, boolean includeVoidedObs, String accessionNumber) throws DAOException {
    Criteria criteria = createGetObservationsCriteria(whom, encounters, questions, answers, personTypes, locations, null, null, obsGroupId, fromDate, toDate, valueCodedNameAnswers, includeVoidedObs, accessionNumber);
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.list().get(0);
}

15 View Complete Implementation : HibernateHL7DAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.hl7.db.HL7DAO#countHL7s(Clreplaced, Integer, String)
 */
@Override
@SuppressWarnings("rawtypes")
public Long countHL7s(Clreplaced clazz, Integer messageState, String query) {
    Criteria crit = getHL7SearchCriteria(clazz, messageState, query);
    crit.setProjection(Projections.rowCount());
    return (Long) crit.uniqueResult();
}

15 View Complete Implementation : GoodsCommentDaoImpl.java
Copyright MIT License
Author : PowerDos
@Override
public int getCountByGoodsId(int goodsId) {
    DetachedCriteria criteria = DetachedCriteria.forClreplaced(GoodsComment.clreplaced);
    criteria.add(Restrictions.eq("goodsid", goodsId));
    criteria.setProjection(Projections.rowCount());
    Object obj = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}

15 View Complete Implementation : GoodsCommentDaoImpl.java
Copyright MIT License
Author : PowerDos
@Override
public int getCountByCommentLevel(int commentLevel) {
    DetachedCriteria criteria = DetachedCriteria.forClreplaced(GoodsComment.clreplaced);
    criteria.add(Restrictions.eq("commentLevel", commentLevel));
    criteria.setProjection(Projections.rowCount());
    Object obj = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}