You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by aris2world <ar...@gmail.com> on 2011/12/18 19:31:27 UTC

[dbutils]

Hi all
I've a question about CaseInsensitiveHashMap in BasicRowProcessor: it
extends HashMap but if it will extend LinkedHashMap I think the resulting
Map could seem more consistent with the executed query to a client
perspective.

I mean: when the method toMap puts the columns of the resultset into the
map, the insertion order is the same of the columns in the select list of
the executed query. It will be useful to me to extract values in the same
order when I'm iterating over the key set of the returned map. This is
accomplished in a simply way with a LinkedHashMap. What do you think about
it?
Thank you
aris

Re: [dbutils]

Posted by aris2world <ar...@gmail.com>.
No it wouldn't.
To me what I'm looking for is not conceptually different from the request
https://issues.apache.org/jira/browse/DBUTILS-34

What I'm discovering is the lack of extensibility of the BasicQueryRunner
class. The only way to return another type of Map is to override the toMap
method (rewriting the code as it is) to create an instance of my custom map.

Better would be one of the following alternatives:
1. a protected method "public Map<String, Object> newMap()", invoked from
the toMap method, that I can override to instantiate my custom map
2. a constructor like the one with the BeanProcessor but with a custom Map
implementation.

At the moment I've duplicated the BasicQueryRunner.


On Mon, Dec 19, 2011 at 5:54 PM, Hasan Diwan <ha...@gmail.com> wrote:

> On 19 December 2011 01:03, aris2world <ar...@gmail.com> wrote:
> > I don't have a generic order for keys, my order is the same of the fields
> > in select list:
> > select <col1>, <col2>, ..., <coln> from ...
> > when the resultset of this query is mapped, values in the map are
> inserted
> > in this order <col1>, <col2>, ..., <coln>.
> > I'd like that map.keySet().iterator() let me iterate over values in that
> > order, i.e. insertion-order.
> > This is a custom order but I have to parse the query to get it. I think
> it
> > should be the order that a client would expect.
> > From the LinkedHashMap javadoc:
> > "This implementation spares its clients from the unspecified, generally
> > chaotic ordering provided by
> > HashMap<http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html>
> >  (and Hashtable<
> > http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable.html>),
> > without incurring the increased cost associated with
> > TreeMap<http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html>
> >
> Wasn't aware of the LinkedHashMap, but would this not work:
> LinkedHashMap map = new LinkedHashMap(foo.toMap());
> --
> Sent from my mobile device
> Envoyait de mon portable
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [dbutils]

Posted by Hasan Diwan <ha...@gmail.com>.
On 19 December 2011 01:03, aris2world <ar...@gmail.com> wrote:
> I don't have a generic order for keys, my order is the same of the fields
> in select list:
> select <col1>, <col2>, ..., <coln> from ...
> when the resultset of this query is mapped, values in the map are inserted
> in this order <col1>, <col2>, ..., <coln>.
> I'd like that map.keySet().iterator() let me iterate over values in that
> order, i.e. insertion-order.
> This is a custom order but I have to parse the query to get it. I think it
> should be the order that a client would expect.
> From the LinkedHashMap javadoc:
> "This implementation spares its clients from the unspecified, generally
> chaotic ordering provided by
> HashMap<http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html>
>  (and Hashtable<
> http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable.html>),
> without incurring the increased cost associated with
> TreeMap<http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html>
>
Wasn't aware of the LinkedHashMap, but would this not work:
LinkedHashMap map = new LinkedHashMap(foo.toMap());
-- 
Sent from my mobile device
Envoyait de mon portable

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [dbutils]

Posted by aris2world <ar...@gmail.com>.
Hi Hasan,
I don't have a generic order for keys, my order is the same of the fields
in select list:
select <col1>, <col2>, ..., <coln> from ...
when the resultset of this query is mapped, values in the map are inserted
in this order <col1>, <col2>, ..., <coln>.
I'd like that map.keySet().iterator() let me iterate over values in that
order, i.e. insertion-order.
This is a custom order but I have to parse the query to get it. I think it
should be the order that a client would expect.
>From the LinkedHashMap javadoc:
"This implementation spares its clients from the unspecified, generally
chaotic ordering provided by
HashMap<http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html>
 (and Hashtable<
http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable.html>),
without incurring the increased cost associated with
TreeMap<http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html>

On Sun, Dec 18, 2011 at 7:46 PM, Hasan Diwan <ha...@gmail.com> wrote:

> On 18 December 2011 10:31, aris2world <ar...@gmail.com> wrote:
> > I've a question about CaseInsensitiveHashMap in BasicRowProcessor: it
> > extends HashMap but if it will extend LinkedHashMap I think the resulting
> > Map could seem more consistent with the executed query to a client
> > perspective.
> > I mean: when the method toMap puts the columns of the resultset into the
> > map, the insertion order is the same of the columns in the select list of
> > the executed query. It will be useful to me to extract values in the same
> > order when I'm iterating over the key set of the returned map. This is
> > accomplished in a simply way with a LinkedHashMap. What do you think
> about
> > it?
>
> I think you should be able to (untested):
> HashMap<String, Object> map = basicRowProcessorInstance.toMap();
> List <String> keys = new ArrayList(map.keySet());
> Collections.sort(keys);
> now keys will be sorted alphabetically by String's default Comparator,
> but you can also specify a custom one.
>
> --
> Sent from my mobile device
> Envoyait de mon portable
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [dbutils]

Posted by Hasan Diwan <ha...@gmail.com>.
On 18 December 2011 10:31, aris2world <ar...@gmail.com> wrote:
> I've a question about CaseInsensitiveHashMap in BasicRowProcessor: it
> extends HashMap but if it will extend LinkedHashMap I think the resulting
> Map could seem more consistent with the executed query to a client
> perspective.
> I mean: when the method toMap puts the columns of the resultset into the
> map, the insertion order is the same of the columns in the select list of
> the executed query. It will be useful to me to extract values in the same
> order when I'm iterating over the key set of the returned map. This is
> accomplished in a simply way with a LinkedHashMap. What do you think about
> it?

I think you should be able to (untested):
HashMap<String, Object> map = basicRowProcessorInstance.toMap();
List <String> keys = new ArrayList(map.keySet());
Collections.sort(keys);
now keys will be sorted alphabetically by String's default Comparator,
but you can also specify a custom one.

-- 
Sent from my mobile device
Envoyait de mon portable

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org