ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From C.Ze...@ads.it
Subject TypeHandlerCallback.valueOf(): exceptions
Date Tue, 24 Oct 2006 15:38:49 GMT


Hi all

I've just read the example about YesNoBoolTypeHandlerCallback (p. 41 of
BATIS-SqlMaps-2_en.pdf, Creating custom Type Handlers))
and the API for the  TypeHandlerCallback  interface

   public java.lang.Object valueOf(java.lang.String s)

   Casts the string representation of a value into a type recognized by
   this type handler. This method is used to translate nullValue values
   into types that can be appropriately compared. If your custom type
   handler cannot support nullValues, or if there is no reasonable string
   representation for this type (e.g. File type), you can simply return the
   String representation as it was passed in. It is not recommended to
   return null, unless null was passed in.

In the documented example a SQLException is raised when the passed string
cannot be converted to a Boolean.

Please note that

I)
The signature of  valueOf() does not mention any exception ("Unexpected
value " + s + " found where " + YES + " or " + NO + " was expected."); )

II)
If I try to raise an exception...

      public Object valueOf( String pString )
      {
            Box< RuntimeException > lBoxRuntimeException = new Box<
RuntimeException >();
            TipoBD lResult = TipoBD.newInstance( pString,
lBoxRuntimeException );
            if ( lResult == null )
            {
      [*]         throw new SQLException ( lBoxRuntimeException.toString()
);

Eclipse complains...

   Unhandled exception type SQLException

Viceversa, If I add throws SQLException the diagnostic becomes

   Exception SQLException is not compatible with throws clause in
   TypeHandlerCallback.valuefOf(String)

III)
The column on the DB cannot contain neither null values nort invalid values
(the integrity is enforced by a proper constraint on the column).
So, it should never come a null value.
Secondly, a null value cannot anyway be handled.
Should I raise an exception, but how, since the code [*] above does not
compile?
Or should I simply return the String representation as it was passed in?
(in this case either null or of any invalid value, if any)?

Please note that another example

      http://www.mail-archive.com/user-java@ibatis.apache.org/msg04873.html

contains code that does not raise any exception at all.
So might I ignore the exception?

Thanks in advance for any explanation.

ciao
Cesare
Mime
View raw message