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:edu.sabanciuniv.sentilab.sare.models.base.documentStore.PersistentDocumentStore.java

/**
 * Gets identifiers of documents in this store.
 * @param em the {@link EntityManager} to get the documents from.
 * @return an {@link Iterable} of document identifiers.
 *///from w w  w  . j a  v a  2s  . c  o  m
public Iterable<byte[]> getDocumentIds(EntityManager em) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<byte[]> cq = cb.createQuery(byte[].class);
    Root<PersistentDocument> doc = cq.from(PersistentDocument.class);
    cq.multiselect(doc.get("id"))
            .where(cb.equal(doc.get("store"), cb.parameter(PersistentDocumentStore.class, "store")));
    TypedQuery<byte[]> tq = em.createQuery(cq);
    tq.setParameter("store", this);
    return tq.getResultList();
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.UserAreaDao.java

/**
 * <p>Update Start date and End date for user areas those are created by the user</p>
 * <p><code>StartDate</code> and <code>EndDate</code> can be NULL or Empty or a Valid Date</p>
 *
 * @param remoteUser User Name/* w  w w.j  a  v  a2s .  c o m*/
 * @param startDate Start Date
 * @param endDate End Date
 * @param type Area Type
 * @throws ServiceException Exception is Date cannot be updated
 *
 * @see UserAreaDao#updateUserAreasForUserAndScope(Date, Date, String)
 */
public void updateUserAreasForUser(String remoteUser, Date startDate, Date endDate, String type)
        throws ServiceException {
    TypedQuery query = (TypedQuery) getEntityManager()
            .createNamedQuery(UserAreasEntity.UPDATE_USERAREA_FORUSER);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    query.setParameter("userName", remoteUser);
    query.setParameter("type", type);
    query.executeUpdate();
}

From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java

public Object getUserByHash(String hash) {
    try {/* www . j a  v a2  s  .c o m*/
        if (hash.length() == 0)
            return new Long(-5);
        String hql = "SELECT u FROM Users as u " + " where u.resethash = :resethash"
                + " AND u.deleted <> :deleted";
        TypedQuery<Users> query = em.createQuery(hql, Users.class);
        query.setParameter("resethash", hash);
        query.setParameter("deleted", "true");
        Users us = null;
        try {
            us = query.getSingleResult();
        } catch (NoResultException ex) {
        }
        if (us != null) {
            return us;
        } else {
            return new Long(-5);
        }
    } catch (Exception e) {
        log.error("[getUserByAdressesId]", e);
    }
    return new Long(-1);
}

From source file:eu.ggnet.dwoss.report.ReportAgentBean.java

@Override
public List<SimpleReportLine> findSimple(SearchParameter search, int firstResult, int maxResults) {
    StringBuilder sb = new StringBuilder("Select l from SimpleReportLine l");
    if (!StringUtils.isBlank(search.getRefurbishId()))
        sb.append(" where l.refurbishId = :refurbishId");
    L.debug("Using created SearchQuery:{}", sb);
    TypedQuery<SimpleReportLine> q = reportEm.createQuery(sb.toString(), SimpleReportLine.class);
    if (!StringUtils.isBlank(search.getRefurbishId()))
        q.setParameter("refurbishId", search.getRefurbishId().trim());
    q.setFirstResult(firstResult);// w  w w  . j  a  va2s  .  c o m
    q.setMaxResults(maxResults);
    return q.getResultList();
}

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

@Override
public List<Message> findProcessingMessages(int interval) {
    final Date startProcessLimit = DateUtils.addSeconds(new Date(), -interval);

    String jSql = "SELECT m " + "FROM " + Message.class.getName() + " m " + "WHERE m.state = '"
            + MsgStateEnum.PROCESSING + "'" + "     AND m.startProcessTimestamp < :startTime";

    TypedQuery<Message> q = em.createQuery(jSql, Message.class);
    q.setParameter("startTime", new Timestamp(startProcessLimit.getTime()));
    q.setMaxResults(MAX_MESSAGES_IN_ONE_QUERY);
    return q.getResultList();
}

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

