ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tracey Annison" <tanni...@trisystems.co.uk>
Subject RE: Problem with using generic and specific custom TypeHandlers
Date Wed, 17 May 2006 15:00:57 GMT
OK, so now we know...


For a generic typeHandler, where every occurrence of a special type has
the same database representation, we can do it simply and automatically.

Specify the fields as the special type in the Java class (ThingIbatis),
and add a TypeHandler definition to sql-map-config.xml, and it'll all
get sorted out automatically :  
===============
<typeHandler javaType="uk....user_type.SpecialType"
callback="uk.co.trisystems.morph.common.utils.SpecialTypeStringTypeHandl
er"/>  
===============


For a specific type handler, where there are several sorts of database
representation for a special type or a Boolean, specify the fields in
the Java (ThingIbatis) as what they are, and define specific
TypeHandlers as needed in the object's xml file. 
Specify a TypeHandler in the ResultMap, and line by line in the SQL : 
===============
<resultMap id="thingResult" class="uk.....persistence.ThingIbatis"> 
        <result column="OCCMCD" property="companyCode"/>
        ...
        <result column="OCTYAG" property="treatyAutoGenClosing"
javaType="java.lang.Boolean" jdbcType="CHAR"
typeHandler="uk.....utils.BooleanToStringYNTypeHandler"/>
        <result column="OCTFAG" property="treatyCode"
javaType="uk....user_type.CodeType" jdbcType="CHAR"
typeHandler="uk.....utils.CodeTypeToStringTypeHandler"/>  
      ...
</resultMap>
        
<select id="getThing" resultMap="thingResult"
resultClass="uk.co.trisystems.morph.ta.persistence.ThingIbatis">
        <![CDATA[
       select '$library$' as library, 
        OCCMCD.
        ...
         OCTYAG,  
        ...
        from $library$/MACPFOC0
              where OCCMCD = #companyCode#
                ...
        ]]>
    </select>
        
        <insert id="insertThing"
parameterClass="uk.....persistence.ThingIbatis">
                <![CDATA[
        insert into
        $library$/MACPFOC0 (OCCMCD,
              ...
             OCTYAG,  
             ...
                           )
        values (#companyCode#,
                 ...
 
#treatyAutoGenClosing,javaType=java.lang.Boolean,handler=uk....utils.Boo
leanToStringYNTypeHandler#,
 
#treatyCode,javaType=uk....user_type.CodeType,handler=uk....utils.CodeTy
peToStringTypeHandler#,
                ...
               )
        ]]>
    </insert>
        
        <update id="updateThing"
parameterClass="uk.....persistence.ThingIbatis">
                <![CDATA[
        update $library$/MACPFOC0
        set OCCLDS = #companyCode#,
             ...
              OCTYAG =
#treatyAutoGenClosing,javaType=java.lang.Boolean,handler=uk.....utils.Bo
oleanToStringYNTypeHandler#,
              OCTFAG =
#treatyCode,javaType=uk....user_type.CodeType,handler=uk.co...
...utils.CodeTypeToStringTypeHandler#,
              ...
              where OCCMCD = #companyCode#
        ...
        ]]>
    </update> 
===============
("..." used here to denote other lines, "uk....." used to denote full
path)
Take note of the presence & absence of quotes & spaces, and the exact
syntax in the TypeHanndler lines in this - THEY ARE IMPORTANT, and it
won't work without it being exactly like this.


Cheers
Tracey Annison



----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged. 
It is intended solely for the addressee. Access to this email by 
anyone else is unauthorised. If you are not the intended recipient, 
any disclosure, copying, distribution, or any action taken or omitted 
to be taken in reliance on it, is prohibited and may be unlawful. 
TriSystems Ltd. cannot accept liability for statements made which are clearly
the sender's own.



Mime
View raw message