Example usage for javax.persistence TypedQuery getSingleResult

List of usage examples for javax.persistence TypedQuery getSingleResult

Introduction

In this page you can find the example usage for javax.persistence TypedQuery getSingleResult.

Prototype

X getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single result.

Usage

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param Id//from   w ww. java 2  s .c om
 * @return
 */
public Object getUserPasswordbyId(Long Id) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n.password FROM NewMember n WHERE n.id = :Id",
            NewMember.class);
    q.setParameter("Id", Id);
    return q.getSingleResult();
}

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param Id/*w w  w  .j a v  a  2 s . co  m*/
 * @return
 */
public Object getUserRolebyId(Long Id) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n.has_role FROM NewMember n WHERE n.id = :Id",
            NewMember.class);
    q.setParameter("Id", Id);
    return q.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllMatchesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllMatchesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:net.nan21.dnet.core.business.service.entity.AbstractEntityReadService.java

/**
 * Find an entity of the given type, using as filter criteria the specified
 * list of attribute values. The filter criteria must uniquely identify an
 * entity./*from   w w w .  j  av a  2s  . c om*/
 * 
 * @param entityClass
 * @param params
 * @return
 * @throws BusinessException
 */
public <T> T findEntityByAttributes(Class<T> entityClass, Map<String, Object> params) {
    CriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();
    CriteriaQuery<T> cq = cb.createQuery(entityClass);
    Root<T> root = cq.from(entityClass);
    cq.select(root);
    Assert.notNull(params);
    Predicate p = null;
    if (entityClass.isAssignableFrom(IModelWithClientId.class)) {
        p = cb.equal(root.get("clientId"), Session.user.get().getClient().getId());
    }
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        p = cb.and(cb.equal(root.get(entry.getKey()), entry.getValue()));
    }
    cq.where(p);
    TypedQuery<T> query = this.getEntityManager().createQuery(cq);
    return (T) query.getSingleResult();
}

From source file:org.jboss.quickstarts.wfk.contact.ContactRepository.java

/**
 * Find just one Contact by the email that is passed in. If there is more then one, only the first will be returned.
 * //w ww . j av a2  s .  c  o m
 * @param email
 * @return Contact
 */
Contact findByEmail(String email) {
    TypedQuery<Contact> query = em.createNamedQuery(Contact.FIND_BY_EMAIL, Contact.class).setParameter("email",
            email);
    Contact contact = query.getSingleResult();
    return contact;
}

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param Id/* ww w . j a v a 2  s  . com*/
 * @return
 */
public Object getUserSigningDatebyId(Long Id) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n.signingDate FROM NewMember n WHERE n.id = :Id",
            NewMember.class);
    q.setParameter("Id", Id);
    return q.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedWinsForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:org.openmeetings.app.data.user.dao.UserSipDataDaoImpl.java

public UserSipData getUserSipDataById(Long userSipDataId) {
    try {/*from  w w w . j  a  v a  2s.  co m*/

        if (userSipDataId == null) {
            return null;
        }

        String hql = "select c from UserSipData as c where c.userSipDataId = :userSipDataId";

        TypedQuery<UserSipData> query = em.createQuery(hql, UserSipData.class);
        query.setParameter("userSipDataId", userSipDataId);
        UserSipData userSipData = null;
        try {
            userSipData = query.getSingleResult();
        } catch (NoResultException ex) {
        }

        return userSipData;
    } catch (Exception ex2) {
        log.error("getUserSipDataById", ex2);
    }
    return null;
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedLosesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedLosesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllUnrankedWinsForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}