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 "George.Francis" <gf...@gmail.com> on 2009/10/21 20:00:01 UTC
queryForMap() ordering
I've tried to find the doco for this, but havent so far. In iBatis, if I use
queryForMap(), the resulting Map ordering (predictably) doesnt follow the
order-by clause of the query (it seems to always order by the Key property
value). Is there an API-level way to determine the Map sort order, or is it
a matter of implementing a Comparator manually?
--
View this message in context: http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25997320.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: queryForMap() ordering
Posted by "George.Francis" <gf...@gmail.com>.
sorry, I got confused there for a moment. ArrayList is fine.
Thanks again.
--
View this message in context: http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p26003892.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: queryForMap() ordering
Posted by "George.Francis" <gf...@gmail.com>.
Thanks Nathan,
If I use queryForList() I get an ArrayList<Person> which is also not an
order-sensitive implementation of List. I guess what I'm missing is how to
get either queryForList() to return a LinkedList<Person>, or queryForMap()
to return a LinkedHashMap<String,Person>
--
View this message in context: http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p26003844.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: queryForMap() ordering
Posted by Nathan Maves <na...@gmail.com>.
Ah I overlooked that you were using queryForMap(). Maybe I can clear this
up for you. If you need a list of ordered objects then use queryForList().
If you want a map based on a key for quick lookup then use queryForMap().
Without knowing what you are trying to query for I dont know which is best
for you.
Maybe an example will help.
Imagine that you have a query that returns more then one Person object. So
your result class for your sqlmap will be a Person class. Now if you want
an order list the use queryForList(). If you want a map based on SSN then
use queryForMap()
Nathan
On Wed, Oct 21, 2009 at 7:35 PM, George.Francis <gf...@gmail.com> wrote:
>
> I've also tried:
> <select id="pcmStatus" resultClass="java.util.LinkedHashMap"
> remapResults="true" >
>
> but this just makes queryForMap() return a HashMap with LinkedHashMaps as
> values...
>
>
> George.Francis wrote:
> >
> > Sorry if this is obvious, but how do I change the Map implementation
> > returned by getSqlMapClientTemplate().queryForMap(...). At the moment it
> > returns a java.util.HashMap.
> >
> > The 'resultMap' attribute of my <select> query refers to the custom
> domain
> > object mapping I have specified - this is the class used for the values
> in
> > the HashMap returned from the queryForMap().
> >
> > I hope that makes sense.
> >
> >
> > nmaves wrote:
> >>
> >> what is your result class for the sqlmap? Have you tried to use
> >> "java.lang.LinkedHashMap" ?
> >> Nathan
> >>
> >> On Wed, Oct 21, 2009 at 12:00 PM, George.Francis
> >> <gf...@gmail.com>wrote:
> >>
> >>>
> >>> I've tried to find the doco for this, but havent so far. In iBatis, if
> I
> >>> use
> >>> queryForMap(), the resulting Map ordering (predictably) doesnt follow
> >>> the
> >>> order-by clause of the query (it seems to always order by the Key
> >>> property
> >>> value). Is there an API-level way to determine the Map sort order, or
> is
> >>> it
> >>> a matter of implementing a Comparator manually?
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25997320.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
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p26002779.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: queryForMap() ordering
Posted by "George.Francis" <gf...@gmail.com>.
I've also tried:
<select id="pcmStatus" resultClass="java.util.LinkedHashMap"
remapResults="true" >
but this just makes queryForMap() return a HashMap with LinkedHashMaps as
values...
George.Francis wrote:
>
> Sorry if this is obvious, but how do I change the Map implementation
> returned by getSqlMapClientTemplate().queryForMap(...). At the moment it
> returns a java.util.HashMap.
>
> The 'resultMap' attribute of my <select> query refers to the custom domain
> object mapping I have specified - this is the class used for the values in
> the HashMap returned from the queryForMap().
>
> I hope that makes sense.
>
>
> nmaves wrote:
>>
>> what is your result class for the sqlmap? Have you tried to use
>> "java.lang.LinkedHashMap" ?
>> Nathan
>>
>> On Wed, Oct 21, 2009 at 12:00 PM, George.Francis
>> <gf...@gmail.com>wrote:
>>
>>>
>>> I've tried to find the doco for this, but havent so far. In iBatis, if I
>>> use
>>> queryForMap(), the resulting Map ordering (predictably) doesnt follow
>>> the
>>> order-by clause of the query (it seems to always order by the Key
>>> property
>>> value). Is there an API-level way to determine the Map sort order, or is
>>> it
>>> a matter of implementing a Comparator manually?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25997320.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
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p26002779.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: queryForMap() ordering
Posted by "George.Francis" <gf...@gmail.com>.
Sorry if this is obvious, but how do I change the Map implementation returned
by getSqlMapClientTemplate().queryForMap(...). At the moment it returns a
java.util.HashMap.
The 'resultMap' attribute of my <select> query refers to the custom domain
object mapping I have specified - this is the class used for the values in
the HashMap returned from the queryForMap().
I hope that makes sense.
nmaves wrote:
>
> what is your result class for the sqlmap? Have you tried to use
> "java.lang.LinkedHashMap" ?
> Nathan
>
> On Wed, Oct 21, 2009 at 12:00 PM, George.Francis
> <gf...@gmail.com>wrote:
>
>>
>> I've tried to find the doco for this, but havent so far. In iBatis, if I
>> use
>> queryForMap(), the resulting Map ordering (predictably) doesnt follow the
>> order-by clause of the query (it seems to always order by the Key
>> property
>> value). Is there an API-level way to determine the Map sort order, or is
>> it
>> a matter of implementing a Comparator manually?
>> --
>> View this message in context:
>> http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25997320.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
>>
>>
>
>
--
View this message in context: http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25999105.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: queryForMap() ordering
Posted by Nathan Maves <na...@gmail.com>.
what is your result class for the sqlmap? Have you tried to use
"java.lang.LinkedHashMap" ?
Nathan
On Wed, Oct 21, 2009 at 12:00 PM, George.Francis <gf...@gmail.com>wrote:
>
> I've tried to find the doco for this, but havent so far. In iBatis, if I
> use
> queryForMap(), the resulting Map ordering (predictably) doesnt follow the
> order-by clause of the query (it seems to always order by the Key property
> value). Is there an API-level way to determine the Map sort order, or is it
> a matter of implementing a Comparator manually?
> --
> View this message in context:
> http://www.nabble.com/queryForMap%28%29-ordering-tp25997320p25997320.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
>
>