List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.liusoft.dlog4j.dao.DiaryDAO.java
License:Open Source License
/** * ()/*from www . ja v a 2s . c om*/ * * @param site * @param user * @param cat_id * @param log_id * @return */ public static DiaryOutlineBean getPrevDiary(SiteBean site, SessionUserObject user, int cat_id, int log_id) { if (site == null) return null; StringBuffer hql = new StringBuffer( "FROM DiaryOutlineBean AS j WHERE j.site.id=:site AND j.status=:status AND j.id<:diary"); if (!site.isOwner(user)) { // hql.append(" AND (j.catalog.type<>:type"); if (user != null) hql.append( " OR (j.catalog.type=:type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))"); hql.append(')'); } if (cat_id > 0) { hql.append(" AND j.catalog.id=:catalog"); } hql.append(" ORDER BY j.id DESC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger("site", site.getId()); q.setInteger("status", DiaryBean.STATUS_NORMAL); q.setInteger("diary", log_id); if (cat_id > 0) q.setInteger("catalog", cat_id); if (!site.isOwner(user)) { q.setInteger("type", CatalogBean.TYPE_OWNER); if (user != null) q.setInteger("user", user.getId()); } q.setMaxResults(1); return (DiaryOutlineBean) q.uniqueResult(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.DiaryDAO.java
License:Open Source License
/** * ()/*www . j av a 2 s.co m*/ * * @param site * @param user * @param cat_id * @param log_id * @return */ public static DiaryOutlineBean getNextDiary(SiteBean site, SessionUserObject user, int cat_id, int log_id) { if (site == null) return null; StringBuffer hql = new StringBuffer( "FROM DiaryOutlineBean AS j WHERE j.site.id=:site AND j.status=:status AND j.id>:diary"); if (!site.isOwner(user)) { // hql.append(" AND (j.catalog.type<>:type"); if (user != null) hql.append( " OR (j.catalog.type=:type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))"); hql.append(')'); } if (cat_id > 0) { hql.append(" AND j.catalog.id=:catalog"); } hql.append(" ORDER BY j.id ASC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger("site", site.getId()); q.setInteger("status", DiaryBean.STATUS_NORMAL); q.setInteger("diary", log_id); if (cat_id > 0) q.setInteger("catalog", cat_id); if (!site.isOwner(user)) { q.setInteger("type", CatalogBean.TYPE_OWNER); if (user != null) q.setInteger("user", user.getId()); } q.setMaxResults(1); return (DiaryOutlineBean) q.uniqueResult(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.DiaryDAO.java
License:Open Source License
/** * /*from w w w . ja v a2s. c om*/ * * @param site * @param user * @param catalog_id * @param year * @param month * @param date * @param fromIdx * @param count * @return */ public static List listDiary(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"); // hql.append(" AND (a.catalog.type<>:cat_type)"); 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("cat_type", CatalogBean.TYPE_OWNER); 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
/** * //w w w. j ava 2s .c o 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
/** * //w w w . j a va 2 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 ava 2 s. co m * * @param site * @param user * @param album_id * @param photo_id * @return */ public static PhotoOutlineBean getPrevPhoto(SiteBean site, SessionUserObject user, int album_id, int photo_id) { if (site == null) return null; boolean is_owner = site.isOwner(user); StringBuffer hql = new StringBuffer( "FROM PhotoOutlineBean AS p WHERE p.status=:photo_status AND p.site.id=:site AND p.id<:photo"); if (!is_owner) { // hql.append(" AND p.album.type=:album_type"); } if (album_id > 0) { hql.append(" AND p.album.id=:album"); } hql.append(" ORDER BY p.id DESC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger("photo_status", PhotoBean.STATUS_NORMAL); q.setInteger("site", site.getId()); q.setInteger("photo", photo_id); if (album_id > 0) q.setInteger("album", album_id); if (!is_owner) q.setInteger("album_type", AlbumBean.TYPE_PUBLIC); q.setMaxResults(1); return (PhotoOutlineBean) q.uniqueResult(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * ()/*from w w w. j av a 2s .c o m*/ * * @param site * @param user * @param album_id * @param photo_id * @return */ public static PhotoOutlineBean getNextPhoto(SiteBean site, SessionUserObject user, int album_id, int photo_id) { if (site == null) return null; StringBuffer hql = new StringBuffer( "FROM PhotoOutlineBean AS p WHERE p.status=:photo_status AND p.site.id=:site AND p.id>:photo"); if (user == null || !site.isOwner(user)) { // hql.append(" AND p.album.type=:album_type"); } if (album_id > 0) { hql.append(" AND p.album.id=:album"); } hql.append(" ORDER BY p.id ASC"); Session ssn = getSession(); try { Query q = ssn.createQuery(hql.toString()); q.setInteger("photo_status", PhotoBean.STATUS_NORMAL); q.setInteger("site", site.getId()); q.setInteger("photo", photo_id); if (album_id > 0) q.setInteger("album", album_id); if (!site.isOwner(user)) q.setInteger("album_type", AlbumBean.TYPE_PUBLIC); q.setMaxResults(1); return (PhotoOutlineBean) q.uniqueResult(); } finally { hql = null; } }
From source file:com.liusoft.dlog4j.dao.PhotoDAO.java
License:Open Source License
/** * // w ww .j a v a2 s. c o 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(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
/** * /*from w w w.ja va 2s .c om*/ * * @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 w w . j a v a 2 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(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; } }