ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Reumann <ric...@gmail.com>
Subject My Boolen handler seems to be only working in one direction...
Date Sun, 14 May 2006 16:38:22 GMT
Based off some examples in the archives, I have this Y-N boolean handle 
that is supposed to handle converting true/false to Y/N in the db and 
vice versa.

The problem seems to be that it's working fine for converting data that 
needs to go into the DB as Y/N, but going the other direction, all my 
boolean object properties are remaining false. I have debugging 
statements in the "getResult" method below and I never the method being 
called (it's not a cache issue either since I have debugging on for 
iBATIS and can see the result set returning).

In my sqlMap-config I've defined:

<typeHandler javaType="java.lang.Boolean" 
callback="com.company.persistence.ibatis.BooleanYNTypeHandler"/>

Does it matter that the bean properties are primitive booleans and not 
Boolean? (I wouldn't think so since it seems to be fine going in the one 
direction -- bean > db).


BooleanYNTypeHandler:

public void setParameter(ParameterSetter setter, Object parameter) 
throws SQLException
{
     if (parameter == null) {
          setter.setString(null);
     } else {
         Boolean bool = (Boolean)parameter;
         String boolVal = "N";
         if (bool.booleanValue()) {
             boolVal = "Y";
         }
         setter.setString(boolVal);
     }
}

public Object getResult(ResultGetter getter) throws SQLException
{
     if (getter.wasNull()){
          return null;
     }

     String dbVal = getter.getString();
     if (dbVal.equalsIgnoreCase("Y")) {
         return Boolean.TRUE;
     } else {
         return Boolean.FALSE;
     }
}

public Object valueOf(String s)
{
     return s;
}

Mime
View raw message