ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "mischa.z" <misch...@gmail.com>
Subject Re: postgres ARRAY type
Date Thu, 11 Jan 2007 15:34:57 GMT
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