Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 2830 invoked from network); 4 Aug 2008 14:44:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Aug 2008 14:44:23 -0000 Received: (qmail 97997 invoked by uid 500); 4 Aug 2008 14:44:19 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 97987 invoked by uid 500); 4 Aug 2008 14:44:19 -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 97976 invoked by uid 99); 4 Aug 2008 14:44:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Aug 2008 07:44:19 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [68.142.200.151] (HELO web30808.mail.mud.yahoo.com) (68.142.200.151) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 04 Aug 2008 14:43:23 +0000 Received: (qmail 93442 invoked by uid 60001); 4 Aug 2008 14:42:47 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=eYisdp4bx0Ro+QplpCNpAFDHNwN2hpqoREPaEac9d3oypAcp4w/xLZrLdQd2eX/xmOu2eE17B3l3vFRyhXo1dvP4Co/0JHbJY0DWTBHKMONkih/ihwGxXiHHfng/yAAs9qPjMhqX+jVkKl61g1vNF4IkaiwoKMI+xaf1ob58/YE=; Received: from [12.171.160.202] by web30808.mail.mud.yahoo.com via HTTP; Mon, 04 Aug 2008 07:42:47 PDT X-Mailer: YahooMailRC/1042.48 YahooMailWebService/0.7.218 Date: Mon, 4 Aug 2008 07:42:47 -0700 (PDT) From: Robert Glover Subject: Re: ExtendedCriteria extends IavEmpExample.Criteria To: user-java@ibatis.apache.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-69028797-1217860967=:92926" Message-ID: <395077.92926.qm@web30808.mail.mud.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org --0-69028797-1217860967=:92926 Content-Type: text/plain; charset=us-ascii From:Robert Glover [mailto:robertgloverjr@yahoo.com] Sent: Thursday, July 31, 2008 5:10 PM To: user-java@ibatis.apache.org Subject: Is there a way using Ibator to do a case-insensitive LIKE compare Disclaimer: I really, really like Ibator and use it in all my projects. A programmer has inherited one of my projects that uses Ibator. He needs to use Ibator to do some name comparisons on people's names. For example, a database column might contain a value of "John .J. Hancock". He wants to use Ibator to do a "LIKE" compare against "%HANCOCK%". Unfortunately it is Oracle 10i, not MySql. So, no match results because Oracle is case sensitive. (MySql is not case sensitive). Short of modifying the java code that Ibator generates, is there any way using Ibator to do the "LIKE" as if the column in the database contained "JOHN J. HANCOCK" instead of "John .J. Hancock"? I realize that one solution would be to create a VIEW of the TABLE that had the column value upper-cased and then run the VIEW into an IBATOR generation, but he would prefer not to have to do that. Thanks in advance, Robert (a bit Ibator fan) -----Inline Message Follows----- -----Inline Attachment Follows----- Take a look in the ibator documentation here: http://svn.apache.org/repos/asf/ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html I describe exactly how to extend the generated example classes to add this functionality. Jeff Butler ================== Thank you Mr. Butler!!! I have pasted below the class I just wrote per your excellent documentation and pointer to same: package frb.bsd.abatorExtended.domain; import org.apache.commons.lang.StringUtils; import frb.bsd.abator.domain.IavEmpExample; import frb.bsd.abator.domain.IavEmpExample.Criteria; /** * purpose: to add support for case-insensitive search to Ibator generated class * * @author b1rdg02 (Robert D Glover) * create date: August 1, 2008 - RDG new * update log: August 1, 2008 - RDG initial create * * background: Jeff Butler, author of Ibator (Abator was renamed to Ibator in Spring, 2008), * recommended writing an over-riding class of this type in in documentation at * the following link: * * http://svn.apache.org/repos/asf/ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html * * The link above describes how to extend the generated example * classes to add functionality for a case insensitive search. * * */ public class IavEmpExampleExtended extends IavEmpExample { @Override protected Criteria createCriteriaInternal() { // TODO Auto-generated method stub return super.createCriteriaInternal(); } public static class ExtendedCriteria extends IavEmpExample.Criteria { /** * Uses org.apache.commons.lang.StringUtils.upperCase because * it will not throw an nullpointer exception if operand is null. * @param value * @return */ public Criteria andLastNameLikeInsensitive(String value) { addCriterion("upper(L_NAME) like", StringUtils.upperCase(value), "lastName"); return this; } /** * Uses org.apache.commons.lang.StringUtils.upperCase because * it will not throw an nullpointer exception if operand is null. * @param value * @return */ public Criteria andFirstNameLikeInsensitive(String value) { addCriterion("upper(F_NAME) like", StringUtils.upperCase(value), "firstName"); return this; } } } =============================== There is a slight problem with the sample code above.... the createCriteriaInternal method should have returned new ExtendedCriteria object. With that change, I am told by a developer (Ilya) who tried it, it works very nicely. (Thanks Ilya!). Robert Glover August 4, 2008 =============================== --0-69028797-1217860967=:92926 Content-Type: text/html; charset=us-ascii


