ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diran Ayandele <Adediran.Ayand...@Sun.COM>
Subject Re: Populating existing beans...
Date Tue, 12 Sep 2006 21:31:33 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000099">
Sorry, misunderstood.&nbsp; I see what you're saying, but I can't answer
that one.&nbsp; <br>
<br>
Diran<br>
<br>
Daniel Pitts wrote:
<blockquote
 cite="mid7E4302A18925394BAC32C7AD1ABE75D4E2FB29@CNET6.cnet.cnwk"
 type="cite">
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta content="MSHTML 6.00.2900.2963" name="GENERATOR">
  <div align="left" dir="ltr"><span class="993184520-12092006"><font
 color="#0000ff" face="Arial" size="2">To clarify more,</font></span></div>
  <div align="left" dir="ltr"><span class="993184520-12092006"><font
 color="#0000ff" face="Arial" size="2">I have a bunch of beans of
different classes.&nbsp; There is a table for each class of bean, with
columns that correspond directly to bean properties. This makes it easy
to do things like &lt;select id="getAuthors"
resultClass="author"&gt;SELECT * from authors&lt;/select&gt;</font></span></div>
  <div align="left" dir="ltr"><span class="993184520-12092006"></span>&nbsp;</div>
  <div align="left" dir="ltr"><span class="993184520-12092006"><font
 color="#0000ff" face="Arial" size="2">What I'd like to do is something
like</font></span></div>
  <div align="left" dir="ltr"><span class="993184520-12092006"><font
 color="#0000ff" face="Arial" size="2">&lt;select id="getSomething"
resultClass="$resultClass$" remapResults="true"&gt;SELECT * FROM
$table$&lt;/select&gt;</font></span></div>
  <br>
  <div class="OutlookMessageHeader" align="left" dir="ltr" lang="en-us">
  <hr tabindex="-1"><font face="Tahoma" size="2"><b>From:</b> Daniel
Pitts [<a class="moz-txt-link-freetext" href="mailto:Daniel.Pitts@cnet.com">mailto:Daniel.Pitts@cnet.com</a>]
<br>
  <b>Sent:</b> Tuesday, September 12, 2006 1:42 PM<br>
  <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:user-java@ibatis.apache.org">user-java@ibatis.apache.org</a><br>
  <b>Subject:</b> RE: Populating existing beans...<br>
  </font><br>
  </div>
  <div align="left" dir="ltr"><span class="411273820-12092006"><font
 color="#0000ff" face="Arial" size="2">Thanks for the reply.</font></span></div>
  <div align="left" dir="ltr"><span class="411273820-12092006"><font
 color="#0000ff" face="Arial" size="2">&nbsp;I'm well aware of queryForMap,
but the problem isn't grouping the objects.</font></span></div>
  <div align="left" dir="ltr"><span class="411273820-12092006"></span>&nbsp;</div>
  <div align="left" dir="ltr"><span class="411273820-12092006"><font
 color="#0000ff" face="Arial" size="2">Basically, I have a bean "graph"
(or tree, or whatever) that has been constructed before there is enough
information to run the final query. Also, I don't know the bean class
before hand (and don't want to add it explicitly to the resultMap or
resultClass argument)</font></span></div>
  <div align="left" dir="ltr"><span class="411273820-12092006"></span>&nbsp;</div>
  <div align="left" dir="ltr"><span class="411273820-12092006"><font
 color="#0000ff" face="Arial" size="2">As an alternative solution to my
problem, if there was a way to do a queryForList, but specify the
result class at runtime, that would be extremely helpful.</font></span></div>
  <br>
  <div class="OutlookMessageHeader" align="left" dir="ltr" lang="en-us">
  <hr tabindex="-1"><font face="Tahoma" size="2"><b>From:</b>
<a class="moz-txt-link-abbreviated" href="mailto:Adediran.Ayandele@Sun.COM">Adediran.Ayandele@Sun.COM</a>
[<a class="moz-txt-link-freetext" href="mailto:Adediran.Ayandele@Sun.COM">mailto:Adediran.Ayandele@Sun.COM</a>]
<br>
  <b>Sent:</b> Tuesday, September 12, 2006 1:24 PM<br>
  <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:user-java@ibatis.apache.org">user-java@ibatis.apache.org</a><br>
  <b>Subject:</b> Re: Populating existing beans...<br>
  </font><br>
  </div>
Daniel, there is queryForMap functionality in iBatis.&nbsp; It looks like
this: SqlMapExecutor.queryForMap(statementName, parameterObject, key).&nbsp;
The key will be a column in your result map which could be your bean.id
property after the result map populates the bean.&nbsp; I am not sure what
you mean by populating existing beans, but I hope this helps.<br>
  <br>
Diran<br>
  <br>
Daniel Pitts wrote:
  <blockquote
 cite="mid7E4302A18925394BAC32C7AD1ABE75D4E2FB08@CNET6.cnet.cnwk"
 type="cite">
    <pre wrap="">I have a 
Map&lt;Integer, MyBean&gt; byId;
Which was built by "byId.put(myBean.getId(), myBean);"
MyBean is the base class, there are many types of "MyBean" objects.

Is there a away to tell iBATIS to use the bean in "byId" map as the
result object? Or do I have to get the result, and copy the values over
myself?

I know it can be done with queryForObject(String, Object, Object); but I
need it for something like queryForList or queryForMap

Thanks,
Daniel.
  </pre>
  </blockquote>
</blockquote>
</body>
</html>

Mime
View raw message