Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 89503 invoked from network); 6 Mar 2006 16:04:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Mar 2006 16:04:45 -0000 Received: (qmail 7093 invoked by uid 500); 6 Mar 2006 16:05:07 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 6617 invoked by uid 500); 6 Mar 2006 16:05:05 -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 6606 invoked by uid 99); 6 Mar 2006 16:05:05 -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 08:05:05 -0800 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=RCVD_IN_BL_SPAMCOP_NET,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of larry.meadors@gmail.com designates 66.249.82.206 as permitted sender) Received: from [66.249.82.206] (HELO xproxy.gmail.com) (66.249.82.206) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 08:05:04 -0800 Received: by xproxy.gmail.com with SMTP id s19so809220wxc for ; Mon, 06 Mar 2006 08:04:43 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P8hq0vqvRddxoV2gdDV3MMp/SuLsX7Sr/RPtm/xmGxIQA5fboSeX8zu16tHD9a/3XtdQLVY/FFkE989hrQ1tnbx4elKESbU3ovFDJfT6FjoJw5GWU5IRTPe1w5OGYrmjj9zmD1nQ0xK9XwZIfYF+5iW/fRn2Q7y/wiNiwAvYBFE= Received: by 10.70.65.5 with SMTP id n5mr6208856wxa; Mon, 06 Mar 2006 08:04:43 -0800 (PST) Received: by 10.70.74.14 with HTTP; Mon, 6 Mar 2006 08:04:43 -0800 (PST) Message-ID: Date: Mon, 6 Mar 2006 09:04:43 -0700 From: "Larry Meadors" Reply-To: lmeadors@apache.org Sender: larry.meadors@gmail.com To: user-java@ibatis.apache.org Subject: Re: CHAR to BOOLEAN - Custom Type Handler In-Reply-To: <440C0726.30907@tid.es> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <440C0726.30907@tid.es> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 SQLExcept= ion { return stringToBool(rs.getString(columnName)); } public Object getResult(ResultSet rs, int columnIndex) throws SQLExceptio= n { 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