Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 9305 invoked from network); 12 May 2006 08:10:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 May 2006 08:10:46 -0000 Received: (qmail 38751 invoked by uid 500); 12 May 2006 08:10:44 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 38597 invoked by uid 500); 12 May 2006 08:10:43 -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 38586 invoked by uid 99); 12 May 2006 08:10:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 May 2006 01:10:43 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=MISSING_MIMEOLE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [195.167.165.141] (HELO trisystems.co.uk) (195.167.165.141) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 May 2006 01:10:41 -0700 Received: by trisystems.co.uk (CommuniGate Pro PIPE 5.0.6) with PIPE id 302297; Fri, 12 May 2006 09:10:20 +0100 Received: from [192.168.1.59] (account tannison@trisystems.co.uk) by trisystems.co.uk (CommuniGate Pro IMAP 5.0.6) with XMIT id 302293 for user-java@ibatis.apache.org; Fri, 12 May 2006 09:10:14 +0100 Subject: RE: Problem with using generic and specific custom TypeHandlers Date: Fri, 12 May 2006 09:06:31 +0100 Organization: TriSystems Ltd. Message-Id: X-ProcessedID: f0dc27668b18db44a25f16fc82d0e879@elvis In-Reply-To: <44635FD1.3020101@munat.com> MIME-Version: 1.0 Thread-Topic: Problem with using generic and specific custom TypeHandlers Priority: Normal Importance: normal X-MSMail-Priority: normal X-Priority: 3 Sensitivity: Normal Thread-Index: AcZ1mvpE2FT9HrFuSq+kxvOrdXy5lg== From: "Tracey Annison" To: "user-java@ibatis.apache.org" X-MAPI-LastModified: Fri, 12 May 2006 09:06:31 +0100 X-Mailer: CommuniGate Pro MAPI Connector 1.1.32/1.1.33 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hiya, Ben Thank you so much for your reply! I added the parameterMap, but I'm still getting it reading & writing 0 and 1 to the Db for the Booleans, not Y/N, T/F, and the other strings I want. My TypeHandler isn't even being called. I don't suppose you could possibly take a look at my files & tell me where I'm going wrong, if I sent them to you personally? I'll owe you a favour, if so! Cheers Tracey Annison -----Original Message----- From: Ben Munat [mailto:bent@munat.com] Sent: 11 May 2006 17:01 To: user-java@ibatis.apache.org Subject: Re: Problem with using generic and specific custom TypeHandlers Hi Tracey, I used a custom type handler on a project last year (for a boolean field on an AS/400 no less :-) ) and I remember struggling to get it to work. I just went and looked at my map I think you need to create a parameterMap for the query that uses the type handler as well as a result map. You specify the type handler for the property that uses it on both ends. So, here's what mine looks like: Hope that helps! b Tracey Annison wrote: > Hiya! > > *** I think I sent this wrong earlier - apologies if it duplicates! > *** > > We are using iBATIS with Java against a quirky AS/400 database. We > have used custom TypeHandlers successfully to globally map enums > against columns holding String codes, but are now trying to map a > variety of codes to Booleans without success. > > As an example, I have three string fields, let's say Fred, Hal, Bill > and Joe. > - Fred and Hal can have values "A", "N", and "Y" > - Bill has values "Y" and "N" (which mean positive & negative) > - Joe has values "1" and "0" (which also mean positive & negative) I > have made a Java enum to hold the A/N/Y values called FlagANY, and a > TypeHandler called TypeHandlerStringANYEnum to convert the string "A", > "N" and "Y" values from the db into the enum FlagANY. I've made Fred > and Hal into FlagANY enums in the Java class ThingIbatis. > > Both Bill and Joe are Booleans in the Java class ThingIbatis, and I > have created TypeHandlers TypeHandlerStringYNBoolean and > TypeHandlerString01Boolean to convert their varying string values into > the appropriate Boolean values. > > In the sql-map-config.xml, I can map the FlagANY fields globally, > which works fine for Fred and Hal - as they're FlagANY in the Java > class, and as their value on the Db are consistent, the TypeHandler > gets invoked from the sql-map-config.xml setting, and all is well. > > Now, Bill and Joe are both Booleans in the Java class, but their > values on the Db differ, so I have to specify their TypeHandlers on a > column-by-column basis in the table's XML file. (I tried omitting the " > javaType=3D"java.lang.Boolean", but that didn't help) > > This ought to work, as far as I can see, but the TypeHandler doesn't > ever get invoked. Is there some special syntax I should be using? > > > Generic TypeHandler in the sql-map-config.xml- javaType=3D"uk.co.package.user_type.FlagANY" > callback=3D"uk.co.package.utils.TypeHandlerStringANYEnum"/> > > And in the thing.xml I can define a ResultMap like this - id=3D"thingResult" class=3D"uk.co.package.persistence.ThingIbatis"> > > > javaType=3D"java.lang.Boolean" > typeHandler=3D"uk.co.package.utils.TypeHandlerStringYNBoolean"/> > > javaType=3D"java.lang.Boolean" > typeHandler=3D"uk.co.package.utils.TypeHandlerString01Boolean"/> > > > > > Cheers > Tracey Annison > > ---------------------------------------------------------------------- > The information in this email is confidential and may be legally > privileged. > It is intended solely for the addressee. Access to this email by > anyone else is unauthorised. If you are not the intended recipient, > any disclosure, copying, distribution, or any action taken or omitted > to be taken in reliance on it, is prohibited and may be unlawful. > TriSystems Ltd. cannot accept liability for statements made which are > clearly the sender's own. ---------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the sender's own.