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.siriusit.spezg.multilib.storage.jpa.JpaPersonRepository.java

@Override
public boolean contains(Person person) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countPersonsByUsername", Long.class);
    return query.setParameter("username", person.getUsername()).getSingleResult() == 1;
}

From source file:org.openmeetings.app.data.flvrecord.FlvRecordingLogDaoImpl.java

public List<FlvRecordingLog> getFLVRecordingLogByRecordingId(Long flvRecordingId) {
    try {/*from   w ww. j  a va  2 s  . c  om*/
        String hql = "select c from FlvRecordingLog as c where c.flvRecording.flvRecordingId = :flvRecordingId";

        TypedQuery<FlvRecordingLog> query = em.createQuery(hql, FlvRecordingLog.class);
        query.setParameter("flvRecordingId", flvRecordingId);
        List<FlvRecordingLog> flvRecordingList = query.getResultList();

        return flvRecordingList;

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

From source file:com.deltastar.task7.core.repository.api.impl.FundRepositoryImpl.java

@Override
public Fund getFundByName(String fundName) {
    TypedQuery<Fund> query = entityManager.createNamedQuery("findFundByFundName", Fund.class);
    query.setParameter("p_fundName", fundName);
    List<Fund> fundList = query.getResultList();
    return (fundList != null && !fundList.isEmpty()) ? fundList.get(0) : null;
}

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

@Override
public List<Mensaje> findMensajeByCuenta(Cuenta cuenta) {

    if (cuenta == null) {
        return null;
    }//from  w ww. ja  v  a  2  s .  c  o  m

    TypedQuery<Mensaje> query = em.createNamedQuery("Mensaje.findMensajeByCuenta", Mensaje.class);
    query.setParameter("idValor", cuenta.getId());

    return query.getResultList();
}

From source file:com.beto.test.securityinterceptor.model.dao.generic.AbstractDao.java

public T getObWithNamedQuery(String query, String paramName, Object param) throws Exception {
    TypedQuery<T> tq = getEntityManager().createNamedQuery(query, entityClass);
    tq.setParameter(paramName, param);
    return tq.getSingleResult();
}

From source file:org.mitre.uma.repository.impl.JpaResourceSetRepository.java

@Override
public Collection<ResourceSet> getAllForOwner(String owner) {
    TypedQuery<ResourceSet> query = em.createNamedQuery(ResourceSet.QUERY_BY_OWNER, ResourceSet.class);
    query.setParameter(ResourceSet.PARAM_OWNER, owner);
    return query.getResultList();
}

From source file:org.cleverbus.core.common.dao.RequestResponseDaoJpaImpl.java

@Override
public List<Request> findByCriteria(Date from, Date to, String subUri, String subRequest) {
    Assert.notNull(from, "the from must not be null");
    Assert.notNull(to, "the to must not be null");

    String jSql = "SELECT r " + "         FROM " + Request.class.getName() + " r "
            + "           WHERE r.reqTimestamp >= :from " + "               AND r.reqTimestamp <= :to ";

    if (hasText(subUri)) {
        jSql += "           AND r.uri like :subUri)";
    }/*  w ww  . j a v  a2s  .  c  o  m*/
    if (hasText(subRequest)) {
        jSql += "           AND r.request like :subRequest)";
    }

    jSql += "           ORDER BY r.reqTimestamp";

    TypedQuery<Request> q = em.createQuery(jSql, Request.class);
    q.setParameter("from", new Timestamp(from.getTime()));
    q.setParameter("to", new Timestamp(to.getTime()));
    if (hasText(subUri)) {
        q.setParameter("subUri", "%" + subUri + "%");
    }
    if (hasText(subRequest)) {
        q.setParameter("subRequest", "%" + subRequest + "%");
    }
    q.setMaxResults(MAX_REQUESTS_IN_ONE_QUERY);

    return q.getResultList();
}

From source file:org.mitre.uma.repository.impl.JpaResourceSetRepository.java

@Override
public Collection<ResourceSet> getAllForClient(String clientId) {
    TypedQuery<ResourceSet> query = em.createNamedQuery(ResourceSet.QUERY_BY_CLIENT, ResourceSet.class);
    query.setParameter(ResourceSet.PARAM_CLIENTID, clientId);
    return query.getResultList();
}

From source file:eu.europa.ec.fisheries.uvms.rules.dao.ValidationMessageDao.java

public List<ValidationMessage> getValidationMessagesById(List<String> ids) throws ServiceException {
    TypedQuery query = this.getEntityManager().createNamedQuery(ValidationMessage.BY_ID,
            ValidationMessage.class);
    query.setParameter("messageIds", ids);
    return query.getResultList();
}

From source file:com.expressui.sample.view.opportunity.OpportunityQuery.java

@Override
public void setParameters(TypedQuery typedQuery) {
    if (!isEmpty(accountName)) {
        typedQuery.setParameter("accountName", "%" + accountName.toUpperCase() + "%");
    }/* w  w w .j a  v a2  s  .  c  o  m*/
    if (!isEmpty(salesStages)) {
        typedQuery.setParameter("salesStages", salesStages);
    }
}