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:de.iai.ilcd.model.dao.ProcessDao.java

/**
 * Get count of processes for provided exchange flow and direction
 * //from   ww w.j  ava  2 s . c o m
 * @param flowUuid
 *            uuid of flow
 * @param direction
 *            direction of flow
 * @return count of processes for provided exchange flow and direction
 */
public long getProcessesForExchangeFlowCount(String flowUuid, ExchangeDirection direction) {
    Query q = this.getProcessesForExchangeFlowQuery(flowUuid, direction, true);
    return (Long) q.getSingleResult();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public FStoreUser readFStoreUserByUsername(String username) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    Query q = entityManager.createQuery("SELECT m FROM FStoreUser m WHERE m.username='" + username + "'");
    return (q.getResultList().size() == 0) ? null : (FStoreUser) q.getSingleResult();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public FStoreProperty readPropertyByName(String name) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM FStoreProperty m WHERE m.name='" + name + "'");
    return (q.getResultList().size() == 0) ? null : (FStoreProperty) q.getSingleResult();

}

From source file:com.sun.socialsite.business.impl.JPAGroupManagerImpl.java

public Group getGroupById(String id) throws SocialSiteException {
    if (id == null) {
        throw new SocialSiteException("id is null");
    }//w  w w .ja va 2s.c  o  m
    Query query = strategy.getNamedQuery("Group.getById");
    query.setParameter(1, id);
    try {
        return (Group) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public UserSession readUserBySessionId(String sessionId) {

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM UserSession m WHERE m.sessionId='" + sessionId + "'");
    return (q.getResultList().size() == 0) ? null : (UserSession) q.getSingleResult();

}

From source file:org.asqatasun.entity.dao.audit.ContentDAOImpl.java

@Override
public boolean hasAdaptedSSP(Audit audit) {
    Query query = entityManager.createQuery("SELECT count(s.id) FROM " + SSPImpl.class.getName() + " s"
            + " JOIN s.audit as a" + " WHERE a = :audit" + " AND s.dom != null " + " AND s.dom != '' ");
    query.setParameter(AUDIT_KEY, audit);
    return (Long) query.getSingleResult() > 0;
}

From source file:org.easyj.orm.jpa.JPAEntityDao.java

private Object getSingleResult(String query, Map<String, Object> params, String queryType) {
    Object o = null;/*from www.ja  va2s.c  o m*/
    Query q;
    try {
        if ("native".equals(queryType)) {
            q = em.createNativeQuery(query);
        } else if ("named".equals(queryType)) {
            q = em.createNamedQuery(query);
        } else {
            q = em.createQuery(query);
        }
        if (setParameters(q, params)) {
            o = q.getSingleResult();
        }
    } finally {
        closeEm();
    }
    return o;
}

From source file:com.sun.socialsite.business.impl.JPAGroupManagerImpl.java

public Group getGroupByHandle(String handle) throws SocialSiteException {
    if (handle == null) {
        throw new SocialSiteException("handle is null");
    }/*from  ww w  .  j a  v  a  2 s . c o  m*/
    Query query = strategy.getNamedQuery("Group.getByHandle");
    query.setParameter(1, handle);
    try {
        return (Group) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:mil.navy.med.dzreg.dao.RegistriesManagerDAO.java

/**
 * Check registry for requested person, return a DzPatients object.
 * @param p//from   w  w  w  .j ava 2  s .c om
 * @return  DzType registry type object
 */
private DzPatients validPerson(PersonType p) throws Exception, NoResultException {
    EntityManager em = null;
    PersistentServiceFactory psf = null;
    DzPatients registeredPatient = null;

    try {
        psf = PersistentServiceFactory.getInstance(REGISTRY_MANAGER_PU);
        em = psf.getEntityManager();

        Query query = em.createNamedQuery("DzPatients.findByPatid");
        query.setParameter("patid", p.getId());
        registeredPatient = (DzPatients) query.getSingleResult();
    } catch (NoResultException nre) {
        throw nre;
    } catch (Exception ex) {
        throw new Exception("Person " + p.getId() + " not found;");
    } finally {
        em.close();
    }

    return registeredPatient;
}

From source file:mil.navy.med.dzreg.dao.RegistriesManagerDAO.java

/**
 * Check registry type, returns a DzType object.
 * @param r// www  . j  av a2  s .  c  o  m
 * @return  DzType registry type object
 */
private DzType validRegistryType(RegistryType r) throws Exception {
    EntityManager em = null;
    PersistentServiceFactory psf = null;
    DzType registry = null;

    try {
        psf = PersistentServiceFactory.getInstance(REGISTRY_MANAGER_PU);
        em = psf.getEntityManager();

        Query query = em.createNamedQuery("DzType.findByDztypeId");
        query.setParameter("dztypeId", r.getRegistryId());
        registry = (DzType) query.getSingleResult();
        if (registry == null) {
            throw new Exception("Invalid/Unknown registy type requested - " + r.getRegistryId());
        }

        log.debug("Located registry - " + registry);

        return registry;
    } catch (javax.persistence.NoResultException nre) {
        throw new Exception("Invalid/Unknown registy type requested - " + r.getRegistryId());
    } catch (Exception ex) {
        throw new Exception("Failed to register patient in registry.");
    } finally {
        em.close();
    }
}