ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Saluja <rahul.sal...@vnl.in>
Subject RE: custom type handler w/ database-specific type
Date Sun, 08 Feb 2009 09:34:22 GMT
Hi John,

As far I can understand from your mail you exactly wish to know how to register your typehandlers
for parameter types in your sqlmap or parametermap well here is the example you can do this:



public class ArraysToStringTypeHandler implements TypeHandlerCallback
{
        private static LoggerIf log_ = LogFactory.getLoggerIf ( ArraysToStringTypeHandler.class.getName
( ) );

        public Object getResult(ResultGetter arg0) throws SQLException
        {
                // TODO Auto-generated method stub
                return null;
        }


        public void setParameter(ParameterSetter setter, Object parameter) throws SQLException
        {
                if (parameter == null) {
            log_.debug("[ArraysToString][setParameter] parameter is coming as NULL");
                        setter.setNull(Types.CHAR);
        } else {
                  //setter.setNull(Types.CHAR);
                log_.debug("[ArraysToString][setParameter] going to call ArraysToString(parameter)
");
                setter.setString(ArraysToString( parameter));
        }
                // TODO Auto-generated method stub

        }


        public Object valueOf(String arg0)
        {
                // TODO Auto-generated method stub
                return null;
        }



        private String ArraysToString(Object obj)
        {
                log_.debug("[ArraysToString][setParameter] inside ArraysToString(parameter)
");
                if ( obj == null)
                {
                        throw new IllegalArgumentException ("Could not convert null to a String
value. " +
                        "Valid argument is an array of type I_U8 Only ");
                }
                else if (obj instanceof com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8
[]  )
                {


                com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8 [] ourData = ( com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8
[])obj;
                        log_.debug("Array contents are of type ----> "+ourData.getClass().getComponentType());
                        int length = ourData.length;
                        log_.debug("so length of our data is " + length);

                        StringBuffer dataHolderSb = new StringBuffer();
                        dataHolderSb.append("{");
                        for(int i = 0 ;i<length ; i++)
                        {

                                dataHolderSb.append(ourData[i].getValue());
                                dataHolderSb.append(",");
                        }
                        dataHolderSb.append("}");
                        return dataHolderSb.toString();


                }
                else{
                        return null;
                }
                //return null;

        }
}




<insert id="ID "
                        parameterClass="com.yourcompany.Classname">
                                insert into TableName (wrongBsic0,oTargetCellUlQual,noTargetCellDlLevel,
                                  noTargetCellUlLevel)
                                values(nextval ('BSCCSALGOHOPM_SEQ'),
                        #wrongBsic0,handler=ArraysToStringTypeHandler#
                                #noTargetCellUlLevel.value#)
                        </insert>


Hope it helps.

Regards
Rahul Saluja






-----Original Message-----
From: Rob Sonke [mailto:rob@tigrou.nl]
Sent: Sunday, February 08, 2009 2:53 PM
To: user-java@ibatis.apache.org
Subject: Re: custom type handler w/ database-specific type

DO you need access to the DataSource or the Connection?

Rob


John Cartwright wrote:
> I think I've worked around this problem by explicitly specifying the
> handler class w/in the in-line parameter map.
> Now I seem to have the problem of TypeHandler class needing access to
> the DataSource...
>
> --john
>
>
> John Cartwright wrote:
>> Hello All,
>>
>> I'm trying to implement a custom type handler to support Oracle's
>> SDO_GEOMETRY type.  I've got it (apparently) working for retrieval of
>> data, but am having trouble w/ inserts into the database. Error says:
>>
>> org.springframework.jdbc.UncategorizedSQLException: SqlMapClient
>> operation; uncategorized SQLException for SQL []; SQL state [null];
>> error code [0];   --- The error occurred in
>> gov/noaa/ngdc/mgg/ufn/Feature.xml.  --- The error occurred while
>> applying a parameter map.  --- Check the
>> Feature.insertShape-InlineParameterMap.  --- Check the parameter
>> mapping for the 'geometry' property.  --- Cause:
>> java.lang.NullPointerException; nested exception is
>> com.ibatis.common.jdbc.exception.NestedSQLException:   --- The error
>> occurred in gov/noaa/ngdc/mgg/ufn/Feature.xml.  --- The error
>> occurred while applying a parameter map.  --- Check the
>> Feature.insertShape-InlineParameterMap.  --- Check the parameter
>> mapping for the 'geometry' property.  --- Cause:
>> java.lang.NullPointerException
>>
>> I'm registering a global type handler w/:
>>
>> <typeHandler
>> callback="gov.noaa.ngdc.mgg.ufn.dao.ibatis.SdoGeometryHandler"
>> javaType="com.vividsolutions.jts.geom.Geometry"
>> jdbcType="SDO_GEOMETRY" />
>>
>>
>> and the inline parameter map for the "geometry" column uses:
>>
>> #geometry:SDO_GEOMETRY#
>>
>>
>> I've tried various other values for JDBC types: STRUCT, OTHER
>> w/o success.
>>
>> Can someone please help me understand a little better about the
>> connections between the the types in the parameter map and the
>> typehandler registration?
>>
>> Thanks!
>>
>> --john
>>
The information contained in this e-mail is private & confidential and may also be legally
privileged. If you are not the intended recipient, please notify us, preferably by e-mail,
and do not read, copy or disclose the contents of this message to anyone.

Mime
View raw message