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:org.openmeetings.app.data.basic.dao.OmTimeZoneDaoImpl.java

public OmTimeZone getOmTimeZone(String jname) {
    try {/*from  www . j a v a2  s . c o m*/
        String hql = "select sl from OmTimeZone as sl " + "WHERE sl.jname LIKE :jname "
                + "OR sl.ical LIKE :jname";
        TypedQuery<OmTimeZone> query = em.createQuery(hql, OmTimeZone.class);
        query.setParameter("jname", jname);
        List<OmTimeZone> sList = query.getResultList();

        if (sList.size() > 0) {
            return sList.get(0);
        }

    } catch (Exception ex2) {
        log.error("[getOmTimeZone]: ", ex2);
    }
    return null;
}

From source file:rzd.vivc.documentexamination.repository.AccountRepositoryImpl.java

@Override
public Account findWithDependencies(Long userID) {
    TypedQuery createQuery = em.createQuery(
            "SELECT a FROM Account a LEFT JOIN FETCH a.user u LEFT JOIN FETCH u.department  WHERE u.id=:id",
            Account.class);
    createQuery.setParameter("id", userID);
    return (Account) createQuery.getResultList().get(0);
}

From source file:com.expressui.sample.dao.query.AccountQuery.java

@Override
public void setParameters(TypedQuery<Serializable> typedQuery) {
    if (hasValue(name)) {
        typedQuery.setParameter("name", "%" + name.toUpperCase() + "%");
    }//w w  w  .  j  av  a2  s.  c  om
    if (hasValue(states)) {
        typedQuery.setParameter("states", states);
    }
    if (hasValue(country)) {
        typedQuery.setParameter("country", country);
    }
}

From source file:com.expressui.sample.view.contact.ContactQuery.java

@Override
public void setParameters(TypedQuery typedQuery) {
    if (!isEmpty(lastName)) {
        typedQuery.setParameter("lastName", "%" + lastName.toUpperCase() + "%");
    }//from  ww w . jav  a 2 s  .c  o m
    if (!isEmpty(states)) {
        typedQuery.setParameter("states", states);
    }
    if (!isEmpty(country)) {
        typedQuery.setParameter("country", country);
    }
}

From source file:com.olp.jpa.domain.docu.ut.repo.DepartmentRepositoryImpl.java

@Override
@Transactional(readOnly = true)//from ww w . j  a  v a  2 s .c o m
public DepartmentBean findByDeptCode(String deptCode) {

    IContext ctx = ContextManager.getContext();
    String tid = ctx.getTenantId();

    //EntityGraph graph = getEntityManager().getEntityGraph("graph.departmentBean.employees");

    TypedQuery<DepartmentBean> query = getEntityManager().createNamedQuery("DepartmentBean.findByCode",
            DepartmentBean.class);
    query.setParameter("code", deptCode); // TODO: Sanitize input, although low risk due to binding
    query.setParameter("tenant", tid);

    //query.setHint("javax.persistence.fetchgraph", graph); // Entity graph is not supported yet in OGM

    DepartmentBean bean = query.getSingleResult();

    //if (bean != null && bean.getEmployees() != null)
    //    bean.getEmployees().size(); // Apparently no way to avoid loading child entity instances, hence EAGER loading

    return (bean);
}

From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Transactional
@Override//from   w  ww .jav  a 2 s  .c  o  m
public List<Bet> getActiveBetsMadeByUser(String username, int startingResult, int resultsCount) {
    TypedQuery<Bet> query = entityManager.createNamedQuery("Bet.findByUsernameByBetResult", Bet.class);
    query.setParameter("username", username);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    return query.setMaxResults(resultsCount).setFirstResult(startingResult).getResultList();
}

From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Override
public List<Bet> getArchivedBetsPageMadeByUser(String username, int startingResult, int resultsCount) {
    TypedQuery<Bet> query = entityManager.createNamedQuery("Bet.findArchivedPageByUsername", Bet.class);
    query.setParameter("username", username);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    return query.setMaxResults(resultsCount).setFirstResult(startingResult).getResultList();
}

From source file:com.epam.ipodromproject.repository.jpa.JPACompetitionRepository.java

@Override
public List<Competition> getAllCompetitionsAfter(Date date, int startingResult, int resultsCount) {
    TypedQuery<Competition> query = entityManager.createNamedQuery("Competition.findAfterDate",
            Competition.class);
    query.setParameter("date", date);
    query.setParameter("state", CompetitionState.NOT_REGISTERED);
    List<Competition> resultList = query.setMaxResults(resultsCount).setFirstResult(startingResult)
            .getResultList();//from w  w  w  . j  a v  a2s  . c o  m
    for (Competition competition : resultList) {
        Hibernate.initialize(competition.getHorses());
    }
    return resultList;
}

From source file:com.siriusit.spezg.multilib.storage.jpa.JpaLoanRepository.java

@Override
public List<? extends Loan> findLoansByUnit(Unit unit) {
    TypedQuery<LoanDomainObject> query = entityManager.createNamedQuery("findLoanByUnit",
            LoanDomainObject.class);
    query.setParameter("unit", unit);
    return query.getResultList();
}

From source file:com.epam.ipodromproject.repository.jpa.JPACompetitionRepository.java

@Override
public List<Competition> getUnoperatedCompetitions(int startingResult, int resultsCount) {
    TypedQuery<Competition> query = entityManager.createNamedQuery("Competition.findUnoperated",
            Competition.class);
    query.setParameter("state", CompetitionState.NOT_REGISTERED);
    query.setParameter("date", new Date());
    List<Competition> resultList = query.setMaxResults(resultsCount).setFirstResult(startingResult)
            .getResultList();//from  w  ww.j av  a  2  s.c  o  m
    for (Competition competition : resultList) {
        Hibernate.initialize(competition.getHorses());
    }
    return resultList;
}