@Override
public List<Message> findMessagesByContent(String substring) {
    Assert.hasText("the substring must not be empty", substring);

    String jSql = "SELECT m " + "     FROM " + Message.class.getName() + " m "
            + " WHERE (m.payload like :substring) ORDER BY m.msgId DESC";

    TypedQuery<Message> q = em.createQuery(jSql, Message.class);
    q.setParameter("substring", "%" + substring + "%");
    q.setMaxResults(MAX_MESSAGES_IN_ONE_QUERY);

    return q.getResultList();
}

From source file:eu.domibus.ebms3.common.dao.PModeDao.java

@Override
public LegConfiguration getLegConfiguration(final String pModeKey) {
    final TypedQuery<LegConfiguration> query = this.entityManager
            .createNamedQuery("LegConfiguration.findByName", LegConfiguration.class);
    query.setParameter("NAME", this.getLegConfigurationNameFromPModeKey(pModeKey));
    return query.getSingleResult();
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.UserAreaDao.java

/**
 * <p>Update Start date and End date for user areas if the user is having scope <code><B>MANAGE_ANY_USER_AREA</B></code>
 * <p><code>StartDate</code> and <code>EndDate</code> can be NULL or Empty or a Valid Date</p>
 *
 * @param startDate Start Date/*from w  ww. j  a  v a  2s  .  c om*/
 * @param endDate End Date
 * @param type Area Type
 * @exception ServiceException Exception is Date cannot be updated
 *
 * @see UserAreaDao#updateUserAreasForUser(String, Date, Date, String)
 */
public void updateUserAreasForUserAndScope(Date startDate, Date endDate, String type) throws ServiceException {
    TypedQuery query = (TypedQuery) getEntityManager()
            .createNamedQuery(UserAreasEntity.UPDATE_USERAREA_FORUSER_AND_SCOPE);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    query.setParameter("type", type);
    query.executeUpdate();
}

From source file:com.music.dao.PieceDao.java

public List<Piece> getUserPieces(Long userId, int page, int pageSize) {
    TypedQuery<Piece> query = getEntityManager().createQuery(
            "SELECT pe.piece FROM PieceEvaluation pe WHERE pe.user.id=:userId AND pe.positive = true ORDER BY pe.dateTime DESC",
            Piece.class);
    query.setParameter("userId", userId);
    query.setFirstResult(page * pageSize);
    query.setMaxResults(pageSize);//from w ww.j  a va 2 s. c om

    return query.getResultList();
}

From source file:eu.domibus.ebms3.common.dao.PModeDao.java

protected String findLegName(final String agreementRef, final String senderParty, final String receiverParty,
        final String service, final String action) throws EbMS3Exception {
    final Query candidatesQuery = this.entityManager
            .createNamedQuery("LegConfiguration.findForPartiesAndAgreements");
    candidatesQuery.setParameter("AGREEMENT", agreementRef);
    candidatesQuery.setParameter("SENDER_PARTY", senderParty);
    candidatesQuery.setParameter("RECEIVER_PARTY", receiverParty);
    final List<LegConfiguration> candidates = candidatesQuery.getResultList();
    if (candidates == null || candidates.isEmpty()) {
        throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0001, "No Candidates for Legs found", null,
                null, null);//  ww w .  j av  a 2  s  .c o  m
    }
    final TypedQuery<String> query = this.entityManager.createNamedQuery("LegConfiguration.findForPMode",
            String.class);
    query.setParameter("SERVICE", service);
    query.setParameter("ACTION", action);
    final Collection<String> candidateIds = new ArrayList();
    for (final LegConfiguration candidate : candidates) {
        candidateIds.add(candidate.getName());
    }
    query.setParameter("CANDIDATES", candidateIds);
    try {
        return query.getSingleResult();
    } catch (final NoResultException e) {
        PModeDao.LOG.info("", e);
    }
    throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0001, "No matching leg found", null, null,
            null);
}