From: Robert Glover [mailto:robertgloverjr@yahoo.com]
Sent: Thursday, July 31, 2008 5:10 PM
To: user-java@ibatis.apache.org
Subject: Is there a way using Ibator to do a case-insensitive LIKE compare

 

   Disclaimer:  I really, really like Ibator and use it in all my projects.

   A programmer has inherited one of my projects that uses Ibator.  He needs to use Ibator to do some name comparisons on people's names.  For example, a database column might contain  a value of "John .J. Hancock".  He wants to use Ibator to do  a "LIKE" compare against "%HANCOCK%".  Unfortunately it is Oracle 10i, not MySql.  So, no match results because Oracle is case sensitive. (MySql is not case sensitive).
     Short of modifying the java code that Ibator generates,  is there any way  using Ibator to do the "LIKE"  as if the column in the database  contained "JOHN J. HANCOCK"  instead of "John .J. Hancock"?
     I realize that one solution would be to create a VIEW of the TABLE that had the column value upper-cased and then run the VIEW into an IBATOR generation, but he would prefer not to have to do that.

Thanks in advance,
Robert (a bit Ibator fan)


-----Inline Message Follows-----
-----Inline Attachment Follows-----
Take a look in the ibator documentation here:
 
I describe exactly how to extend the generated example classes to add this functionality.
 
Jeff Butler
==================
   Thank you Mr. Butler!!!  I have pasted below the class I just wrote per your excellent documentation and pointer to same:

package frb.bsd.abatorExtended.domain;

import org.apache.commons.lang.StringUtils;
import frb.bsd.abator.domain.IavEmpExample;
import frb.bsd.abator.domain.IavEmpExample.Criteria;

/**
 * purpose: to add support for case-insensitive search to Ibator generated class
 *
 * @author b1rdg02 (Robert D Glover)
 * create date:  August 1, 2008 - RDG new
 * update log:  August 1, 2008 - RDG initial create
 *
 * background: Jeff Butler, author of Ibator (Abator was renamed to Ibator in Spring, 2008),
 *          recommended writing an over-riding class of this type in in documentation at
 *          the following link:
 *          
 * http://svn.apache.org/repos/asf/ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html
 *
 *           The link above describes how to extend the generated example
 *           classes to add functionality for a case insensitive search.
 *
 *
 */
public class IavEmpExampleExtended extends IavEmpExample {

    @Override
    protected Criteria createCriteriaInternal() {
        // TODO Auto-generated method stub
        return super.createCriteriaInternal();
    }
    public static class ExtendedCriteria extends IavEmpExample.Criteria {
       
        /**
         *     Uses org.apache.commons.lang.StringUtils.upperCase because
         *     it will not throw an nullpointer exception if operand is null.
         * @param value
         * @return
         */
        public Criteria andLastNameLikeInsensitive(String value) {
            addCriterion("upper(L_NAME) like", StringUtils.upperCase(value), "lastName");
            return this;
        }
        /**
         *     Uses org.apache.commons.lang.StringUtils.upperCase because
         *     it will not throw an nullpointer exception if operand is null.
         * @param value
         * @return
         */
        public Criteria andFirstNameLikeInsensitive(String value) {
            addCriterion("upper(F_NAME) like", StringUtils.upperCase(value), "firstName");
            return this;
        }       
       
    }
   
}
===============================
      There is a slight problem with the sample code above.... the createCriteriaInternal method should have returned new ExtendedCriteria object.  With that change, I am told by a developer (Ilya) who tried it, it works very nicely.  (Thanks Ilya!).
Robert Glover  August 4, 2008
===============================

--0-69028797-1217860967=:92926--