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

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

Introduction

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

Prototype

public static Projection rowCount() 

Source Link

Usage

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

License:Open Source License

public long count(Criterion condition) {
    DynamicQuery dynamicQuery = this.getService().newDynamicQuery();

    dynamicQuery.setProjection(ProjectionFactoryUtil.rowCount());

    if (condition != null) {
        dynamicQuery.add(condition);//from  w  w  w  .j  a  v a  2  s  .c o  m
    }

    try {
        List<?> list = this.getService().executeDynamicQuery(dynamicQuery);

        if (list != null) {
            return (Long) list.get(0);
        }
    } catch (Exception e) {
        _log.error("Error executing count");
        throw new RuntimeException(e);
    }

    return -1;
}

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 www .  ja  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;
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.business.CongDanBusiness.java

License:Apache License

/**
 * This is  function countByCongDan//w ww  . ja  v a2s  . co  m
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param ten
 * @return long
 */
public static long countByCongDan(String ten) {

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(CongDan.class);
    Criterion criterion = null;
    ten = ten.toUpperCase();

    criterion = RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + ten + StringPool.PERCENT);
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ho", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("dem", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("tenDayDu", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("email", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ma", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("soCmnd", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.and(criterion,
            RestrictionsFactoryUtil.eq("tinhtrang", Constants.TINHTRANG_SONG));
    criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));

    query = query.add(criterion);
    query.setProjection(ProjectionFactoryUtil.rowCount());

    long count = 0;

    try {
        Iterator<Long> resultsItr = CongDanLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (SystemException se) {
        // _log.error(se.getMessage(), se);
    }

    return count;
}

From source file:org.oep.cmon.portlet.doanhnghiep.quanlytaikhoan.business.QuanLyTaiKhoan.java

License:Apache License

/**
 * This is  function get count DoanhNghiep
 * Version: 1.0// w w w  . ja  v a 2s .  co m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param ten
 * @param loaiDoiTuongId
 * @throws trangThai
 * @return long
 */
public static long countByDoanhNghiep(String ten, long loaiDoiTuongId, int trangThai) {

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(DoanhNghiep.class);

    if (!ten.equals("")) {
        Criterion criterion = null;
        ten = ten.toUpperCase();
        criterion = RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + ten + StringPool.PERCENT);

        criterion = RestrictionsFactoryUtil.or(criterion, RestrictionsFactoryUtil.ilike("tenTiengNuocNgoai",
                StringPool.PERCENT + ten + StringPool.PERCENT));
        criterion = RestrictionsFactoryUtil.or(criterion,
                RestrictionsFactoryUtil.ilike("tenVietTat", StringPool.PERCENT + ten + StringPool.PERCENT));

        criterion = RestrictionsFactoryUtil.or(criterion, RestrictionsFactoryUtil.ilike("emailDoanhNghiep",
                StringPool.PERCENT + ten + StringPool.PERCENT));
        criterion = RestrictionsFactoryUtil.or(criterion,
                RestrictionsFactoryUtil.ilike("soGCNDKKD", StringPool.PERCENT + ten + StringPool.PERCENT));
        criterion = RestrictionsFactoryUtil.and(criterion,
                RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));
        query = query.add(criterion);
    }
    if (loaiDoiTuongId != 0) {
        Criterion criterion1 = RestrictionsFactoryUtil.eq("loaiDoiTuongId", loaiDoiTuongId);
        criterion1 = RestrictionsFactoryUtil.and(criterion1,
                RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));
        query = query.add(criterion1);
    }
    if (trangThai != 99) {
        Criterion criterion2 = null;
        if (trangThai == 2) {
            criterion2 = RestrictionsFactoryUtil.isNull("taiKhoanNguoiDungId");
        } else
            criterion2 = RestrictionsFactoryUtil.isNotNull("taiKhoanNguoiDungId");

        criterion2 = RestrictionsFactoryUtil.and(criterion2,
                RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));
        query = query.add(criterion2);
    }

    //query.setProjection(ProjectionFactoryUtil.max("thuTuHienThi"));
    query.setProjection(ProjectionFactoryUtil.rowCount());
    //query.setProjection(ProjectionFactoryUtil.sum("counter"));
    //DynamicQueryInitializ dqi = new DynamicQueryInitializerImpl(query);

    long count = 0;

    try {
        Iterator<Long> resultsItr = DoanhNghiepLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (SystemException se) {
        // _log.error(se.getMessage(), se);
    }

    return count;
}

