List of usage examples for com.liferay.portal.kernel.dao.orm QueryUtil iterate
public static Iterator<?> iterate(Query query, Dialect dialect, int start, int end, boolean unmodifiable)
From source file:org.oep.cmon.dao.tlct.service.persistence.DanhMucGiayToFinderImpl.java
License:Apache License
/** * This is fucntion listByCongDan //from w ww. j a va 2s. co m * Version: 1.0 * * History: * DATE AUTHOR DESCRIPTION * ------------------------------------------------- * 3-March-2013 Nam Dinh Create new * @param Long doiTuongId * @return List<DanhMucGiayTo> */ public List<DanhMucGiayTo> listByCongDan(Long doiTuongId) 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 dmgt.daxoa=0 and dtgt.daxoa=0 and dtgt.trangthai=1 and dt.daxoa=0"); if (Validator.isNotNull(doiTuongId)) { sql.append(" AND dt.id = ?"); } 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(doiTuongId)) { qPos.add(doiTuongId); } Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, false); 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); } }