deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-1242 only use CriteriaBuilder.select if 1 param
Date Thu, 13 Apr 2017 16:19:49 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 11f0e32c5 -> 4aa12e065


DELTASPIKE-1242 only use CriteriaBuilder.select if 1 param

CriteriaBuilder.multiselect should only be used if multiple return values
are required. Using multiselect for everyting might cost performance and
trigger wrong execution paths in JPA providers.


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/4aa12e06
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/4aa12e06
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/4aa12e06

Branch: refs/heads/master
Commit: 4aa12e06536de2f5acc151844a9bdf26f7c28b49
Parents: 11f0e32
Author: Mark Struberg <struberg@apache.org>
Authored: Thu Apr 13 18:18:01 2017 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Thu Apr 13 18:18:01 2017 +0200

----------------------------------------------------------------------
 .../apache/deltaspike/data/impl/criteria/QueryCriteria.java   | 7 ++++++-
 .../apache/deltaspike/data/impl/criteria/CriteriaTest.java    | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4aa12e06/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
index 4157114..48e0318 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/QueryCriteria.java
@@ -143,7 +143,12 @@ public class QueryCriteria<C, R> implements Criteria<C, R>
             CriteriaBuilder builder = entityManager.getCriteriaBuilder();
             CriteriaQuery<R> query = createCriteriaQuery(builder);
             From<C, C> root = query.from(entityClass);
-            if (!selections.isEmpty())
+            if (selections.size() == 1)
+            {
+                Selection<?>[] selections = prepareSelections(query, builder, root);
+                query.select((Selection<? extends R>) selections[0]);
+            }
+            if (selections.size() > 1)
             {
                 query.multiselect(prepareSelections(query, builder, root));
             }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4aa12e06/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
index 20aa84b..72261a9 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
@@ -354,7 +354,7 @@ public class CriteriaTest extends TransactionalTestCase
         assertNull(result2);
     }
 
-    @Test
+    @Test // SELECT COUNT(DISTINCT(s.name)) FROM Simple s WHERE s.name = 'should_create_count_criteria'
     public void should_create_count_criteria()
     {
         // given


Mime
View raw message