Example usage for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil count

List of usage examples for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil count

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm ProjectionFactoryUtil count.

Prototype

public static Projection count(String propertyName) 

Source Link

Usage

From source file:com.idetronic.portlet.service.impl.staff_activeLocalServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Object> getDepartment() {

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(staff_active.class);
    query.setProjection(ProjectionFactoryUtil.projectionList()
            .add(ProjectionFactoryUtil.groupProperty("bk_jab_sekarang_desc"))
            .add(ProjectionFactoryUtil.count("bk_jab_sekarang_desc")));

    try {/*from   www.  j  a v a 2  s .  com*/
        // catList = dynamicQuery(query);
        List<Object> result = dynamicQuery(query);
        return result;

    } catch (SystemException ex) {
        ex.printStackTrace();
        return null;
    }

    // return catList;
}

From source file:com.idetronic.service.impl.StaffLocalServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Object> getDepartment() {

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(Staff.class);
    query.setProjection(ProjectionFactoryUtil.projectionList()
            .add(ProjectionFactoryUtil.groupProperty("bk_jab_sekarang_desc"))
            .add(ProjectionFactoryUtil.count("bk_jab_sekarang_desc")));

    // DynamicQuery query =
    // DynamicQueryFactoryUtil.forClass(FAQEntry.class);

    // query.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("category")));
    // query.setProjection(ProjectionFactoryUtil.count("category"));
    // query.addOrder(OrderFactoryUtil.asc("displayOrder"));

    try {/* w w w .j av a 2 s  . c  o m*/
        // catList = dynamicQuery(query);
        List<Object> result = dynamicQuery(query);
        return result;

    } catch (SystemException ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:com.liferay.lms.service.impl.SurveyResultLocalServiceImpl.java

License:Open Source License

public double getPercentageByQuestionIdAndAnswerId(long questionId, long answerId) throws SystemException {
    double res = 0;

    ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
            "portletClassLoader");
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(SurveyResult.class, classLoader)
            .add(PropertyFactoryUtil.forName("questionId").eq(new Long(questionId)))
            .add(PropertyFactoryUtil.forName("answerId").eq(new Long(answerId)))
            .setProjection(ProjectionFactoryUtil.count("answerId"));

    @SuppressWarnings("unchecked")
    List<Long> results = SurveyResultLocalServiceUtil.dynamicQuery(query);

    long total = getTotalAnswersByQuestionId(questionId);

    if (total > 0 && results.size() > 0) {
        res = results.get(0) / (double) total * 100;
    }/*from w  w w .  ja  v  a 2s . co  m*/

    return res;
}

From source file:com.liferay.lms.service.impl.SurveyResultLocalServiceImpl.java

License:Open Source License

public long getTotalAnswersByQuestionId(long questionId) throws SystemException {
    long res = new Long(0);

    ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),
            "portletClassLoader");
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(SurveyResult.class, classLoader)
            .add(PropertyFactoryUtil.forName("questionId").eq(new Long(questionId)))
            .setProjection(ProjectionFactoryUtil.count("questionId"));

    @SuppressWarnings("unchecked")
    List<Long> results = SurveyResultLocalServiceUtil.dynamicQuery(query);

    if (results.size() > 0)
        res = results.get(0);/*from w  w  w. j  a v  a 2s .  com*/

    return res;
}

From source file:jorgediazest.util.model.ModelImpl.java

License:Open Source License

protected Projection getPropertyProjection(String attribute, String op) {

    if ("rowCount".equals(op)) {
        return ProjectionFactoryUtil.rowCount();
    }//from  w ww  .  j  a v  a  2 s. c om

    if (!this.hasAttribute(attribute)) {
        return null;
    }

    if (isPartOfPrimaryKeyMultiAttribute(attribute)) {
        attribute = "primaryKey." + attribute;
    }

    Projection property = null;

    if (Validator.isNull(op)) {
        property = ProjectionFactoryUtil.property(attribute);
    } else if ("count".equals(op)) {
        property = ProjectionFactoryUtil.count(attribute);
    } else if ("countDistinct".equals(op)) {
        property = ProjectionFactoryUtil.countDistinct(attribute);
    } else if ("groupProperty".equals(op)) {
        property = ProjectionFactoryUtil.groupProperty(attribute);
    } else if ("max".equals(op)) {
        property = ProjectionFactoryUtil.max(attribute);
    } else if ("min".equals(op)) {
        property = ProjectionFactoryUtil.min(attribute);
    } else if ("sum".equals(op)) {
        property = ProjectionFactoryUtil.sum(attribute);
    }

    return property;
}