Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Query uniqueResult.

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:com.bloatit.data.DaoKudosable.java

License:Open Source License

/**
 * Use a HQL query to find if a member as already kudosed this kudosable.
 * /*from www.j  a  va  2s  . c om*/
 * @param member The member that could have kudosed this kudosable. (Don't
 *            even think of passing a null member)
 * @return true if member has kudosed, false otherwise.
 */
public boolean hasKudosed(final DaoMember member) {
    final Query q = SessionManager.getNamedQuery("kudosable.getKudos.byMember.size");
    q.setEntity("member", member);
    q.setEntity("this", this);
    return (Long) q.uniqueResult() > 0;
}

From source file:com.bloatit.data.DaoKudosable.java

License:Open Source License

/**
 * Use a HQL query to find if a member as already kudosed this kudosable.
 * //from w  w w . j  a  v  a  2 s .  c  o m
 * @param member The member that could have kudosed this kudosable. (Don't
 *            even think of passing a null member)
 * @return true if member has kudosed, false otherwise.
 */
public int getVote(final DaoMember member) {
    final Query q = SessionManager.getNamedQuery("kudosable.getKudos.byMember.value");
    q.setEntity("member", member);
    q.setEntity("this", this);
    // return 0 if no vote
    final Integer vote = (Integer) q.uniqueResult();
    if (vote == null) {
        return 0;
    }
    return vote;
}

From source file:com.bloatit.data.DaoMember.java

License:Open Source License

/**
 * This method use a HQL request./*from www  . j  a va  2 s  .  c o  m*/
 *
 * @param email the email we are looking for.
 * @return true if found
 */
public static boolean emailExists(final String email) {
    final Query q1 = SessionManager.getNamedQuery("member.byEmail.size").setString("email", email);
    if (((Long) q1.uniqueResult()) > 0) {
        return true;
    }
    final Query q2 = SessionManager.getNamedQuery("member.byEmailToActivate.size").setString("emailToActivate",
            email);
    return ((Long) q2.uniqueResult()) > 0;
}

From source file:com.bloatit.data.DaoMember.java

License:Open Source License

/**
 * Finds a DaoMember using its email.//w w  w. j  a va 2  s.co  m
 *
 * @param email the email of the member
 * @return the member matching <code>email</code> or <i>null</i> if not
 *         found
 */
public static DaoMember getByEmail(final String email) {
    if (email == null) {
        return null;
    }

    final Query q = SessionManager.getNamedQuery("member.byEmail");
    q.setString("email", email);
    return (DaoMember) q.uniqueResult();

}

From source file:com.bloatit.data.DaoMember.java

License:Open Source License

public long getInvitationCount() {
    final Query q = SessionManager.getNamedQuery("member.invitationCount");
    q.setEntity("member", this);
    q.setParameter("state", State.PENDING);
    return (Long) q.uniqueResult();
}

From source file:com.bloatit.data.DaoMember.java

License:Open Source License

/**
 * Checks if is in team./*  w w  w  .  j  a  v  a2 s  .co  m*/
 *
 * @param team the team
 * @return if the current member is in the "team".
 */
public boolean isInTeam(final DaoTeam team) {
    final Query q = SessionManager.getNamedQuery("member.isInTeam");
    q.setEntity("member", this);
    q.setEntity("team", team);
    return ((Long) q.uniqueResult()) >= 1;
}

From source file:com.bloatit.data.DaoMilestone.java

License:Open Source License

public BigDecimal getAmountPaid() {
    final Query q = SessionManager.getNamedQuery("milestone.getAmountPaid");
    q.setEntity("this", this);
    final BigDecimal uniqueResult = (BigDecimal) q.uniqueResult();
    if (uniqueResult == null) {
        return BigDecimal.ZERO;
    }/*  www .  j a v a2 s.  c o m*/

    return uniqueResult;
}

From source file:com.bloatit.data.DaoMilestone.java

License:Open Source License

/**
 * Gets the released date.//from   w  w w  .j  a  v  a  2s.c o m
 * 
 * @return the releaseDate
 */
public Date getReleasedDate() {
    final Query query = SessionManager.createFilter(this.releases, "select max(creationDate)");
    return (Date) query.uniqueResult();
}

From source file:com.bloatit.data.DaoOffer.java

License:Open Source License

/**
 * @return tells if this offer has release.
 *///w ww  . j a va2  s.c  om
public boolean hasRelease() {
    final Query query = SessionManager.createFilter(this.milestones,
            "SELECT count(*) WHERE this.releases is not empty");
    return !((Long) query.uniqueResult()).equals(0L);
}

From source file:com.bloatit.data.DaoOffer.java

License:Open Source License

/**
 * @return the last release on this offer.
 *///from   w  ww. j a  v a2 s  .co  m
public DaoRelease getLastRelease() {
    final Query query = SessionManager.getNamedQuery("offer.getLastRelease").setEntity("this", this);
    return (DaoRelease) query.uniqueResult();
}