PS - I have nothing against the ternary operator!  I didn't write that section of the manual, so I don't make any claims about the code style :)

I figured as much. I just felt a little saucy (devious attitude). :o)

 

 

 

Thanks for the info. The TypeHandlerCallback is easier so that is the one I will use.

I’ll just change my TypeHandler to be a TypeHandlerCallback…

 

 

package qcom.cas.commons.ibatis.typehandler;

 

import java.sql.SQLException;

 

import com.ibatis.sqlmap.client.extensions.ParameterSetter;

import com.ibatis.sqlmap.client.extensions.ResultGetter;

import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;

 

public class StringBooleanTypeHandler implements TypeHandlerCallback {

 

            public Object valueOf(String value) {

                        if (value.equals("Y")) {

                                    return Boolean.TRUE;

                        } else {

                                    return Boolean.FALSE;

                        }

            }

 

            public void setParameter(ParameterSetter param, Object value) throws SQLException {

                        Boolean bValue = (Boolean) value;

                        param.setString(bValue.booleanValue() ? "Y" : "N");

            }

 

            public Object getResult(ResultGetter rg) throws SQLException {

                        return valueOf(rg.getString());

            }

 

}

 

It works. It is a lot shorter and easier to read. I dig it.

 

 


From: Jeff Butler [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 29, 2006 10:34 AM
To: [email protected]
Subject: Re: Jeff RE: How do you map a Java boolean property to a VARCHAR(1) that contains 'Y' or 'N'?

 

Hi Rick,

 

It turns out that you can use either one.  TypeHandlerCallback is a bit simpler to implement than TypeHandler, but either will do.  We call the XML attributes "typeHandler" for brevity.

 

If you use TypeHandlerCallback, then the class com.ibatis.sqlmap.engine.type.CustomTypeHandler is used internally to simulate a full TypeHandler.

 

Off to update the documentation...sigh...

 

Jeff Butler

 

PS - I have nothing against the ternary operator!  I didn't write that section of the manual, so I don't make any claims about the code style :)

 



 

On 6/29/06, Rick <[EMAIL PROTECTED] > wrote:

Jeff,

 

I downloaded the guide out of svn. It does mention TypeHandler (which is what I used), but it also mentions TypeHandlerCallback.

 

TypeHandler seems very similar to TypeHandlerCallback, with the exception that TypeHandlerCallback seems to have the ability to be applied globally.

 

Which should I use? What is the difference?

 

You were right about the example, it is very similar to what I did.

 

 

P.S.

Mine was more terse….

I don't use constants unless they are needed in more than one method or their value is not clear what they are doing.

What do you have against the ternary operator?

 

 

--Rick Hightower


 

Reply via email to