Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion ResultSet

Date: Thu, 16 Aug 2012 06:53:24 -0700 (PDT)
From: Sathish V <sathishv...@gmail.com>
To: jdbi@googlegroups.com
Message-Id: <05fe9d23-5fc8-4917-ae15-8b213d8f6ba0@googlegroups.com>
In-Reply-To: <d23fc127-6678-453f-b803-841671933bf9@googlegroups.com>
References: <1d8e8095-4745-4fa3-91b2-74f551360b02@googlegroups.com> <634a3540-bf8d-461d-8451-ee48d589534e@googlegroups.com>
 <CAKKdvLuag+yRso+O4=wtsMmvKpWRjRWXap3KNQxV3CkWSKtexQ@mail.gmail.com>
 <d23fc127-6678-453f-b803-841671933bf9@googlegroups.com>
Subject: Re: ResultSet
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1454_27501089.1345125204928"

------=_Part_1454_27501089.1345125204928
Content-Type: multipart/alternative; 
	boundary="----=_Part_1455_32062710.1345125204928"

------=_Part_1455_32062710.1345125204928
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

I Just figured out to use *registerOutParameter<http://jdbi.codehaus.org/maven_site/apidocs/org/skife/jdbi/v2/Call.html#registerOutParameter%28int,%20int,%20org.skife.jdbi.v2.CallableStatementMapper%29>
*(int position, int sqlType, CallableStatementMapper<http://jdbi.codehaus.org/maven_site/apidocs/org/skife/jdbi/v2/CallableStatementMapper.html>
 mapper) CallableStatementMapper for this... am I correct?

-Sathish

