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 Richard Bibb <ri...@aimhedge.com> on 2009/08/20 09:51:04 UTC

Returning Three ArrayLists

I think I'm probably trying to use iBatis in a way that goes against it's
design, but for what I need to do it's correct.

If I have a query like:

select Number1, Number2, Number3
from SOME_TABLE
where COL_DATE > EARLY_TIME
and COLD_DATE < LATER_TIME

Assume that the query returns many rows, 

I would like to be able to return this data as three ArrayList<Double>. I
know I can return one ArrayList<SomeClass> where SomeClass contains three
numbers but that just adds a second layer of processing that I don't want to
do. I also know I could do three separate queries but as some of the numbers
may not have entries on some days it would again add a layer of processing
to add null data back into the ArrayLists returned

I tried doing a result map containing three collections but the data
returned was wrong (all of the collections seemed to get populated with data
from the first row). 
-- 
View this message in context: http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25057560.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Returning Three ArrayLists

Posted by Richard Bibb <ri...@aimhedge.com>.
I agree, meaningful names count for a great deal and can make documentation
superfluous.


Clinton Begin wrote:
> 
> I'll fully admit that I'm just being a jerk about the JavaDocs... :-)
> 
> JavaDocs would be a welcome addition to the iBATIS API, particularly the
> public API.
> 
> Where I don't like Javadocs is like:
> 
> 
> /**
>  * gets the result object
>  */
> public Object getResultObject() {...}
> 
> 
> Clinton
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25064755.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Returning Three ArrayLists

Posted by Clinton Begin <cl...@gmail.com>.
I'll fully admit that I'm just being a jerk about the JavaDocs... :-)

JavaDocs would be a welcome addition to the iBATIS API, particularly the
public API.

Where I don't like Javadocs is like:


/**
 * gets the result object
 */
public Object getResultObject() {...}


Clinton

On Thu, Aug 20, 2009 at 9:17 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> Excellent. It's working now.
>
> I read your dislike of JavaDoc but from my point of view it would be
> seriously helpful in eclipse as it would stop me having to revert back to
> the manual all the time. Manuals are great for concepts. JavaDoc for the
> fiddly bits. Only an opinion :thinking:
>
>
> Clinton Begin wrote:
> >
> > Don't worry about the nextResultObject method.  It's just used to update
> > the
> > result object and the count, it probably shouldn't be public, or maybe
> > resultcontext should be immutable... but for now, just ignore that
> method.
> > It's used internally by the ResultSetHandler.  I might make it an
> > interface
> > and keep that method behind it in the implementation.
> >
> > iBATIS iterates through the results for you, just pass your
> implementation
> > of ResultHandler into the select method.
> >
> >
> > Clinton
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25063971.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: Returning Three ArrayLists

Posted by Richard Bibb <ri...@aimhedge.com>.
Excellent. It's working now.

I read your dislike of JavaDoc but from my point of view it would be
seriously helpful in eclipse as it would stop me having to revert back to
the manual all the time. Manuals are great for concepts. JavaDoc for the
fiddly bits. Only an opinion :thinking:


Clinton Begin wrote:
> 
> Don't worry about the nextResultObject method.  It's just used to update
> the
> result object and the count, it probably shouldn't be public, or maybe
> resultcontext should be immutable... but for now, just ignore that method.
> It's used internally by the ResultSetHandler.  I might make it an
> interface
> and keep that method behind it in the implementation.
> 
> iBATIS iterates through the results for you, just pass your implementation
> of ResultHandler into the select method.
> 
> 
> Clinton
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25063971.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Returning Three ArrayLists

Posted by Clinton Begin <cl...@gmail.com>.
Don't worry about the nextResultObject method.  It's just used to update the
result object and the count, it probably shouldn't be public, or maybe
resultcontext should be immutable... but for now, just ignore that method.
It's used internally by the ResultSetHandler.  I might make it an interface
and keep that method behind it in the implementation.

iBATIS iterates through the results for you, just pass your implementation
of ResultHandler into the select method.


Clinton

