[seam-commits] Seam SVN: r10260 - in trunk/src: main/org/jboss/seam/persistence and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Mar 31 20:17:50 EDT 2009


Author: dan.j.allen
Date: 2009-03-31 20:17:50 -0400 (Tue, 31 Mar 2009)
New Revision: 10260

Modified:
   trunk/src/main/org/jboss/seam/framework/EntityQuery.java
   trunk/src/main/org/jboss/seam/framework/Query.java
   trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
   trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
   trunk/src/test/unit/org/jboss/seam/test/unit/QueryTest.java
Log:
JBSEAM-3032 refactoring


Modified: trunk/src/main/org/jboss/seam/framework/EntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/seam/framework/EntityQuery.java	2009-03-31 21:31:32 UTC (rev 10259)
+++ trunk/src/main/org/jboss/seam/framework/EntityQuery.java	2009-04-01 00:17:50 UTC (rev 10260)
@@ -8,11 +8,11 @@
 import javax.transaction.SystemException;
 
 import org.jboss.seam.annotations.Transactional;
+import org.jboss.seam.persistence.PersistenceProvider;
 import org.jboss.seam.persistence.QueryParser;
+import org.jboss.seam.persistence.PersistenceProvider.Feature;
 import org.jboss.seam.transaction.Transaction;
 
-import org.jboss.seam.util.Reflections;
-
 /**
  * A Query object for JPA.
  * 
@@ -41,9 +41,8 @@
          throw new IllegalStateException("entityManager is null");
       }
       
-      Object delegate = getEntityManager().getDelegate();
-      if (!(Reflections.isClassAvailable("org.hibernate.Session") && delegate instanceof org.hibernate.Session)) {
-          setUseCompliantCountQuerySubject(true);
+      if (!PersistenceProvider.instance().supportsFeature(Feature.WILDCARD_AS_COUNT_QUERY_SUBJECT)) {
+         setUseWildcardAsCountQuerySubject(false);
       }
    }
 

Modified: trunk/src/main/org/jboss/seam/framework/Query.java
===================================================================
--- trunk/src/main/org/jboss/seam/framework/Query.java	2009-03-31 21:31:32 UTC (rev 10259)
+++ trunk/src/main/org/jboss/seam/framework/Query.java	2009-04-01 00:17:50 UTC (rev 10260)
@@ -48,7 +48,7 @@
    
    private String groupBy;
    
-   private boolean useCompliantCountQuerySubject = false;
+   private boolean useWildcardAsCountQuerySubject = true;
    private DataModel dataModel;
    
    private String parsedEjbql;
@@ -295,7 +295,7 @@
       String subject = "*";
       // to be JPA-compliant, we need to make this query like "select count(u) from User u"
       // however, Hibernate produces queries some databases cannot run when the primary key is composite
-      if (useCompliantCountQuerySubject) {
+      if (!useWildcardAsCountQuerySubject) {
           Matcher subjectMatcher = SUBJECT_PATTERN.matcher(ejbql);
           if ( subjectMatcher.find() )
           {
@@ -570,12 +570,12 @@
       }
    }
 
-   protected boolean isUseCompliantCountQuerySubject() {
-      return useCompliantCountQuerySubject;
+   protected boolean isUseWildcardAsCountQuerySubject() {
+      return useWildcardAsCountQuerySubject;
    }
 
-   protected void setUseCompliantCountQuerySubject(boolean useCompliantCountQuerySubject) {
-       this.useCompliantCountQuerySubject = useCompliantCountQuerySubject;
+   protected void setUseWildcardAsCountQuerySubject(boolean useCompliantCountQuerySubject) {
+       this.useWildcardAsCountQuerySubject = useCompliantCountQuerySubject;
    }
 
 }

Modified: trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-03-31 21:31:32 UTC (rev 10259)
+++ trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2009-04-01 00:17:50 UTC (rev 10260)
@@ -83,6 +83,13 @@
          log.debug("no Hibernate Search, sorry :-(", e);
       }
    }
+
+   @Override
+   public void init()
+   {
+      super.init();
+      featureSet.add(Feature.WILDCARD_AS_COUNT_QUERY_SUBJECT);
+   }
    
    /**
     * Wrap the Hibernate Session in a proxy that supports HQL

Modified: trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-03-31 21:31:32 UTC (rev 10259)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2009-04-01 00:17:50 UTC (rev 10260)
@@ -3,7 +3,10 @@
 
 import java.lang.reflect.Method;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
+import javax.annotation.PostConstruct;
 import javax.persistence.EntityManager;
 import javax.persistence.OptimisticLockException;
 import javax.transaction.Synchronization;
@@ -34,7 +37,35 @@
 @Install(precedence=BUILT_IN, classDependencies="javax.persistence.EntityManager")
 public class PersistenceProvider
 {
+   public enum Feature {
+      /**
+       * Identifies whether this JPA provider supports using a wildcard as the subject of a count query.
+       *
+       * <p>Here's a count query that uses a wildcard as the subject.</p>
+       * <pre>select count(*) from Vehicle v</pre>
+       * <p>Per the JPA 1.0 spec, using a wildcard as a subject of a count query is not permitted. Instead,
+       * the subject must be the entity or the alias, as in this count query:</p>
+       * <pre>select count(v) from Vehciel v</pre>
+       * <p>Hibernate supports the wildcard syntax as an vendor extension. Furthermore, Hibernate produces
+       * an invalid SQL query when using the compliant subject if the entity has a composite primary key.
+       * Therefore, we prefer to use the wildcard syntax if it is supported.</p>
+       */
+      WILDCARD_AS_COUNT_QUERY_SUBJECT
+   }
+
+   protected Set<Feature> featureSet = new HashSet<Feature>();
+
+   @PostConstruct // @Create method not called on stateless components
+   public void init() {}
+   
    /**
+    * Indicate whether this JPA provider supports the feature defined by the provided Feature enum value.
+    */
+   public boolean supportsFeature(Feature feature) {
+       return featureSet.contains(feature);
+   }
+
+   /**
     *  Set the flush mode to manual-only flushing. Called when
     *  an atomic persistence context is required.
     */

Modified: trunk/src/test/unit/org/jboss/seam/test/unit/QueryTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/QueryTest.java	2009-03-31 21:31:32 UTC (rev 10259)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/QueryTest.java	2009-04-01 00:17:50 UTC (rev 10260)
@@ -73,7 +73,7 @@
    class CompliantUnitQuery extends UnitQuery {
 
       public CompliantUnitQuery() {
-         setUseCompliantCountQuerySubject(true);
+         setUseWildcardAsCountQuerySubject(false);
       }
       
    }




More information about the seam-commits mailing list