Allow typeHandler class to implement TypeHandler interface
----------------------------------------------------------

         Key: IBATIS-37
         URL: http://nagoya.apache.org/jira/browse/IBATIS-37
     Project: iBatis for Java
        Type: Improvement
  Components: SQL Maps  
    Versions: 2.0.8    
    Reporter: Juergen Hoeller


Hi Clinton and team,

We plan to provide BLOB/CLOB type handlers for iBATIS SQL Maps 2 in Spring, 
delegating to Spring's LobHandler abstraction. I've checked out your new 
TypeHandler support, which looks like a nice hook for this.

Spring's LobHandler expects to work on PreparedStatements and ResultSets. For 
this reason, the TypeHandlerCallback mechanism in SQL Maps cannot be used; we 
need to provide plain TypeHandler implementations. I've already implemented 
such TypeHandlers; there's no obstacle there.

Unfortunately, the typeHandler attribute in XML SQL mapping files just accepts 
TypeHandlerCallback implementations as of iBATIS 2.0.8, throwing a nasty 
ClassCastException else.

To make this more flexible, I suggest to load the specified class and check 
whether it is a TypeHandler or TypeHandlerCallback implementation. This should 
be straightforward to add to XmlSqlMapClientBuilder: just add a corresponding 
check to line 912/913.

  Object typeHandler = Resources.classForName(callback).newInstance();
  if (typeHandler instanceof TypeHandler) {
    handler = (TypeHandler) handler;
  }
  else if (typeHandler instanceof TypeHandlerCallback) {
    handler = new CustomTypeHandler((TypeHandlerCallback) typeHandlerCallback);
  }
  else {
    throw SqlMapException("Invalid type handler class: ...");
  }

This should be pretty trivial to add and not cause any side effects, as far as 
I can see. It would be great if you could get this into iBATIS 2.0.9 (or 
whatever your next planned release is).

Thanks in advance,

Juergen

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira

Reply via email to