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:modelo.dao.GestionHistoricoImpl.java

@Override
public Historico obtenerUltimoHistorico(String referencia, int usuario) {
    Query q = em.createNamedQuery("Historico.findLastDateByRef");
    q.setParameter(1, referencia);
    q.setParameter(2, usuario);/* w  w w .j  a  v a  2  s.c  o m*/
    q.setMaxResults(1);
    try {
        return (Historico) q.getSingleResult();
    } catch (Exception e) {
        return new Historico(null);
    }
}

From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java

@Override
public boolean setPartlyFailedState(Message msg) {
    Assert.notNull(msg, "the msg must not be null");

    // change state to PARTLY_FAILED
    String jSql = "UPDATE " + Message.class.getName() + " SET state = ?1, lastUpdateTimestamp = ?2"
            + " WHERE msgId = ?3 AND state IN (?4)";

    Query q = em.createQuery(jSql);
    q.setParameter(1, MsgStateEnum.PARTLY_FAILED);
    q.setParameter(2, new Date());
    q.setParameter(3, msg.getMsgId());//from   ww w  .  j a  va2s .co m
    q.setParameter(4, Arrays.asList(MsgStateEnum.CANCEL, MsgStateEnum.FAILED));

    return q.executeUpdate() > 0;
}

From source file:com.brienwheeler.svc.users.impl.UserRoleDao.java

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

From source file:net.chrissearle.flickrvote.dao.JpaImageDao.java

/**
 * Method getImagesWithRank will return all images with a given rank.
 *
 * @param rank of type long// w  w  w . ja  va  2 s. c  o  m
 * @return Images with the given rank.
 */
@SuppressWarnings("unchecked")
public List<Image> getImagesWithRank(long rank) {
    Query query = entityManager.createQuery("select i from Image i where i.finalRank = :rank");
    query.setParameter("rank", rank);

    return (List<Image>) query.getResultList();
}

From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java

@Override
public void removeExtCalls(Message msg, boolean totalRestart) {
    Assert.notNull(msg, "the msg must not be null");

    String jSql = "DELETE " + "FROM " + ExternalCall.class.getName() + " c " + "WHERE c.msgId = ?1 ";

    if (!totalRestart) {
        // delete only confirmations
        jSql += "AND c.operationName = '" + ExternalCall.CONFIRM_OPERATION + "'";
    }/* w  w w.  j  av a  2  s .com*/

    Query q = em.createQuery(jSql);
    q.setParameter(1, msg.getMsgId());
    int updatedCount = q.executeUpdate();

    Log.debug(updatedCount + " external calls were deleted for message with msgID=" + msg.getMsgId());
}

From source file:com.dhenton9000.birt.jpa.service.impl.EmployeesServiceImpl.java

@Override
public List<Employees> getEmployeesForOffice(String officeCode) {
    String qString = "select employees from " + "Offices o join o.employees employees "
            + "where o.officeCode = :id ";

    Query q = entityManager.createQuery(qString);
    q.setParameter("id", officeCode);

    List<Employees> officeEmployees = q.getResultList();

    //   http://www.objectdb.com/java/jpa/query/jpql/select

    return officeEmployees;
}

From source file:br.org.indt.ndg.server.language.LanguageManagerBean.java

@Override
public String getLanguagePath(String locale) {
    Query q = manager.createNamedQuery("languages.getPath");
    q.setParameter("locale", locale + "%");

    Language language = (Language) q.getSingleResult();

    return language.getPath();
}

From source file:br.org.indt.ndg.server.language.LanguageManagerBean.java

@Override
public String getFontPath(String locale) {
    Query q = manager.createNamedQuery("languages.getPath");
    q.setParameter("locale", locale + "%");

    Language language = (Language) q.getSingleResult();

    return language.getFontPath();
}

From source file:org.jboss.spring.quickstarts.greeter.greeter_spring.domain.UserDaoImpl.java

@Transactional
public User getForUsername(String username) {
    try {//from www  .  java 2s. c  o m
        Query query = entityManager.createQuery("select u from User u where u.username = ?");
        query.setParameter(1, username);
        return (User) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.mycompany.login.mb.LoginBean.java

public List carregaBombas() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
    Usuario usuario = (Usuario) session.getAttribute("usuarioLogado");
    Query query = em.createQuery("SELECT numserie FROM Bombas u WHERE u.nomecliente = :nomecliente");
    query.setParameter("nomecliente", usuario.getVinculo());
    bombasusuario = query.getResultList();
    return bombasusuario;
}