List of usage examples for org.hibernate.criterion DetachedCriteria setProjection
public DetachedCriteria setProjection(Projection projection)
From source file:org.encuestame.persistence.dao.imp.CommentDao.java
License:Apache License
public Long getTotalCommentsbyItem(final Long id, final TypeSearchResult itemType, final CommentOptions commentOptions, final SearchPeriods period) { final DetachedCriteria criteria = DetachedCriteria.forClass(Comment.class); criteria.setProjection(Projections.rowCount()); if (itemType.equals(TypeSearchResult.TWEETPOLL)) { criteria.createAlias("tweetPoll", "tweetPoll"); criteria.add(Restrictions.eq("tweetPoll.tweetPollId", id)); } else if (itemType.equals(TypeSearchResult.POLL)) { criteria.createAlias("poll", "poll"); criteria.add(Restrictions.eq("poll.pollId", id)); } else if (itemType.equals(TypeSearchResult.SURVEY)) { criteria.createAlias("survey", "survey"); criteria.add(Restrictions.eq("survey.sid", id)); } else {/*from w w w . ja v a 2s . com*/ log.error(" Search result type undefined " + itemType); } if (!commentOptions.equals(CommentOptions.ALL)) { criteria.add(Restrictions.eq("commentOptions", commentOptions)); } if (period != null) { calculateSearchPeriodsDates(period, criteria, "createdAt"); } @SuppressWarnings("unchecked") List<Comment> results = (List<Comment>) getHibernateTemplate().findByCriteria(criteria); log.trace("Retrieve total comments by " + itemType + "--->" + results.size()); return (Long) (results.get(0) == null ? 0 : results.get(0)); }
From source file:org.encuestame.persistence.dao.imp.CommentDao.java
License:Apache License
public Long getTotalCommentsbyTypeAndStatus(final TypeSearchResult itemType, final CommentOptions commentOptions, final SearchPeriods period) { final DetachedCriteria criteria = DetachedCriteria.forClass(Comment.class); criteria.setProjection(Projections.rowCount()); if (itemType.equals(TypeSearchResult.TWEETPOLL)) { criteria.createAlias("tweetPoll", "tweetPoll"); criteria.add(Restrictions.isNotNull("tweetPoll")); } else if (itemType.equals(TypeSearchResult.POLL)) { criteria.createAlias("poll", "poll"); criteria.add(Restrictions.isNotNull("poll")); } else if (itemType.equals(TypeSearchResult.SURVEY)) { criteria.createAlias("survey", "survey"); criteria.add(Restrictions.isNotNull("survey")); } else {//from w ww.j a v a 2s . c o m log.error(" Search result type undefined " + itemType); } if (!commentOptions.equals(CommentOptions.ALL)) { criteria.add(Restrictions.eq("commentOptions", commentOptions)); } if (period != null) { calculateSearchPeriodsDates(period, criteria, "createdAt"); } @SuppressWarnings("unchecked") List<Comment> results = (List<Comment>) getHibernateTemplate().findByCriteria(criteria); log.trace("Retrieve total comments by " + itemType + "--->" + 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
public final Long getTotalHitsbyType(final Long id, final TypeSearchResult searchHitby, final Integer period) { Date startDate = null;/*from w w w .j a va 2 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> getHashTagHitsRange(final Long tagId, final SearchPeriods period) { final DetachedCriteria criteria = DetachedCriteria.forClass(Hit.class); criteria.createAlias("hashTag", "hashTag"); criteria.add(Restrictions.eq("hashTag.hashTagId", tagId)); criteria.addOrder(Order.desc("hitDate")); // define as a VISIT category criteria.add(Restrictions.eq("hitCategory", HitCategory.VISIT)); ProjectionList projList = Projections.projectionList(); projList.add(Projections.groupProperty("hitDate")); projList.add(Projections.rowCount()); criteria.setProjection(projList); return (List<Hit>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.HashTagDao.java
License:Apache License
public Date getMaxHashTagRankingDate() { DetachedCriteria criteria = DetachedCriteria.forClass(HashTagRanking.class); criteria.setProjection(Projections.max("rankingDate")); @SuppressWarnings("unchecked") List<HashTagRanking> results = (List<HashTagRanking>) getHibernateTemplate().findByCriteria(criteria); return (Date) (results.get(0) == null ? new Date() : results.get(0)); }
From source file:org.encuestame.persistence.dao.imp.HashTagDao.java
License:Apache License
/** * Get max-min tag frecuency./*from www . ja va 2 s . c o m*/ * * @param tag * @param filter * @return */ @SuppressWarnings("unchecked") public List<Object[]> getMaxMinTagFrecuency() { final DetachedCriteria criteria = DetachedCriteria.forClass(HashTag.class); ProjectionList projectList = Projections.projectionList(); projectList.add(Projections.max("hits")); projectList.add(Projections.min("hits")); criteria.setProjection(projectList); return (List<Object[]>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.NotificationDao.java
License:Apache License
/** * Retrieve Notification Status/*w ww . jav a 2s. c o m*/ * @param secUser * @return */ public final Long retrieveTotalNotificationStatus(final Account secUser) { final DetachedCriteria criteria = DetachedCriteria.forClass(Notification.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("account", secUser)); @SuppressWarnings("unchecked") final List<Notification> results = (List<Notification>) getHibernateTemplate().findByCriteria(criteria); log.debug("retrieveTotalNotReadedNotificationStatus " + results.size()); return (Long) (results.get(0) == null ? 0 : results.get(0)); //return retrieveCountNotification(secUser, "select count(*) from Notification WHERE account = :secUser"); }
From source file:org.encuestame.persistence.dao.imp.NotificationDao.java
License:Apache License
/** * Retrieve total not readed notification status. * @param user {@link UserAccount}./*from w ww.ja va 2 s .c o m*/ * @return total not readed notification. */ @SuppressWarnings("unchecked") public final Long retrieveTotalNotReadedNotificationStatus(final Account user) { final DetachedCriteria crit = DetachedCriteria.forClass(Notification.class); crit.setProjection(Projections.rowCount()); crit.add(Restrictions.eq("readed", Boolean.FALSE)); final List<Notification> results = (List<Notification>) getHibernateTemplate().findByCriteria(crit); log.debug("retrieveTotalNotReadedNotificationStatus " + results.size()); 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<Object[]> getPollsRangeStats(final String tagName, final SearchPeriods period) { final DetachedCriteria detached = DetachedCriteria.forClass(Poll.class).createAlias("hashTags", "hashTags") .setProjection(Projections.id()) .add(Subqueries.propertyIn("hashTags.hashTagId", DetachedCriteria.forClass(HashTag.class, "hash").setProjection(Projections.id()) .add(Restrictions.in("hash.hashTag", new String[] { tagName })))); final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class, "poll"); criteria.add(Subqueries.propertyIn("poll.pollId", detached)); criteria.addOrder(Order.desc("poll.createDate")); criteria.add(Restrictions.eq("publish", Boolean.TRUE)); calculateSearchPeriodsDates(period, criteria, "createDate"); ProjectionList projList = Projections.projectionList(); projList.add(Projections.groupProperty("createDate")); projList.add(Projections.rowCount()); criteria.setProjection(projList); return (List<Object[]>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.PollDao.java
License:Apache License
public Long getTotalVotesByPollIdAndDateRange(final Long pollId, final SearchPeriods period) { final DetachedCriteria criteria = DetachedCriteria.forClass(PollResult.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("poll.pollId", pollId)); if (period != null) { calculateSearchPeriodsDates(period, criteria, "votationDate"); }//from ww w. ja v a2 s .co m @SuppressWarnings("unchecked") List<PollResult> results = (List<PollResult>) getHibernateTemplate().findByCriteria(criteria); return (Long) (results.get(0) == null ? 0 : results.get(0)); }