4 Replies Latest reply on Jan 23, 2007 5:32 AM by Pete Muir

    org.jboss.seam.framework Query too case sensitive

    Leo Baschy Novice

      Method getCountEjbql() could use an intermediate variable

      String ejbqlLowerCase = ejbql.toLowerCase()
      and use that ejbqlLowerCase for the two indexOf calls.

      That lower case I'm sure about.

      Further, it might be better to have extra spaces to make that an
      indexOf(" order ")
      to avoid mistaking orderNumber and such or use a regular expression (tabs, line breaks, parentheses, etc). If you need to roll those regular expression, ask me, I might find to do them right.

      Maybe also
      indexOf(" from ")
      or a regular expression there too. Precompile the regular expression into a static variable, is that ok here?

        • 1. Re: org.jboss.seam.framework Query too case sensitive
          Gavin King Master

          Please submit a patch (in diff format) to CVS.

          • 2. Re: org.jboss.seam.framework Query too case sensitive
            Leo Baschy Novice

            Here is my code. I'll try again with CVS, I've figured out anonymous CVS for Seam, I've figured out you want JIRA to submit diff, but both with TortoiseCVS and with Eclipse (to a Windows machine) I'm getting double line breaks, so my diff is wrong. I try again in a couple of days.

            Meanwhile so the suspense doesn't become unbearable...

            import java.util.regex.Matcher;
            import java.util.regex.Pattern;
            
             private static final Pattern FROM_PATTERN =
             Pattern.compile
             ("[^a-z0-9_](from)[^a-z0-9_]",Pattern.CASE_INSENSITIVE);
            
             private static final Pattern ORDER_PATTERN =
             Pattern.compile
             ("[^a-z0-9_](order)[^a-z0-9_]",Pattern.CASE_INSENSITIVE);
            
             protected String getCountEjbql() {
             String ejbql = getRenderedEjbql();
             //
             Matcher fromMatcher = FROM_PATTERN.matcher(ejbql);
             boolean foundFrom = fromMatcher.find();
             int fromLoc = fromMatcher.start(1);
             //
             Matcher orderMatcher = ORDER_PATTERN.matcher(ejbql);
             boolean foundOrder = orderMatcher.find();
             int orderLoc = foundOrder ? orderMatcher.start(1) : ejbql.length();
             //
             return "select count(*) " + ejbql.substring(fromLoc, orderLoc);
             }


            These patterns could use some more research, but now they prevent mismatches for tokens named orderForm and fromAddress, and they're case-insensitive.

            • 3. Re: org.jboss.seam.framework Query too case sensitive
              Leo Baschy Novice

              Had no luck with diff against CVS with Eclipse on Windows, neither with TortoiseCVS. Probably a line-feed on platform problem. Then tried WinCVS. Is this a good format?

              RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/Query.java,v
              retrieving revision 1.14
              diff -u -w -b -r1.14 Query.java
              --- Query.java 16 Dec 2006 14:06:58 -0000 1.14
              +++ Query.java 23 Jan 2007 09:22:35 -0000
              @@ -3,6 +3,8 @@
               import java.util.ArrayList;
              
               import java.util.List;
              
               import java.util.StringTokenizer;
              
              +import java.util.regex.Matcher;
              +import java.util.regex.Pattern;
              
              
               import javax.faces.model.DataModel;
              
              
              
              @@ -34,6 +36,11 @@
               public abstract Object getSingleResult();
              
               public abstract Long getResultCount();
              
              
              
              + private static final Pattern FROM_PATTERN =
              + Pattern.compile("[^a-z0-9_](from)[^a-z0-9_]", Pattern.CASE_INSENSITIVE);
              + private static final Pattern ORDER_PATTERN =
              + Pattern.compile("[^a-z0-9_](order)[^a-z0-9_]", Pattern.CASE_INSENSITIVE);
              +
               @Create
              
               public void validate()
              
               {
              
              @@ -205,9 +212,15 @@
               protected String getCountEjbql()
              
               {
              
               String ejbql = getRenderedEjbql();
              
              - int fromLoc = ejbql.indexOf("from");
              
              - int orderLoc = ejbql.indexOf("order");
              
              - if (orderLoc<0) orderLoc = ejbql.length();
              
              +
              + Matcher fromMatcher = FROM_PATTERN.matcher(ejbql);
              + boolean foundFrom = fromMatcher.find();
              + int fromLoc = fromMatcher.start(1);
              +
              + Matcher orderMatcher = ORDER_PATTERN.matcher(ejbql);
              + boolean foundOrder = orderMatcher.find();
              + int orderLoc = foundOrder ? orderMatcher.start(1) : ejbql.length();
              +
               return "select count(*) " + ejbql.substring(fromLoc, orderLoc);
              
               }


              I'll be happy to write it up in JIRA (first report problem then supply this solution) if this is an acceptable format. Let me know.

              • 4. Re: org.jboss.seam.framework Query too case sensitive
                Pete Muir Master

                Yes, that's a patch :) You can just attach that as a file to a JIRA issue. Thanks.