List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:com.liusoft.dlog4j.dao.DiaryDAO.java
License:Open Source License
/** * /* ww w. j a v a2 s . co m*/ * * @param site * @param user * @param catalog_id * @param year * @param month * @param date * @param fromIdx * @param count * @return */ public static List listDiary(SiteBean site, SessionUserObject user, int catalog_id, int year, int month, int date, int fromIdx, int count, boolean withContent) { StringBuffer hql = new StringBuffer("FROM "); hql.append(withContent ? "DiaryBean" : "DiaryOutlineBean"); hql.append(" AS a WHERE a.status=:status AND a.site.id=:site"); // (2006-5-22 by Winter Lau) if (user == null || site.getOwner().getId() != user.getId()) { // hql.append(" AND (a.catalog.type<>:cat_type"); if (user != null) hql.append( " OR (a.catalog.type=:cat_type AND a.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))"); hql.append(')'); } if (catalog_id > 0) hql.append(" AND a.catalog.id=:catalog"); if (year > 0 || month > 0 || date > 0) { hql.append(" AND a.writeTime >= :beginTime AND a.writeTime < :endTime"); } hql.append(" ORDER BY a.id DESC"); try { Session ssn = getSession(); Query q = ssn.createQuery(hql.toString()); q.setInteger("status", DiaryBean.STATUS_NORMAL); q.setInteger("site", site.getId()); if (user == null || site.getOwner().getId() != user.getId()) { q.setInteger("cat_type", CatalogBean.TYPE_OWNER); if (user != null) { q.setInteger("user", user.getId()); } } if (catalog_id > 0) { q.setInteger("catalog", catalog_id); } if (year > 0 || month > 0 || date > 0) { Calendar[] cals = genTimeParams(year, month, date); q.setTimestamp("beginTime", cals[0].getTime()); q.setTimestamp("endTime", cals[1].getTime()); } if (fromIdx > 0) q.setFirstResult(fromIdx); if (count > 0) q.setMaxResults(count); return q.list(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.DiaryDAO.java
License:Open Source License
/** * /*from ww w. ja v a2 s. c o m*/ * * @param site * @param user * @param fromIdx * @param count * @return */ public static List listDiaryReplies(SiteBean site, int fromIdx, int count, SessionUserObject user) { StringBuffer hql = new StringBuffer( "FROM DiaryReplyBean AS r WHERE r.status=:status AND r.site.id=:site AND r.diary.status=:diary_status"); if (!site.isOwner(user)) { // hql.append(" AND (r.diary.catalog.type<>:cat_type"); if (user != null) hql.append( " OR (r.diary.catalog.type=:cat_type AND r.diary.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:userid))"); hql.append(')'); 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.setInteger("status", DiaryReplyBean.STATUS_NORMAL); q.setInteger("site", site.getId()); q.setInteger("diary_status", DiaryOutlineBean.STATUS_NORMAL); if (!site.isOwner(user)) { q.setInteger("cat_type", CatalogBean.TYPE_OWNER); 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.PhotoDAO.java
License:Open Source License
/** * //from w w w.j av a2 s. c om * * @param site * @param user * @param album_id * @param month_stamp * ,20050620056 * @param fromIdx * @param count * @return * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#list_photos(SiteBean, * int, int) */ public static List listPhotos(SiteBean site, SessionUserObject user, int album_id, int month_stamp, int date, int fromIdx, int count) { StringBuffer hql = new StringBuffer("FROM PhotoOutlineBean AS p WHERE p.site.id=:site"); if (album_id > 0) hql.append(" AND (p.album.id=:album OR p.album.parent.id=:album)"); if (month_stamp > 190000 && month_stamp < 209912) { hql.append(" AND p.year=:year AND p.month=:month"); } if (user == null || site.getOwner().getId() != user.getId()) { hql.append(" AND p.status<>:hidden_status AND p.album.type=:owner_album"); } if (date > 0) { hql.append(" AND p.date=:date"); } hql.append(" ORDER BY p.id DESC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger("site", site.getId()); if (album_id > 0) q.setInteger("album", album_id); if (month_stamp > 190000 && month_stamp < 209912) { q.setInteger("year", month_stamp / 100); q.setInteger("month", month_stamp % 100); } if (user == null || site.getOwner().getId() != user.getId()) { q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE); q.setInteger("owner_album", AlbumBean.TYPE_PUBLIC); } if (date > 0) { q.setInteger("date", date); } q.setFirstResult(fromIdx); q.setMaxResults(count); return q.list(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * /*w w w. j a v a 2 s . c o m*/ * * @param album * @param fromIdx * @param count * @return */ public static List listPhotos(AlbumBean album, int fromIdx, int count) { Query q = getSession().getNamedQuery("PHOTOS_OF_ALBUM"); q.setInteger("album", album.getId()); // q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE); if (fromIdx > 0) q.setFirstResult(fromIdx); if (count > 0) q.setMaxResults(count); return q.list(); }
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * //from w ww. j ava2 s . co m * * @param site * @param user * @param album_id * @param month_stamp * ,20050620056 * @param fromIdx * @param count * @return * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#list_photos(SiteBean, * int, int) */ public static List listPhotos(int album_id, int month_stamp, int date, int fromIdx, int count) { StringBuffer hql = new StringBuffer("FROM PhotoOutlineBean AS p WHERE 1=1"); if (album_id > 0) hql.append(" AND (p.album.id=:album OR p.album.parent.id=:album)"); else { // hql.append(" AND (TO_DAYS(NOW()) - TO_DAYS(p.site.createTime) > // 2)"); } if (month_stamp > 190000 && month_stamp < 209912) { hql.append(" AND p.year=:year AND p.month=:month"); } hql.append(" AND p.status<>:hidden_status AND p.album.type=:owner_album"); if (date > 0) { hql.append(" AND p.date=:date"); } hql.append(" AND p.site.status=:site_status ORDER BY p.id DESC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setCacheable(true).setCacheRegion("query.new_photos"); if (album_id > 0) q.setInteger("album", album_id); if (month_stamp > 190000 && month_stamp < 209912) { q.setInteger("year", month_stamp / 100); q.setInteger("month", month_stamp % 100); } q.setInteger("hidden_status", PhotoBean.STATUS_PRIVATE); q.setInteger("owner_album", AlbumBean.TYPE_PUBLIC); if (date > 0) { q.setInteger("date", date); } q.setInteger("site_status", SiteBean.STATUS_NORMAL); q.setFirstResult(fromIdx); q.setMaxResults(count); return q.list(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * // ww w. ja v a 2 s .co 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
/** * //from w w w . j av a 2 s.co m * * @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
/** * //from www. j ava 2 s . c om * * @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) {//from w w w. j a va 2s . co 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) {//from ww w .j a v a 2s. c o m 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; }