[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rhq-commits
Subject:    [rhq] Branch 'release/jon3.2.x' - modules/enterprise
From:       lkrejci <lkrejci () fedoraproject ! org>
Date:       2013-11-28 13:14:05
Message-ID: 20131128131405.D10A660DA0 () fedorahosted ! org
[Download RAW message or body]

 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java \
|    3 -  modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java \
|   24 +++++++++-  2 files changed, 25 insertions(+), 2 deletions(-)

New commits:
commit ea707eaf2cb4650b15a04ea1d8c228961807bbac
Author: Lukas Krejci <lkrejci@redhat.com>
Date:   Thu Nov 28 13:39:26 2013 +0100

    [BZ 1035767] - Enable altering count query along with alterProjection
    If CriteriaQueryGeneration.alterProjection changes the projection such
    that the actual number of returned results changes (e.g. using distinct),
    the default count query would no longer match and the returned results
    would be inconsistent with the count found by the count query.
    
    Because alterProjection is essentially free-form JPQL, we need to provide
    a similar means to alter the count query so that the data query and count
    query can be modified to return consistent data.
    (cherry picked from commit 25f768afb5c72e5eb0fa17c6789b3b8aaa895be9)

diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java \
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
 index d53a037..5d5c48a 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
                
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementScheduleManagerBean.java
 @@ -1485,6 +1485,7 @@ public class MeasurementScheduleManagerBean implements \
                MeasurementScheduleManage
             // the JPQL above, I've chosen to just make a change to the custom \
altered projection, using  // the JPQL to guide me.
             generator.alterProjection(" distinct orderingField0");
+            generator.alterCountProjection(" count(distinct orderingField0)");
             CriteriaQueryRunner<MeasurementDefinition> queryRunner = new \
CriteriaQueryRunner(criteria, generator,  entityManager);
             definitions = queryRunner.execute();
@@ -1609,4 +1610,4 @@ public class MeasurementScheduleManagerBean implements \
MeasurementScheduleManage  //        }
     //    }
 
-}
\ No newline at end of file
+}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java \
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java
 index a1f3122..36b3770 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java
                
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java
 @@ -84,6 +84,7 @@ public final class CriteriaQueryGenerator {
     private String alias;
     private String className;
     private String projection;
+    private String countProjection;
     private String groupByClause;
     private String havingClause;
     private static String NL = System.getProperty("line.separator");
@@ -411,7 +412,10 @@ public final class CriteriaQueryGenerator {
         boolean useJoinFetch = projection == null && pc.isUnlimited() && \
!fetchFields.isEmpty();  
         if (countQuery) {
-            if (groupByClause == null) { // non-grouped method
+            if (countProjection != null) {
+                //just use whatever we are told
+                results.append(countProjection).append(NL);
+            } else if (groupByClause == null) { // non-grouped method
                 // use count(*) instead of count(alias) due to \
https://bugzilla.redhat.com/show_bug.cgi?id=699842  \
results.append("COUNT(*)").append(NL);  } else {
@@ -840,6 +844,24 @@ public final class CriteriaQueryGenerator {
         this.projection = projection;
     }
 
+    /**
+     * Sometimes the altered projection ({@link #alterProjection(String)}) might \
cause the result set to have different +     * number of results than the \
default/unaltered projection. Leaving the count query in the default form could then \
+     * generate seemingly inconsistent results, where the data query and the count \
query wouldn't match up. +     * <p/>
+     * An example of a projection that might alter the number of results is the \
{@code " distinct ..."} projection that +     * would only return distinct results \
from a dataset, while the default count query (COUNT(*)) would produce the +     * \
count including duplicate results that were eliminated in the returned data. +     * \
<p/> +     * In these cases one can also alter the count query to count the results \
the data query will return. +     *
+     * @param countProjection a complete JPQL fragment expressing the count \
expression (e.g. +     *                        {@code COUNT(DISTINCT ...)})
+     */
+    public void alterCountProjection(String countProjection) {
+        this.countProjection = countProjection;
+    }
+
     public boolean isProjectionAltered() {
         return this.projection != null;
     }


_______________________________________________
rhq-commits mailing list
rhq-commits@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/rhq-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic