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.iselect.kernal.account.dao.UserDaoExtImpl.java

@Override
public UserModelImpl getByUserName(String username) {
    Query query = em.createNamedQuery(UserModelImpl.GET_BY_USERNAME, UserModelImpl.class);
    query.setParameter(UserModelImpl.PARAM_USERNAME, username);
    return (UserModelImpl) query.getSingleResult();
}

From source file:edu.mum.dao.impl.AuthorityDaoImpl.java

@Override
public Authority findOneByName(String name) {
    Query query = entityManager.createQuery("from Authority e where e.name = :name");
    query.setParameter("name", name);
    List<Authority> authority = query.getResultList();
    if (authority.isEmpty()) {
        return null;
    } else {/*from   ww  w . j av  a  2s  . c  o  m*/
        return authority.get(0);
    }

}

From source file:com.gymadmin.persistence.dao.impl.PaymentDaoImpl.java

@Override
public List<PaymentEntity> findActiveByCustomer(Integer customerId) {
    Query namedQuery = em.createNamedQuery("PaymentEntity.findActiveByCustomer");
    namedQuery.setParameter("customerId", customerId);
    return (List<PaymentEntity>) namedQuery.getResultList();
}

From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.UserRoleDaoImpl.java

@Override
public UserRole find(long id) {
    final Query query = em.createQuery("from UserRole where id = :id");
    query.setParameter("id", id);
    return (UserRole) query.getSingleResult();
}

From source file:at.irian.demo.jsfatwork.repository.jpa.JpaUserRepository.java

public User loadUser(String userName) {
    Query query = this.entityManager.createNamedQuery(FIND_USER_BY_NAME);
    query.setParameter(PARAMETER_USER, userName);

    List result = query.getResultList(); //don't use getSingleResult()
    if (result != null && result.size() == 1) {
        return (User) result.iterator().next();
    }/*  w w w .  j  a v a2 s .co  m*/
    return null;
}

From source file:at.irian.demo.jsfatwork.repository.jpa.JpaVotingRepository.java

@Override
public List<Vote> loadVotes(User user) {
    Query query = this.entityManager.createNamedQuery(FIND_ALL_VOTES_OF_USER);
    query.setParameter(PARAMETER_USER, user);

    return query.getResultList();
}

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

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public User findByUsername(String username) {
    Query query = entityManager.createQuery("from User where username = :username");
    query.setParameter("username", username);
    return getSingleResultOrNull(query);
}

From source file:eu.domibus.common.dao.PartyDao.java

public Collection<Identifier> findPartyIdentifiersByEndpoint(String endpoint) {
    final Query query = this.em.createNamedQuery("Party.findPartyIdentifiersByEndpoint");
    query.setParameter("ENDPOINT", endpoint);

    return query.getResultList();
}

From source file:cz.muni.expense.data.RuleRepository.java

public List<Rule> findRulesByUserId(Long userId) {
    Query query = em.createQuery("SELECT r FROM Rule r " + "WHERE r.user.id = :userId");
    query.setParameter("userId", userId);
    return query.getResultList();
}

From source file:com.tamnd2.basicwebapp.core.repositories.jpa.JpaAccountRepo.java

@Override
public Account findAccountByName(String name) {
    Query query = em.createQuery("SELECT a FROM Account a WHERE a.name=?1");
    query.setParameter(1, name);
    List<Account> accounts = query.getResultList();
    if (accounts.isEmpty()) {
        return null;
    } else {//  w  w w. ja  v a2 s  .c o m
        return accounts.get(0);
    }
}