On Thursday, August 16, 2012 7:19:16 PM UTC+5:30, Sathish V wrote:
>
> the h.createCall(procedure) doesnt have any method like map? How can I 
> attach that to a Mapper?
> I am trying to map a cursor output from a procedure.
>
> Regards
> Sathish
>
> On Tuesday, August 14, 2012 4:03:28 AM UTC+5:30, Brian McCallister wrote:
>>
>> Sorry.
>>
>> .map(new OrderedMapper())
>>
>> -Brian
>>
>> On Mon, Aug 13, 2012 at 1:55 PM, Alan J <alan.ju...@gmail.com> wrote:
>>
>>> Sorry but I get:  
>>> exception java.lang.ClassCastException: OrderedMapper cannot be cast to 
>>> java.util.Map
>>>
>>> public class OrderedMapper implements ResultSetMapper<Map<String, 
>>> Object>>
>>> {
>>>     public Map<String, Object> map(int index, ResultSet r, 
>>> StatementContext ctx)
>>>     {
>>>         Map<String, Object> row = new OrderedResultMap();
>>>         ResultSetMetaData m;
>>>         try
>>>         {
>>>             m = r.getMetaData();
>>>         }
>>>         catch (SQLException e)
>>>         {
>>>             throw new ResultSetException("Unable to obtain metadata from 
>>> result set", e, ctx);
>>>         }
>>>
>>>         try
>>>         {
>>>             for (int i = 1; i <= m.getColumnCount(); i ++)
>>>             {
>>>                 String key = m.getColumnName(i);
>>>                 String alias = m.getColumnLabel(i);
>>>                 Object value = r.getObject(i);
>>>                 row.put(alias != null ? alias : key, value);
>>>             }
>>>         }
>>>         catch (SQLException e)
>>>         {
>>>             throw new ResultSetException("Unable to access specific 
>>> metadata from " +
>>>                                          "result set metadata", e, ctx);
>>>         }
>>>         return row;
>>>     }
>>>
>>>     private static class OrderedResultMap extends LinkedHashMap<String, 
>>> Object>
>>>     {
>>>         public static final long serialVersionUID = 1L;
>>>
>>>         @Override
>>>         public Object get(Object o)
>>>         {
>>>             return super.get(((String)o).toLowerCase());
>>>         }
>>>
>>>         @Override
>>>         public Object put(String key, Object value)
>>>         {
>>>             return super.put(key.toLowerCase(), value);
>>>         }
>>>
>>>         @Override
>>>         public boolean containsKey(Object key)
>>>         {
>>>             return super.containsKey(((String)key).toLowerCase());
>>>
>>>         }
>>>     }
>>> }
>>>
>>> On Wednesday, August 1, 2012 10:27:07 PM UTC-5, Alan J wrote:
>>>
>>>> When I do this
>>>>   List<Map<String,Object>> sel = dbh.createQuery('select * from blah')
>>>>
>>>> then want to go thru the Map keyset, theyre in sorted order.
>>>> How can I use the Map functionality but preserve DB column ordering?
>>>>
>>>
>>
------=_Part_1455_32062710.1345125204928
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

I Just figured out to use <code><b><a href=3D"http://jdbi.codehaus.org/mave=
n_site/apidocs/org/skife/jdbi/v2/Call.html#registerOutParameter%28int,%20in=
t,%20org.skife.jdbi.v2.CallableStatementMapper%29">registerOutParameter</a>=
</b>(int&nbsp;position,
                     int&nbsp;sqlType,
                     <a href=3D"http://jdbi.codehaus.org/maven_site/apidocs=
/org/skife/jdbi/v2/CallableStatementMapper.html" title=3D"interface in org.=
skife.jdbi.v2">CallableStatementMapper</a>&nbsp;mapper)</code> CallableStat=
ementMapper for this... am I correct?<br><br>-Sathish<br><br>On Thursday, A=
ugust 16, 2012 7:19:16 PM UTC+5:30, Sathish V wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;">the h.createCall(procedure) doesnt have any method li=
ke map? How can I attach that to a Mapper?<br>I am trying to map a cursor o=
utput from a procedure.<br><br>Regards<br>Sathish<br><br>On Tuesday, August=
 14, 2012 4:03:28 AM UTC+5:30, Brian McCallister wrote:<blockquote class=3D=
"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc soli=
d;padding-left:1ex">Sorry.<div><br></div><div>.map(new OrderedMapper())</di=
v><div><br></div><div>-Brian</div><div><br></div><div><div class=3D"gmail_q=
uote">On Mon, Aug 13, 2012 at 1:55 PM, Alan J <span dir=3D"ltr">&lt;<a>alan=
.ju...@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Sorry but I get:&nbsp; <br>exception java.la=
ng.ClassCastException: OrderedMapper cannot be cast to java.util.Map<br><br=
><span><span style=3D"background-color:rgb(204,204,204)"></span></span><spa=
n style=3D"color:rgb(204,204,204)">public class OrderedMapper implements Re=
sultSetMapper&lt;Map&lt;String, Object&gt;&gt;</span><br style=3D"color:rgb=
(204,204,204)">

<span style=3D"color:rgb(204,204,204)">{</span><br style=3D"color:rgb(204,2=
04,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp; public M=
ap&lt;String, Object&gt; map(int index, ResultSet r, StatementContext ctx)<=
/span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp; {</span><br style=
=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map&lt;String, Object&gt; row =3D new Or=
deredResultMap();</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; ResultSetMetaData m;</span><br style=3D"color:rgb(204,204,204)"><spa=
n style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; try</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(=
204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br style=
=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m =3D r.getMetaData();</span><br style=3D"co=
lor:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style=3D"color:rgb(204,204,204)"><=
span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; catch (SQLException e)</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; {</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rg=
b(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; throw new ResultSetException("Unable to obtain metadata from result=
 set", e, ctx);</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; }</span><br style=3D"color:rgb(204,204,204)"><br style=3D"color:rgb(=
204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; try</span><br style=3D"color:rgb(204,204,204)"><span s=
tyle=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i =3D 1; i &lt;=3D m.getColumnCount=
(); i ++)</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:r=
gb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; {</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String key =3D m.get=
ColumnName(i);</span><br style=3D"color:rgb(204,204,204)"><span style=3D"co=
lor:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String alias =3D m.getColumnLabel(i);=
</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object value =3D r.g=
etObject(i);</span><br style=3D"color:rgb(204,204,204)"><span style=3D"colo=
r:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; row.put(alias !=3D null ? alias : key, =
value);</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style=3D"color:rgb(204,204,204)"=
><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; }</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:r=
gb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (SQLExcep=
tion e)</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; {</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rg=
b(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; throw new ResultSetException("Unable to access specific metadata fr=
om " +</span><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "result set met=
adata", e, ctx);</span><br style=3D"color:rgb(204,204,204)"><span style=3D"=
color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span>=
<br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; return row;</span><br style=3D"color:rgb(204,204,204)"><span style=
=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp; }</span><br style=3D"color:r=
gb(204,204,204)"><br style=3D"color:rgb(204,204,204)"><span style=3D"color:=
rgb(204,204,204)">&nbsp;&nbsp;&nbsp; private static class OrderedResultMap =
extends LinkedHashMap&lt;String, Object&gt;</span><br style=3D"color:rgb(20=
4,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp; {</span><br style=
=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static final long serialVersionUI=
D =3D 1L;</span><br style=3D"color:rgb(204,204,204)"><br style=3D"color:rgb=
(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; @Override</span><br style=3D"color:rgb(204,204,204)"><span style=3D"=
color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public O=
bject get(Object o)</span><br style=3D"color:rgb(204,204,204)"><span style=
=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</s=
pan><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return super.get(((String)o).<wbr>toLowerCas=
e());</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(2=
04,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style=
=3D"color:rgb(204,204,204)">

<br style=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)"=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Override</span><br style=3D"co=
lor:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp; public Object put(String key, Object value)</s=
pan><br style=3D"color:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; {</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rg=
b(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; return super.put(key.toLowerCase(), value);</span><br style=3D"colo=
r:rgb(204,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; }</span><br style=3D"color:rgb(204,204,204)"><br style=3D"color:rgb(=
204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; @Override</span><br style=3D"color:rgb(204,204,204)"><=
span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; public boolean containsKey(Object key)</span><br style=3D"color:rgb(2=
04,204,204)">

<span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; {</span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rg=
b(204,204,204)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; return super.containsKey(((String)<wbr>key).toLowerCase());</span><=
div>

<br style=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(204,204,204)"=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style=3D"color:rgb(=
204,204,204)"><span style=3D"color:rgb(204,204,204)">&nbsp;&nbsp;&nbsp; }</=
span><br style=3D"color:rgb(204,204,204)"><span style=3D"color:rgb(204,204,=
204)">}</span><br>

<br>On Wednesday, August 1, 2012 10:27:07 PM UTC-5, Alan J wrote:</div><div=
><div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex=
;border-left:1px #ccc solid;padding-left:1ex">When I do this<br>

&nbsp; List&lt;Map&lt;String,Object&gt;&gt; sel =3D dbh.createQuery('select=
 * from blah')<br><br>then want to go thru the Map keyset, theyre in sorted=
 order.<br>How can I use the Map functionality but preserve DB column order=
ing?<br>

</blockquote></div></div></blockquote></div><br></div>
</blockquote></blockquote>
------=_Part_1455_32062710.1345125204928--

------=_Part_1454_27501089.1345125204928--