ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Glover <robertglove...@yahoo.com>
Subject Re: ExtendedCriteria extends IavEmpExample.Criteria
Date Mon, 04 Aug 2008 14:42:47 GMT




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
===============================
Mime
View raw message