ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: postgres ARRAY type
Date Thu, 11 Jan 2007 15:51:05 GMT
Looks fine to me.

Brandon

On 1/11/07, mischa.z <mischa.z@gmail.com> wrote:
>
> mischa.z wrote:
> > Hey,
> >
> > I can't seem to find the correct mapping for the postgres ARRAY type in
> > the ibatis docs (do I have to write my own handler?). Can anyone give me
> > a hint. Thanks.
> > -Mischa
> >
>
> I guess I found a solution (although I'm not sure if this is the best
> way to do it).
> For dealing with postgres' boolean[] type I wrote the following handler
> for mapping it to a Java type boolean[]:
>
>
> public class PGBooleanArrayTypeMapper
>    implements TypeHandlerCallback
> {
>      public void setParameter(
>          ParameterSetter setter,
>          Object parameter)
>        throws SQLException
>      {
>        throw new UnsupportedOperationException("Not implemented yet");
>      }
>
>      public Object getResult(
>          ResultGetter getter)
>        throws SQLException
>      {
>        ResultSet dbResult = getter.getArray().getResultSet();
>        boolean[] result = new boolean[255]; // expecting fix num of
> elements
>        while (dbResult.next())
>        {
>          String element = dbResult.getString(2);
>          result[dbResult.getInt(1)-1] = element.equals("YES") ? true :
> false;
>        }
>
>        return result;
>      }
>
>      public Object valueOf(
>          String s)
>      {
>        throw new UnsupportedOperationException("Not implemented yet");
>      }
> }
>
>
> The mapping for the sqlmap looks like:
>
> <resultMap id="get-codes-result" class="test.Codes">
>         <result property="codes" column="code" jdbcType="ARRAY"
> javaType="java.sql.Array" typeHandler="test.PGBooleanArrayTypeMapper"/>
> </resultMap>
>
> -Mischa
>

Mime
View raw message