Example usage for org.hibernate.criterion Projections rowCount

List of usage examples for org.hibernate.criterion Projections rowCount

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections rowCount.

Prototype

public static Projection rowCount() 

Source Link

Document

The query row count, ie.

Usage

From source file:com.lakeside.data.sqldb.PageBaseDao.java

License:Apache License

/**
 * countCriteria./*  ww w  .  j  av a2  s .c o m*/
 */
@SuppressWarnings("unchecked")
protected int countCriteriaResult(final Criteria c) {
    CriteriaImpl impl = (CriteriaImpl) c;

    // Projection?OrderBy??,??Count?
    Projection projection = impl.getProjection();
    ResultTransformer transformer = impl.getResultTransformer();

    List<CriteriaImpl.OrderEntry> orderEntries = null;
    try {
        orderEntries = (List<CriteriaImpl.OrderEntry>) ReflectionUtils.getFieldValue(impl, "orderEntries");
        ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList<Object>());
    } catch (Exception e) {
        logger.error("??:{}", e.getMessage());
    }

    // Count
    int totalCount = (Integer) c.setProjection(Projections.rowCount()).uniqueResult();

    // ?Projection,ResultTransformerOrderBy??
    c.setProjection(projection);

    if (projection == null) {
        c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    }
    if (transformer != null) {
        c.setResultTransformer(transformer);
    }
    try {
        ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries);
    } catch (Exception e) {
        logger.error("??:{}", e.getMessage());
    }

    return totalCount;
}

From source file:com.liferay.portal.dao.orm.hibernate.ProjectionFactoryImpl.java

License:Open Source License

public Projection rowCount() {
    return new ProjectionImpl(Projections.rowCount());
}

From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java

License:Open Source License

public int countProcessDefinitions(String name, boolean latest) {
    try {/*from ww w.j  av  a 2  s  . co m*/
        Criteria criteria = _session.createCriteria(ProcessDefinition.class);

        if (latest) {
            criteria.setProjection(Projections.countDistinct("name"));
        } else {
            criteria.setProjection(Projections.rowCount());
        }

        if (name != null) {
            criteria.add(Restrictions.eq("name", name));
        }

        Number count = (Number) criteria.uniqueResult();

        return count.intValue();
    } catch (Exception e) {
        throw new JbpmException(e);
    }
}

From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java

License:Open Source License

protected int criteriaCount(Criteria criteria) {
    criteria.setProjection(Projections.rowCount());

    List<Integer> results = criteria.list();

    if (results.isEmpty()) {
        return 0;
    } else {/*from  ww w  . j  a  v a 2  s  . co  m*/
        return results.get(0);
    }
}

From source file:com.liferay.portal.workflow.jbpm.WorkflowLogManagerImpl.java

License:Open Source License

protected int getWorkflowLogsCount(long companyId, long workflowTaskId, long workflowInstanceId,
        List<Integer> logTypes) throws WorkflowException {

    JbpmContext jbpmContext = _jbpmConfiguration.createJbpmContext();

    try {//from w  ww  .  ja v  a  2s.co m
        Session session = jbpmContext.getSession();

        Criteria criteria = session.createCriteria(WorkflowLogImpl.class);

        addJoin(criteria, workflowTaskId, workflowInstanceId);
        addLogTypesJunction(criteria, logTypes);

        criteria.setProjection(Projections.rowCount());

        List<Long> results = criteria.list();

        if (results.isEmpty()) {
            return 0;
        } else {
            return (results.get(0)).intValue();
        }
    } catch (Exception e) {
        throw new WorkflowException(e);
    } finally {
        jbpmContext.close();
    }
}

From source file:com.lighting.platform.base.dao.HibernateDao.java

License:Apache License

/**
 * countCriteria./*www.  j a  v  a 2  s  . c o m*/
 */
protected long countCriteriaResult(final Criteria c) {
    org.hibernate.internal.CriteriaImpl impl = (CriteriaImpl) c;

    // Projection?ResultTransformer?OrderBy??,??Count?
    Projection projection = impl.getProjection();
    ResultTransformer transformer = impl.getResultTransformer();

    List<CriteriaImpl.OrderEntry> orderEntries = null;
    try {
        orderEntries = (List) ReflectionUtils.getFieldValue(impl, "orderEntries");
        ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList());
    } catch (Exception e) {
        logger.error("??:" + e.getMessage());
    }

    // Count
    Long totalCountObject = (Long) c.setProjection(Projections.rowCount()).uniqueResult();
    long totalCount = (totalCountObject != null) ? totalCountObject : 0;

    // ?Projection,ResultTransformerOrderBy??
    c.setProjection(projection);

    if (projection == null) {
        c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    }
    if (transformer != null) {
        c.setResultTransformer(transformer);
    }
    try {
        ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries);
    } catch (Exception e) {
        logger.error("??:" + e.getMessage());
    }

    return totalCount;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

public Integer findNumLics(String isvId, String prodId) {
    Integer numLics = 0;//from   w ww.j a va 2  s.  com
    try {
        Long lpid = Long.parseLong(prodId);
        Long lisvid = Long.parseLong(isvId);
        Criteria criteria = getSession().createCriteria(License.class);
        criteria.add(Restrictions.eq("isv.id", lisvid));
        criteria.add(Restrictions.eq("product.id", lpid));
        criteria.setProjection(Projections.rowCount());
        numLics = (Integer) criteria.list().get(0);
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return numLics;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

public Integer findNumUnpaidForLics(Long isvId, Long prodId) {
    Integer numLics = 0;/* w  w w .ja  v  a 2s  .  c o m*/
    try {
        Criteria criteria = getSession().createCriteria(License.class);
        criteria.add(Restrictions.eq("isv.id", isvId));
        criteria.add(Restrictions.eq("product.id", prodId));
        criteria.add(Restrictions.eq("inUse", true));
        criteria.add(Restrictions.eq("decom", false));
        criteria.add(Restrictions.ilike("paymentStatus", LicensePaymentStatus.OVERDRAFT.name()));
        criteria.setProjection(Projections.rowCount());
        numLics = (Integer) criteria.list().get(0);
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return numLics;
}

From source file:com.lm.lic.manager.hibernate.LicenseDAO.java

License:Open Source License

/**
 * Find the number of licenses who are credited (paid for) but not yet used.
 * //from w w w . ja v  a 2s .com
 * @param isvId
 * @param prodId
 * @return
 */
public Integer findNumCreditedLics(Long isvId, Long prodId) {
    Integer numLics = 0;
    try {
        Criteria criteria = getSession().createCriteria(License.class);
        criteria.add(Restrictions.eq("isv.id", isvId));
        criteria.add(Restrictions.eq("product.id", prodId));
        criteria.add(Restrictions.eq("inUse", false));
        criteria.add(Restrictions.eq("decom", false));
        criteria.add(Restrictions.ne("paymentStatus", LicensePaymentStatus.OVERDRAFT.name()));
        criteria.setProjection(Projections.rowCount());
        numLics = (Integer) criteria.list().get(0);
    } catch (RuntimeException re) {
        log.error("find by property name failed", re);
        throw re;
    }
    return numLics;
}