ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Problem w/enum and TypeHandlerCallback
Date Tue, 17 Oct 2006 06:46:33 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii" 
format="flowed" delsp="yes;" plain; text Content-Type: 7bit 
Content-Transfer-Encoding:>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT color=#0000ff size=2><SPAN 
class=981004306-17102006>I'm using Enums without difficulty. I've implemented a 
<FONT size=2>TypeHandlerCallback to accommodate the set and get in the following 
manner:</FONT></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff><SPAN class=981004306-17102006>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT

size=2> Object getResult(ResultGetter getter) <B><FONT 
color=#7f0055>throws</B></FONT></FONT><FONT size=2> SQLException
{</FONT></P>
<P align=left><FONT size=2>String value = getter.getString();</FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>if</FONT></B></FONT><FONT

size=2> (getter.wasNull())</FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>return</FONT></B></FONT><FONT

size=2> <B><FONT color=#7f0055>null</B></FONT></FONT><FONT
size=2>;</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>return</FONT></B></FONT><FONT

size=2>&nbsp;<SPAN 
class=981004306-17102006>YourEnum.</SPAN><I>valueOf</I>(value);</FONT></P>
<P><FONT size=2>}</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>public</B></FONT><FONT

size=2> </FONT><B><FONT color=#7f0055 size=2>void</B></FONT><FONT
size=2> 
setParameter(ParameterSetter setter, Object parameter)</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>throws</B></FONT><FONT

size=2> SQLException {</P>
<P align=left></P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT
size=2> 
(parameter == </FONT><B><FONT color=#7f0055 size=2>null</B></FONT><FONT
size=2>) 
{</P>
<P align=left>setter.setNull(Types.</FONT><I><FONT color=#0000c0 
size=2>VARCHAR</I></FONT><FONT size=2>);</P>
<P align=left>} </FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT

size=2> {</FONT></P>
<P align=left><FONT size=2><SPAN class=981004306-17102006>YourEnum 
en</SPAN>&nbsp;= (<SPAN class=981004306-17102006>YourEnum</SPAN>) 
parameter;</FONT></P>
<P align=left><FONT size=2>setter.setString(<SPAN 
class=981004306-17102006>en</SPAN>.toString());</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2>}</FONT></P></SPAN></FONT></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Tom Duffey &lt;tduffey@utilivisor.com&gt;

[mailto:Tom Duffey &lt;tduffey@utilivisor.com&gt;] <BR><B>Sent:</B>
Monday, 
October 16, 2006 4:48 PM<BR><B>To:</B> 
user-java@ibatis.apache.org<BR><B>Subject:</B> Problem w/enum and 
TypeHandlerCallback<BR></FONT><BR></DIV>
<DIV></DIV>Hi All, <BR><BR>I'm having a problem with Java 5 Enums
and iBATIS 
<BR>TypeHandlerCallbacks. I've read the wiki article and it doesn't help 
<BR>with my particular issue. Retrieving objects is working fine but 
<BR>inserting/updating them is throwing this NPE: 
<BR><BR>java.lang.NullPointerException <BR>at 
com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter 
<BR>(UnknownTypeHandler.java:72) <BR>at 
<BR>com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete 
<BR>r(BasicParameterMap.java:165) <BR>at 
<BR>com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete 
<BR>rs(BasicParameterMap.java:125) <BR>at 
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate 
<BR>(SqlExecutor.java:76) <BR>at 
<BR>com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUp 
<BR>date(GeneralStatement.java:200) <BR>at 
<BR>com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat 
<BR>e(GeneralStatement.java:78) <BR>at 
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert 
<BR>(SqlMapExecutorDelegate.java:446) <BR>at 
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert 
<BR>(SqlMapSessionImpl.java:82) <BR>at 
org.springframework.orm.ibatis.SqlMapClientTemplate 
<BR>$9.doInSqlMapClient(SqlMapClientTemplate.java:358) <BR>at 
org.springframework.orm.ibatis.SqlMapClientTemplate.execute 
<BR>(SqlMapClientTemplate.java:188) <BR>at 
org.springframework.orm.ibatis.SqlMapClientTemplate.insert 
<BR>(SqlMapClientTemplate.java:356) <BR>... <BR><BR>Here's my basic
setup: 
<BR><BR>public interface Tenant { <BR>public enum Type { FOO, BAR } <BR>public

Type getType(); <BR>public void setType(Type type); <BR>... <BR>} <BR>public

class TenantImpl implements Tenant { <BR>private Type type; <BR>public Type 
getType() { return type; } <BR>public void setType(Type type) { this.type = 
type; } <BR>... <BR>} <BR><BR>My type handler for Tenant$Type looks
a lot like 
the examples in the <BR>wiki article. The types are mapped in my SqlMapConfig: 
<BR><BR><TYPEHANDLER <BR 
javaType="foo.bar.Tenant$Type">callback="com.utilivisor.dao.ibatis.TenantTypeEnumTypeHandler"/&gt;

<BR><BR>I'm messing around with UnknownTypeHandler.setParameter() and am very

<BR>confused. I checked the incoming value of parameter.getClass() and <BR>it
is 
correct, i.e., foo.bar.Tenant$Type. usingJavaPre5 is set <BR>(Which is confusing 
by itself because I am using Java5) so <BR>getBaseClass() is called and the new 
searchClass is foo.bar.Tenant. <BR>I do not have or want a type handler for 
foo.bar.Tenant. Can anyone <BR>help? <BR><BR>Tom <BR><BR></BODY></HTML>


Mime
View raw message