Package org.hibernate.transform

Examples of org.hibernate.transform.ResultTransformer


        query.addScalar("COMMENT_COUNT", Hibernate.LONG);
        query.setFirstResult( pager.getQueryFirstResult() );
        query.setMaxResults( pager.getQueryMaxResults() );

        query.setResultTransformer(
            new ResultTransformer() {
                public Object transformTuple(Object[] result, String[] aliases) {
                    BlogEntry be = new BlogEntry();
                    be.setEntryDocument( (WikiDocument)result[0]);
                    blogEntryMap.put(be.getEntryDocument().getId(), be); // Put in map so we can attach comment count later
                    return be;
                }
                public List transformList(List list) { return list; }
            }
        );

        List<BlogEntry> result = (List<BlogEntry>)query.list();

        if (countComments && result.size() > 0) {
            // The risk here is that pager.getQueryMaxResults() is too large for the IN() operator of some DBs...
            StringBuilder commentQueryString = new StringBuilder();
            commentQueryString.append("select doc.NODE_ID as DOC_ID, count(c1.NODE_ID) as COMMENT_COUNT").append(" ");
            commentQueryString.append("from WIKI_DOCUMENT doc").append(" ");
            commentQueryString.append("left outer join WIKI_NODE c1 on doc.NODE_ID = c1.PARENT_NODE_ID").append(" ");
            commentQueryString.append("where doc.NODE_ID in (:blogEntriesIds)").append(" ");
            commentQueryString.append("group by doc.NODE_ID");

            SQLQuery commentQuery = getSession().createSQLQuery(commentQueryString.toString());
            commentQuery.setComment("Finding comment count for blog entries");
            commentQuery.addScalar("DOC_ID");
            commentQuery.addScalar("COMMENT_COUNT");
            commentQuery.setParameterList("blogEntriesIds", blogEntryMap.keySet());

            commentQuery.setResultTransformer(
              new ResultTransformer() {
                  public Object transformTuple(Object[] result, String[] aliases) {
                      BlogEntry be = blogEntryMap.get( ((BigInteger)result[0]).longValue() );
                      be.setCommentCount( ((BigInteger)result[1]).longValue() );
                      return null;
                  }
View Full Code Here


        if (projectYear)    query.addScalar("YEAR", Hibernate.INTEGER);
        if (projectMonth)   query.addScalar("MONTH", Hibernate.INTEGER);
        if (projectDay)     query.addScalar("DAY", Hibernate.INTEGER);

        query.setResultTransformer(
            new ResultTransformer() {
                public Object transformTuple(Object[] result, String[] aliases) {
                    BlogEntryCount beCount = new BlogEntryCount();
                    beCount.setNumOfEntries( (Long)result[0] );
                    if (projectYear)    beCount.setYear( (Integer)result[1] );
                    if (projectMonth)   beCount.setMonth( (Integer)result[2] );
View Full Code Here

        getSession(true).getNamedQuery("forumTopicsForUser")
                .setParameterList("parentDirectories", forumDirectories)
                .setParameter("user", user)
                .setComment("Finding forum topcis for user: " + user)
                .setResultTransformer(
                        new ResultTransformer() {
                            public Object transformTuple(Object[] result, String[] strings) {
                                WikiDocument doc = (WikiDocument) result[0];
                                topicInfoMap.put(
                                        doc.getId(),
                                        new TopicInfo(doc)
                                );
                                return null;
                            }
                            public List transformList(List list) { return list; }
                        }
                )
                .setFirstResult(firstResult)
                .setMaxResults(maxResults)
                .list();

        if (topicInfoMap.size() > 0) {
            getSession(true).getNamedQuery("forumTopicsReplies")
                .setParameterList("topicIds", topicInfoMap.keySet())
                .setComment("Retrieving forum topic replies")
                .setResultTransformer(
                    new ResultTransformer() {
                        public Object transformTuple(Object[] result, String[] strings) {
                            if (topicInfoMap.containsKey((Long)result[1])) {
                                TopicInfo info = topicInfoMap.get( (Long)result[1] );
                                info.setNumOfReplies((Long)result[2]);
                                info.setLastComment((WikiComment)result[0]);
View Full Code Here

        getSession(true).getNamedQuery("forums")
            .setParameter("parentDir", forumsDirectory)
            .setComment("Finding all forums")
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] result, String[] strings) {
                        forumInfoMap.put(
                            (Long) result[0],
                            new ForumInfo( (WikiDirectory)result[1])
                        );
                        return null;
                    }
                    public List transformList(List list) { return list; }
                }
            )
            .list();

        // Find topic and replies count (topics are just wiki documents in the forum directories)
        getSession(true).getNamedQuery("forumTopicReplyCount")
            .setParameter("parentDirId", forumsDirectory.getId())
            .setParameter("readAccessLevel", currentAccessLevel)
            .setComment("Finding topic and replies count for all forums")
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] result, String[] strings) {
                        if (forumInfoMap.containsKey((Long)result[0])) {
                            ForumInfo info = forumInfoMap.get( (Long)result[0] );
                            info.setTotalNumOfTopics((Long)result[1]);
                            info.setTotalNumOfPosts(info.getTotalNumOfTopics());
                            if (result[2] != null) {
                                info.setTotalNumOfPosts(info.getTotalNumOfPosts() + (Long)result[2]);
                            }
                        }
                        return null;
                    }
                    public List transformList(List list) { return list; }
                }
            )
            .list();

        // Append last topic WikiDocument (faster if we do it with a MySQL specific LIMIT subselect)
        List<Object[]> forumsAndLastTopics = getSession(true).getNamedQuery("forumLastTopic")
            .setParameter("parentDirId", forumsDirectory.getId())
            .setParameter("readAccessLevel", currentAccessLevel)
            .setComment("Finding last topics for all forums")
            .list();
        for (Object[] lastTopicRow : forumsAndLastTopics) {
            if (forumInfoMap.containsKey((Long)lastTopicRow[0])) {
                WikiDocument lastTopic = wikiNodeDAO.findWikiDocument( (Long)lastTopicRow[1] );
                forumInfoMap.get( (Long)lastTopicRow[0] ).setLastTopic( lastTopic );
            }
        }

        // Append last reply WikiComment
        for (final Long forumId : forumInfoMap.keySet()) {
            getSession(true).getNamedQuery("forumLastReply")
                    .setParameter("parentDirId", forumId)
                    .setParameter("readAccessLevel", currentAccessLevel)
                    .setComment("Finding last replies for forum : " + forumId)
                    .setResultTransformer(
                        new ResultTransformer() {
                            public Object transformTuple(Object[] result, String[] strings) {
                                forumInfoMap.get(forumId).setLastComment( (WikiComment)result[0] );
                                return null;
                            }
                            public List transformList(List list) { return list; }
View Full Code Here

            .setParameter("parentDir", directory)
            .setParameter("lastLoginDate", lastLoginDate)
            .setComment("Finding unread topics")
            .setCacheable(true)
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] objects, String[] strings) {
                        unreadTopics.put((Long)objects[0], (Long)objects[1]);
                        return null;
                    }
                    public List transformList(List list) { return list;}
                }
            )
            .list();

        getSession(true).getNamedQuery(unreadRepliesQuery)
            .setParameter("parentDirId", directory.getId())
            .setParameter("readAccessLevel", currentAccessLevel)
            .setParameter("lastLoginDate", lastLoginDate)
            .setComment("Finding unread replies")
            .setCacheable(true)
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] objects, String[] strings) {
                        unreadTopics.put((Long)objects[0], (Long)objects[1]);
                        return null;
                    }
                    public List transformList(List list) { return list;}
