Example usage for org.hibernate.criterion DetachedCriteria addOrder

List of usage examples for org.hibernate.criterion DetachedCriteria addOrder

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria addOrder.

Prototype

public DetachedCriteria addOrder(Order order) 

Source Link

Document

Adds an ordering

Usage

From source file:org.encuestame.persistence.dao.imp.PollDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Poll> getPolls(final Integer maxResults, final Integer start, final SearchPeriods range) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(Poll.class);
    criteria.add(Restrictions.eq("publish", Boolean.TRUE));
    if (range != null) {
        //  criteria.add(Restrictions.gt("createdAt", range));
        calculateSearchPeriodsDates(range, criteria, "createDate");
    }//w w w  . j a v  a 2 s.c  o  m
    criteria.addOrder(Order.desc("createDate"));
    return (List<Poll>) filterByMaxorStart(criteria, maxResults, start);
}

From source file:org.encuestame.persistence.dao.imp.PollDao.java

License:Apache License

/**
 *
 * @param property//from w w  w  .java2  s.  c  om
 * @param property_value
 * @param itemId
 * @param criteria
 * @param isCompleted
 * @param isScheduled
 * @param isFavourite
 * @param isPublished
 * @param keyword
 * @param period
 */
public void criteriaAdvancedSearch(final String property, final String property_value, final Object itemId,
        final DetachedCriteria criteria, final Boolean isCompleted, final Boolean isScheduled,
        final Boolean isFavourite, final Boolean isPublished, final Boolean isHidden,
        final Boolean isPasswordProtected, final String keyword, final String period) {
    // criteria.add(Restrictions.eq("editorOwner.uid", userId)); -- POLL
    criteria.createAlias(property, property);
    criteria.add(Restrictions.eq(property + "." + property_value, itemId));
    criteria.addOrder(Order.desc("createDate"));
    this.advancedPollSearchOptions(criteria, isCompleted, isScheduled, isFavourite, isPublished, isHidden,
            isPasswordProtected, keyword, period);
}

From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Survey> retrieveSurveyByUserId(final Long userId, final Integer maxResults, final Integer start) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(Survey.class);
    criteria.createAlias("editorOwner", "editorOwner");
    criteria.add(Restrictions.eq("editorOwner.uid", userId));
    criteria.addOrder(Order.desc("createDate"));
    return (List<Survey>) filterByMaxorStart(criteria, maxResults, start);
}

From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Survey> retrieveSurveyByAccount(final Long userId, final Integer maxResults, final Integer start) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(Survey.class);
    criteria.createAlias("owner", "owner");
    criteria.add(Restrictions.eq("owner.uid", userId));
    criteria.addOrder(Order.desc("createDate"));
    return (List<Survey>) filterByMaxorStart(criteria, maxResults, start);
}

From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Survey> getSurveysByHashTagName(final String tagName, final Integer startResults,
        final Integer limitResults, final TypeSearchResult filterby, final SearchPeriods searchPeriods) {
    final DetachedCriteria detached = DetachedCriteria.forClass(Survey.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(Survey.class, "survey");
    criteria.add(Subqueries.propertyIn("survey.sid", detached));
    if (filterby.equals(TypeSearchResult.HASHTAG)) {
        criteria.addOrder(Order.desc("survey.createDate"));
    } else if (filterby.equals(TypeSearchResult.HASHTAGRATED)) {
        criteria.addOrder(Order.desc("numbervotes"));
    }// ww  w.  j  a v a 2s  .  co  m
    calculateSearchPeriodsDates(searchPeriods, detached, "createDate");
    return (List<Survey>) filterByMaxorStart(criteria, limitResults, startResults);
}

From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Survey> getSurveysbyHashTagNameAndDateRange(final String tagName, final SearchPeriods period) {
    final DetachedCriteria detached = DetachedCriteria.forClass(Survey.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(Survey.class, "survey");
    criteria.add(Subqueries.propertyIn("survey.sid", detached));
    criteria.addOrder(Order.desc("survey.createDate"));
    calculateSearchPeriodsDates(period, criteria, "survey.createDate");
    return (List<Survey>) getHibernateTemplate().findByCriteria(criteria);
}

From source file:org.encuestame.persistence.dao.imp.SurveyDaoImp.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Object[]> getSurveysRangeStats(final String tagName, final SearchPeriods period) {
    final DetachedCriteria detached = DetachedCriteria.forClass(Survey.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(Survey.class, "survey");
    criteria.add(Subqueries.propertyIn("survey.sid", detached));
    criteria.addOrder(Order.desc("survey.createDate"));
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.groupProperty("createDate"));
    projList.add(Projections.rowCount());
    criteria.setProjection(projList);/*w  w w.  j a  v  a2s  .  c o  m*/
    return (List<Object[]>) getHibernateTemplate().findByCriteria(criteria);
}

From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java

License:Apache License

/**
 * Retrieve Tweets Poll by User Id.//w w  w  .j  a va 2  s .c om
 *
 * @param userId
 *            userId
 * @return list of tweet pools.
 */
@SuppressWarnings("unchecked")
public List<TweetPoll> retrieveTweetsByUserId(final String keyWord, final Long userId, final Integer maxResults,
        final Integer start, final Boolean isCompleted, final Boolean isScheduled, final Boolean isPublished,
        final Boolean isFavourite, final String period) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class);
    criteria.createAlias("tweetOwner", "tweetOwner");
    // removed because is the advancedSearchOptions should inject this value
    // criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE));
    criteria.add(Restrictions.eq("tweetOwner.id", userId));
    criteria.addOrder(Order.desc("createDate"));
    advancedTweetPollSearchOptions(criteria, isCompleted, isScheduled, isFavourite, isPublished, keyWord,
            period);
    return (List<TweetPoll>) filterByMaxorStart(criteria, maxResults, start);
}

From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<TweetPoll> getTweetpollByHashTagName(final String tagName, final Integer startResults,
        final Integer limitResults, final TypeSearchResult filterby, final SearchPeriods periods) {
    final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.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(TweetPoll.class, "tweetPoll");
    criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached));
    //if filters are defined.
    if (filterby != null) {
        if (filterby.equals(TypeSearchResult.HASHTAG)) {
            criteria.addOrder(Order.desc("tweetPoll.createDate"));
        } else if (filterby.equals(TypeSearchResult.HASHTAGRATED)) {
            criteria.addOrder(Order.desc("numbervotes"));
        }/*from  w  w w  .  j a  v  a 2s  . co  m*/
    }
    criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE));
    calculateSearchPeriodsDates(periods, detached, "createDate");
    return (List<TweetPoll>) filterByMaxorStart(criteria, limitResults, startResults);
}

From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java

License:Apache License

@SuppressWarnings("unchecked")
//FUTURE: this method return a List<Object[]> instead List<TweetPoll>
public List<TweetPoll> getTweetPollsbyHashTagNameAndDateRange(final String tagName,
        final SearchPeriods period) {
    final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.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(TweetPoll.class, "tweetPoll");
    criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached));
    criteria.addOrder(Order.desc("tweetPoll.createDate"));
    criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE));
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.groupProperty("createDate"));
    projList.add(Projections.rowCount());
    criteria.setProjection(projList);/*from www .ja  v  a 2s  .c o  m*/
    // calculateSearchPeriodsDates(period, criteria, "createDate");

    return (List<TweetPoll>) getHibernateTemplate().findByCriteria(criteria);
}