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:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Override
public List<Bet> getBetsByCompetition(Long competitionID) {
    TypedQuery<Bet> query = entityManager.createNamedQuery("Bet.findByCompetitionID", Bet.class);
    query.setParameter("competitionID", competitionID);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    return query.getResultList();
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.EmployeeRepositoryImplementation.java

@Override
public List<Employee> getAll() {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<Employee> list = new LinkedList<>();
    try {//from  w  w  w .j a v a  2  s  .co m
        em.getTransaction().begin();

        TypedQuery<Employee> query = em.createNamedQuery("Employee.findAll", Employee.class);
        list = query.getResultList();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(EmployeeRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return list;
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancyRepositoryImplementation.java

@Override
public List<Vacancy> getAll() {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<Vacancy> list = new LinkedList<>();
    try {//from w ww  .  j  a  va 2  s  .  com
        em.getTransaction().begin();

        TypedQuery<Vacancy> query = em.createNamedQuery("Vacancy.findAll", Vacancy.class);
        list = query.getResultList();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(VacancyRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return list;
}

From source file:net.dontdrinkandroot.persistence.dao.GenericJpaDao.java

/**
 * Finds all entities by the given {@link CriteriaQuery} and limit the result set.
 * // w ww .  j  a v  a 2  s  .c  om
 * @param maxResults
 *            The maximum number of results to retrieve.
 */
protected <V> List<V> find(final CriteriaQuery<V> criteriaQuery, final int maxResults) {
    final TypedQuery<V> query = this.getEntityManager().createQuery(criteriaQuery);
    query.setMaxResults(maxResults);

    return query.getResultList();
}

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

@Override
@Nullable/* w  ww. j  a  va2s . c o  m*/
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public ExternalCall getExternalCall(String operationName, String entityId) {
    Assert.notNull(operationName, "operationName (uri) must not be null");
    Assert.notNull(entityId, "entityId (operation key) must not be null");

    String jSql = "SELECT c FROM " + ExternalCall.class.getName() + " c "
            + "WHERE c.operationName = ?1 AND c.entityId = ?2";
    TypedQuery<ExternalCall> q = em.createQuery(jSql, ExternalCall.class);
    q.setParameter(1, operationName);
    q.setParameter(2, entityId);

    List<ExternalCall> results = q.getResultList();
    if (results.isEmpty()) {
        return null;
    }

    if (results.size() > 1) {
        throw new MultipleDataFoundException(
                String.format("Multiple ExternalCall instances found for operationName/entityId: %s/%s",
                        operationName, entityId));
    }

    return results.get(0);
}

From source file:org.mitre.oauth2.repository.impl.JpaAuthorizationCodeRepository.java

@Override
@Transactional(value = "defaultTransactionManager")
public AuthorizationCodeEntity getByCode(String code) {
    TypedQuery<AuthorizationCodeEntity> query = manager.createNamedQuery(AuthorizationCodeEntity.QUERY_BY_VALUE,
            AuthorizationCodeEntity.class);
    query.setParameter("code", code);

    AuthorizationCodeEntity result = JpaUtil.getSingleResult(query.getResultList());
    return result;
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2ClientRepository.java

@Override
public ClientDetailsEntity getClientByClientId(String clientId) {
    TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery(ClientDetailsEntity.QUERY_BY_CLIENT_ID,
            ClientDetailsEntity.class);
    query.setParameter(ClientDetailsEntity.PARAM_CLIENT_ID, clientId);
    return JpaUtil.getSingleResult(query.getResultList());
}

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

public List<PrivateMessageFolder> getPrivateMessageFolderByUserId(Long userId) {
    try {//from   ww w .  j a  v a 2  s . co m
        String hql = "select c from PrivateMessageFolder c " + "where c.userId = :userId ";

        TypedQuery<PrivateMessageFolder> query = em.createQuery(hql, PrivateMessageFolder.class);
        query.setParameter("userId", userId);

        List<PrivateMessageFolder> privateMessageFolders = query.getResultList();

        return privateMessageFolders;
    } catch (Exception e) {
        log.error("[getPrivateMessageFolderByUserId]", e);
    }
    return null;
}

From source file:com.june.app.board.repository.jpa.BoardRepositoryImpl.java

@Override
public Collection<Board> boardListWithPaging(Board vo) {
    int bbsId = vo.getBbsId();
    int pageSize = vo.getPageSize();
    int pageNumber = (int) vo.getPageIndex();

    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<Board> criteriaQuery = criteriaBuilder.createQuery(Board.class);

    Root<Board> from = criteriaQuery.from(Board.class);
    CriteriaQuery<Board> select = criteriaQuery.select(from);
    if (bbsId > 0) {
        criteriaQuery.where(criteriaBuilder.equal(from.get("bbsId"), bbsId));
    }/*from ww  w  . j  av  a  2  s  . co m*/
    /**list desc for date*/
    criteriaQuery.orderBy(criteriaBuilder.desc(from.get("frstRegistPnttm")));
    TypedQuery<Board> typedQuery = em.createQuery(select);

    typedQuery.setFirstResult((pageNumber - 1) * pageSize);
    typedQuery.setMaxResults(pageSize);

    Collection<Board> fooList = typedQuery.getResultList();

    return fooList;

}

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

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