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:net.navasoft.madcoin.backend.model.controller.helper.impl.JPAHelper.java

/**
 * Gets the quantity./*from w ww.  jav  a2 s  . co  m*/
 * 
 * @param dbAccess
 *            the db access
 * @param target
 *            the target
 * @return the quantity
 * @since 28/08/2014, 11:20:27 PM
 */
public int getQuantity(EntityManager dbAccess, Class<Entity> target) {
    CriteriaQuery<Long> cq = dbAccess.getCriteriaBuilder().createQuery(Long.class);
    Root<Entity> rt = cq.from(target);
    cq.select(dbAccess.getCriteriaBuilder().count(rt));
    Query q = dbAccess.createQuery(cq);
    return ((Long) q.getSingleResult()).intValue();
}

From source file:com.cimpoint.mes.server.repositories.StepStatusRepository.java

public EStepStatus findStepStatusByName(String stepStatusName) {
    try {//from   ww  w .j a v a 2s  .c  o  m
        Query qry = getEntityManager().createQuery("select o from EStepStatus o where o.name = ?1")
                .setParameter(1, stepStatusName).setMaxResults(1);
        EStepStatus step = (EStepStatus) qry.getSingleResult();
        return step;
    } catch (NoResultException ex) {
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:vlove.dao.impl.GenericDaoImpl.java

/**
 * @see vlove.dao.GenericDao#namedQuerySingle(String, Map)
 *///from w ww. j  a v a  2 s . com
@Override
public <T> T namedQuerySingle(String query, Map<String, Object> parameters) {
    Query q = em.createNamedQuery(query);
    applyParameters(q, parameters);
    try {
        return (T) q.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

@Override
public int countJobExecutions() {
    Query q = em.createNativeQuery("SELECT COUNT(1) from BATCH_JOB_EXECUTION");
    BigInteger count = (BigInteger) q.getSingleResult();
    return count.intValue();
}

From source file:pl.com.bottega.ecommerce.businessprocess.ordertracking.OrderShipmentStatusTrackerSagaManager.java

private OrderShipmentStatusTrackerData findByShipmentId(AggregateId shipmentId) {
    Query query = entityManager.createQuery("from OrderShipmentStatusTrackerData where shipmentId=:shipmentId")
            .setParameter("shipmentId", shipmentId);
    return (OrderShipmentStatusTrackerData) query.getSingleResult();
}

From source file:com.vizaco.onlinecontrol.dao.jpa.JpaStudentDaoImpl.java

@Override
public Student findById(String id) {
    Query query = this.em.createQuery(
            "SELECT DISTINCT student FROM Student student left join fetch student.users WHERE student.studentId =:id");
    query.setParameter("id", id);
    return (Student) query.getSingleResult();
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketCategoryDAOJpa.java

private long getNodeCount() {
    return (Long) this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query q = em.createQuery("SELECT COUNT(tc) FROM TicketCategory tc");
            return q.getSingleResult();
        }// w w  w  . j  a v  a  2s . com
    });
}

From source file:org.zkbase.dao.BasicDao.java

/**
 * @return a single object that satisfies the query.
 * @throws NoResultException/*  w  w  w . j  av  a  2  s.c  o m*/
 *             if there is no result
 * @throws NonUniqueResultException
 *             if more than one result
 * @throws IllegalStateException
 *             if called for a Java Persistence query language UPDATE or
 *             DELETE statement
 */
public Object findSingle(String queryString, Object... params) {
    Query query = entityManager.createQuery(queryString);
    setParameters(query, params);
    return query.getSingleResult();
}

From source file:DAO.MessagesDAOImpl.java

@Transactional(readOnly = true)
@Override/*from   w ww  .  j a  va 2 s . c  o  m*/
public MessagesEntity find(int id) {
    Query q = em.createQuery("SELECT m FROM MessagesEntity m where m.id = ?");
    q.setParameter(1, id);
    try {
        return (MessagesEntity) q.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:org.openwms.wms.receiving.ReceivingOrderDaoImpl.java

/**
 * {@inheritDoc}/*  w  w  w  . j a  va 2 s  .com*/
 */
@Override
public ReceivingOrderPosition findByKey(OrderPositionKey key) {
    Query query = em.createNamedQuery(ReceivingOrderPosition.NQ_FIND_POSITION_KEY);
    query.setParameter(ReceivingOrderPosition.QP_FIND_WITH_POSITION_KEY, key);
    return (ReceivingOrderPosition) query.getSingleResult();
}