Example usage for javax.persistence Query getSingleResult

List of usage examples for javax.persistence Query getSingleResult

Introduction

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

Prototype

Object getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single untyped result.

Usage

From source file:es.ucm.fdi.dalgs.learningGoal.repository.LearningGoalRepository.java

public LearningGoal getLearningGoalByName(String name) {

    Query query = em.createQuery("SELECT l FROM LearningGoal l WHERE isDeleted = false AND l.name = ?1");
    query.setParameter(1, name);/*from   ww  w. j  a v  a  2  s .co m*/

    return (LearningGoal) query.getSingleResult();
}

From source file:org.kuali.mobility.push.dao.PreferenceDaoImpl.java

public Preference findPreference(Long id) {
    Query query = entityManager.createQuery("select p from Preference p where p.id = :id");
    query.setParameter("id", id);
    Preference result;//  w w  w.  j  a  v  a  2 s. com
    try {
        result = (Preference) query.getSingleResult();
    } catch (Exception e) {
        LOG.info("Exception: " + e.getMessage());
        result = null;
    }
    return result;

}

From source file:be.fedict.eid.applet.beta.SessionContextManagerBean.java

private SessionContextEntity getSessionContextEntity(String httpSessionId) {
    Query query = this.entityManager
            .createQuery("FROM SessionContextEntity AS sc WHERE sc.httpSessionId = :httpSessionId");
    query.setParameter("httpSessionId", httpSessionId);
    SessionContextEntity sessionContextEntity = (SessionContextEntity) query.getSingleResult();
    return sessionContextEntity;
}

From source file:com.xyz.framework.data.impl.JpaDao.java

/**
 * countHql.// www .j  av a  2s.co  m
 * 
 * ???jpaQl?,??jpaQl?count?.
 */
public int countJpaQlResult(final String jpaQl) {

    String sql = " select count(1) from " + entityClass.getName() + " e ";
    if (jpaQl != null && jpaQl.trim().length() > 0)
        sql += " where " + jpaQl;
    String countQl = sql;
    int oi = sql.indexOf("order");
    if (oi > 0)
        countQl = sql.substring(0, oi);

    if (countQl.trim().length() > 0) {
        Query query = entityManager.createQuery(countQl);
        return (Integer) query.getSingleResult();
    } else {
        return 0;
    }
}

From source file:de.iai.ilcd.model.dao.UserGroupDao.java

public Long getGroupsCount(Organization org) {
    if (org == null) {
        return null;
    }//  w  w w. j a  va2s.co m
    EntityManager em = PersistenceUtil.getEntityManager();

    try {
        Query q = em.createQuery(
                "SELECT COUNT(DISTINCT g) FROM UserGroup g WHERE g.organization.id = :orgId ORDER BY g.groupName");
        q.setParameter("orgId", org.getId());
        return (Long) q.getSingleResult();
    } catch (Exception e) {
        return null;
    }
}

From source file:cz.fi.muni.pa165.dao.PrintedBookDAOImpl.java

@Override
public PrintedBook find(PrintedBook t) {
    if (t == null) {
        throw new IllegalArgumentException("Printed Book null");
    }/*  ww  w . j  a va2s .c o  m*/

    try {
        final Query query = em.createQuery("SELECT m FROM PrintedBook as m WHERE m.idPrintedBook = :i");
        query.setParameter("i", t.getIdPrintedBook());
        return (PrintedBook) query.getSingleResult();
    } catch (RuntimeException E) {
        throw new DAException(E.getMessage());
    }
}

From source file:be.fedict.eid.pkira.blm.model.contracts.ContractRepositoryBean.java

@Override
public int countCertificatesByFilter(String userRrn, CertificatesFilter certificatesFilter) {
    StringBuilder queryString = new StringBuilder();

    queryString.append("SELECT COUNT(certificate) FROM ");
    appendFromAndWhere(certificatesFilter, queryString);

    Query query = entityManager.createQuery(queryString.toString());
    addQueryParameters(userRrn, certificatesFilter, query);

    return ((Long) query.getSingleResult()).intValue();
}

From source file:DAO.PersonnesStatutsDAOImpl.java

@Transactional(readOnly = true)
@Override/*from   w w w .  j  a v  a2  s.c  o m*/
public boolean exist(PersonnesEntity p, StatutsEntity s) {
    Query q = em.createQuery(
            "SELECT ps FROM PersonnesStatutsEntity ps WHERE ps.personne.id = ? AND ps.statut.id = ?");
    q.setParameter(1, p.getId());
    q.setParameter(2, s.getId());
    return q.getSingleResult() != null;
}

From source file:com.expressui.core.dao.security.UserDao.java

/**
 * Finds User by login name./* w w  w  .j  a  v  a2s. c om*/
 *
 * @param loginName login name to query
 * @return found user
 */
public User findByLoginName(String loginName) {
    Query query = getEntityManager().createQuery("SELECT u FROM User u "
            + " LEFT JOIN FETCH u.userRoles ur LEFT JOIN FETCH ur.role r LEFT JOIN FETCH r.permissions"
            + " WHERE u.loginName = :loginName");
    query.setParameter("loginName", loginName);

    return (User) query.getSingleResult();
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.ClaimDAOJPAImpl.java

@Override
public void updateClaim(String claimType, Claim claim) {
    Query query = null;
    query = em.createQuery("select c from Claim c where c.claimtype=:claimtype");
    query.setParameter("claimtype", claimType);

    //@SuppressWarnings("rawtypes")
    ClaimEntity claimEntity = (ClaimEntity) query.getSingleResult();

    domain2entity(claim, claimEntity);// w  w w . ja v a2 s  .  c  o  m

    LOG.debug("Claim '{}' added", claim.getClaimType());
    em.persist(claimEntity);
}