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, Date value, TemporalType temporalType);

Source Link

Document

Bind an instance of java.util.Date to a positional parameter.

Usage

From source file:com.siberhus.ngai.core.CrudHelper.java

public final static Query createQueryObject(EntityManager em, String queryString, List<Object> paramList) {
    if (em == null) {
        throw new IllegalArgumentException("EntityManager is null");
    }//from   w  ww.j  a v  a 2s  . co  m
    Query query = em.createQuery(queryString);
    for (int i = 0; i < paramList.size(); i++) {
        Object param = paramList.get(i);
        if (param instanceof TemporalObject) {
            TemporalObject tempParam = ((TemporalObject) param);
            query.setParameter(i + 1, tempParam.getTemporalObject(), tempParam.getTemporalType());
        } else {
            query.setParameter(i + 1, param);
        }
    }
    return query;
}

From source file:com.hmsinc.epicenter.model.util.ModelUtils.java

/**
 * Applies all parameters necessary to a query (Hibernate native Query).
 * /* ww w . j  a  v a 2 s . co m*/
 * @param query
 * @param parameters
 * @return
 */
public static org.hibernate.Query applyParameters(final org.hibernate.Query query,
        final Map<String, Object> parameters) {
    for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
        if (parameter.getValue() instanceof Collection) {
            query.setParameterList(parameter.getKey(), (Collection<?>) parameter.getValue());
        } else if (parameter.getValue() instanceof Geometry) {
            query.setParameter(parameter.getKey(), parameter.getValue(), geometryType);
        } else {
            query.setParameter(parameter.getKey(), parameter.getValue());
        }
    }
    return query;
}

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

public List<Poll> loadOpenPolls(User user) {
    Query openPolls = this.entityManager.createNamedQuery(FIND_OPEN_POLLS);
    openPolls.setParameter(PARAMETER_CURRENT_DATE, new Date(), TemporalType.DATE);
    openPolls.setParameter(PARAMETER_USER, user);

    return openPolls.getResultList();
}

From source file:org.mitre.openid.connect.repository.impl.JpaEventRepository.java

@SuppressWarnings("unchecked")
@Override/*  w ww.  j  a  va2 s  .c om*/
@Transactional
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize) {

    Query query = manager.createQuery("SELECT e FROM Event e WHERE e.timestamp BETWEEN :start AND :end");

    query = query.setParameter("start", start, TemporalType.DATE);
    query = query.setParameter("end", end, TemporalType.DATE);
    query = query.setFirstResult(startChunk);
    query = query.setMaxResults(chunkSize);

    return query.getResultList();
}