Example usage for org.springframework.dao.support DataAccessUtils uniqueResult

List of usage examples for org.springframework.dao.support DataAccessUtils uniqueResult

Introduction

In this page you can find the example usage for org.springframework.dao.support DataAccessUtils uniqueResult.

Prototype

@Nullable
public static <T> T uniqueResult(@Nullable Collection<T> results)
        throws IncorrectResultSizeDataAccessException 

Source Link

Document

Return a unique result object from the given Collection.

Usage

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

/**
 * Search By Param String {@link TweetPollSwitch}.
 *
 * @param param/*from  w w  w. jav  a  2s.  c  o m*/
 *            param
 * @param value
 *            value
 * @return
 */
private TweetPollSwitch searchByParamStringTweetPollSwitch(final String param, final String value) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPollSwitch.class);
    criteria.add(Restrictions.eq(param, value));
    return (TweetPollSwitch) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

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

public TweetPollSwitch getAnswerTweetSwitch(final TweetPoll tweetPoll, final QuestionAnswer questionAnswer) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPollSwitch.class);
    criteria.add(Restrictions.eq("tweetPoll", tweetPoll));
    criteria.add(Restrictions.eq("answers", questionAnswer));
    return (TweetPollSwitch) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

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

public TweetPollFolder getTweetPollFolderByIdandUser(final Long folderId, final Account account) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPollFolder.class);
    criteria.add(Restrictions.eq("users", account));
    criteria.add(Restrictions.eq("status", org.encuestame.utils.enums.Status.ACTIVE));
    criteria.add(Restrictions.eq("id", folderId));
    return (TweetPollFolder) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

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

public TweetPoll getTweetPollByIdandUserId(final Long tweetPollId, final Long userId) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class);
    criteria.add(Restrictions.eq("tweetOwner.uid", userId));
    criteria.add(Restrictions.eq("tweetPollId", tweetPollId));
    return (TweetPoll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

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

public TweetPoll getTweetPollByIdandSlugName(final Long tweetPollId, final String slugName)
        throws UnsupportedEncodingException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class);
    criteria.createAlias("question", "q");
    criteria.add(Restrictions.eq("tweetPollId", tweetPollId));
    criteria.add(Restrictions.eq("q.slugQuestion", RestFullUtil.encodeUTF8(slugName)));
    return (TweetPoll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

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

public TweetPoll checkIfTweetPollHasHashTag(final String tagName, final SearchPeriods periods,
        final Long tpoll) {
    final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class)
            .createAlias("hashTags", "hashTags").setProjection(Projections.id())
            .add(Restrictions.eq("tweetPoll.tweetPollId", tpoll))
            .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.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE));
    calculateSearchPeriodsDates(periods, detached, "createDate");
    return (TweetPoll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
}

From source file:org.jasig.portal.permission.dao.jpa.JpaPermissionOwnerDao.java

@Override
public IPermissionOwner getPermissionOwner(String fname) {
    final TypedQuery<PermissionOwnerImpl> query = this.createCachedQuery(this.findPermissionOwnerByFname);
    query.setParameter(this.fnameParameter, fname);

    final List<PermissionOwnerImpl> owners = query.getResultList();
    final IPermissionOwner owner = DataAccessUtils.uniqueResult(owners);
    return owner;

}

From source file:org.ojbc.adapters.analyticsstaging.custody.dao.AnalyticalDatastoreDAOImpl.java

@Override
public Integer getPersonIdByUniqueId(String uniqueId) {
    String sqlString = "SELECT top 1 PersonID FROM Person WHERE PersonUniqueIdentifier = ? order by PersonTimestamp desc";

    List<Integer> personIds = jdbcTemplate.queryForList(sqlString, Integer.class, uniqueId);

    return DataAccessUtils.uniqueResult(personIds);
}