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:com.simplecrud.dao.UserInfoDao.java

/**
 *
 * @param username//w  ww  . j  av a2s .  co m
 * @return EMAIL
 */
public Object getUserEmail(String username) {

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

From source file:com.headissue.pigeon.survey.answer.AnswerHandler.java

UserMap loadUserMap(Survey _survey, int _mapId, EntityManager _manager) {
    TypedQuery<UserMap> q = _manager.createNamedQuery("answerUserMan.findBySurveyAndId", UserMap.class);
    q.setParameter("survey", _survey);
    q.setParameter("mapId", _mapId);
    return JPAUtils.getSingleResult(q);
}

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

private License findByCompanyCodeAndLicenseCode(int companyCode, int licenseCode) {
    String jpql = "select l from License l where l.entCode = :entCode AND l.licenseCode = :licenseCode";
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    //   query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    query.setParameter("entCode", companyCode);
    query.setParameter("licenseCode", licenseCode);
    List<License> licenses = query.getResultList();
    if (licenses.size() == 1)
        return licenses.get(0);
    else//  ww w  . j  a  v a 2 s  .  com
        return null;
}

From source file:cn.newgxu.lab.core.repository.impl.AbstractCommonDaoImpl.java

/**
 * ??<b style="color: red;"> :xxx </b>?????
 * @param hql ?hql//from   w  w  w.  j  a  v  a2  s  . co  m
 * @param type 
 * @param objects ?map, ?
 * @return ?
 */
protected T executeQuery(String hql, Class<T> clazz, Map<String, Object> params) {
    TypedQuery<T> query = em.createQuery(hql, clazz);
    if (params != null) {
        for (String name : params.keySet()) {
            query.setParameter(name, params.get(name));
        }
    }
    return query.getSingleResult();
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java

public Account getFollower(Account account, Long accountId) {
    String qlString = "FROM AccountFollower " + "WHERE account = :account " + "AND follower.id = :follower";

    TypedQuery<AccountFollower> query = this.em.createQuery(qlString, AccountFollower.class);
    query.setParameter("account", account);
    query.setParameter("follower", accountId);

    List<AccountFollower> followers = query.getResultList();

    return followers.isEmpty() ? null : followers.get(0).getFollower();
}

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

@Transactional(readOnly = true)
public JpaEntry getFullEntry(long entryId) {
    Validate.isTrue(entryId > 0, "Invalid entryId: " + entryId);

    TypedQuery<JpaEntry> query = entityManager.createNamedQuery("JpaEntry.getFullById", JpaEntry.class);
    query.setParameter("entryId", entryId);
    return query.getSingleResult();
}

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

/**
 *
 * @param username//from   w  ww . ja v a 2s  .  com
 * @return SIGNING DATE
 */
public Object getUserSigningDate(String username) {

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

From source file:org.syncope.core.persistence.dao.impl.RoleDAOImpl.java

@Override
public SyncopeRole find(final Long id) {
    TypedQuery<SyncopeRole> query = entityManager.createQuery("SELECT e FROM SyncopeRole e WHERE e.id = :id",
            SyncopeRole.class);
    query.setParameter("id", id);

    SyncopeRole result = null;// w  w  w . j av  a2 s . co  m
    try {
        result = query.getSingleResult();
    } catch (NoResultException e) {
    }

    return result;
}

From source file:eu.europa.ec.fisheries.uvms.exchange.dao.bean.ExchangeLogDaoBean.java

@Override
public ExchangeLog getExchangeLogByGuid(String logGuid, TypeRefType typeRefType) throws ExchangeDaoException {
    try {/* w w w.  jav  a  2 s .  c o m*/
        TypedQuery<ExchangeLog> query = em.createNamedQuery(ExchangeConstants.LOG_BY_GUID, ExchangeLog.class);
        query.setParameter("typeRefType", typeRefType);
        query.setParameter("guid", logGuid);
        return query.getSingleResult();
    } catch (NoResultException e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new NoEntityFoundException("[ Error when getting entity by ID. ]");
    } catch (Exception e) {
        LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting entity by ID. ] ");
    }
}

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

public Integer sumOfSearch(String searchType, Object keyWord) {
    String jpql = new String();
    ///*from  w ww.  ja  va2 s.c  o m*/
    //      if (searchType.equals("???")) {
    if (searchType.equals("???")) {
        jpql = "select lic from License lic where lic.licTypeCode =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.uploadDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("")) {
        jpql = "select lic from License lic where lic.expireDate =:keyWord order by lic.licenseCode";
    }
    if (searchType.equals("?")) {
        jpql = "select lic from License lic where lic.isExpire =:keyWord order by lic.licenseCode";
    }
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    //query.setHint(QueryHints.RESULT_TYPE, ResultType.Map);
    query.setParameter("keyWord", keyWord);
    int sum = ((query.getResultList().size()) - 1) / PublicVariable.rows + 1;
    return sum;
}