View Full Code Here

            .setParameter("readAccessLevel", currentAccessLevel)
            .setComment("Retrieving forum topics list")
            .setFirstResult(new Long(firstResult).intValue())
            .setMaxResults(new Long(maxResults).intValue())
            .setResultTransformer(
                    new ResultTransformer() {
                        public Object transformTuple(Object[] result, String[] strings) {
                            Long topicId = (Long) result[0];
                            Integer sticky = (Integer)result[1];
                            Boolean hasReplies = (Boolean)result[2];
                            topicInfoMap.put(topicId, new TopicInfo(sticky, hasReplies));
                            return null;
                        }
                        public List transformList(List list) { return list; }
                    }
            )
            .list();

        if (topicInfoMap.keySet().size() == 0) return topicInfoMap; // Early exit possible

        // Retrieve the topic entity instances and shove them into the map
        getSession(true).getNamedQuery("forumTopics")
            .setParameterList("topicIds", topicInfoMap.keySet())
            .setComment("Retrieving forum topic list instances")
            .setResultTransformer(
                    new ResultTransformer() {
                        public Object transformTuple(Object[] result, String[] strings) {
                            WikiDocument topicInstance = (WikiDocument)result[0];
                            topicInfoMap.get(topicInstance.getId()).setTopic(topicInstance);
                            return null;
                        }
                        public List transformList(List list) { return list; }
                    }
            )
            .list();


        // Figure out which and if we even should query the reply instances
        List<Long> topicIdsWithReplies = new ArrayList<Long>();
        for (Map.Entry<Long, TopicInfo> entry : topicInfoMap.entrySet()) {
            if (entry.getValue().isReplies()) topicIdsWithReplies.add(entry.getKey());
        }

        if (topicIdsWithReplies.size() == 0) return topicInfoMap; // Early exit possible
       
        getSession(true).getNamedQuery("forumTopicsReplies")
            .setParameterList("topicIds", topicIdsWithReplies)
            .setComment("Retrieving forum topic replies")
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] result, String[] strings) {
                        if (topicInfoMap.containsKey((Long)result[1])) {
                            TopicInfo info = topicInfoMap.get( (Long)result[1] );
                            info.setNumOfReplies((Long)result[2]);
                            info.setLastComment((WikiComment)result[0]);
View Full Code Here

            .setParameterList("ignoreUserInRoles", excludeRoles )
            .setMaxResults(maxResults)
            .setComment("Retrieving forum posters and rating points")
            .setCacheable(true)
            .setResultTransformer(
                new ResultTransformer() {
                    public Object transformTuple(Object[] result, String[] strings) {
                        ((User)result[0]).setRatingPoints((Long)result[1]);
                        postersAndRatingPoints.add((User)result[0]);
                        return null;
                    }
View Full Code Here

          key,
          result
      );
    }
   
    ResultTransformer resolvedTransformer = resolveResultTransformer( queryParameters.getResultTransformer() );
    if ( resolvedTransformer != null ) {
      result = (
          areResultSetRowsTransformedImmediately() ?
              key.getResultTransformer().retransformResults(
                  result,
View Full Code Here

          key,
          result
      );
    }

    ResultTransformer resolvedTransformer = resolveResultTransformer( queryParameters.getResultTransformer() );
    if ( resolvedTransformer != null ) {
      result = (
          areResultSetRowsTransformedImmediately() ?
              key.getResultTransformer().retransformResults(
                  result,
View Full Code Here

          key,
          result
      );
    }

    ResultTransformer resolvedTransformer = resolveResultTransformer( queryParameters.getResultTransformer() );
    if ( resolvedTransformer != null ) {
      result = (
          areResultSetRowsTransformedImmediately() ?
              key.getResultTransformer().retransformResults(
                  result,
View Full Code Here

TOP

Related Classes of org.hibernate.transform.ResultTransformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.