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.healthcit.cacure.dao.FormDao.java

/**
 * @return Next Ord Number in ordered entities.
 *//*  w ww . jav  a 2 s  .c  om*/
@Transactional(propagation = Propagation.SUPPORTS)
public Integer calculateNextOrdNumber(Long moduleId) {
    String jpql = "select MAX(ord + 1) from BaseForm f where f.module.id = :moduleId";
    Query query = em.createQuery(jpql);
    query.setParameter("moduleId", moduleId);
    return (Integer) query.getSingleResult();
}

From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java

public ApplicationDomain getApplicationDomainByPk(String domainName) {
    Query query = createEntityManager().createNamedQuery("ApplicationDomain.getByPk");
    query.setParameter("pk", domainName);
    return (ApplicationDomain) query.getSingleResult();
}

From source file:gwap.rest.UserPicture.java

protected ArtResource createPicture(JSONObject payload) {
    ArtResource artResource = new ArtResource();

    Query query = entityManager.createNamedQuery("person.byDeviceId");
    query.setParameter("deviceId", payload.get("userid").toString());
    Person person = (Person) query.getSingleResult();
    artResource.setArtist(person);/*from  w w w  . j  av  a  2s  .  co m*/

    Calendar now = GregorianCalendar.getInstance();
    artResource.setDateCreated(new SimpleDateFormat("dd.MM.yyyy").format(now.getTime()));

    artResource.setSkip(true); // should not show up for artigo tagging

    Location location = new Location();
    location.setType(LocationType.APP);
    if (payload.containsKey("name"))
        location.setName(payload.get("name").toString());

    GeoPoint geoPoint = new GeoPoint();
    geoPoint.setLatitude(Float.parseFloat(payload.get("latitude").toString()));
    geoPoint.setLongitude(Float.parseFloat(payload.get("longitude").toString()));
    entityManager.persist(geoPoint);

    entityManager.persist(location);
    entityManager.flush();
    LocationGeoPoint locationGeoPoint = new LocationGeoPoint();
    locationGeoPoint.setGeoPoint(geoPoint);
    locationGeoPoint.setLocation(location);
    entityManager.persist(locationGeoPoint);
    entityManager.flush();
    location.getGeoRepresentation().add(locationGeoPoint);

    artResource.setShownLocation(location);
    entityManager.persist(artResource);

    entityManager.flush();
    return artResource;
}

From source file:com.eu.evaluation.server.dao.AbstractDAO.java

public int countAll() {
    Query query = entityManager.createQuery(JPQL_SELECT_COUNT);
    return (Integer) query.getSingleResult();
}

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

public Long getUsersCount(Organization org) {
    if (org == null) {
        return null;
    }/*from  ww  w . java2s  .c  o m*/
    EntityManager em = PersistenceUtil.getEntityManager();

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

From source file:com.mycompany.testeproject.AusenciaDAO.java

public Tausencia getAusenciaByIdAusencia(Integer idAusencia) {
    Query q = em.createNamedQuery("Tausencia.findByIdAusencia");
    q.setParameter("idAusencia", idAusencia);
    Ausencia ausencia = null;/*  ww w .ja  v  a2s .  c  om*/
    Tausencia savedAusencia = null;

    if (ausencia.getIdAusencia() != null) {
        savedAusencia = em.find(Tausencia.class, ausencia.getIdAusencia());
        return (Tausencia) q.getSingleResult();
    } else {
        return null;
    }
}

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

@Override
public Role getRole(String name, List<String> expandList) {
    Query query = null;
    query = em.createQuery("select r from Role r where r.name=:name");
    query.setParameter("name", name);

    //@SuppressWarnings("rawtypes")
    Object roleObj = query.getSingleResult();
    return entity2domain((RoleEntity) roleObj, expandList);
}

From source file:com.assetmanager.service.auth.PersistentTokenRepositoryImpl.java

/**
 * Gets the token for the given series.//from   w  w w .  jav  a2  s.  c o m
 *
 * @param series the series
 * @return the remember me token
 */
@Override
public final PersistentRememberMeToken getTokenForSeries(final String series) {
    PersistentLogin persistentLogin = null;
    final Query query = entityManager.createQuery("SELECT p FROM PersistentLogin p WHERE series = :series");
    query.setParameter("series", series);

    try {
        persistentLogin = (PersistentLogin) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }

    return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(),
            persistentLogin.getToken(), persistentLogin.getLastUsed());
}

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

public Sender findSenderByName(String name) {
    Query query = entityManager.createQuery("select s from Sender s where s.name = :name");
    query.setParameter("name", name);
    Sender s;//from   w w  w . ja  v a2  s.  com
    try {
        s = (Sender) query.getSingleResult();
    } catch (NoResultException e) {
        LOG.info("Sender with name " + name + " was not found or was invalid.");
        return null;
    }
    return s;
}

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

@Override
public void deleteRole(String name) {
    Query query = null;
    query = em.createQuery("select r from Role r where r.name=:name");
    query.setParameter("name", name);

    //@SuppressWarnings("rawtypes")
    Object roleObj = query.getSingleResult();
    em.remove(roleObj);/*  w ww . j  a v  a2s.c  o  m*/

    LOG.debug("Role '{}' deleted", name);
}