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.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByInviter(long id, User user) {
    Session session = getSession();/*from  w w w .ja v a 2  s  .  com*/
    Query query = session.getNamedQuery("Friend.getByInviter");
    query.setLong("id", id);
    query.setEntity("user", user);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static int getInviteCount(User user) {
    Session session = getSession();/*from w ww  .  j a  va2s  .  c  o  m*/
    Query query = session.getNamedQuery("Friend.getInviteCount");
    query.setString("email", user.getPrimaryEmail());
    return (Integer) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByUser(User user, User friend) {
    Session session = getSession();/*from  ww  w . j  a v  a2s.  co  m*/
    Query query = session.getNamedQuery("Friend.getByUser");
    query.setEntity("inviter", user);
    query.setEntity("invitee", friend);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Rating.java

License:Apache License

public static Rating findProgramRating(User user, String programId) {
    Permissions.checkUser(user);/*from   w ww. j  a  v a 2  s  .  c om*/
    Session session = getSession();
    Query query = session.getNamedQuery("Rating.getProgram");
    query.setEntity("user", user);
    query.setString("programId", programId);
    return (Rating) query.uniqueResult();
}

From source file:com.appeligo.search.entity.ToNotify.java

License:Apache License

/**
 * //from w w w  .  ja  v a2 s. c  om
 * @param email
 * @return
 */
public static ToNotify findByEmail(String email) {
    Session session = getSession();
    Query query = session.getNamedQuery("ToNotify.findByEmail");
    query.setString("email", email);
    return (ToNotify) query.uniqueResult();
}

From source file:com.appeligo.search.entity.User.java

License:Apache License

/**
 * /*  w  w  w  . j  a v  a2 s.co m*/
 * @param username
 * @return
 */
@SuppressWarnings("unchecked")
public static User findByUsernameAndSecret(String username, String registrationSecret) {
    Session session = getSession();
    Query query = session.getNamedQuery("User.findByUsernameAndRegistrationSecret");
    query.setString("username", username);
    query.setString("registrationSecret", registrationSecret);
    if (log.isInfoEnabled()) {
        log.info("Attempting to load user by " + username + " and " + registrationSecret);
    }
    User user = (User) query.uniqueResult();
    return user;
}

From source file:com.aptech.model.AbstractDao.java

public Integer count(Class clazz) {
    Long size = null;//w  w w  .j a v  a 2 s .  c  o  m
    try {
        startOperation();
        Query query = session.createQuery("select count(*) from " + clazz.getName());
        size = (Long) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return size.intValue();
}

From source file:com.aptech.model.ProductDao.java

public Integer count() {
    Long size = null;/*from w  w  w.j av a  2  s  .c o  m*/
    startOperation2();
    try {
        Query query = session.createQuery("select count(*) from " + Product.class.getName());
        size = (Long) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return size.intValue();
}

From source file:com.aptech.model.ProductDao.java

public Integer countWithCategoryId(Integer catId) {
    Long size = null;//from   www .j  av a2 s  . c  o m
    startOperation2();
    try {
        Query query = session.createQuery(
                "select count(*) from " + Product.class.getName() + " p where p.category.id = " + catId);
        size = (Long) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return size.intValue();
}

From source file:com.asociate.dao.AsociacionDAO.java

/**
 *
 * @param value/*from  w  w w .  ja  va2s . co  m*/
 * @return
 */
public boolean comprobarCIF(String value) {
    boolean existe = false;
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Query qu = sesion.createQuery("Select A.cif from Asociacion A where A.cif=:cif").setString("cif", value);
    Object salida = qu.uniqueResult();

    if (salida != null) {
        existe = true;
    }
    sesion.flush();
    sesion.close();

    return existe;
}