Example usage for org.hibernate Query setResultTransformer

List of usage examples for org.hibernate Query setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Query setResultTransformer.

Prototype

@Deprecated
Query<R> setResultTransformer(ResultTransformer transformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:org.inbio.neoportal.core.dao.impl.TaxonDescriptionDAOImpl.java

License:Open Source License

@Override
public List<TaxonDescriptionFullCDTO> findAllByScientificName(final String scientificName,
        final String provider) {
    Session session = getSessionFactory().getCurrentSession();
    Query query = session.createQuery(
            "from TaxonDescription as td" + " where lower(td.scientificName) = lower(:scientificName)"
                    + " and lower(td.institutionCode) = lower(:provider)");
    query.setParameter("scientificName", scientificName);
    query.setParameter("provider", provider);
    query.setResultTransformer(new TaxonDescriptionFullTransformer());

    //query.setCacheable(true);
    return query.list();

}

From source file:org.inbio.neoportal.core.dao.impl.TaxonDescriptionDAOImpl.java

License:Open Source License

@Override
public List<TaxonDescriptionFullCDTO> findAllByScientificName(final String scientificName) {
    Session session = getSessionFactory().getCurrentSession();
    Query query = session.createQuery(
            "from TaxonDescription as td" + " where lower(td.scientificName) = lower(:scientificName)");
    query.setParameter("scientificName", scientificName);
    query.setResultTransformer(new TaxonDescriptionFullTransformer());

    //query.setCacheable(true);
    return query.list();
}

From source file:org.inbio.neoportal.image_crawler.DAO.DefaultM3sDAO.java

License:Open Source License

public List<Map<String, Object>> getImages(int offset, int quantity) {
    Session session = sessionFactoryM3s.getCurrentSession();

    Query query = session.createSQLQuery("select m.media_id, tm.taxon_id, "
            + "p.first_name || ' ' || p.last_name as author, " + "t.name as rights " + "from core.media m "
            + "left join core.taxon_media tm ON m.media_id = tm.media_id "
            + "left join core.person p ON m.author_person_id = p.person_id "
            + "left join core.use_policy up ON m.use_policy_id = up.use_policy_id "
            + "left join core.text_translation t ON up.name_text_id = t.text_id "
            + "where tm.taxon_id is not null");
    query.setFirstResult(offset);/*from w  ww  . j  av  a2s.c om*/
    query.setMaxResults(quantity);
    query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

    List<Map<String, Object>> result = query.list();
    return result;
}

From source file:org.jasig.ssp.dao.external.ExternalStudentFinancialAidAwardTermDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<ExternalStudentFinancialAidAwardTerm> getStudentFinancialAidAwardsBySchoolId(String schoolId) {
    Query criteria = createHqlQuery("SELECT faAward.schoolId as faAward_schoolId, "
            + "faAward.accepted as faAward_accepted, " + "faAward.termCode as faAward_termCode "
            + "FROM ExternalStudentFinancialAidAwardTerm as faAward, Term as faAwardTerm "
            + "WHERE faAward.schoolId = :schoolId AND faAward.termCode = faAwardTerm.code "
            + "ORDER BY faAwardTerm.startDate DESC");
    criteria.setParameter("schoolId", schoolId);
    criteria.setResultTransformer(
            new NamespacedAliasToBeanResultTransformer(ExternalStudentFinancialAidAwardTerm.class, "faAward_"));
    return (List<ExternalStudentFinancialAidAwardTerm>) criteria.list();

}

From source file:org.jasig.ssp.dao.external.ExternalStudentTranscriptTermDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<ExternalStudentTranscriptTerm> getExternalStudentTranscriptTermsBySchoolId(String schoolId) {
    Query criteria = createHqlQuery("SELECT transcript.schoolId as transcript_schoolId, "
            + "transcript.creditHoursForGpa as transcript_creditHoursForGpa, "
            + "transcript.creditHoursEarned as transcript_creditHoursEarned, "
            + "transcript.creditHoursAttempted as transcript_creditHoursAttempted, "
            + "transcript.creditHoursNotCompleted as transcript_creditHoursNotCompleted, "
            + "transcript.creditCompletionRate as transcript_creditCompletionRate, "
            + "transcript.totalQualityPoints as transcript_totalQualityPoints, "
            + "transcript.gradePointAverage as transcript_gradePointAverage, "
            + "transcript.termCode as transcript_termCode "
            + "FROM ExternalStudentTranscriptTerm as transcript, Term as transcriptTerm "
            + "WHERE transcript.schoolId = :schoolId AND transcript.termCode = transcriptTerm.code "
            + "ORDER BY transcriptTerm.startDate DESC");
    criteria.setParameter("schoolId", schoolId);
    criteria.setResultTransformer(
            new NamespacedAliasToBeanResultTransformer(ExternalStudentTranscriptTerm.class, "transcript_"));
    return (List<ExternalStudentTranscriptTerm>) criteria.list();
}

From source file:org.jasig.ssp.dao.PersonSearchDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<PersonSearchResult2> search(PersonSearchRequest personSearchRequest) {
    Term currentTerm;/* w ww .  j a va  2  s .c om*/
    FilterTracker filterTracker = new FilterTracker();
    try {
        currentTerm = termService.getCurrentTerm();
    }
    //If there is no current term, lets degrade silently
    catch (ObjectNotFoundException e) {
        LOGGER.error(
                "CURRENT TERM NOT SET, org.jasig.ssp.dao.PersonSearchDao.search(PersonSearchRequest) is being called but will not function properly");
        currentTerm = new Term();
        currentTerm.setName("CURRENT TERM NOT SET");
        currentTerm.setStartDate(Calendar.getInstance().getTime());
        currentTerm.setEndDate(Calendar.getInstance().getTime());

    }
    StringBuilder stringBuilder = buildSelect();

    buildFrom(personSearchRequest, stringBuilder);

    buildJoins(personSearchRequest, stringBuilder);

    buildWhere(personSearchRequest, filterTracker, stringBuilder);

    Query query = createHqlQuery(stringBuilder.toString());

    addBindParams(personSearchRequest, query, currentTerm);
    query.setResultTransformer(
            new NamespacedAliasToBeanResultTransformer(PersonSearchResult2.class, "person_"));
    return query.list();
}

From source file:org.jasig.ssp.dao.PlanDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<PlanCourseCountTO> getPlanCountByCourse(SearchPlanTO form) {

    final StringBuilder selectAndFrom = new StringBuilder("select count(distinct pc.id) as plan_studentCount, ")
            .append("pc.courseCode as plan_courseCode, ").append("pc.formattedCourse as plan_formattedCourse, ")
            .append("pc.courseTitle as plan_courseTitle, ").append("pc.termCode as plan_termCode ")
            .append("from Plan p, PlanCourse pc, Person person");

    final StringBuilder where = new StringBuilder(
            " where p.objectStatus = :objectStatus and pc.plan.id = p.id and p.person.id = person.id ");

    final boolean isPlanStatusFilter = form.getPlanStatus() != null;
    boolean calculateMapPlanStatus = false;
    if (isPlanStatusFilter) {
        calculateMapPlanStatus = Boolean
                .parseBoolean(configService.getByNameEmpty("calculate_map_plan_status").trim().toLowerCase());
        if (calculateMapPlanStatus) {
            selectAndFrom.append(", MapStatusReport msr ");
            where.append(" and msr.planStatus = :planStatus ");
            where.append(" and msr.plan = p and msr.person.id = person.id");
        } else {//  ww w. j a  va 2s.c  o  m
            selectAndFrom.append(", ExternalPersonPlanStatus ps ");
            where.append(" and ps.status = :planStatus ");
            where.append(" and ps.schoolId = person.schoolId ");
        }
    }

    buildQueryCourseFilters(form, selectAndFrom, where);
    final String queryStr = selectAndFrom.append(where)
            .append(" group by pc.courseCode, pc.formattedCourse, pc.courseTitle, pc.termCode").toString();

    Query query = createHqlQuery(queryStr).setInteger("objectStatus", ObjectStatus.ACTIVE.ordinal());
    bindSearchPlanQueryParams(form, query);
    List<PlanCourseCountTO> planCoursesCount = query
            .setResultTransformer(new NamespacedAliasToBeanResultTransformer(PlanCourseCountTO.class, "plan_"))
            .list();

    return planCoursesCount;
}

From source file:org.jasig.ssp.dao.PlanDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<PlanStudentStatusTO> getPlanStudentStatusByCourse(SearchPlanTO form) {

    final StringBuilder selectAndFrom = new StringBuilder("select ")
            .append("distinct person.schoolId as plan_studentId, ")
            .append("pc.formattedCourse as plan_formattedCourse, ")
            .append("pc.courseTitle as plan_courseTitle, ").append("p.objectStatus as plan_planObjectStatus, ");

    final boolean calculateMapPlanStatus = Boolean
            .parseBoolean(configService.getByNameEmpty("calculate_map_plan_status").trim().toLowerCase());
    final boolean isPlanStatusFilter = form.getPlanStatus() != null;

    // subqueries b/c you can't do outer joins with Hibernate Theta-style joins, but if no plan status filter is
    // specified we want to return plans w/o status
    if (calculateMapPlanStatus) {
        selectAndFrom.append(/*from   w w  w . jav  a2  s.  c  om*/
                "(select msr.planStatus from MapStatusReport msr where msr.plan.id = p.id and msr.person.id = person.id")
                .append(isPlanStatusFilter ? " and msr.planStatus = :planStatus" : "")
                .append(") as plan_planStatus, ");
        selectAndFrom.append(
                "(select msr.planNote from MapStatusReport msr where msr.plan.id = p.id and msr.person.id = person.id")
                .append(isPlanStatusFilter ? " and msr.planStatus = :planStatus" : "")
                .append(") as plan_statusDetails ");
    } else {
        selectAndFrom.append(
                "(select ps.status from ExternalPersonPlanStatus ps where ps.schoolId = person.schoolId")
                .append(isPlanStatusFilter ? " and ps.status = :planStatus" : "")
                .append(") as plan_planStatus, ");
        selectAndFrom.append(
                "(select ps.statusReason from ExternalPersonPlanStatus ps where ps.schoolId = person.schoolId")
                .append(isPlanStatusFilter ? " and ps.status = :planStatus" : "")
                .append(") as plan_statusDetails ");
    }

    selectAndFrom.append(" from Plan p, Person person, PlanCourse pc ");
    final StringBuilder where = new StringBuilder(
            " where p.objectStatus = :objectStatus and pc.plan.id = p.id and p.person.id = person.id ");
    buildQueryCourseFilters(form, selectAndFrom, where);
    final String queryStr = selectAndFrom.append(where).toString();

    Query query = createHqlQuery(queryStr).setInteger("objectStatus", ObjectStatus.ACTIVE.ordinal());
    bindSearchPlanQueryParams(form, query);
    List<PlanStudentStatusTO> planStudentStatus = query.setResultTransformer(
            new NamespacedAliasToBeanResultTransformer(PlanStudentStatusTO.class, "plan_")).list();

    return planStudentStatus;
}

From source file:org.jboss.seam.wiki.test.nestedset.NestedSetTests.java

License:LGPL

private void showDirTree(String startDirName) throws Exception {
    if (log.isTraceEnabled()) {

        Session session = getHibernateSession();

        TestDirectory startDir = getTestDirectory(session, startDirName);
        if (startDir == null) {
            throw new RuntimeException("Could not find start dir with name: " + startDirName);
        }/*from   ww  w.  ja  v a 2  s . c o m*/

        NestedSetQueryBuilder nsQuery = new NestedSetQueryBuilder(startDir);
        Query nestedSetQuery = session.createQuery(nsQuery.getSimpleQuery());
        nestedSetQuery.setParameter("nsThread", startDir.getNodeInfo().getNsThread());
        nestedSetQuery.setParameter("nsLeft", startDir.getNodeInfo().getNsLeft());
        nestedSetQuery.setParameter("nsRight", startDir.getNodeInfo().getNsRight());

        // This comparator sorts the TestItems by name!
        Comparator<NestedSetNodeWrapper<TestDirectory>> comp = new Comparator<NestedSetNodeWrapper<TestDirectory>>() {
            public int compare(NestedSetNodeWrapper<TestDirectory> o, NestedSetNodeWrapper<TestDirectory> o2) {
                return o.getWrappedNode().getName().compareTo(o2.getWrappedNode().getName());
            }
        };

        NestedSetNodeWrapper<TestDirectory> startNodeWrapper = new NestedSetNodeWrapper<TestDirectory>(startDir,
                comp);
        nestedSetQuery.setResultTransformer(new NestedSetResultTransformer<TestDirectory>(startNodeWrapper));

        nestedSetQuery.list(); // Append all children hierarchically to the startNodeWrapper

        log.trace(
                "######################################## TREE BEGIN #####################################################");
        renderDirTree(startNodeWrapper);
        log.trace(
                "######################################## TREE END   #####################################################");

        session.close();
    }
}

From source file:org.jnap.core.persistence.hibernate.DaoSupport.java

License:Apache License

/**
 * /*from   www  .j a  v a2s .c  om*/
 * @param hql
 * @param returnType
 * @param params
 * @return
 */
protected <T> List<T> find(String hql, Class<T> returnType, Object... params) {
    Query query = getSession().createQuery(hql);
    query.setResultTransformer(Transformers.aliasToBean(returnType));
    QueryUtils.setIndexedParameters(query, params);
    return query.list();
}