[seam-commits] Seam SVN: r14143 - in branches/community/Seam_2_3/jboss-seam/src: test/java/org/jboss/seam/test/unit and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Aug 8 06:58:37 EDT 2011


Author: manaRH
Date: 2011-08-08 06:58:36 -0400 (Mon, 08 Aug 2011)
New Revision: 14143

Modified:
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/framework/Query.java
   branches/community/Seam_2_3/jboss-seam/src/test/java/org/jboss/seam/test/unit/QueryTest.java
Log:
JBSEAM-4694 fixed query subject pattern to allow DISTINCT in getCountEjbql

Modified: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/framework/Query.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/framework/Query.java	2011-08-08 08:53:39 UTC (rev 14142)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/framework/Query.java	2011-08-08 10:58:36 UTC (rev 14143)
@@ -28,7 +28,7 @@
 public abstract class Query<T, E> 
       extends PersistenceController<T> //TODO: extend MutableController!
 {
-   private static final Pattern SUBJECT_PATTERN = Pattern.compile("^select\\s+(\\w+(?:\\s*\\.\\s*\\w+)*?)(?:\\s*,\\s*(\\w+(?:\\s*\\.\\s*\\w+)*?))*?\\s+from", Pattern.CASE_INSENSITIVE); 
+   private static final Pattern SUBJECT_PATTERN = Pattern.compile("^select\\s+((distinct)?\\s?\\w+(?:\\s*\\.\\s*\\w+)?)(?:\\s,\\s*(\\w+(?:\\s*\\.\\s*\\w+)?))?\\s+from", Pattern.CASE_INSENSITIVE); 
    private static final Pattern FROM_PATTERN = Pattern.compile("(^|\\s)(from)\\s",       Pattern.CASE_INSENSITIVE);
    private static final Pattern WHERE_PATTERN = Pattern.compile("\\s(where)\\s",         Pattern.CASE_INSENSITIVE);
    private static final Pattern ORDER_PATTERN = Pattern.compile("\\s(order)(\\s)+by\\s", Pattern.CASE_INSENSITIVE);

Modified: branches/community/Seam_2_3/jboss-seam/src/test/java/org/jboss/seam/test/unit/QueryTest.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/test/java/org/jboss/seam/test/unit/QueryTest.java	2011-08-08 08:53:39 UTC (rev 14142)
+++ branches/community/Seam_2_3/jboss-seam/src/test/java/org/jboss/seam/test/unit/QueryTest.java	2011-08-08 10:58:36 UTC (rev 14143)
@@ -30,7 +30,16 @@
       query.parseEjbql();
       // TODO this should eventually become count(p)
       assertEquals(query.getCountEjbql(), "select count(*) from Person p");
-      
+
+      // trying to reproduce bug JBSEAM-4694
+      query.setUseWildcardAsCountQuerySubject(false);
+      query.setEjbql("select distinct p from Person p");
+      query.setOrderColumn("username");
+      query.parseEjbql();
+      // TODO this should eventually become count(p)
+      assertEquals(query.getCountEjbql(), "select count(distinct p) from Person p");
+      query.setUseWildcardAsCountQuerySubject(true);
+     
       query.setEjbql("select v from Vehicle v join fetch v.person");
       query.setOrderColumn("make");
       query.parseEjbql();
@@ -46,7 +55,8 @@
       query.parseEjbql();
       assertEquals(query.getCountEjbql(), "select count(*) from Vehicle v");
       
-      query = new CompliantUnitQuery();
+//      query = new CompliantUnitQuery();
+      query.setUseWildcardAsCountQuerySubject(false);
       query.setEjbql("select p from Person p");
       query.parseEjbql();
       assertEquals(query.getCountEjbql(), "select count(p) from Person p");
@@ -71,14 +81,19 @@
       {
          return super.getCountEjbql();
       }
-      
-   }
 
-   class CompliantUnitQuery extends UnitQuery {
-
-      public CompliantUnitQuery() {
-         setUseWildcardAsCountQuerySubject(false);
+      /** Making setter method accessible for reproducing JBSEAM-4694. */
+      public void setUseWildcardAsCountQuerySubject(boolean useCompliantCountQuerySubject) {
+         super.setUseWildcardAsCountQuerySubject(useCompliantCountQuerySubject);
       }
       
    }
+
+//   class CompliantUnitQuery extends UnitQuery {
+//
+//      public CompliantUnitQuery() {
+//         setUseWildcardAsCountQuerySubject(false);
+//      }
+//      
+//   }
 }



More information about the seam-commits mailing list