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.brienwheeler.svc.users.impl.UserRoleDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@SuppressWarnings("unchecked")
public List<String> findByUserAsStrings(User user) {
    Query query = entityManager.createQuery("select role from UserRole where user = :user");
    query.setParameter("user", user);
    return (List<String>) query.getResultList();
}

From source file:com.healthcit.cacure.dao.QuestionTableDao.java

@Override
public TableQuestion getById(Long id) {
    Query query = em.createQuery("from TableQuestion q where id = :Id");
    query.setParameter("Id", id);
    return (TableQuestion) query.getSingleResult();
}

From source file:pdsanchez.mywebtools.model.dao.jpa.CategoryDAOJPAImpl.java

@Override
public Category find(String name) {
    Category c = null;/* w  ww  .j av  a2s.c  o m*/

    Query q = getEntityManager().createQuery("select o from Category o where lower(o.categoryName) = :name");
    q.setParameter("name", name.toLowerCase());
    List<Category> list = q.getResultList();
    if (!list.isEmpty()) {
        c = list.get(0);
    }

    return c;
}

From source file:com.healthcit.cacure.dao.ModuleDao.java

/**
 * Deletes only module with empty forms, otherwise throws NoResultException exception.
 * @param moduleId Long/*from  w  ww .  j a v a  2  s .  co m*/
 */
public void deleteModuleWithEmptyForms(Long moduleId) {
    //prevent from deleting a Module item that has forms.
    //This scenario may appear by editing the URL.
    String jpql = "select m from BaseModule m left join m.forms f " + "where m.id = :moduleId and f is null";
    Query query = em.createQuery(jpql);
    query.setParameter("moduleId", moduleId);
    try {
        BaseModule module = (BaseModule) query.getSingleResult();
        delete(module);
    } catch (NoResultException e) {
        logger.info("try to delete an not empty module");
    }
}

From source file:de.inetsource.jsfforum.db.ThreadFacade.java

public List<Thread> findArticlesFromTopic(Integer forumId) {
    Query query = getEntityManager().createNamedQuery("Thread.findByForumId");
    query.setParameter("id", new Forum(forumId));
    return query.getResultList();
}

From source file:dao.LocalisationDAOImpl.java

@Override
public LocalisationEntity findForExperience(Long experienceId) {
    Query q = this.em.createQuery("SELECT l FROM LocalisationEntity l WHERE l.experience.id = ?");
    q.setParameter(1, experienceId);
    return (LocalisationEntity) q.getSingleResult();
}

From source file:modelo.dao.GestionProductosImpl.java

@Override
public Producto obtenerProducto(String referencia, int usuario) {
    Query q = em.createNamedQuery("Producto.findByReferencia");
    q.setParameter(1, referencia);
    q.setParameter(2, usuario);/*from   w ww  .  ja v  a 2 s.c  o m*/
    try {
        return (Producto) q.getSingleResult();
    } catch (Exception e) {
        return new Producto();

    }
}

From source file:com.brienwheeler.svc.ledger.impl.LedgerEntryDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@SuppressWarnings("unchecked")
public List<LedgerEntry> getLedger(long userId) {
    Query query = entityManager.createQuery("from LedgerEntry where user_id = :userId order by timestamp");
    query.setParameter("userId", userId);
    return (List<LedgerEntry>) query.getResultList();
}

From source file:com.sct.descubriendoturuta.service.RutaServiceImpl.java

@Override
@Transactional/*from  w  ww  . j  a v a 2 s  .c  o  m*/
public List<Ruta> obtenerRutas(int usuarioId) {

    Query query = em.createQuery("select r from Ruta r Where r.usuarioId = :p order by r.id desc");
    query.setParameter("p", usuarioId);

    return query.getResultList();
}

From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java

public List<String> setValueList(ConfigurationParameter parameter, List<String> valueList) {
    List<String> oldValue = getValueList(parameter);

    Query query = entityManager.createNativeQuery(SQL_DELETE);
    query.setParameter(1, String.valueOf(parameter));
    query.executeUpdate();/*w w w  .ja va2 s  .  co m*/

    for (String value : valueList) {
        query = entityManager.createNativeQuery(SQL_INSERT);
        query.setParameter(1, String.valueOf(parameter));
        query.setParameter(2, value);
        query.executeUpdate();
    }
    return oldValue;
}