On Thu, Aug 20, 2009 at 7:54 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> Hi Clinton
>
> Your reply was exactly what I wanted. My only problem is that I'm not quite
> sure how to use the ResultContext object that is returned to me (iBatis3.0)
>
> ResultContext has a number of methods associated with it. One tells you how
> many rows were returned, another gives you a resultObject and the confusing
> one is the nextResultObject method. It looks to me as if I'm meant to
> itterate over the result set using nextResultObject. Is that right and if
> so
> what is the getResultObject method for?
>
>
>
> Clinton Begin wrote:
> >
> > It's against the design of SQL and JDBC, but not iBATIS.... :-)
> >
> > Just write a custom RowHandler (or ResultHandler in iBATIS 3).
> >
> > I'll use pseudocode since I don't know which version you're using....
> >
> > //assume you just map the results to a HashMap originally
> >
> > List list1;
> > List list2;
> > List list3;
> > handleResult(Object result) {
> >   Map map = (Map) result;
> >   list1.add(map.get("Number1");
> >   list2.add(map.get("Number2");
> >   list3.add(map.get("Number3");
> > }
> >
> > Clinton
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25062567.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: Returning Three ArrayLists

Posted by Richard Bibb <ri...@aimhedge.com>.
Hi Clinton

Your reply was exactly what I wanted. My only problem is that I'm not quite
sure how to use the ResultContext object that is returned to me (iBatis3.0)

ResultContext has a number of methods associated with it. One tells you how
many rows were returned, another gives you a resultObject and the confusing
one is the nextResultObject method. It looks to me as if I'm meant to
itterate over the result set using nextResultObject. Is that right and if so
what is the getResultObject method for?



Clinton Begin wrote:
> 
> It's against the design of SQL and JDBC, but not iBATIS.... :-)
> 
> Just write a custom RowHandler (or ResultHandler in iBATIS 3).
> 
> I'll use pseudocode since I don't know which version you're using....
> 
> //assume you just map the results to a HashMap originally
> 
> List list1;
> List list2;
> List list3;
> handleResult(Object result) {
>   Map map = (Map) result;
>   list1.add(map.get("Number1");
>   list2.add(map.get("Number2");
>   list3.add(map.get("Number3");
> }
> 
> Clinton
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25062567.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Returning Three ArrayLists

Posted by Clinton Begin <cl...@gmail.com>.
It's against the design of SQL and JDBC, but not iBATIS.... :-)

Just write a custom RowHandler (or ResultHandler in iBATIS 3).

I'll use pseudocode since I don't know which version you're using....

//assume you just map the results to a HashMap originally

List list1;
List list2;
List list3;
handleResult(Object result) {
  Map map = (Map) result;
  list1.add(map.get("Number1");
  list2.add(map.get("Number2");
  list3.add(map.get("Number3");
}

Clinton

On Thu, Aug 20, 2009 at 1:51 AM, Richard Bibb <ri...@aimhedge.com>wrote:

>
> I think I'm probably trying to use iBatis in a way that goes against it's
> design, but for what I need to do it's correct.
>
> If I have a query like:
>
> select Number1, Number2, Number3
> from SOME_TABLE
> where COL_DATE > EARLY_TIME
> and COLD_DATE < LATER_TIME
>
> Assume that the query returns many rows,
>
> I would like to be able to return this data as three ArrayList<Double>. I
> know I can return one ArrayList<SomeClass> where SomeClass contains three
> numbers but that just adds a second layer of processing that I don't want
> to
> do. I also know I could do three separate queries but as some of the
> numbers
> may not have entries on some days it would again add a layer of processing
> to add null data back into the ArrayLists returned
>
> I tried doing a result map containing three collections but the data
> returned was wrong (all of the collections seemed to get populated with
> data
> from the first row).
> --
> View this message in context:
> http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25057560.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: Returning Three ArrayLists

Posted by Richard Yee <ry...@cruzio.com>.
Ibatis won't do that for you. In your dao method you need to iterate  
through the list of three doubles and create the three lists of  
doubles. You'd then have to return them in a map or list or something

R

Sent from my iPhone

On Aug 20, 2009, at 12:51 AM, Richard Bibb <ri...@aimhedge.com>  
wrote:

>
> I think I'm probably trying to use iBatis in a way that goes against  
> it's
> design, but for what I need to do it's correct.
>
> If I have a query like:
>
> select Number1, Number2, Number3
> from SOME_TABLE
> where COL_DATE > EARLY_TIME
> and COLD_DATE < LATER_TIME
>
> Assume that the query returns many rows,
>
> I would like to be able to return this data as three  
> ArrayList<Double>. I
> know I can return one ArrayList<SomeClass> where SomeClass contains  
> three
> numbers but that just adds a second layer of processing that I don't  
> want to
> do. I also know I could do three separate queries but as some of the  
> numbers
> may not have entries on some days it would again add a layer of  
> processing
> to add null data back into the ArrayLists returned
>
> I tried doing a result map containing three collections but the data
> returned was wrong (all of the collections seemed to get populated  
> with data
> from the first row).
> -- 
> View this message in context: http://www.nabble.com/Returning-Three-ArrayLists-tp25057560p25057560.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org