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.ushahidi.swiftriver.core.api.dao.impl.JpaActivityDao.java

public List<Activity> find(long accountId, Integer count, Long lastId, Boolean newer, Boolean followers) {
    String qlString = "SELECT ac " + "FROM Activity ac " + "JOIN ac.account a ";

    qlString += (followers) ? "JOIN a.followers f JOIN f.follower a2 WHERE a2.id = :accountId "
            : "WHERE a.id = :accountId ";

    if (newer != null && newer) {
        if (lastId != null) {
            qlString += "AND ac.id > :lastId ";
        }/*from  www  .ja va  2 s .c o  m*/
        qlString += "ORDER BY ac.id ASC ";
    } else {
        if (lastId != null) {
            qlString += "AND ac.id < :lastId ";
        }
        qlString += "ORDER BY ac.id DESC ";
    }

    TypedQuery<Activity> query = em.createQuery(qlString, Activity.class);
    query.setParameter("accountId", accountId);

    if (lastId != null) {
        query.setParameter("lastId", lastId).setMaxResults(count);
    }

    List<Activity> activities = query.getResultList();

    if (activities.size() == 0)
        return null;

    return activities;

}

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

@Override
@Transactional(value = "defaultTransactionManager")
public List<AuthenticationHolderEntity> getOrphanedAuthenticationHolders() {
    TypedQuery<AuthenticationHolderEntity> query = manager
            .createNamedQuery(AuthenticationHolderEntity.QUERY_GET_UNUSED, AuthenticationHolderEntity.class);
    query.setMaxResults(MAXEXPIREDRESULTS);
    List<AuthenticationHolderEntity> unusedAuthenticationHolders = query.getResultList();
    return unusedAuthenticationHolders;
}

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

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

        TypedQuery<Employee> query = em.createNamedQuery("Employee.findAllFreeEmployees", 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.deltastar.task7.core.repository.api.impl.PositionViewRepositoryImpl.java

@Override
public List<PositionView> getPositionViewListByCustomerId(int customerId, byte positionStatus) {
    TypedQuery<PositionView> query = entityManager.createNamedQuery("findPositionViewByCustomerIdAndStatus",
            PositionView.class);
    query.setParameter("p_customerId", customerId);
    query.setParameter("p_status", positionStatus);
    List<PositionView> result = query.getResultList();

    if (positionStatus == CCConstants.POSITION_STATUS_IN_POSSESSION && !Util.isEmptyList(result)) {
        List<PositionView> filteredResult = new ArrayList<>();
        for (PositionView aResult : result) {
            if (aResult.getShares() > 0) {
                filteredResult.add(aResult);
            }//w  w  w  .  ja va2s. c om
        }
        result = filteredResult;
    }
    return result;
}

From source file:com.sixsq.slipstream.persistence.Run.java

public static List<RunView> viewList(User user, String moduleResourceUri, Integer offset, Integer limit,
        String cloudServiceName) throws ConfigurationException, ValidationException {
    List<RunView> views = null;
    EntityManager em = PersistenceUtil.createEntityManager();
    try {/*from  w  ww.  j  a va 2 s . c  o m*/
        CriteriaBuilder builder = em.getCriteriaBuilder();
        CriteriaQuery<Run> critQuery = builder.createQuery(Run.class);
        Root<Run> rootQuery = critQuery.from(Run.class);
        critQuery.select(rootQuery);
        Predicate where = viewListCommonQueryOptions(builder, rootQuery, user, moduleResourceUri,
                cloudServiceName);
        if (where != null) {
            critQuery.where(where);
        }
        critQuery.orderBy(builder.desc(rootQuery.get("startTime")));
        TypedQuery<Run> query = em.createQuery(critQuery);
        if (offset != null) {
            query.setFirstResult(offset);
        }
        query.setMaxResults((limit != null) ? limit : DEFAULT_LIMIT);
        List<Run> runs = query.getResultList();
        views = convertRunsToRunViews(runs);
    } finally {
        em.close();
    }
    return views;
}

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

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

    String jSql = "SELECT c " + "FROM " + ExternalCall.class.getName() + " c " + "WHERE c.state = '"
            + ExternalCallStateEnum.PROCESSING + "'" + "     AND c.lastUpdateTimestamp < :time";

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

From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java

public List<LdapConfig> getLdapConfigs() {
    try {/*w w  w  .j ava  2 s  .  c o  m*/
        log.debug("selectMaxFromConfigurations ");

        String hql = "select c from LdapConfig c " + "where c.deleted LIKE 'false' ";

        //get all users
        TypedQuery<LdapConfig> query = em.createQuery(hql, LdapConfig.class);
        List<LdapConfig> ll = query.getResultList();

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

From source file:org.openmeetings.app.data.calendar.daos.AppointmentCategoryDaoImpl.java

public List<AppointmentCategory> getAppointmentCategoryList() {
    try {// ww  w . j a va2  s.c o m

        String hql = "select a from AppointmentCategory a " + "WHERE a.deleted <> :deleted ";

        TypedQuery<AppointmentCategory> query = em.createQuery(hql, AppointmentCategory.class);
        query.setParameter("deleted", "true");

        List<AppointmentCategory> listAppointmentCategory = query.getResultList();

        return listAppointmentCategory;
    } catch (Exception ex2) {
        log.error("[AppointmentCategory]: " + ex2);
    }
    return null;
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.LexiconBuilderController.java

/**
 * Gets all the documents being used to build the lexicon.
 * @param em the {@link EntityManager} to use.
 * @param builder the {@link LexiconBuilderDocumentStore} to use.
 * @param seen whether to show only seen or unseen documents; {@code null} means no filtering.
 * @return the {@link List} of {@link LexiconBuilderDocument} objects.
 */// w  w w .j a va 2s  .  c  o  m
public List<LexiconBuilderDocument> getDocuments(EntityManager em, LexiconBuilderDocumentStore builder,
        Boolean seen) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(builder, CannedMessages.NULL_ARGUMENT, "builder");

    TypedQuery<LexiconBuilderDocument> query = this.getDocumentsQuery(em, builder, seen);
    return query.getResultList();
}

From source file:org.mitre.uma.service.impl.JpaRegisteredClientService.java

private SavedRegisteredClient getSavedRegisteredClientFromStorage(String issuer) {
    TypedQuery<SavedRegisteredClient> query = em.createQuery(
            "SELECT c from SavedRegisteredClient c where c.issuer = :issuer", SavedRegisteredClient.class);
    query.setParameter("issuer", issuer);

    SavedRegisteredClient saved = JpaUtil.getSingleResult(query.getResultList());
    return saved;
}