Example usage for javax.persistence Query setParameter

List of usage examples for javax.persistence Query setParameter

Introduction

In this page you can find the example usage for javax.persistence Query setParameter.

Prototype

Query setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

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();
            }//from   w ww.j a  v  a 2 s .c om
        }
    });
}

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

public static AttributeProtocolUriEntity findAttribute(EntityManager entityManager, String uri,
        String protocolId) {//from   w w  w .  j  a  va 2  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.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: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:ar.edu.unlp.sedici.sedici2003.model.Personas.java

public static int findPersonasesByApellidoYNombreCount(String apellido, String nombre) {
    if (apellido == null || apellido.length() == 0)
        apellido = "";
    if (nombre == null)
        nombre = "";

    apellido = Personas.convertirParaQuery(apellido);
    nombre = Personas.convertirParaQuery(nombre);

    String where = Personas.generateCondition(apellido, nombre);

    /*if (apellido == null || apellido.length() == 0) apellido="";
    if (nombre == null) nombre = "";//w  w w. j  a v  a  2 s .c o  m
    String where=Personas.generateCondition(apellido, nombre);*/

    EntityManager em = Personas.entityManager();
    Query q = em.createQuery("SELECT count(o) FROM Personas AS o " + where);
    if (apellido.length() != 0)
        q.setParameter("apellido", apellido);
    if (nombre.length() != 0)
        q.setParameter("nombre", nombre);
    return Integer.valueOf(q.getResultList().get(0).toString());
}

From source file:com.impetus.kvapps.runner.ExecutorService.java

private static List<User> findByEmail(final EntityManager em, String query, String parameter) {
    Query q = em.createNamedQuery(query);
    q.setParameter(1, parameter);

    List<User> users = q.getResultList();

    return users;
}

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 .  ja v  a2s  .  com
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.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();
}