Example usage for javax.persistence TypedQuery setParameter

List of usage examples for javax.persistence TypedQuery setParameter

Introduction

In this page you can find the example usage for javax.persistence TypedQuery setParameter.

Prototype

TypedQuery<X> setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedWinsForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:com.beto.test.securityinterceptor.security.UserPageRoleServiceImpl.java

@Override
public List<SecPageRoleDef> getAuthorizedPages(List<String> roles) throws Exception {
    TypedQuery<SecPageRoleDef> typedQuery = em.createQuery("SELECT p FROM PageRole p WHERE p.role IN=:roles",
            SecPageRoleDef.class);
    List<SecPageRoleDef> resultList = typedQuery.setParameter("roles", roles).getResultList();
    if (logger.isDebugEnabled()) {
        for (SecPageRoleDef pageRole : resultList) {
            logger.debug(pageRole.toString());
        }//ww  w.  j  ava2 s . c o  m
    }
    return resultList;
}

From source file:com.mycompany.login.filter.AutenticacaoFilter.java

/**
 * Metodos de acesso ao BD/*from  ww w.j a v a  2  s  .c  o m*/
 *
 * @param login
 * @param senha
 * @return   
 */
public Usuario buscarUsuario(String login, String senha) throws IOException {
    em = factory.createEntityManager();
    com.mycompany.login.bean.Usuario usuario = null;
    try {
        TypedQuery<Usuario> query = em.createQuery(
                "SELECT u FROM Usuario u WHERE u.login = :login AND u.senha = :senha", Usuario.class);
        query.setParameter("login", login);
        query.setParameter("senha", senha);

        usuario = (Usuario) query.getSingleResult();

    } catch (NoResultException e) {
        System.out.println("DAO: No foi encontrado resultado!");

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        em.close();
    }

    return usuario;
}

From source file:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param id/*from  ww w .j a  v a 2  s . co m*/
 * @return
 */
public Object getUserEmailbyId(Long id) {

    TypedQuery<NewMember> q = em.createQuery("SELECT n.email FROM NewMember n WHERE n.id = :id",
            NewMember.class);
    q.setParameter("id", id);
    return q.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedLosesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedLosesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public List<Match> getAllUnrankedMatchesForPlayer(Player p) {
    TypedQuery<Match> query = entityManager.createNamedQuery("allUnrankedMatchesForPlayer", Match.class);
    query.setParameter("player", p);
    return query.getResultList();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllUnrankedWinsForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllUnrankedLosesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}

From source file:org.jasig.portlet.notice.service.jpa.JpaNotificationDao.java

@Override
@Transactional(readOnly = true)/*  w  w  w  .  j  a  v a  2  s. c  om*/
public List<JpaEvent> getEvents(long entryId, String username) {
    Validate.isTrue(entryId > 0, "Argument 'entryId' must be greater than zero (0)");
    Validate.notEmpty(username, "Argument 'username' cannot be empty");

    final String jpql = "SELECT v FROM JpaEvent v WHERE v.username = :username "
            + "AND v.entry = (SELECT e FROM JpaEntry e WHERE e.id = :entryId) " + "ORDER BY v.timestamp";
    TypedQuery<JpaEvent> query = entityManager.createQuery(jpql, JpaEvent.class);
    query.setParameter("username", username);
    query.setParameter("entryId", entryId);
    List<JpaEvent> rslt = query.getResultList();
    return rslt;
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllRankedMatchesForPlayer(Player p) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedMatchesForPlayer", Long.class);
    query.setParameter("player", p);
    return query.getSingleResult();
}