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:fr.univrouen.poste.domain.PosteCandidatureFile.java

public static Long getSumFileSize() {
    String sql = "SELECT SUM(file_size) FROM poste_candidature_file";
    Query q = entityManager().createNativeQuery(sql);
    BigDecimal bigValue = (BigDecimal) q.getSingleResult();
    if (bigValue != null) {
        return bigValue.longValue();
    } else {/*from   ww w  .  jav a2  s .com*/
        return new Long(0);
    }
}

From source file:fr.univrouen.poste.domain.PosteCandidatureFile.java

public static Long getSumNbPages() {
    String sql = "SELECT SUM(nb_pages) FROM poste_candidature_file";
    Query q = entityManager().createNativeQuery(sql);
    BigDecimal bigValue = (BigDecimal) q.getSingleResult();
    if (bigValue != null) {
        return bigValue.longValue();
    } else {//from w w w  .  j  av a  2  s . co  m
        return new Long(0);
    }
}

From source file:com.callcenter.domain.Role.java

public static Role findRoleByNameIn(final java.util.Collection<String> names) {
    EntityManager em = Role.entityManager();
    Query q = em.createQuery("SELECT Role FROM Role AS role WHERE role.name in (:names)");
    q.setParameter("names", names);
    return (Role) q.getSingleResult();
}

From source file:ch.entwine.weblounge.bridge.oaipmh.harvester.LastHarvested.java

public static Option<Date> getLastHarvestDate(PersistenceEnv penv, final String url) {
    return penv.tx(new Function<EntityManager, Option<Date>>() {
        public Option<Date> apply(EntityManager em) {
            Query q = em.createNamedQuery("findLastHarvested");
            q.setParameter("url", url);
            try {
                return some((Date) q.getSingleResult());
            } catch (NoResultException e) {
                return none();
            }//w  w  w . j  a v a 2  s .c  o m
        }
    });
}

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

static EntitlementEntity getEntitlementEntity(String name, EntityManager em) {
    Query query = null;
    query = em.createQuery("select e from Entitlement e where e.name=:name");
    query.setParameter("name", name);

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

From source file:com.webbfontaine.valuewebb.model.util.TTUtils.java

public static String getTTStatus(Object id) {
    Query query = Utils.getEntityManager().createQuery("SELECT status FROM TtGen tt WHERE tt.id = :id");
    Utils.setDirectRead(query).setParameter("id", id);
    return (String) query.getSingleResult();
}

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

static ClaimEntity getClaimEntity(String claimType, EntityManager em) {
    Query query = null;
    query = em.createQuery("select c from Claim c where c.claimType=:claimtype");
    query.setParameter("claimtype", claimType);

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

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

static TrustedIdpEntity getTrustedIdpEntity(String realm, EntityManager em) {
    Query query = null;
    query = em.createQuery("select t from TrustedIDP t where t.realm=:realm");
    query.setParameter("realm", realm);

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

From source file:be.fedict.eid.idp.entity.AttributeProtocolUriEntity.java

public static AttributeProtocolUriEntity findAttribute(EntityManager entityManager, String uri,
        String protocolId) {//from  w ww.j av a2  s  .  c  o  m

    Query query = entityManager.createNamedQuery(FIND_ATTRIBUTE);
    query.setParameter("uri", uri);
    query.setParameter("protocolId", protocolId);
    try {
        return (AttributeProtocolUriEntity) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

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

static RoleEntity getRoleEntity(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 (RoleEntity) query.getSingleResult();
}