You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by John Cartwright <Jo...@noaa.gov> on 2009/02/07 00:43:17 UTC

custom type handler w/ database-specific type

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


RE: custom type handler w/ database-specific type

Posted by Rahul Saluja <ra...@vnl.in>.
And one more thing which I forgot to mention don't forget to declare your typehandler with alias in you sqlmapconfig file in following manner

<typeAlias alias="ArraysToStringTypeHandler" type="com.hns.hss.nmf.server.log.manager.util.ArraysToStringTypeHandler" />

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.

RE: custom type handler w/ database-specific type

Posted by Rahul Saluja <ra...@vnl.in>.
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.

Re: custom type handler w/ database-specific type

Posted by Rob Sonke <ro...@tigrou.nl>.
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
>>

Re: custom type handler w/ database-specific type

Posted by John Cartwright <Jo...@noaa.gov>.
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
>