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.tapas.evidence.repository.TeacherRepositoryImpl.java

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

From source file:org.openwms.wms.receiving.ReceivingOrderDaoImpl.java

/**
 * {@inheritDoc}//from ww  w  .ja  va2  s.  com
 */
@Override
public ReceivingOrderPosition findByKey(OrderPositionKey key) {
    Query query = em.createNamedQuery(ReceivingOrderPosition.NQ_FIND_POSITION_KEY);
    query.setParameter(ReceivingOrderPosition.QP_FIND_WITH_POSITION_KEY, key);
    return (ReceivingOrderPosition) query.getSingleResult();
}

From source file:com.gerenciaProyecto.DaoImple.ProductoDaoImpl.java

@Override
public Producto ObtenerProductoId(Integer p_IdProducto) {
    EntityManager em = getEntityManager();
    List<Producto> lista = new ArrayList<Producto>();
    Query q = em.createQuery("SELECT p FROM Producto p WHERE p.id = :id");
    q.setParameter("id", p_IdProducto);
    lista = q.getResultList();//from w  ww . j  a v a2s . com
    for (Producto lista1 : lista) {
        if (lista1.getId() == p_IdProducto) {
            return lista1;
        }
    }
    return null;
}

From source file:com.luna.common.repository.UserRepository2Impl.java

public BaseInfo findBaseInfoByUserId(Long userId) {
    String ql = "select bi from BaseInfo bi where bi.user.id=?1";
    Query query = entityManager.createQuery(ql);
    query.setParameter(1, userId);
    query.setMaxResults(1);/*from www  . ja va2 s  .  co  m*/
    List<BaseInfo> baseInfoList = query.getResultList();
    if (baseInfoList.size() > 0) {
        return baseInfoList.get(0);
    }
    return null;
}

From source file:org.kuali.mobility.user.dao.UserDaoImpl.java

public User findUserByGuid(Long guid) {
    Query query = entityManager.createQuery("select u from User u where u.guid = :guid");
    query.setParameter("guid", guid);
    try {/*from  w  w w  . j  av  a2s  .co  m*/
        return (User) query.getSingleResult();
    } catch (Exception e) {
        return null;
    }
}

From source file:org.opentides.dao.impl.NotificationDaoImpl.java

@Override
@Transactional(readOnly = true)/*from  www.j a  v  a2  s .c  om*/
public long countNewPopup(long userId) {
    String queryString = getJpqlQuery("jpql.notification.countNewPopup");
    Query queryObject = getEntityManager().createQuery(queryString);
    queryObject.setParameter("userId", userId);
    return (Long) queryObject.getSingleResult();
}

From source file:com.srinathavan.mwbng.core.repositories.jpa.JpaAccountRepo.java

@Override
public Account findAccountByName(String name) {
    Query query = em.createQuery("select a from Account a where a.username=?");
    query.setParameter(0, name);
    List<Account> accounts = query.getResultList();
    if (accounts.size() == 0) {
        return null;
    }//from   ww  w. j a  v a2s  .  co  m
    return accounts.get(0);
}

From source file:org.syncope.core.persistence.dao.impl.PolicyDAOImpl.java

@Override
public List<? extends Policy> find(final PolicyType type) {
    final Query query = entityManager.createQuery("SELECT e FROM Policy e WHERE e.type=:type");
    query.setParameter("type", type);

    return query.getResultList();
}

From source file:com.ewcms.publication.PublishIntegratedTest.java

private void updateTemplateSourceStutas() {
    JpaTemplate template = createJpaTemplate();
    template.execute(new JpaCallback<Object>() {
        @Override/*from   www.java2  s.c  om*/
        public Object doInJpa(EntityManager em) throws PersistenceException {
            em.getTransaction().begin();
            String hql = "Update TemplateSource o Set o.release= ?1 Where o.release = ?2";
            Query query = em.createQuery(hql);
            query.setParameter(1, Boolean.FALSE);
            query.setParameter(2, Boolean.TRUE);
            query.executeUpdate();
            em.getTransaction().commit();
            return null;
        }
    });
}

From source file:com.ewcms.publication.PublishIntegratedTest.java

private void updateResourceStutas() {
    JpaTemplate template = createJpaTemplate();
    template.execute(new JpaCallback<Object>() {
        @Override/*w ww  .j a  v  a  2 s  . c om*/
        public Object doInJpa(EntityManager em) throws PersistenceException {
            em.getTransaction().begin();
            String hql = "Update Resource o Set o.status= ?1 Where o.status = ?2";
            Query query = em.createQuery(hql);
            query.setParameter(1, Resource.Status.NORMAL);
            query.setParameter(2, Resource.Status.RELEASED);
            query.executeUpdate();
            em.getTransaction().commit();
            return null;
        }
    });
}