[jboss-cvs] jboss-seam/src/main/org/jboss/seam/framework ...

Gavin King gavin.king at jboss.com
Thu Jan 25 02:58:45 EST 2007


  User: gavin   
  Date: 07/01/25 02:58:45

  Modified:    src/main/org/jboss/seam/framework  Query.java
  Log:
  apply JBSEAM-698
  
  Revision  Changes    Path
  1.15      +17 -4     jboss-seam/src/main/org/jboss/seam/framework/Query.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Query.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/Query.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- Query.java	16 Dec 2006 14:06:58 -0000	1.14
  +++ Query.java	25 Jan 2007 07:58:45 -0000	1.15
  @@ -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;
   
  @@ -14,6 +16,9 @@
   
   public abstract class Query
   {
  +   private static final Pattern FROM_PATTERN = Pattern.compile("(^|\\s)(from)\\s", Pattern.CASE_INSENSITIVE);
  +   private static final Pattern ORDER_PATTERN = Pattern.compile("\\s(order)(\\s)+by\\s", Pattern.CASE_INSENSITIVE);
  +
      private String ejbql;
      private Integer firstResult;
      private Integer maxResults;
  @@ -205,9 +210,17 @@
      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);
  +      if ( !fromMatcher.find() )
  +      {
  +         throw new IllegalArgumentException("no from clause found in query");
  +      }
  +      int fromLoc = fromMatcher.start(2);
  +      
  +      Matcher orderMatcher = ORDER_PATTERN.matcher(ejbql);
  +      int orderLoc = orderMatcher.find() ? orderMatcher.start(1) : ejbql.length();
  +
         return "select count(*) " + ejbql.substring(fromLoc, orderLoc);
      }
      
  
  
  



More information about the jboss-cvs-commits mailing list