From source file:org.oep.cmon.portlet.doanhnghiep.xacthuc.utils.XacThucDoanhNghiepUtils.java

License:Apache License

@SuppressWarnings("unchecked")
public static long countListCongDan(String ten) {
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(CongDan.class);
    Criterion criterion = null;/*from  ww w .ja  v a2s. co m*/
    ten = ten.toUpperCase();

    criterion = RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + ten + StringPool.PERCENT);
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ho", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("dem", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("tenDayDu", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("email", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ma", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("soCmnd", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.and(criterion,
            RestrictionsFactoryUtil.eq("tinhtrang", Constants.TINHTRANG_SONG));
    criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));

    query = query.add(criterion);
    query.setProjection(ProjectionFactoryUtil.rowCount());

    long count = 0;

    try {
        Iterator<Long> resultsItr = CongDanLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (SystemException se) {
        // _log.error(se.getMessage(), se);
    }

    return count;
}

From source file:org.oep.cmon.portlet.document.business.CitizenDocumentBusiness.java

License:Apache License

public static Long countByChungThucHistory(Long danhMucGiayToId, Long congDanId) throws Exception {

    long count = 0;
    try {//from  w  w  w  . j a va 2 s  .  c om
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(TaiLieuChungThuc.class);

        Criterion criterion = null;

        criterion = RestrictionsFactoryUtil.eq("chuSohuuId", congDanId);

        if (Validator.isNotNull(danhMucGiayToId)) {
            criterion = RestrictionsFactoryUtil.and(criterion,
                    RestrictionsFactoryUtil.eq("danhMucGiayToId", danhMucGiayToId));
        }

        query = query.add(criterion);
        query.setProjection(ProjectionFactoryUtil.rowCount());

        Iterator<Long> resultsItr = TaiLieuChungThucLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (Exception se) {
        _log.error(se.getMessage(), se);
        throw se;
    }

    return count;
}

From source file:org.oep.cmon.portlet.quanlyvaitro.business.QuanLyVaiTroBusiness.java

License:Apache License

/**
 * This is function countByVaiTro/*  w  w  w.  j a v  a  2 s .  c o m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param maTen
 * @throws Exception
 * @return Long
 */
public static Long countByVaiTro(String maTen) throws Exception {

    long count = 0;
    try {
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(VaiTro.class);

        // This is a test line for display all request if there's no search
        // criteria
        Criterion criterion = null;
        criterion = RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE);

        if (!Helpers.isEmpty(maTen)) {
            criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.or(
                    RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + maTen + StringPool.PERCENT),
                    RestrictionsFactoryUtil.ilike("ma", StringPool.PERCENT + maTen + StringPool.PERCENT)));
        }

        query = query.add(criterion);
        query.setProjection(ProjectionFactoryUtil.rowCount());

        Iterator<Long> resultsItr = VaiTroLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (Exception se) {
        _log.error(se.getMessage(), se);
        throw se;
    }

    return count;
}

From source file:org.oep.cmon.portlet.quanlyvaitro.business.QuanLyVaiTroBusiness.java

License:Apache License

/**
 * This is function checkExistingVaiTro//from w w w.j  av  a2 s  . c om
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param vaiTroId
 * @param ma
 * @throws Exception
 * @return boolean
 */
