ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "March, Andres" <ama...@soe.sony.com>
Subject RE: specify typehandler for byte[]
Date Mon, 09 Jan 2006 17:30:09 GMT
I want to emphasize that this works when I specify the handler per
column in the sqlmap parameter map because I don't need to specify the
javaType there.  But I want to specify it globally, so I don't have to
create parameterMaps and typeHandler declarations for every column.

 

My class has a property like this:

 

Private ds byte[ ]

 

The db tables are like this:

 

CREATE TABLE bugs.x86_seg_reg

(

  id int8 NOT NULL DEFAULT nextval('x86_seg_reg_id_seq'::regclass),

  ds numeric(16) NOT NULL,

  es numeric(16) NOT NULL,

  fs numeric(16) NOT NULL,

  gs numeric(16) NOT NULL,

  CONSTRAINT x86_seg_reg_pkey PRIMARY KEY (id)

)

 

The sql created from the default type handler does setBytes() but
Postgres interprets that as a bytea column type.  So I created my own
type handler:

<typeHandler javaType="byte[]" jdbcType="NUMERIC"
callback="com.soe.freerealms.dao.ibatis.ByteArrayBigDecimalTypeHandler"/
>

 

So it will do a setBigDecimal instead:

 

/*

             * (non-Javadoc)

             * 

             * @see
com.ibatis.sqlmap.engine.type.TypeHandler#setParameter(java.sql.Prepared
Statement,

             *      int, java.lang.Object, java.lang.String)

             */

            public void setParameter(PreparedStatement ps, int i, Object
parameter,

                                    String jdbcType) throws SQLException
{

                        BigDecimal decParam = new BigDecimal(new
BigInteger(1,(byte[]) parameter));

                        ps.setBigDecimal(i, decParam);

 

            }

 

 

________________________________

From: Nathan.Maves@Sun.COM [mailto:Nathan.Maves@Sun.COM] 
Sent: Sunday, January 08, 2006 6:50 PM
To: user-java@ibatis.apache.org
Subject: Re: specify typehandler for byte[]

 

Andres,

 

I guess I am confused as to what you are trying to do.  Can you give an
example of the data?

 

Nathan

 

 

On Jan 6, 2006, at 7:22 PM, March, Andres wrote:





I'm trying to write the bytes to a numeric column not a binary one.  The
default one uses setBytes().  I need to do setBigDecimal().

 

________________________________

From: Nathan.Maves@Sun.COM [mailto:Nathan.Maves@Sun.COM] 
Sent: Friday, January 06, 2006 6:19 PM
To: user-java@ibatis.apache.org
Subject: Re: specify typehandler for byte[]

 

why is the default not good enough for you?

 

On Jan 6, 2006, at 6:51 PM, March, Andres wrote:






Well, I learned something new today - the internal representation of
class names.  This mapping does not fail like before:

 

typeHandler =jdbcType"NUMERIC" =<javaType"byte[]"
=callback"com.soe.freerealms.dao.ibatis.ByteArrayBigDecimalTypeHandler"

But I get an error because iBatis is doing a class.forName() on the
javaType attribute.  Is there any way to do this mapping?

-----------------------------------------

Platform - Apps Engineering

desk: 858.577.3373





 


Mime
View raw message