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.expressui.core.dao.security.PermissionDao.java

/**
 * Finds all permissions for a given role.
 *
 * @param role role to query// www .j  a  va  2  s. com
 * @return all permissions for role
 */
public List<Permission> findByRole(Role role) {
    Query query = getEntityManager().createQuery("SELECT p FROM Permission p WHERE p.role = :role");
    query.setParameter("role", role);

    return query.getResultList();
}

From source file:com.mothsoft.alexis.dao.TermDaoImpl.java

public Term find(String termValue, PartOfSpeech partOfSpeech) {
    final Query query = this.em
            .createQuery("FROM Term WHERE value = :termValue AND partOfSpeechEnumValue = :partOfSpeech");
    query.setParameter("termValue", termValue);
    query.setParameter("partOfSpeech", (byte) partOfSpeech.getValue());
    query.setHint("org.hibernate.cacheable", true);

    @SuppressWarnings("unchecked")
    final List<Term> results = query.getResultList();
    final Term result = results != null && results.size() == 1 ? results.get(0) : null;
    return result;
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.EnvironmentDaoJpaImpl.java

@Override
public List<Environment> findByOrg(String org) {

    List<Environment> list;
    String queryString = "SELECT e FROM Environment e WHERE e.org LIKE :orgName";
    Query query = getEntityManager().createQuery(queryString);

    list = query.setParameter("orgName", org).getResultList();

    return list;/* w ww  . ja va 2 s . co  m*/
}

From source file:com.impetus.kundera.graphbrowser.service.IMDBService.java

public void findActorByName() {
    Query query = em.createQuery("select a from Actor a where a.name=:name");
    query.setParameter("name", "Tom Cruise");
    List<Actor> actors = query.getResultList();
    System.out.println(actors);//from  w w w.ja  v  a  2  s  .co m
}

From source file:com.tapas.evidence.repository.ResponsiblePersonRepositoryImpl.java

@Override
@SuppressWarnings("unchecked")
public List<ResponsiblePerson> findAll() {
    final Long tenantId = ((EvidenceUserDetails) SecurityContextHolder.getContext().getAuthentication()
            .getPrincipal()).getTenantId();
    Query query = this.entityManager.createNamedQuery(ResponsiblePerson.QUERY_NAME_FIND_ALL_BY_DELETED_FLAG);
    query.setParameter("deleted", Boolean.FALSE);
    query.setParameter("tenantId", tenantId);
    return query.getResultList();
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.EnvironmentDaoJpaImpl.java

@Override
public List<Environment> findByOrgAndVdcAndName(String org, String vdc, String name) {

    List list;//from  ww w .ja  va  2s  .c o  m
    String queryString = "SELECT e FROM Environment e WHERE e.org LIKE :orgName and e.vdc = :vdcName and e.name=:envName";
    Query query = getEntityManager().createQuery(queryString);

    list = query.setParameter("orgName", org).setParameter("vdcName", vdc).setParameter("envName", name)
            .getResultList();

    return list;
}

From source file:info.toegepaste.www.service.PdfServiceImpl.java

@Override
@TransactionAttribute(REQUIRES_NEW)//from   w w w .ja v a  2 s.  c o  m
public Test getTestById(int id) {
    Test test = null;
    Query q = em.createNamedQuery("Test.findByTestid");
    q.setParameter("testid", id);
    test = (Test) q.getSingleResult();
    return test;
}

From source file:pl.edu.uksw.j2eecourse.service.BookRentalServiceImpl.java

@Override
public Book findByIsbn(String isbn) {
    Query q = entityManager.createQuery("Select b from Book b where b.isbn = :isbn");
    q.setParameter("isbn", isbn);
    try {/*w  w w.j a  va  2  s  .  co  m*/
        return (Book) q.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}

From source file:vente.service.ArticleServiceImpl.java

public List<Article> findByTypeArticle(TypeArticle typeArticle) {
    List<Article> articles = new ArrayList<>();
    if (typeArticle == TypeArticle.MIXTE) {
        TypeArticle enfant = TypeArticle.ENFANT;
        Query query = em.createQuery(
                "SELECT a FROM Article a EXCEPT SELECT a1 FROM Article a1 WHERE a1.typeArticle = :enfant");
        query.setParameter("enfant", enfant);
        articles = query.getResultList();

    } else {//from ww  w.j  a va2s. co  m
        Query query = em.createQuery("SELECT a FROM Article a WHERE a.typeArticle = :typeArticle");
        query.setParameter("typeArticle", typeArticle);
        articles = query.getResultList();
    }
    return articles;
}

From source file:ea.ejb.PostFacade.java

public void deletePost(BigDecimal id_post) {
    Query q;

    q = em.createQuery("DELETE FROM Post p WHERE p.idPost=:ID");
    q.setParameter("ID", id_post);

    q.executeUpdate();//from   www.  j a  v a2 s . c o m
}