public static boolean checkExistingVaiTro(String vaiTroId, String ma) throws Exception {
    long count = 0;
    try {
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(VaiTro.class);

        // This is a test line for display all request if there's no search
        // criteria
        Criterion criterion = null;
        criterion = RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE);

        if (!Helpers.isEmpty(vaiTroId)) {
            criterion = RestrictionsFactoryUtil.and(criterion,
                    RestrictionsFactoryUtil.ne("id", Long.valueOf(vaiTroId)));
        }

        if (!Helpers.isEmpty(ma)) {
            criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("ma", ma));
        }

        query = query.add(criterion);
        query.setProjection(ProjectionFactoryUtil.rowCount());

        Iterator<Long> resultsItr = VaiTroLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (Exception se) {
        _log.error(se.getMessage(), se);
        throw se;
    }

    return (count > 0) ? true : false;
}

From source file:org.oep.cmon.portlet.tainguyen.action.TaiNguyenPortlet.java

License:Apache License

/**
 * This is function countByTaiNguyen/*from w ww .  jav  a 2  s.  c  om*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param ten
 * @param ungDungId
 * @param heThongId
 * @return long
 */
@SuppressWarnings("unchecked")
public long countByTaiNguyen(String ten, Long ungDungId, Long heThongId) {
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(TaiNguyen.class);

    Criterion criterion = null;

    criterion = RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + ten + StringPool.PERCENT);
    if (ungDungId != null) {
        criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("ungDungId", ungDungId));
    }
    if (heThongId != null) {
        criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("heThongId", heThongId));
    }
    criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));

    query = query.add(criterion);
    //query.setProjection(ProjectionFactoryUtil.max("thuTuHienThi"));
    query.setProjection(ProjectionFactoryUtil.rowCount());
    //query.setProjection(ProjectionFactoryUtil.sum("counter"));
    //DynamicQueryInitializ dqi = new DynamicQueryInitializerImpl(query);

    long count = 0;

    try {
        Iterator<Long> resultsItr = TaiNguyenLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (SystemException se) {
        // _log.error(se.getMessage(), se);
    }

    return count;

}

From source file:org.oep.cmon.portlet.taocongdan.business.TaoCongDanBusiness.java

License:Apache License

/**
  * This is fucntion countByCongDan//w w w . j a  v a 2s.  c  o  m
  * Version: 1.0
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String ten, String taiKhoanNguoiDungId
  * @return long
  */
@SuppressWarnings("unchecked")
public static long countByCongDan(String ten, String taiKhoanNguoiDungId) {
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(CongDan.class);
    Criterion criterion = null;
    ten = ten.toUpperCase();

    criterion = RestrictionsFactoryUtil.ilike("ten", StringPool.PERCENT + ten + StringPool.PERCENT);
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ho", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("dem", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("tenDayDu", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("email", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("ma", StringPool.PERCENT + ten + StringPool.PERCENT));
    criterion = RestrictionsFactoryUtil.or(criterion,
            RestrictionsFactoryUtil.ilike("soCmnd", StringPool.PERCENT + ten + StringPool.PERCENT));

    if (taiKhoanNguoiDungId != "") {
        if (taiKhoanNguoiDungId.equals(String.valueOf(Constants.TaoCongDan.CO_TAI_KHOAN))) {
            criterion = RestrictionsFactoryUtil.and(criterion,
                    RestrictionsFactoryUtil.isNotNull("taiKhoanNguoiDungId"));
        } else {
            criterion = RestrictionsFactoryUtil.and(criterion,
                    RestrictionsFactoryUtil.isNull("taiKhoanNguoiDungId"));
        }
    }

    criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.eq("daXoa", Constants.ACTIVE));

    query = query.add(criterion);

    query.setProjection(ProjectionFactoryUtil.rowCount());

    long count = 0;

    try {
        Iterator<Long> resultsItr = CongDanLocalServiceUtil.dynamicQuery(query).iterator();

        if (resultsItr.hasNext()) {
            count = ((Long) resultsItr.next()).longValue();
        }
    } catch (SystemException se) {
        // _log.error(se.getMessage(), se);
    }

    return count;
}