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.openmeetings.app.data.basic.Navimanagement.java

public List<Naviglobal> getMainMenu(long user_level, long USER_ID) {
    try {//from ww w. java2  s  .co m
        TypedQuery<Naviglobal> query = em.createNamedQuery("getNavigation", Naviglobal.class);
        query.setParameter("level_id", user_level);
        List<Naviglobal> navi = query.getResultList();
        return navi;
    } catch (Exception ex2) {
        log.error("getMainMenu", ex2);
    }
    return null;
}

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

public List<Piece> getByPreferences(UserPreferences preferences) {
    String queryStr = "SELECT piece FROM Piece piece ORDER BY likes DESC, generationTime DESC";
    if (!preferences.isDefault()) {
        queryStr = addPreferenceCriteria(preferences, "SELECT piece FROM Piece piece WHERE ")
                + " ORDER BY likes DESC, generationTime DESC";
    }//from www  .ja  va2  s . com
    TypedQuery<Piece> query = getEntityManager().createQuery(queryStr, Piece.class);
    query.setMaxResults(30);

    return query.getResultList();
}

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

public SignalMessage findSignalMessageByMessageId(final String messageId) {

    final TypedQuery<SignalMessage> query = this.em.createNamedQuery("Messaging.findSignalMessageByMessageId",
            SignalMessage.class);
    query.setParameter("MESSAGE_ID", messageId);

    return DataAccessUtils.singleResult(query.getResultList());
}

From source file:hr.diskobolos.persistence.impl.EvaluationAnswerPersistenceImpl.java

@Override
public Map<MemberRegister, Integer> fetchTotalPointsPerMemberRegister(QuestionnaireType questionnaireType) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> cq = cb.createTupleQuery();
    Root<EvaluationAnswer> evaluationAnswer = cq.from(EvaluationAnswer.class);
    Join<EvaluationAnswer, QuestionChoicesDef> choiceDef = evaluationAnswer.join(EvaluationAnswer_.answer);
    Join<QuestionChoicesDef, EvaluationQuestionDef> questionDef = choiceDef
            .join(QuestionChoicesDef_.evaluationQuestionDef);
    ParameterExpression<QuestionnaireType> questionnaireTypeParam = cb.parameter(QuestionnaireType.class,
            "questionnaireType");
    Expression<Integer> value = evaluationAnswer.get(EvaluationAnswer_.answer).get(QuestionChoicesDef_.value)
            .as(Integer.class);
    cq.multiselect(evaluationAnswer.get(EvaluationAnswer_.memberRegister).alias("memberRegister"),
            value.alias("value"));
    cq.where(cb.equal(questionDef.get(EvaluationQuestionDef_.questionnaireType), questionnaireTypeParam));
    TypedQuery<Tuple> query = entityManager.createQuery(cq);
    query.setParameter("questionnaireType", questionnaireType);
    List<Tuple> result = query.getResultList();
    Map<MemberRegister, Integer> pointsPerMemberRegister = result.stream().collect(Collectors.groupingBy(t -> {
        return t.get("memberRegister", MemberRegister.class);
    }, Collectors.summingInt(t -> t.get("value", Integer.class))));

    return pointsPerMemberRegister;
}

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

@Override
public List<BasicSkill> getSkillsNotInVacancy(Vacancy vacancy) {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<BasicSkill> list = new LinkedList<>();
    try {//from w w w . j  a va  2s .  c o m
        em.getTransaction().begin();

        TypedQuery<BasicSkill> query = em.createNamedQuery("BasicSkill.findSkillsNotInVacancy",
                BasicSkill.class);
        query.setParameter("vacancy", vacancy);
        list = query.getResultList();

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

    return list;
}

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

public List<ErrorLogEntry> getUnnotifiedErrorsForMessage(String messageId) {
    final TypedQuery<ErrorLogEntry> query = this.em
            .createNamedQuery("ErrorLogEntry.findUnnotifiedErrorsByMessageId", ErrorLogEntry.class);
    query.setParameter("MESSAGE_ID", messageId);
    return query.getResultList();
}

From source file:com.ewcms.content.particular.dao.FrontProjectArticleDAO.java

public List<ProjectArticle> findProjectArticleBySector(Long organId) {
    String hql = "From ProjectArticle As p where p.organ.id=:organId and p.release=true Order By p.published desc ";
    TypedQuery<ProjectArticle> query = this.getEntityManager().createQuery(hql, ProjectArticle.class);
    query.setParameter("organId", Integer.valueOf(organId.toString()));
    return query.getResultList();
}

From source file:com.plan.proyecto.repositorios.DaoCuentaImpl.java

@Override
public Cuenta findByEmailAndPassword(String email, String pwd) {
    TypedQuery<Cuenta> query = em.createNamedQuery("Cuenta.findByEmailAndPassword", Cuenta.class);
    query.setParameter("valorEmail", email);
    query.setParameter("valorPassword", pwd);
    List<Cuenta> lista = query.getResultList();
    if (lista.isEmpty()) {
        return null;
    }//from  w w w  .  j  a va 2s.  c om
    return lista.get(0);
}

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

/**
 * Gets the size of a set cover (number of covered documents).
 * @param em the {@link EntityManager} to use.
 * @param setCover the {@link DocumentSetCover} whose size is required.
 * @return the {@link Long} count of documents.
 *///from w w  w. j  av a  2 s .  co m
public long getCoverSize(EntityManager em, DocumentSetCover setCover) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(setCover, CannedMessages.NULL_ARGUMENT, "setCover");

    TypedQuery<byte[]> query = em.createQuery(
            "SELECT scd.id FROM SetCoverDocument scd " + "WHERE scd.store=:sc " + "AND scd.flag=true",
            byte[].class);
    query.setParameter("sc", setCover);

    return query.getResultList().size();
}

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

@Override
public List<BasicSkill> getSkillsNotInEmployee(Employee employee) {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<BasicSkill> list = new LinkedList<>();
    try {/*from w w  w.  j a  v  a  2s . c  om*/
        em.getTransaction().begin();

        TypedQuery<BasicSkill> query = em.createNamedQuery("BasicSkill.findSkillsNotInEmployee",
                BasicSkill.class);
        query.setParameter("employee", employee);
        list = query.getResultList();

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

    return list;
}