Example usage for javax.persistence TypedQuery getResultList

List of usage examples for javax.persistence TypedQuery getResultList

Introduction

In this page you can find the example usage for javax.persistence TypedQuery getResultList.

Prototype

List<X> getResultList();

Source Link

Document

Execute a SELECT query and return the query results as a typed List.

Usage

From source file:org.cleverbus.core.reqres.RequestResponseTest.java

/**
 * Test saving response only, there is no request.
 *///www.j ava 2s . c  om
@Test
public void testSavingResponseOnly() throws Exception {
    setPrivateField(reqSendingEventNotifier, "enable", Boolean.FALSE);

    // prepare target route
    prepareTargetRoute(TARGET_URI, null);

    // action
    mock.expectedMessageCount(1);
    producer.sendBody(REQUEST);

    // verify
    TypedQuery<Request> queryReq = em.createQuery("FROM " + Request.class.getName(), Request.class);
    List<Request> requests = queryReq.getResultList();
    assertThat(requests.size(), is(0));

    TypedQuery<Response> queryRes = em.createQuery("FROM " + Response.class.getName(), Response.class);
    List<Response> responses = queryRes.getResultList();
    assertThat(responses.size(), is(1));
}

From source file:org.bigtester.ate.model.data.dao.ElementInputDataDaoImpl.java

/**
 * Gets the value.//www. j  a v a2  s.co  m
 *
 * @param inputDataID
 *            the input data id
 * @return the value
 */
public String getValue(String inputDataID, String repeatStepName, String repeatStepExternalLoopPath,
        int iteration) throws RepeatTestDataException {

    if ("".equals(repeatStepExternalLoopPath))
        return getValue(inputDataID, repeatStepName, iteration);//NOPMD
    List<ElementInputData> retVal;
    String sql = "select p from ElementInputData p where repeatStepExternalLoopPath=:repeatStepExternalLoopPath and FirstTimeExecution= 'No' and p.stepEIDsetID = :stepEIDsetID and p.repeatStepName=:repeatStepName and p.iteration=:iteration";
    TypedQuery<ElementInputData> query = getDbEM().createQuery(sql, ElementInputData.class);
    query.setParameter("repeatStepExternalLoopPath", repeatStepExternalLoopPath);
    query.setParameter("stepEIDsetID", inputDataID);
    query.setParameter("repeatStepName", repeatStepName);
    query.setParameter("iteration", iteration);
    retVal = (List<ElementInputData>) query.getResultList();
    if (retVal.isEmpty()) {
        throw new RepeatTestDataException(ExceptionMessage.MSG_TESTDATA_NOTFOUND,
                ExceptionErrorCode.REPEATTESTDATA_NOTFOUND, repeatStepName, repeatStepExternalLoopPath,
                iteration);
    } else if (retVal.size() > 1) { // NOPMD
        throw new RepeatTestDataException(ExceptionMessage.MSG_TESTDATA_DUPLICATED,
                ExceptionErrorCode.REPEATTESTDATA_DUPLICATED, repeatStepName, repeatStepExternalLoopPath,
                iteration);
    } else {
        return retVal.get(0).getDataValue();
    }

}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

@Override
public Page<T> findAll(Specification<T> spec, Pageable pageable, EntityGraphType type,
        String... attributeGraph) {
    final TypedQuery<T> typedQuery = getQuery(spec, pageable);

    if (attributeGraph != null && attributeGraph.length > 0) {
        final EntityGraph<T> entityGraph = this.entityManager.createEntityGraph(getDomainClass());
        buildEntityGraph(entityGraph, attributeGraph);
        typedQuery.setHint(type.getType(), entityGraph);
    }// w  w w .  j  av a2 s .co m

    return pageable == null ? new PageImpl<T>(typedQuery.getResultList())
            : readPage(typedQuery, pageable, spec);
}

From source file:org.cleverbus.core.reqres.RequestResponseTest.java

/**
 * Test saving response with message only, there is no request.
 *///from  w w w .  j a  v a2 s. c  om
@Test
@Transactional
public void testSavingResponseWithMsgOnly() throws Exception {
    setPrivateField(reqSendingEventNotifier, "enable", Boolean.FALSE);

    // prepare target route
    prepareTargetRoute(TARGET_URI, null);

    // action
    mock.expectedMessageCount(1);

    Message msg = insertMessage();

    producer.sendBodyAndHeader(REQUEST, AsynchConstants.MSG_HEADER, msg);

    // verify
    TypedQuery<Response> queryRes = em.createQuery("FROM " + Response.class.getName(), Response.class);
    List<Response> responses = queryRes.getResultList();
    assertThat(responses.size(), is(1));
}

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

@Override
@Nullable/*from  w w  w  .j  a  v a2 s  . co  m*/
public Message findPartlyFailedMessage(int interval) {
    // find message that was lastly processed before specified interval
    Date lastUpdateLimit = DateUtils.addSeconds(new Date(), -interval);

    String jSql = "SELECT m " + "FROM " + Message.class.getName() + " m " + "WHERE m.state = '"
            + MsgStateEnum.PARTLY_FAILED + "'" + "     AND m.lastUpdateTimestamp < :lastTime"
            + " ORDER BY m.msgTimestamp";

    TypedQuery<Message> q = em.createQuery(jSql, Message.class);
    q.setParameter("lastTime", new Timestamp(lastUpdateLimit.getTime()));
    q.setMaxResults(1);
    List<Message> messages = q.getResultList();

    if (messages.isEmpty()) {
        return null;
    } else {
        return messages.get(0);
    }
}

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

@Override
@Nullable/*from w ww  . j av a2s. co m*/
public Message findPostponedMessage(int interval) {
    // find message that was lastly processed before specified interval
    Date lastUpdateLimit = DateUtils.addSeconds(new Date(), -interval);

    String jSql = "SELECT m " + "FROM " + Message.class.getName() + " m " + "WHERE m.state = '"
            + MsgStateEnum.POSTPONED + "'" + "     AND m.lastUpdateTimestamp < :lastTime"
            + " ORDER BY m.msgTimestamp";

    TypedQuery<Message> q = em.createQuery(jSql, Message.class);
    q.setParameter("lastTime", new Timestamp(lastUpdateLimit.getTime()));
    q.setMaxResults(1);
    List<Message> messages = q.getResultList();

    if (messages.isEmpty()) {
        return null;
    } else {
        return messages.get(0);
    }
}

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:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImpl.java

/**
 * {@inheritDoc}/*  w  ww  .ja  v  a2 s .  c o m*/
 */
@Override
public List<String> getAllHostsWithActiveJobs() {
    log.debug("Called");

    final TypedQuery<String> query = entityManager
            .createNamedQuery(JobExecutionEntity.QUERY_FIND_HOSTS_BY_STATUS, String.class);
    query.setParameter("statuses", JobStatus.getActiveStatuses());

    return query.getResultList();
}

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

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