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:org.kuali.mobility.user.dao.UserDaoImpl.java

public User findUserByUserId(String userId) {
    Query query = entityManager.createQuery("select u from User u where u.userId = :userId");
    query.setParameter("userId", userId);
    try {/*  ww  w  .  jav  a2  s. c o m*/
        return (User) query.getSingleResult();
    } catch (Exception e) {
        return null;
    }
}

From source file:bankconsoleapp.repositories.SavingDao.java

@Transactional
public void deposit(String acnum, int amount) {

    int newBalance = 0;

    Query q1 = em.createQuery("From SavingAccount SA WHERE SA.accNum='" + acnum + "'");
    List<SavingAccount> SA = q1.getResultList();
    for (SavingAccount sav : SA) {
        newBalance = sav.getBalance() + amount;
    }/*w  ww.  j  a  v a  2s .co m*/

    Query q = em.createQuery("update SavingAccount set balance=:bal where accNum=:an");
    q.setParameter("an", acnum);
    q.setParameter("bal", newBalance);
    q.executeUpdate();

    em.flush();

}

From source file:bankconsoleapp.repositories.SavingDao.java

@Transactional
public void withdraw(String acnum, int amount) {

    int newBalance = 0;

    Query q1 = em.createQuery("From SavingAccount SA WHERE SA.accNum='" + acnum + "'");
    List<SavingAccount> SA = q1.getResultList();
    for (SavingAccount sav : SA) {
        newBalance = sav.getBalance() - amount;
    }/*from w ww  .  j a v a2 s . c  o  m*/

    Query q = em.createQuery("update SavingAccount set balance=:bal where accNum=:an");
    q.setParameter("an", acnum);
    q.setParameter("bal", newBalance);
    q.executeUpdate();

    em.flush();

}

From source file:dao.ExperienceDAOImpl.java

@Override
public List<ExperienceEntity> findExperiencesForProfil(Long profileId) {
    Query q;
    q = this.em.createQuery("SELECT e FROM ExperienceEntity e WHERE e.profile.id = ?");
    q.setParameter(1, profileId);
    return q.getResultList();
}

From source file:es.ucm.fdi.dalgs.mailbox.respository.MailBoxRepository.java

public MessageBox getMessageBox(String code) {

    Query query = null;

    query = em.createQuery("select m FROM MessageBox m where m.code=?1");
    query.setParameter(1, code);

    if (query.getResultList().isEmpty())
        return null;
    else/*from  ww  w .j a v  a 2 s  .  c  o m*/
        return (MessageBox) query.getSingleResult();
}

From source file:fr.norad.visuwall.core.persistence.dao.WallDAOImpl.java

@Override
public Wall find(String wallName) throws NotFoundException {
    Query query = entityManager.createNamedQuery(Wall.QUERY_WALLBYNAME);
    query.setParameter(Wall.QUERY_PARAM_NAME, wallName);
    Wall wall = (Wall) query.getSingleResult();

    // TODO replace with lazy load with extended entityManager or eager request 
    for (SoftwareAccess softwareInfo : wall.getSoftwareAccesses()) {
        softwareInfo.getProjectIds();//  w  w  w  .j a v a  2s .c o  m
        softwareInfo.getViewNames();
    }
    return wall;
}

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

@Override
public long countDuplicate(SystemCodes code) {
    String queryString = getJpqlQuery("jpql.systemcodes.countDuplicate");
    Query queryObject = getEntityManager().createQuery(queryString);
    queryObject.setParameter("keyName", code.getKey());
    // if id is null it means it is a new systemCodes
    if (code.getId() == null) {
        queryObject.setParameter("id", 0l);
    } else {/*from ww w  . j  a  va  2s .c  o m*/
        queryObject.setParameter("id", code.getId());
    }
    return (Long) queryObject.getSingleResult();
}

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

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

From source file:com.expressui.sample.dao.PermissionDao.java

public List<Permission> findByRole(Role role) {
    Query query = getEntityManager().createQuery("SELECT p FROM Permission p WHERE p.role = :role");
    query.setParameter("role", role);

    return query.getResultList();
}

From source file:com.plan.proyecto.repositorios.DaoCuentaImpl.java

@Override
public List<Cuenta> findAmigosByCuenta(Cuenta cuenta) {
    Query query = em.createNamedQuery("Cuenta.findAmigosByCuenta");
    query.setParameter("idorigen", cuenta.getId());
    return query.getResultList();
}