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.businessmanager.dao.StorageFileDaoImpl.java

@Override
public StorageFile getLatestStorageFile(User user, String fileId) {
    TypedQuery<StorageFile> query = getEntityManager().createQuery(
            "FROM StorageFile s WHERE s.fileId = :fileId AND s.user = :user ORDER BY s.version DESC",
            StorageFile.class).setParameter("fileId", fileId).setParameter("user", user);

    List<StorageFile> resultList = query.getResultList();

    if (resultList.size() > 0) {
        return resultList.get(0);
    }//  w w w.j a  v a 2 s .com

    return null;
}

From source file:eu.domibus.common.dao.MessageLogDao.java

public List<MessageLogEntry> findPaged(int from, int max, String column, boolean asc,
        HashMap<String, Object> filters) {

    CriteriaBuilder cb = this.em.getCriteriaBuilder();
    CriteriaQuery<MessageLogEntry> cq = cb.createQuery(MessageLogEntry.class);
    Root<MessageLogEntry> mle = cq.from(MessageLogEntry.class);
    cq.select(mle);//from   ww w .  j  a  va2  s.c o m
    List<Predicate> predicates = new ArrayList<Predicate>();
    for (Map.Entry<String, Object> filter : filters.entrySet()) {
        if (filter.getValue() != null) {
            if (filter.getValue() instanceof String) {
                if (!filter.getValue().toString().isEmpty()) {
                    switch (filter.getKey().toString()) {
                    case "receivedFrom":
                        predicates.add(cb.greaterThanOrEqualTo(mle.<Date>get("received"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    case "receivedTo":
                        predicates.add(cb.lessThanOrEqualTo(mle.<Date>get("received"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    default:
                        predicates.add(cb.like(mle.<String>get(filter.getKey()), (String) filter.getValue()));
                        break;
                    }
                }
            } else {
                predicates.add(cb.equal(mle.<String>get(filter.getKey()), filter.getValue()));
            }
        }
    }
    cq.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    if (column != null) {
        if (asc) {
            cq.orderBy(cb.asc(mle.get(column)));
        } else {
            cq.orderBy(cb.desc(mle.get(column)));
        }

    }
    final TypedQuery<MessageLogEntry> query = this.em.createQuery(cq);
    query.setFirstResult(from);
    query.setMaxResults(max);
    return query.getResultList();
}

From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java

public List<TestTypeDTO> getTestTypeDTOList() {
    TypedQuery<TestTypeDTO> query = createEntityManager().createQuery("SELECT t FROM TestTypeDTO t",
            TestTypeDTO.class);
    return query.getResultList();
}

From source file:com.pingdu.dao.licenseDao.LicenseDao.java

public License getLicenseInfo(int entCode, int licenseCode) {
    String jpql = "select l from License l where l.licenseCode=:licenseCode ANDl.entCode=:entCode";
    TypedQuery<License> query = em().createQuery(jpql, License.class);
    query.setParameter("licenseCode", licenseCode);
    query.setParameter("entCode", entCode);
    List<License> licenses = query.getResultList();
    if (licenses.size() == 1) {
        return licenses.get(0);
    } else {/*from   w ww . ja v  a 2  s. c  o m*/
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
        System.out.println("????");
    }
    License license = new License();
    return license;
}

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

public List<AppointmentReminderTyps> getAppointmentReminderTypList() {
    log.debug("getAppointmenetReminderTypList");

    try {/*w w  w  .j a  v a 2 s . c o  m*/

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

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

        List<AppointmentReminderTyps> listAppointmentReminderTyp = query.getResultList();

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

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

@Nullable
@Override/*from www  . j  a  v  a 2  s .  c  o m*/
public Request findLastRequest(String uri, String responseJoinId) {
    Assert.hasText(uri, "the uri must not be empty");
    Assert.hasText(responseJoinId, "the responseJoinId must not be empty");

    String jSql = "SELECT r " + "FROM " + Request.class.getName() + " r "
            + "WHERE r.responseJoinId = :responseJoinId AND r.uri = :uri " + "ORDER BY r.reqTimestamp";

    TypedQuery<Request> q = em.createQuery(jSql, Request.class);
    q.setParameter("responseJoinId", responseJoinId);
    q.setParameter("uri", uri);

    // we search by unique key - it's not possible to have more records
    List<Request> requests = q.getResultList();
    if (requests.isEmpty()) {
        return null;
    } else {
        return requests.get(0); // if find more items then return first one only
    }
}

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

@Override
public Collection<ApprovedSite> getByClientIdAndUserId(String clientId, String userId) {

    TypedQuery<ApprovedSite> query = manager.createNamedQuery(ApprovedSite.QUERY_BY_CLIENT_ID_AND_USER_ID,
            ApprovedSite.class);
    query.setParameter(ApprovedSite.PARAM_USER_ID, userId);
    query.setParameter(ApprovedSite.PARAM_CLIENT_ID, clientId);

    return query.getResultList();
}

From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java

public List<AssetStateType> getAssetStateTypeList() {
    TypedQuery<AssetStateType> query = createEntityManager().createQuery("SELECT t FROM AssetStateType t",
            AssetStateType.class);
    return query.getResultList();
}

From source file:br.eti.danielcamargo.backend.hsnpts.core.business.MicrocicloService.java

/**
 * Se o microciclo existir e for incompleto, ele  retornado.
 * <br />/*w  ww.j av  a 2s.c  om*/
 * Se o microciclo no existir ou estiver completo, cria um novo.
 *
 * @param alunoId
 * @return
 * @throws
 * br.eti.danielcamargo.backend.hsnpts.core.business.exceptions.ProgramaFinalizadoException
 */
@Transactional
public Microciclo resolverMicrociclo(Long alunoId) throws ProgramaFinalizadoException {

    StringBuilder hql = new StringBuilder();

    hql.append("SELECT ");
    hql.append(" p ");
    hql.append("FROM ");
    hql.append("  Programa p ");
    hql.append("WHERE ");
    hql.append("  p.aluno.id = :alunoId ");
    hql.append("  AND p.dataTermino IS NULL ");

    TypedQuery<Programa> queryPrograma = em.createQuery(hql.toString(), Programa.class);
    queryPrograma.setParameter("alunoId", alunoId);
    Programa programa = queryPrograma.getSingleResult();

    hql.append("SELECT ");
    hql.append(" m ");
    hql.append("FROM ");
    hql.append(" Microciclo m ");
    hql.append("WHERE ");
    hql.append(" m.programa = :programa ");
    hql.append("ORDER BY ");
    hql.append(" m.numero DESC ");

    TypedQuery<Microciclo> queryMicrociclo = em.createQuery(hql.toString(), Microciclo.class);
    queryMicrociclo.setParameter("programa", programa);
    queryMicrociclo.setMaxResults(1);

    List<Microciclo> result = queryMicrociclo.getResultList();

    HsnPersonal hsnPersonal = HsnPersonalUtils.getInstance();
    ObjetivoPrograma objetivoPrograma = programa.getObjetivoPrograma();
    FrequenciaSemanal frequenciaSemanal = programa.getFrequenciaSemanal();

    if (result.isEmpty()) {
        //criar primeiro microciclo
        Microciclo microciclo = hsnPersonal.buscarMicrociclo(objetivoPrograma, frequenciaSemanal, 1);
        microciclo.setPrograma(programa);
        save(microciclo);
        return microciclo;
    } else {
        //verificar se o programa esta finalizado
        Microciclo microciclo = result.get(0);
        if (microciclo.getDataTermino() != null) {
            if (microciclo.getNumero().equals(24)) {
                throw new ProgramaFinalizadoException();
            }
            microciclo = hsnPersonal.buscarMicrociclo(objetivoPrograma, frequenciaSemanal, 1);
            microciclo.setPrograma(programa);
            save(microciclo);
            return microciclo;
        }
        return microciclo;
    }
}

From source file:com.silverpeas.notification.delayed.repository.DelayedNotificationRepositoryImpl.java

@Override
public List<Integer> findUsersToBeNotified(final Set<NotifChannel> aimedChannels,
        final Set<DelayedNotificationFrequency> aimedFrequencies,
        final boolean isThatUsersWithNoSettingHaveToBeNotified) {

    // Parameters
    final List<TypedParameter<?>> parameters = new ArrayList<TypedParameter<?>>();

    // Query/*from w  w w  . j a  v  a  2 s  .  c o m*/
    final StringBuilder query = new StringBuilder();
    query.append("select distinct d.userId from DelayedNotificationData d ");
    query.append("  left outer join d.delayedNotificationUserSetting p ");
    query.append("where d.channel in (:");
    query.append(
            TypedParameterUtil.addNamedParameter(parameters, "channels", NotifChannel.toIds(aimedChannels)));
    query.append(") and ( ");
    query.append("  (p.id is not null and p.frequency in (:");
    query.append(TypedParameterUtil.addNamedParameter(parameters, "frequencies",
            DelayedNotificationFrequency.toCodes(aimedFrequencies))).append(")) ");
    if (isThatUsersWithNoSettingHaveToBeNotified) {
        query.append("  or p.id is null ");
    }
    query.append(") ");

    // Typed query
    final TypedQuery<Integer> typedQuery = em.createQuery(query.toString(), Integer.class);

    // Parameters
    TypedParameterUtil.computeNamedParameters(typedQuery, parameters);

    // Result
    return typedQuery.getResultList();
}