Example usage for com.liferay.portal.kernel.dao.orm QueryUtil iterate

List of usage examples for com.liferay.portal.kernel.dao.orm QueryUtil iterate

Introduction

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

Prototype

public static Iterator<?> iterate(Query query, Dialect dialect, int start, int end) 

Source Link

Usage

From source file:org.oep.cmon.dao.thamso.service.persistence.AnhXaFinderImpl.java

License:Apache License

/**
  * This is fucntion search//from w w  w  . jav  a2  s  .  co  m
  * Version: 1.0
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String keyword,Long appId,String table,int start,int end
  * @return List<AnhXa>
  */
public List<AnhXa> search(String keyword, Long appId, String table, int start, int end) throws SystemException {
    Session session = null;
    try {
        session = openSession();

        StringBuffer sql = new StringBuffer("");
        sql.append(
                " SELECT a.id,a.madng,a.tendng,a.makhac,a.tenkhac,a.tenbang,a.danhmucungdungid FROM CMON_DANHMUCANHXA a");

        sql.append(" WHERE a.daXoa=0 ");

        if (keyword != null && keyword.trim().length() > 0) {
            sql.append(" AND (a.tenkhac like ? OR a.tendng like ?) ");
        }
        if (table != null && table.trim().length() > 0) {
            sql.append(" AND a.tenbang = ? ");
        }
        if (appId != null && appId.intValue() > 0) {
            sql.append(" AND a.danhmucungdungid = ? ");
        }

        sql.append(" ORDER BY LOWER(a.tendng) ASC");

        SQLQuery q = session.createSQLQuery(sql.toString());
        q.addScalar("id", Type.LONG);
        q.addScalar("madng", Type.STRING);
        q.addScalar("tendng", Type.STRING);
        q.addScalar("makhac", Type.STRING);
        q.addScalar("tenkhac", Type.STRING);
        q.addScalar("tenbang", Type.STRING);
        q.addScalar("danhmucungdungid", Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        if (keyword != null && keyword.trim().length() > 0) {
            qPos.add("%" + keyword + "%");
        }
        if (table != null && table.trim().length() > 0) {
            qPos.add(table);
        }

        if (appId != null && appId.intValue() > 0) {
            qPos.add(appId);
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end);
        List<AnhXa> result = new ArrayList<AnhXa>();
        while (itr.hasNext()) {
            Object[] a = itr.next();
            AnhXa t = new AnhXaImpl();
            t.setId((Long) a[0]);
            t.setMaDNG((String) a[1]);
            t.setTenDNG((String) a[2]);
            t.setMaKhac((String) a[3]);
            t.setTenKhac((String) a[4]);
            t.setTenBang((String) a[5]);
            if (a[6] != null) {
                t.setUngDungId((Long) a[6]);
            }
            result.add(t);
        }
        return result;

    } catch (Exception e) {
        throw new SystemException(e);
    } finally {

        closeSession(session);
    }

}

From source file:org.oep.cmon.dao.thamso.service.persistence.ThamSoFinderImpl.java

License:Apache License

/**
  * This is fucntion searchByTen /*from www . j av a 2 s.c  om*/
  * Version: 1.0
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String ten,int start,int end
  * @return List<ThamSo>
  */
public List<ThamSo> searchByTen(String ten, int start, int end) throws SystemException {
    Session session = null;
    try {
        session = openSession();

        StringBuffer sql = new StringBuffer("");
        sql.append(" SELECT t.ID,t.NAME,t.GIATRI FROM CMON_THAMSO t");

        sql.append(" WHERE tt.daXoa=0 ");

        if (ten != null) {
            sql.append(" AND LOWER(t.TEN) like LOWER(?) ");
        }

        sql.append(" ORDER BY LOWER(t.TEN) ASC");

        SQLQuery q = session.createSQLQuery(sql.toString());
        QueryPos qPos = QueryPos.getInstance(q);

        if (ten != null) {
            qPos.add("%" + ten + "%");
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end);
        List<ThamSo> result = new ArrayList<ThamSo>();
        while (itr.hasNext()) {
            Object[] a = itr.next();
            ThamSo t = new ThamSoClp();
            t.setId(Long.valueOf(a[0].toString()));
            t.setTen((String) a[1]);
            t.setGiaTri((String) a[2]);

            result.add(t);
        }
        return result;

    } catch (Exception e) {
        throw new SystemException(e);
    } finally {

        closeSession(session);
    }
}

From source file:org.oep.cmon.dao.tlct.service.persistence.DanhMucGiayToFinderImpl.java

License:Apache License

/**
  * This is fucntion searchDanhMucGiayTo 
  * Version: 1.0// w ww  . j a  va  2  s. c o m
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String group,Long doiTuongId, int start, int end
  * @return List<DanhMucGiayTo>
  */
@Override
public List<DanhMucGiayTo> searchDanhMucGiayTo(String group, Long doiTuongId, int start, int end) {
    // TODO Auto-generated method stub
    Session session = null;
    List<DanhMucGiayTo> list = new ArrayList<DanhMucGiayTo>();
    try {
        session = openSession();
        StringBuffer sql = new StringBuffer("");
        sql.append("SELECT distinct dmgt.ID AS ID, dmgt.TEN AS TEN, dmgt.MA AS MA from CMON_DANHMUCGIAYTO dmgt "
                + " LEFT JOIN CMON_DMGIAYTO2DOITUONGSUDUNG dtgt ON dtgt.LOAIGIAYTOID=dmgt.ID "
                + " LEFT JOIN CMON_LOAIDOITUONG dt ON dt.ID=dtgt.LOAIDOITUONGID " + " WHERE dmgt.daxoa=0 ");

        if (Validator.isNotNull(group)) {
            sql.append(" AND (LOWER(dmgt.TEN) like LOWER(?) OR LOWER(dmgt.MA) like LOWER(?) )");
        }
        if (Validator.isNotNull(doiTuongId)) {
            sql.append(" AND dt.id = ?");
        }

        sql.append(" ORDER BY LOWER(dmgt.TEN) ASC ");

        SQLQuery q = session.createSQLQuery(sql.toString());
        //q.setCacheable(false);
        //q.addEntity("DanhMucGiayTo", DanhMucGiayToImpl.class);
        q.addScalar("ID", Type.LONG);
        q.addScalar("TEN", Type.STRING);
        q.addScalar("MA", Type.STRING);

        QueryPos qPos = QueryPos.getInstance(q);

        if (Validator.isNotNull(group)) {
            qPos.add("%" + group + "%");
            qPos.add("%" + group + "%");
            //qPos.add(group);
        }

        if (Validator.isNotNull(doiTuongId)) {
            qPos.add(doiTuongId);
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end);
        while (itr.hasNext()) {
            Object[] a = itr.next();
            DanhMucGiayTo t = new DanhMucGiayToImpl();
            t.setId(Long.valueOf(a[0].toString()));
            t.setTen((String) a[1]);
            t.setMa(a[2].toString());
            list.add(t);
        }
        return list;

    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        closeSession(session);
    }
    return list;
}

From source file:org.oep.cmon.dao.tlct.service.persistence.DanhMucGiayToFinderImpl.java

License:Apache License

/**
  * This is fucntion searchByTTHCIdOrGDId
  * Version: 1.0//from   w  w  w  . j av  a2s.c o  m
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String group,String doituong, Long tthcid, Long dgId, Integer daXoa, int start,int end
  * @return List<DanhMucGiayTo>
  */
public List<DanhMucGiayTo> searchByTTHCIdOrGDId(String group, String doituong, Long tthcid, Long dgId,
        Integer daXoa, int start, int end) throws SystemException {

    Session session = null;
    List<DanhMucGiayTo> list = new ArrayList<DanhMucGiayTo>();
    try {
        session = openSession();

        StringBuffer sql = new StringBuffer("");
        sql.append(
                " Select distinct dmgt.ID AS ID, dmgt.TEN AS TEN, dmgt.MA AS MA from cmon_danhmucgiayto dmgt ");
        sql.append(" LEFT JOIN CMON_DMGIAYTO2DOITUONGSUDUNG dtgt ON dtgt.LOAIGIAYTOID=dmgt.ID ");
        sql.append(" LEFT JOIN CMON_LOAIDOITUONG dt ON dt.ID=dtgt.LOAIDOITUONGID ");
        sql.append(" WHERE 1=1 ");

        if (Validator.isNotNull(group)) {
            sql.append(" AND (LOWER(dmgt.TEN) like LOWER(?) OR LOWER(dmgt.MA) like LOWER(?) )");
        }
        if (Validator.isNotNull(doituong)) {
            sql.append(" AND dt.MA like ?");
        }

        if (tthcid != null) {
            sql.append(" AND dmgt.id not in (Select tt2gt.danhmucgiaytoid from  cmon_thutuc2giayto tt2gt ");
            sql.append(" where tt2gt.thutuchanhchinhid=? ");
        }
        if (dgId != null) {
            sql.append(" AND tt2gt.giaidoan=? ");
        }
        if (daXoa != null) {
            sql.append(" AND tt2gt.daxoa=?) ");
            sql.append(" AND dmgt.daxoa=? ");
        }

        sql.append(" ORDER BY dmgt.ten ASC");

        SQLQuery q = session.createSQLQuery(sql.toString());
        q.addScalar("ID", Type.LONG);
        q.addScalar("TEN", Type.STRING);
        q.addScalar("MA", Type.STRING);

        QueryPos qPos = QueryPos.getInstance(q);

        if (Validator.isNotNull(group)) {
            qPos.add("%" + group + "%");
            qPos.add("%" + group + "%");
        }

        if (Validator.isNotNull(doituong)) {
            qPos.add(doituong);
        }

        if (Validator.isNotNull(tthcid)) {
            qPos.add(tthcid);
        }

        if (Validator.isNotNull(dgId)) {
            qPos.add(dgId);
        }
        if (Validator.isNotNull(daXoa)) {
            qPos.add(daXoa);
            qPos.add(daXoa);
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end);
        while (itr.hasNext()) {
            Object[] a = itr.next();
            DanhMucGiayTo t = new DanhMucGiayToImpl();
            t.setId(Long.valueOf(a[0].toString()));
            t.setTen((String) a[1]);
            t.setMa(a[2].toString());
            list.add(t);
        }
        return list;

    } catch (Exception e) {
        throw new SystemException(e);
    } finally {

        closeSession(session);
    }
}

From source file:org.oep.cmon.dao.tlct.service.persistence.TaiLieuChungThucFinderImpl.java

License:Apache License

/**
  * This is fucntion searchByCongDanId2DanhMucGiayTo
  * Version: 1.0//w  w w.  j a  va  2  s .  c  om
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param String group,   Long congDanId, Long doiTuongId, int start, int end
  * @return List<TaiLieuChungThuc>
  */
public List<TaiLieuChungThuc> searchByCongDanId2DanhMucGiayTo(String group, Long congDanId, Long doiTuongId,
        int start, int end) {
    // TODO Auto-generated method stub
    Session session = null;
    List<TaiLieuChungThuc> list = new ArrayList<TaiLieuChungThuc>();
    try {
        session = openSession();
        StringBuffer sql = new StringBuffer("");
        sql.append(" SELECT DISTINCT nlttl.ID AS ID, dmgt.TEN AS TEN, dmgt.MA AS MA, nlttl.TRANGTHAI "
                + ", nlttl.NGAYUPLOAD,  nlttl.hieuluctungay, nlttl.hieulucdenngay, nlttl.DANHMUCGIAYTOID, nlttl.noiluutruid,nlttl.phienban as PHIENBAN "
                + " FROM CMON_NOILUUTRUTAILIEU nlttl "
                + " INNER JOIN CMON_DANHMUCGIAYTO dmgt ON dmgt.ID=nlttl.DANHMUCGIAYTOID "
                + " LEFT JOIN CMON_DMGIAYTO2DOITUONGSUDUNG dtgt ON dtgt.LOAIGIAYTOID=dmgt.ID "
                + " LEFT JOIN CMON_LOAIDOITUONG dt ON dt.ID=dtgt.LOAIDOITUONGID "
                + " WHERE dmgt.daxoa=0 and dtgt.daxoa=0 and dtgt.trangthai=1 and dt.daxoa=0");

        if (Validator.isNotNull(group)) {
            sql.append(" AND (LOWER(dmgt.TEN) like LOWER(?) OR LOWER(dmgt.MA) like LOWER(?) )");
        }
        if (Validator.isNotNull(congDanId)) {
            sql.append(" AND nlttl.chusohuuId = ?");
            sql.append(
                    " AND ( nlttl.danhmucgiaytoid, nlttl.phienban ) IN ( SELECT danhmucgiaytoid, MAX(phienban) FROM cmon_noiluutrutailieu where chusohuuid=? GROUP BY danhmucgiaytoid ) ");
        }
        if (Validator.isNotNull(doiTuongId)) {
            sql.append(" AND dt.id = ?");
        }

        sql.append(" ORDER BY nlttl.NGAYUPLOAD DESC, LOWER(dmgt.TEN) ASC ");

        SQLQuery q = session.createSQLQuery(sql.toString());
        q.addScalar("ID", Type.LONG);
        q.addScalar("TEN", Type.STRING);
        q.addScalar("MA", Type.STRING);
        q.addScalar("TRANGTHAI", Type.INTEGER);
        q.addScalar("NGAYUPLOAD", Type.DATE);
        q.addScalar("HIEULUCTUNGAY", Type.DATE);
        q.addScalar("HIEULUCDENNGAY", Type.DATE);
        q.addScalar("DANHMUCGIAYTOID", Type.LONG);
        q.addScalar("NOILUUTRUID", Type.LONG);
        q.addScalar("PHIENBAN", Type.INTEGER);

        QueryPos qPos = QueryPos.getInstance(q);

        if (Validator.isNotNull(group)) {
            qPos.add("%" + group + "%");
            qPos.add("%" + group + "%");
        }
        if (Validator.isNotNull(congDanId)) {
            qPos.add(congDanId);
            qPos.add(congDanId);
        }

        if (Validator.isNotNull(doiTuongId)) {
            qPos.add(doiTuongId);
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), start, end);
        while (itr.hasNext()) {
            Object[] a = itr.next();
            TaiLieuChungThuc t = new TaiLieuChungThucImpl();
            t.setId(Long.valueOf(a[0].toString()));
            t.setTen((String) a[1]);
            t.setGhiChu(a[2].toString());
            t.setTrangThai(Integer.valueOf(a[3].toString()));
            t.setNgayUpload((java.util.Date) a[4]);
            t.setHieuLucTuNgay((java.util.Date) a[5]);
            t.setHieuLucDenNgay((java.util.Date) a[6]);
            t.setDanhMucGiayToId(Long.valueOf(a[7].toString()));
            t.setNoiLuuTruId(Long.valueOf(a[8].toString()));
            t.setPhienBan(Integer.valueOf(a[9].toString()));
            list.add(t);
        }
        return list;

    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        closeSession(session);
    }
    return list;
}