List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * /*from ww w . j av a2 s. c o m*/ * * @param site * @param user * @param fromIdx * @param count * @return */ public static List listPhotoReplies(SiteBean site, int fromIdx, int count, SessionUserObject user) { boolean is_owner = site.isOwner(user); StringBuffer hql = new StringBuffer( "FROM PhotoReplyBean AS r WHERE r.status=:status AND r.site.id=:site AND r.photo.status=:photo_status"); if (!is_owner) { // hql.append(" AND r.photo.album.type=:album_type"); hql.append(" AND (r.ownerOnly = 0 OR r.user.id=:userid)"); } hql.append(" ORDER BY r.id DESC"); Session ssn = getSession(); Query q = ssn.createQuery(hql.toString()); q.setCacheable(true).setCacheRegion("query.new_replies_of_site"); q.setInteger("status", PhotoReplyBean.STATUS_NORMAL); q.setInteger("photo_status", PhotoBean.STATUS_NORMAL); q.setInteger("site", site.getId()); if (!is_owner) { q.setInteger("album_type", AlbumBean.TYPE_PUBLIC); q.setInteger("userid", (user != null) ? user.getId() : -1); } if (fromIdx > 0) q.setFirstResult(fromIdx); if (count > 0) q.setMaxResults(count); return q.list(); }
From source file:com.liusoft.dlog4j.dao.SiteDAO.java
License:Open Source License
/** * // ww w. j av a 2 s.c om * * @param fromIdx * @param count * @return */ protected static List listSitesOrderBy(int fromIdx, int count, String hql) { Session ssn = getSession(); Query q = ssn.getNamedQuery(hql); if (fromIdx > 0) q.setFirstResult(fromIdx); if (count > 0) q.setMaxResults(count); List objs = q.list(); List<SiteBean> sites = new ArrayList<SiteBean>(); for (int i = 0; i < objs.size(); i++) { Object[] res = (Object[]) objs.get(i); int siteid = ((Number) res[0]).intValue(); SiteBean site = new SiteBean(siteid); site.setUniqueName((String) res[1]); site.setFriendlyName((String) res[2]); sites.add(site); } return sites; }
From source file:com.liusoft.dlog4j.dao.TagDAO.java
License:Open Source License
/** * // w ww.j ava 2 s. c o m * * @param site * @param fromIdx * @param count * @return */ public static List listTags(SiteBean site, int fromIdx, int count) { StringBuffer hql = new StringBuffer("SELECT t.name,COUNT(*) FROM TagBean t"); if (site != null) hql.append(" WHERE t.site.id = ?"); hql.append(" GROUP BY t.name ORDER BY 2 DESC"); Query query = getSession().createQuery(hql.toString()); query.setCacheable(true); query.setCacheRegion(CACHE_KEY); if (site != null) query.setInteger(0, site.getId()); if (fromIdx > 0) query.setFirstResult(fromIdx); if (count > 0) query.setMaxResults(count); List<String> tags = new ArrayList<String>(); List results = query.list(); for (int i = 0; results != null && i < results.size(); i++) { tags.add((String) ((Object[]) results.get(i))[0]); } return tags; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findIsvLicenses(Long isvId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) {//w ww . j a va2 s . c o m List<License> licenses = null; try { String qs = "from License as lic where lic.isv.id= :isvId and lic.decom= :decom order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("isvId", isvId); query.setParameter("decom", false); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseIsvLicenses(Long isvId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) {//ww w .java2s . c om List<License> licenses = null; try { String qs = "from License as lic where lic.isv.id= :isvId and inUse= :inUse order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("isvId", isvId); query.setParameter("inUse", true); query.setParameter("decom", false); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findProdLicenses(Long prodId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) {//ww w. java2s .c o m List<License> licenses = null; try { String qs = "from License as lic where lic.product.id= :prodId and lic.decom=false order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("prodId", prodId); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseProdLicenses(Long prodId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) {/*from ww w .j ava2s. com*/ List<License> licenses = null; try { String qs = "from License as lic where lic.product.id= :prodId and inUse= :inUse and lic.decom= :decom order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("prodId", prodId); query.setParameter("inUse", true); query.setParameter("decom", false); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findIsvProdLicenses(Long isvId, Long prodId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) { List<License> licenses = null; try {/* ww w .j av a 2 s .c o m*/ String qs = "from License as lic where lic.isv.id= :isvId and lic.product.id= :prodId and lic.decom= :decom order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("isvId", isvId); query.setParameter("prodId", prodId); query.setParameter("decom", false); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseIsvProdLicenses(Long isvId, Long prodId, Long prodDefId, Long storeId, Long platformId, Integer firstResult, Integer maxResults, String orderBy, String orderDir) { List<License> licenses = null; try {//from w ww. ja va 2 s .c om String qs = "from License as lic where lic.isv.id= :isvId and "; if (prodId != null) qs += "lic.product.id= :prodId and "; else if (prodDefId != null) qs += "lic.product.productDef.id= :prodDefId and "; if (storeId != null) qs += "lic.product.listingStore.id= :storeId and "; if (platformId != null) qs += "lic.product.platform.id= :platformId and "; qs += "inUse= :inUse and decom= :decom order by lic." + orderBy + " " + orderDir; Query query = getSession().createQuery(qs); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setParameter("isvId", isvId); if (prodId != null) query.setParameter("prodId", prodId); else if (prodDefId != null) query.setParameter("prodDefId", prodDefId); if (storeId != null) query.setParameter("storeId", storeId); if (platformId != null) query.setParameter("platformId", platformId); query.setParameter("inUse", true); query.setParameter("decom", false); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findOverdraftLicenses(Long isvId, Long prodId, Integer maxResults) { List<License> licenses = null; try {// w ww . j av a 2 s .c om String qs = "from License as lic where lic.isv.id= :isvId and lic.product.id= :prodId and lic.decom= :decom and " + "lic.paymentStatus= :paymentStatus"; Query query = getSession().createQuery(qs); query.setMaxResults(maxResults); query.setParameter("isvId", isvId); query.setParameter("prodId", prodId); query.setParameter("decom", false); query.setParameter("paymentStatus", LicensePaymentStatus.OVERDRAFT.name()); licenses = query.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }