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.dspace.content.dao.impl.CollectionDAOImpl.java

License:BSD License

@Override
@SuppressWarnings("unchecked")
public List<Map.Entry<Collection, Long>> getCollectionsWithBitstreamSizesTotal(Context context)
        throws SQLException {
    String q = "select col as collection, sum(bit.sizeBytes) as totalBytes from Item i join i.collections col join i.bundles bun join bun.bitstreams bit group by col";
    Query query = createQuery(context, q);
    query.setResultTransformer(new BasicTransformerAdapter() {
        @Override//from w  ww .  j  ava2s  .co m
        public Object transformTuple(Object[] tuple, String[] aliases) {
            return new java.util.AbstractMap.SimpleImmutableEntry<>((Collection) tuple[0], (Long) tuple[1]);
        }
    });
    return ((List<Map.Entry<Collection, Long>>) query.list());
}

From source file:org.dspace.content.dao.impl.WorkspaceItemDAOImpl.java

License:BSD License

@Override
@SuppressWarnings("unchecked")
public List<Map.Entry<Integer, Long>> getStageReachedCounts(Context context) throws SQLException {
    Query query = createQuery(context,
            "SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi"
                    + " group by wi.stageReached order by wi.stageReached");
    query.setResultTransformer(new BasicTransformerAdapter() {
        @Override/*from  w  w  w  .  j a  v a  2s . c o  m*/
        public Object transformTuple(Object[] tuple, String[] aliases) {
            return new java.util.AbstractMap.SimpleImmutableEntry((Integer) tuple[0], (Long) tuple[1]);
        }
    });
    return (List<Map.Entry<Integer, Long>>) query.list();
}

From source file:org.ednovo.gooru.domain.service.DomainRepositoryHibernate.java

License:Open Source License

@Override
public List<Map<String, String>> getDomainAttributes(Integer courseId, Integer domainId, int limit,
        int offset) {
    Query query = getSession().createSQLQuery(GET_DOMAIN_ATTRIBUTES);
    query.setParameter(COURSE_ID, courseId);
    query.setParameter(DOMAIN_ID, domainId);
    query.setMaxResults(limit > MAX_LIMIT ? MAX_LIMIT : limit);
    query.setFirstResult(offset);//w  w  w  . j av a  2s  . co m
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    return list(query);
}

From source file:org.ednovo.gooru.domain.service.TaxonomyCourseRepositoryHibernate.java

License:Open Source License

@Override
public List<Map<String, Object>> getDomains(Integer courseId, int limit, int offset) {
    Query query = getSession().createSQLQuery(GET_DOMAINS).setParameter(COURSE_ID, courseId);
    query.setMaxResults(limit > MAX_LIMIT ? MAX_LIMIT : limit);
    query.setFirstResult(offset);//  ww  w  . j  a v a  2 s .co m
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    return list(query);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.index.ContentIdexDaoImpl.java

License:Open Source License

@Override
public Map<String, Object> getQuizInfo(long contentId) {
    Query query = createSQLQuery(GET_QUIZ_INFO).setLong(CONTENT_ID, contentId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List results = query.list();//from w w  w .ja  v a2 s  .  co  m
    return (results.size() > 0 ? (Map<String, Object>) results.get(0) : null);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.index.ContentIdexDaoImpl.java

License:Open Source License

@Override
public Map<String, Object> getAnswerAndHint(long contentId) {
    Query query = createSQLQuery(GET_QUESTION_AND_HINT).setLong(CONTENT_ID, contentId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List results = query.list();/*from   ww w . j a v  a2 s  . c  om*/
    return (results.size() > 0 ? (Map<String, Object>) results.get(0) : null);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.resource.ResourceRepositoryHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  ww w  .ja  v a 2 s  .  c o  m*/
public Map<String, Object> getResourceCollectionInfo(long contentId) {
    String sql = "SELECT CONCAT_WS(\",\",GROUP_CONCAT(DISTINCT l.goals SEPARATOR \" , \") ,GROUP_CONCAT(DISTINCT l.vocabulary SEPARATOR\" , \"),GROUP_CONCAT(DISTINCT l.notes SEPARATOR \" , \"),GROUP_CONCAT(DISTINCT l.narration SEPARATOR \" , \")) as \"collection.classplanContent\",GROUP_CONCAT(DISTINCT l.lesson SEPARATOR \" , \") as \"collection.lesson\" FROM learnguide l WHERE l.content_id =:contentId";
    Query query = getSession().createSQLQuery(sql);
    query.setParameter("contentId", contentId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    @SuppressWarnings("rawtypes")
    List results = query.list();
    return (Map<String, Object>) ((results.size() > 0) ? results.get(0) : null);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.resource.ResourceRepositoryHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w ww  . ja  v a 2s  .c om*/
public List<Map<String, Object>> getPartyPermissions(long contentId) {
    String sql = "select cp.party_uid as uId,p.party_name as name,p.party_type as type FROM content_permission cp INNER JOIN party p on p.party_uid = cp.party_uid WHERE cp.content_id=:contentId";
    Query query = getSession().createSQLQuery(sql);
    query.setParameter("contentId", contentId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.resource.ResourceRepositoryHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w w  w .j av  a 2s  .  com*/
public Map<String, Object> getContentSubscription(long contentId) {
    String sql = "select a.resource_id as subscribed_content_id ,count(*) as subscriberCount from content c inner join annotation a on a.resource_id = c.content_id where a.type_name='subscription' and c.content_id=:contentId";
    Query query = getSession().createSQLQuery(sql);
    query.setParameter("contentId", contentId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    @SuppressWarnings("rawtypes")
    List results = query.list();
    return (Map<String, Object>) ((results.size() > 0) ? results.get(0) : null);
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.SubdomainRepositoryHibernate.java

License:Open Source License

@Override
public Map<String, Object> getSubdomain(Integer subdomainId) {
    Query query = getSession().createSQLQuery(SUBDOMAIN);
    query.setParameter(SUBDOMAIN_ID, subdomainId);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> results = list(query);
    return (Map<String, Object>) ((results.size() > 0) ? results.get(0) : null);
}