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:com.webbfontaine.valuewebb.model.util.TTUtils.java

/**
 * @return null if entity not found, true if TT is frozen, false otherwize
 *//*w w  w .  j  a  va2s.c  o  m*/
public static Boolean isTTFreezed(long id) {
    Query query = Utils.getEntityManager().createQuery("SELECT frozen FROM TtGen tt WHERE tt.id = :id");
    query.setParameter("id", id);
    query.setHint("org.hibernate.cacheMode", CacheMode.IGNORE);
    return (Boolean) query.getSingleResult();
}

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

static ApplicationEntity getApplicationEntity(String realm, EntityManager em) {
    Query query = null;
    query = em.createQuery("select a from Application a where a.realm=:realm");
    query.setParameter("realm", realm);

    //@SuppressWarnings("rawtypes")
    return (ApplicationEntity) query.getSingleResult();
}

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

static IdpEntity getIdpEntity(String realm, EntityManager em) {
    Query query = null;
    query = em.createQuery("select i from IDP i where i.realm=:realm");
    query.setParameter("realm", realm);

    //@SuppressWarnings("rawtypes")
    return (IdpEntity) query.getSingleResult();
}

From source file:models.SkillTag.java

public static Page<SkillTagListVo> listTagByCate(Long cateId, Integer page, Integer start, Integer limit,
        String searchText) {/* w w w . java 2  s.co m*/
    String hql1 = "select count(s) from SkillTag s where s.industryId=? and s.id<>?";
    if (searchText != null && !"".equals(searchText)) {
        hql1 += " and (s.tagName like ? or s.tagNameEn like ?)";
    }
    Query query1 = JPA.em().createQuery(hql1);
    query1.setParameter(1, cateId);
    query1.setParameter(2, cateId);
    if (searchText != null && !"".equals(searchText)) {
        query1.setParameter(3, "%" + searchText + "%");
        query1.setParameter(4, "%" + searchText + "%");
    }
    Long total = (Long) query1.getSingleResult();

    String hql2 = "from SkillTag s left join fetch s.industry where s.industryId=? and s.id<>?";
    if (searchText != null && !"".equals(searchText)) {
        hql2 += " and (s.tagName like ? or s.tagNameEn like ?)";
    }
    hql2 += " order by s.seq asc";

    Query query2 = JPA.em().createQuery(hql2);
    query2.setParameter(1, cateId);
    query2.setParameter(2, cateId);
    if (searchText != null && !"".equals(searchText)) {
        query2.setParameter(3, "%" + searchText + "%");
        query2.setParameter(4, "%" + searchText + "%");
    }

    List<SkillTag> skillTags = query2.setFirstResult(start).setMaxResults(limit).getResultList();
    Page<SkillTagListVo> p = new Page<SkillTagListVo>();
    p.setTotal(total);

    List<SkillTagListVo> sklvs = new ArrayList<SkillTagListVo>();
    for (SkillTag skillTag : skillTags) {
        SkillTagListVo sklv = new SkillTagListVo();
        sklv.setId(skillTag.id);
        if (skillTag.industry != null) {
            sklv.setIndustryId(skillTag.industry.id);
            sklv.setIndustryName(skillTag.industry.tagName);
        }
        sklv.setHits(skillTag.hits);
        sklv.setTagNameEn(skillTag.tagNameEn);
        sklv.setTagName(skillTag.tagName);
        sklv.setSeq(skillTag.seq);
        sklv.setTagType(skillTag.tagType);
        sklvs.add(sklv);
    }
    p.setData(sklvs);
    return p;
}

From source file:com.brienwheeler.lib.db.dao.NonDeletableDaoBase.java

@SuppressWarnings("unchecked")
protected <T> T getSingleResultOrNull(Query query) {
    try {//from   w w  w . j av  a 2  s . c o m
        return (T) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.juliuskrah.multipart.repository.impl.HibernateAccountRepository.java

@Override
public Optional<Account> findByUsername(String username) {
    CriteriaBuilder qb = this.em.getCriteriaBuilder();
    CriteriaQuery<Account> query = qb.createQuery(Account.class);
    Root<Account> root = query.from(Account.class);
    Predicate predicate = qb.like(root.get(Account_.username), username);
    query.where(predicate);//  w  w  w  .j a va 2s.com
    Query q = this.em.createQuery(query);

    return Optional.of((Account) q.getSingleResult());
}

From source file:fr.desbureaux.repository.ActivitiRepository.java

public String getActiveActiviti() {
    EntityManager em = this.entityManagerFactory.createEntityManager();
    try {/*from  w  ww.  j  a va 2s .  co  m*/
        Query query = em.createNativeQuery("select act_id_ from act_ru_execution");
        return (String) query.getSingleResult();
    } catch (NoResultException nre) {
        return "none";
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java

public int count() {
    javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
    javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
    cq.select(getEntityManager().getCriteriaBuilder().count(rt));
    javax.persistence.Query q = getEntityManager().createQuery(cq);
    return ((Long) q.getSingleResult()).intValue();
}

From source file:se.inera.intyg.intygstjanst.persistence.model.dao.impl.HealthCheckDaoImpl.java

@Override
public boolean checkTimeFromDb() {
    Time timestamp;//  ww w . j  a va  2s  .c o m
    try {
        Query query = entityManager.createNativeQuery(CURR_TIME_SQL);
        timestamp = (Time) query.getSingleResult();
    } catch (Exception e) {
        LOGGER.error("checkTimeFromDb failed with exception: " + e.getMessage());
        return false;
    }
    return timestamp != null;

}

From source file:pdsanchez.mywebtools.model.dao.jpa.GenericDAOJPAImpl.java

@Override
public int count() {
    javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
    javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
    cq.select(getEntityManager().getCriteriaBuilder().count(rt));
    javax.persistence.Query q = getEntityManager().createQuery(cq);
    return ((Long) q.getSingleResult()).intValue();
}