Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 49450 invoked from network); 6 Mar 2006 17:32:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Mar 2006 17:32:51 -0000 Received: (qmail 11401 invoked by uid 500); 6 Mar 2006 17:33:36 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 11383 invoked by uid 500); 6 Mar 2006 17:33:35 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 11371 invoked by uid 99); 6 Mar 2006 17:33:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 09:33:35 -0800 X-ASF-Spam-Status: No, hits=0.3 required=10.0 tests=MAILTO_TO_SPAM_ADDR X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.247.21.91] (HELO wis.nl) (83.247.21.91) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 09:33:34 -0800 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: CHAR to BOOLEAN - Custom Type Handler X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Date: Mon, 6 Mar 2006 18:32:56 +0100 Message-ID: <50CA25BD6EEA954FA592C097399942E30E4636DB@CM1.wis.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: CHAR to BOOLEAN - Custom Type Handler Thread-Index: AcZBPXHfupQFXByURyC5J014nZIaHQABhodw From: "Niels Beekman" To: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N It is a lot easier to implement interface TypeHandlerCallback, this = implementation will then be wrapped in a class that hides = PreparedStatement and other artifacts. For a good example which you can modify: http://www.mail-archive.com/user-java@ibatis.apache.org/msg02792.html Hope this helps, Niels -----Original Message----- From: ggb275@tid.es [mailto:ggb275@tid.es]=20 Sent: maandag 6 maart 2006 17:48 To: user-java@ibatis.apache.org Subject: Re: CHAR to BOOLEAN - Custom Type Handler Thank you Larry, it worked. I think it could be simpler to use the same strings used by the Boolean=20 class ("true" and "false", ignoring case). At least to define them as=20 the default values for TRUE_STRING/FALSE_STRING. package com.ibatis.sqlmap.engine.type; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.ibatis.sqlmap.engine.type.TypeHandler; public class TrueFalseTypeHandler implements TypeHandler { public void setParameter(PreparedStatement ps, int i, Object=20 parameter, String jdbcType) throws SQLException { ps.setString( i, ((Boolean) parameter).toString() ); } public Object getResult(ResultSet rs, String columnName) throws=20 SQLException { return Boolean.valueOf( rs.getString( columnName ) ); } public Object getResult(ResultSet rs, int columnIndex) throws=20 SQLException { return Boolean.valueOf( rs.getString( columnIndex ) ); } public Object getResult(CallableStatement cs, int columnIndex)=20 throws SQLException { return Boolean.valueOf( cs.getString( columnIndex ) ); } public Object valueOf(String string) { =20 return Boolean.valueOf( string ); =20 } public boolean equals(Object object, String string) { return Boolean.valueOf( string ).equals( object ); } } Best regards, Guido Garc=EDa Bernardo. Larry Meadors escribi=F3: > I think this will work: > > =3D=3D=3D > > package com.ibatis.sqlmap.engine.type; > > import java.sql.PreparedStatement; > import java.sql.SQLException; > import java.sql.ResultSet; > import java.sql.CallableStatement; > > public class BooleanYNTypeHandler implements TypeHandler { > protected String TRUE_STRING =3D "Y"; > protected String FALSE_STRING =3D "N"; > public void setParameter(PreparedStatement ps, int i, Object > parameter, String jdbcType) throws SQLException { > ps.setString(i, boolToString((Boolean) parameter)); > } > > public Object getResult(ResultSet rs, String columnName) throws = SQLException { > return stringToBool(rs.getString(columnName)); > } > > public Object getResult(ResultSet rs, int columnIndex) throws = SQLException { > return stringToBool(rs.getString(columnIndex)); > } > > public Object getResult(CallableStatement cs, int columnIndex) > throws SQLException { > return stringToBool(cs.getString(columnIndex)); > } > > public Object valueOf(String s) { > return stringToBool(s); > } > > public boolean equals(Object object, String string) { > return string.equalsIgnoreCase(boolToString((Boolean) object)); > } > private String boolToString(Boolean b){ > if(null =3D=3D b) return null; > return b.booleanValue()?TRUE_STRING:FALSE_STRING; > } > private Boolean stringToBool(String s){ > if (null =3D=3D s) return null; > return Boolean.valueOf(s.equalsIgnoreCase(TRUE_STRING)); > } > } > > =3D=3D=3D > > Let me know if it does, and we'll try to add it to the default type > handlers in the next release. > > It would be a real simple exercise to add a BooleanTFTypeHandler, too > - just subclass this and make the default constructor set TRUE_STRING > =3D "T" and FALSE_STRING =3D "F". > > Larry > > =20