You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Kris Barnhoorn <kr...@biassweb.be> on 2005/01/07 12:26:59 UTC

RE: access a resultmap

Hi Clinton,

Thank you for taking interest in my case.


I'd like to access this to create some sql fragment.

In my web pages I have a list where users can define dynamic criteria.
for this to work I have to send the actual name of the column.

But if I would create some method that translates a particular property
to his sql column based on the resultmap, I could use propertynames and
not sql column names.

So:

In webpage: propertyName / value / [AND | OR]  
		Add filter

In page handler(struts action):

	Create criteria (I use a own version of the Criteria class in
ORB)
	Send it with DAO

	
	In DAO:
	
	Set the Criteria in the SqlQuery class

       <select id="getPojos" parameterClass="org.foo.SqlQuery"
             resultClass="org.foo.Pojo">
             SELECT *
             FROM `pojos`
             WHERE
             <dynamic>
                   <isNotEmpty property="whereCriteriaString">
                         $whereCriteriaString$
                   </isNotEmpty>
             </dynamic>
       </select>
	
	So it is in the Criteria class I would create a method that
handles 	the conversion.	


Greetz,
Kris.

-----Oorspronkelijk bericht-----
Van: Clinton Begin [mailto:clinton.begin@gmail.com] 
Verzonden: vrijdag 31 december 2004 18:38
Aan: ibatis-user-java@incubator.apache.org
Onderwerp: Re: access a resultmap

I'd be more interested in why.  ;-)

The short answer to your question is "no".  But of course, there's ways.

What are you trying to do?

Cheers,
Clinton


On Fri, 31 Dec 2004 17:26:38 +0100, Kris Barnhoorn <kr...@biassweb.be>
wrote:
> Hi,
> 
> I was wondering if you can access a resultmap through the iBatis API
> To know what sql column is attached to a specific property
> 
> something like
> 
> ResultMap rm = getResultMap("rmName");
> rm.getColumnOfProperty("reference");
> 
> Thank you,
> Kris.
> 
>


RE: access a resultmap

Posted by Kris Barnhoorn <kr...@biassweb.be>.
Meanwhile this seems to work

public class LinkSqlMapDAO extends BaseSqlMapDAO implements LinkDAO{
    
    private final static String resultMapName = "Link.linkResult";
    
    private HashMap resultMappings;

....

    private void initResultMappings(){
       resultMappings = new HashMap();
       SqlMapClientImpl smci = (SqlMapClientImpl)getSqlMapExecutor();
       SqlMapExecutorDelegate smed =
SqlMapExecutorDelegate)smci.getDelegate();
       ResultMap rm = smed.getResultMap(resultMapName);
       ResultMapping[] rms = rm.getResultMappings();
       for (int i =0;i<rms.length;i++){
          resultMappings.put(
           ((BasicResultMapping)rms[i]).getPropertyName(),
           ((BasicResultMapping)rms[i]).getColumnName()
          );
       }
    }

    public String getColumnName(String property){
       if (resultMappings==null){
          initResultMappings();
       }
       String columnName = (String)resultMappings.get(property);
       return (columnName!=null)?columnName:property;
    }
}


Kris.

-----Oorspronkelijk bericht-----
Van: Kris Barnhoorn [mailto:kris@biassweb.be] 
Verzonden: vrijdag 7 januari 2005 12:27
Aan: ibatis-user-java@incubator.apache.org; cbegin@ibatis.com
Onderwerp: RE: access a resultmap

Hi Clinton,

Thank you for taking interest in my case.


I'd like to access this to create some sql fragment.

In my web pages I have a list where users can define dynamic criteria.
for this to work I have to send the actual name of the column.

But if I would create some method that translates a particular property
to his sql column based on the resultmap, I could use propertynames and
not sql column names.

So:

In webpage: propertyName / value / [AND | OR]  
		Add filter

In page handler(struts action):

	Create criteria (I use a own version of the Criteria class in
ORB)
	Send it with DAO

	
	In DAO:
	
	Set the Criteria in the SqlQuery class

       <select id="getPojos" parameterClass="org.foo.SqlQuery"
             resultClass="org.foo.Pojo">
             SELECT *
             FROM `pojos`
             WHERE
             <dynamic>
                   <isNotEmpty property="whereCriteriaString">
                         $whereCriteriaString$
                   </isNotEmpty>
             </dynamic>
       </select>
	
	So it is in the Criteria class I would create a method that
handles 	the conversion.	


Greetz,
Kris.

-----Oorspronkelijk bericht-----
Van: Clinton Begin [mailto:clinton.begin@gmail.com] 
Verzonden: vrijdag 31 december 2004 18:38
Aan: ibatis-user-java@incubator.apache.org
Onderwerp: Re: access a resultmap

I'd be more interested in why.  ;-)

The short answer to your question is "no".  But of course, there's ways.

What are you trying to do?

Cheers,
Clinton


On Fri, 31 Dec 2004 17:26:38 +0100, Kris Barnhoorn <kr...@biassweb.be>
wrote:
> Hi,
> 
> I was wondering if you can access a resultmap through the iBatis API
> To know what sql column is attached to a specific property
> 
> something like
> 
> ResultMap rm = getResultMap("rmName");
> rm.getColumnOfProperty("reference");
> 
> Thank you,
> Kris.
> 
>