List of usage examples for org.hibernate.criterion Restrictions between
public static Criterion between(String propertyName, Object low, Object high)
From source file:org.encuestame.persistence.dao.imp.CommentDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Comment> getTopRatedComments(final CommentsSocialOptions socialOption, final Integer timeRange, final Integer maxResults, final Integer startResults) { final DetachedCriteria criteria = DetachedCriteria.forClass(Comment.class); log.debug("getTopRatedComments start date " + getCommentTimeRange(timeRange)); log.debug("getTopRatedComments end date " + getNextDayMidnightDate()); criteria.add(Restrictions.between("createdAt", getCommentTimeRange(timeRange), getNextDayMidnightDate())); if (socialOption != null) { if (socialOption.equals(CommentsSocialOptions.LIKE)) { criteria.addOrder(Order.desc("likeVote")); } else if (socialOption.equals(CommentsSocialOptions.DISLIKE)) { criteria.addOrder(Order.desc("dislikeVote")); } else {/*from w w w .j ava 2 s .c o m*/ criteria.addOrder(Order.desc("likeVote")); } } else { criteria.addOrder(Order.desc("likeVote")); } return (List<Comment>) filterByMaxorStart(criteria, maxResults, startResults); }
From source file:org.encuestame.persistence.dao.imp.FrontEndDao.java
License:Apache License
public final Long getTotalHitsbyType(final Long id, final TypeSearchResult searchHitby, final Integer period) { Date startDate = null;/*from w w w. jav a2 s . co m*/ Date endDate = null; if (period != null) { final DateTime dateTime = new DateTime(); endDate = dateTime.toDate(); startDate = DateUtil.minusDaysToCurrentDate(period, dateTime.toDate()); } final DetachedCriteria criteria = DetachedCriteria.forClass(Hit.class); criteria.setProjection(Projections.rowCount()); if (searchHitby.equals(TypeSearchResult.TWEETPOLL)) { criteria.createAlias("tweetPoll", "tweetPoll"); criteria.add(Restrictions.eq("tweetPoll.tweetPollId", id)); } else if (searchHitby.equals(TypeSearchResult.POLL)) { criteria.createAlias("poll", "poll"); criteria.add(Restrictions.eq("poll.pollId", id)); } else if (searchHitby.equals(TypeSearchResult.SURVEY)) { criteria.createAlias("survey", "survey"); criteria.add(Restrictions.eq("survey.sid", id)); } else if (searchHitby.equals(TypeSearchResult.HASHTAG)) { criteria.createAlias("hashTag", "hashTag"); criteria.add(Restrictions.eq("hashTag.hashTagId", id)); } else { log.error(" Search hit result type undefined " + searchHitby); } if (startDate != null && endDate != null) { criteria.add(Restrictions.between("hitDate", startDate, endDate)); } //define as a VISIT category criteria.add(Restrictions.eq("hitCategory", HitCategory.VISIT)); @SuppressWarnings("unchecked") List<Hit> results = (List<Hit>) getHibernateTemplate().findByCriteria(criteria); log.debug("Retrieve total hits by " + searchHitby + "--->" + results.size()); return (Long) (results.get(0) == null ? 0 : results.get(0)); }
From source file:org.encuestame.persistence.dao.imp.FrontEndDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Hit> getHashTagHitsbyDateRange(final Long tagId, final Integer period) { Date startDate = null;//from ww w . ja v a 2 s .c om Date endDate = null; if (period != null) { final Calendar hi = Calendar.getInstance(); hi.add(Calendar.DAY_OF_YEAR, -period); startDate = hi.getTime(); endDate = Calendar.getInstance().getTime(); } final DetachedCriteria criteria = DetachedCriteria.forClass(Hit.class); criteria.createAlias("hashTag", "hashTag"); criteria.add(Restrictions.eq("hashTag.hashTagId", tagId)); criteria.addOrder(Order.desc("hitDate")); criteria.add(Restrictions.between("hitDate", startDate, endDate)); //define as a VISIT category criteria.add(Restrictions.eq("hitCategory", HitCategory.VISIT)); return (List<Hit>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.NotificationDao.java
License:Apache License
@SuppressWarnings("unchecked") public final List<Notification> loadNotificationByDate(final Account user, final Integer limit, final Integer start, final Date startDate, final Date endDate, final Boolean onlyUnread) { final DetachedCriteria criteria = DetachedCriteria.forClass(Notification.class); criteria.add(Restrictions.or(Restrictions.eq("account", user), Restrictions.isNull("account"))); criteria.add(Restrictions.between("created", startDate, endDate)); criteria.addOrder(Order.desc("created")); return (List<Notification>) getHibernateTemplate().findByCriteria(criteria, start, limit); }
From source file:org.encuestame.persistence.dao.imp.PollDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Poll> getPollByUserIdDate(final Date date, final UserAccount userAcc, final Integer maxResults, final Integer start) { final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class); criteria.add(Restrictions.eq("editorOwner", userAcc)); criteria.add(Restrictions.eq("isHidden", Boolean.FALSE)); if (date != null) { criteria.add(Restrictions.between("createDate", date, getNextDayMidnightDate())); }// w ww .j a v a 2 s . c o m return (List<Poll>) filterByMaxorStart(criteria, maxResults, start); }
From source file:org.encuestame.persistence.dao.imp.PollDao.java
License:Apache License
public Long getMaxPollLikeVotesbyUser(final Long userId, final Date dateFrom, final Date dateTo) { DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class); criteria.setProjection(Projections.max("likeVote")); criteria.createAlias("editorOwner", "editorOwner"); criteria.add(Restrictions.eq("editorOwner.uid", userId)); criteria.add(Restrictions.between("createDate", dateFrom, dateTo)); @SuppressWarnings("unchecked") List<Poll> results = (List<Poll>) getHibernateTemplate().findByCriteria(criteria); return (Long) (results.get(0) == null ? 0 : results.get(0)); }
From source file:org.encuestame.persistence.dao.imp.PollDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Poll> retrievePollByDate(final Account owner, final Date initDate, final Date endDate, final Integer maxResults, final Integer start) { final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class); criteria.add(Restrictions.between("createDate", initDate, endDate)); criteria.add(Restrictions.eq("owner", owner)); return (List<Poll>) filterByMaxorStart(criteria, maxResults, start); }
From source file:org.encuestame.persistence.dao.imp.PollDao.java
License:Apache License
public List<Poll> retrievePollByDate(final PollSearchBean bean, final Long userId, final Date initDate) { final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class); criteria.createAlias("owner", "owner"); criteria.add(Restrictions.eq("owner.id", userId)); criteria.add(Restrictions.between("createDate", initDate, getNextDayMidnightDate())); return useAvancedSearch(criteria, bean); }
From source file:org.encuestame.persistence.dao.imp.ScheduleDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Schedule> retrieveScheduled(final Status status, final Date minimumDate) { final DetachedCriteria criteria = DetachedCriteria.forClass(Schedule.class); // Between Minimun date and currently date criteria.add(Restrictions.between("scheduleDate", minimumDate, DateUtil.getCurrentCalendarDate())); criteria.add(Restrictions.eq("status", status)); return (List<Schedule>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java
License:Apache License
@SuppressWarnings("unchecked") public List<Survey> retrieveSurveyByDate(final Account account, final Date initDate, final Integer maxResults, final Integer start) { final DetachedCriteria criteria = DetachedCriteria.forClass(Survey.class); criteria.createAlias("owner", "owner"); criteria.add(Restrictions.between("createDate", initDate, getNextDayMidnightDate())); criteria.add(Restrictions.eq("owner", account)); return (List<Survey>) filterByMaxorStart(criteria, maxResults, start); }