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.luna.common.repository.UserRepository2Impl.java

public List<SchoolInfo> findAllSchoolTypeByUserId(Long userId) {
    String ql = "select si from SchoolInfo si where si.user.id=?1";
    Query query = entityManager.createQuery(ql);
    query.setParameter(1, userId);
    return query.getResultList();
}

From source file:com.sixsq.slipstream.persistence.Run.java

@SuppressWarnings("unchecked")
public static List<Run> listOldTransient(User user, int timeout)
        throws ConfigurationException, ValidationException {
    if (timeout <= 0) {
        timeout = DEFAULT_TIMEOUT;
    }/*from www  . ja v  a2  s  .co m*/
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -timeout);
    Date back = calendar.getTime();

    EntityManager em = PersistenceUtil.createEntityManager();
    Query q = createNamedQuery(em, "oldInStatesRuns");
    q.setParameter("user", user.getName());
    q.setParameter("before", back);
    q.setParameter("states", States.transition());
    List<Run> runs = q.getResultList();
    em.close();
    return runs;
}

From source file:com.brienwheeler.svc.usergroups.impl.UserGroupMemberDao.java

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

From source file:com.sun.socialsite.business.impl.JPAContextRuleManagerImpl.java

public ContextRule getRuleById(String id) throws SocialSiteException {
    if (id == null) {
        throw new SocialSiteException("userid is null");
    }//w  w w  .jav  a  2 s  .c o m
    Query query = strategy.getNamedQuery("ContextRule.getById");
    query.setParameter(1, id);
    try {
        return (ContextRule) query.getSingleResult();
    } catch (NonUniqueResultException ne) {
        throw new SocialSiteException(String.format("ERROR: more than one rule with id: %s", id));
    } catch (NoResultException ex) {
        return null;
    }
}

From source file:com.iselect.kernal.geo.dao.CountryDaoImpl.java

@Override
public CountryModel getCountryById(Long id) throws EntityNotFoundException {
    CountryModel model = null;/* w w w . j av a2 s  . co m*/
    Query query = this.em.createNamedQuery("country.findById", CountryModelImpl.class);
    query.setParameter("id", id);
    try {
        model = (CountryModel) query.getSingleResult();
    } catch (NoResultException nre) {
        throw new EntityNotFoundException(id.toString(), nre);
    }
    return model;
}

From source file:DAO.IMCDAOImpl.java

@Transactional
@Override/*  ww  w  .  j  av  a  2 s  .c om*/
public IMCEntity find(int id) {
    Query q = em.createQuery("SELECT i FROM IMCEntity i where i.id = ?");
    q.setParameter(1, id);
    try {
        return (IMCEntity) q.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:Professor.java

  public Professor findProfessorNoCacheNamed(int empId) {
  Query q = em.createNamedQuery("findProfessorNoCache");
  q.setParameter(1, empId);
  try {/*from  w ww .ja v a 2 s.c  o m*/
    return (Professor) q.getSingleResult();
  } catch (NoResultException e) {
    return null;
  }
}

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

@Override
public List<Usuario> listar() {
    EntityManager em = getEntityManager();
    List<Usuario> lista = new ArrayList<Usuario>();
    Query q = em.createQuery("SELECT u FROM Usuario u where u.estado= :estado ");
    q.setParameter("estado", Usuario.ESTADOS.ACTIVO.getEstado());
    lista = q.getResultList();/* w w  w. j a  v a 2s  .  c o m*/
    return lista;
}

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

@Override
public List<Usuario> listarInactivos() {
    EntityManager em = getEntityManager();
    List<Usuario> lista = new ArrayList<Usuario>();
    Query q = em.createQuery("SELECT u FROM Usuario u where u.estado= :estado ");
    q.setParameter("estado", 'I');
    lista = q.getResultList();//ww  w  .  j a  v  a2s .c  o m
    return lista;
}

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

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