-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Value injection using Transformers.aliasToBean()
PostPosted: Fri Feb 05, 2010 10:41 am 
Beginner
Beginner

Joined: Tue Sep 08, 2009 9:49 am
Posts: 23
Hi,

I'm using the Transformers class, to inject the return values of an sql query into the unmanaged class (DTO) SearchResultItem.
Now what I don't get is, how to inject return values from that sql query into the member class Domain of SearchResultItem?

For example I want it to inject the value of the domain column, into SearchResultItem.Domain.domain.

Any ideas?

Best regards
Humppa

SearchResultItem:
Code:
public abstract class SearchResultItem
{
   protected String headline;
   protected String body;
   protected String link;
   protected Float rank;
   protected Integer number;
   protected Domain domain;
   
   public SearchResultItem(String headline, String body, String link, Float rank, Integer number)
   {
      this.headline = headline;
      this.body = body;
      this.link = link;
      this.rank = rank;
      this.number = number;
   }

   public SearchResultItem()
   {
   }
   
   @Override
   public String toString()
   {
      return this.headline;
   }

   public String getHeadline()
   {
      return headline;
   }

   public void setHeadline(String headline)
   {
      this.headline = headline;
   }

   public String getBody()
   {
      return body;
   }

   public void setBody(String body)
   {
      this.body = body;
   }

   public String getLink()
   {
      return link;
   }

   public void setLink(String link)
   {
      this.link = link;
   }

   public Float getRank()
   {
      return rank;
   }

   public void setRank(Float rank)
   {
      this.rank = rank;
   }

   public Integer getNumber()
   {
      return number;
   }

   public void setNumber(Integer number)
   {
      this.number = number;
   }

   public Domain getDomain()
   {
      return domain;
   }

   public void setDomain(Domain domain)
   {
      this.domain = domain;
   }
   
   
}


Domain Class:
Code:
public abstract class Domain
{
   protected Integer id;
   protected String domain;
   
   public Domain(Integer id, String domain)
   {
      this.id = id;
      this.domain = domain;
   }
   public Domain()
   {
   }
   
   public Integer getId()
   {
      return id;
   }
   public void setId(Integer id)
   {
      this.id = id;
   }
   public String getDomain()
   {
      return domain;
   }
   public void setDomain(String domain)
   {
      this.domain = domain;
   }
}


the SQL query:
Code:
   <sql-query name="Search.SQL.ByFTS">
      <query-param name="query" type="string"/>
      <query-param name="domain" type="string"/>
      <query-param name="language" type="string"/>

      
      
      <!-- 'string'||'%' concats two strings -->
      <![CDATA[
         SELECT d.domain AS item.domain.domain, d.id AS item.domain.domainid, p.title AS item.headline, p.url AS item.link, ts_headline(p.text, to_tsquery(regconfig(:language), :query), 'MaxWords=35') AS item.body, ts_rank_cd('{0.4,0.6,0.8,1.0}',p.fti, to_tsquery(regconfig(:language), :query),32) AS item.rank
         FROM page p
         INNER JOIN domain d ON p.domainid = d.id
         WHERE
         p.url LIKE :domain||'%' AND p.fti @@ to_tsquery(:query)
         ORDER BY rank DESC, p.lastcrawl
      ]]>
      
      <!--
         SELECT d.domain AS domain, d.id as domainid, p.title AS headline, p.url AS link, ts_headline(p.text, to_tsquery(regconfig(:language), :query), 'MaxWords=35') as body, ts_rank_cd('{0.4,0.6,0.8,1.0}',p.fti, to_tsquery(regconfig(:language), :query),32) AS rank
         FROM page p
         INNER JOIN domain d ON p.domainid = d.id
         WHERE
         p.url LIKE :domain||'%' AND p.fti @@ to_tsquery(:query)
         ORDER BY rank DESC, p.lastcrawl
       -->
   </sql-query>


Execution of the query:
Code:
            List<SearchResultItem> list = (List<SearchResultItem>)this.getSession()   .getNamedQuery("Search.SQL.ByFTS")
                                    .setParameter("domain", query.getDomain())
                                    .setParameter("query", query.getQuery())
                                    .setParameter("language", query.getLanguage().name().toLowerCase())
                                    .setMaxResults(query.getPageItemCnt())
                                    .setFirstResult(itemOffset)
                                    [b].setResultTransformer(Transformers.aliasToBean(SearchResultItem.class))[/b]
                                    .list();



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.