deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hwellm...@apache.org
Subject deltaspike git commit: DELTASPIKE-1057 Fix type parameters of OrderBy query processor
Date Thu, 31 Dec 2015 10:57:50 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 07bf170e8 -> 2acb0b76f


DELTASPIKE-1057 Fix type parameters of OrderBy query processor

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

Branch: refs/heads/master
Commit: 2acb0b76f38f88e824c6882901ecf04f9ebec0eb
Parents: 07bf170
Author: Harald Wellmann <hwellmann@apache.org>
Authored: Thu Dec 31 11:57:11 2015 +0100
Committer: Harald Wellmann <hwellmann@apache.org>
Committed: Thu Dec 31 11:57:33 2015 +0100

----------------------------------------------------------------------
 .../data/impl/criteria/QueryCriteria.java           | 16 ++++++----------
 .../data/impl/criteria/processor/OrderBy.java       | 16 ++++++++--------
 2 files changed, 14 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2acb0b76/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 89e6b42..8b20995 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
@@ -81,7 +81,7 @@ public class QueryCriteria<C, R> implements Criteria<C, R>
     private final boolean ignoreNull = true;
     private boolean distinct = false;
 
-    private final OrderBy orderByProcessor = new OrderBy();
+    private final OrderBy<C> orderByProcessor = new OrderBy<C>();
     private final List<PredicateBuilder<C>> builders = new LinkedList<PredicateBuilder<C>>();
     private final List<QueryProcessor<C>> processors = new LinkedList<QueryProcessor<C>>();
     private final List<QuerySelection<? super C, ?>> selections = new LinkedList<QuerySelection<?
super C, ?>>();
@@ -141,7 +141,7 @@ public class QueryCriteria<C, R> implements Criteria<C, R>
         try
         {
             CriteriaBuilder builder = entityManager.getCriteriaBuilder();
-            CriteriaQuery<?> query = createCriteriaQuery(builder);
+            CriteriaQuery<R> query = createCriteriaQuery(builder);
             From<C, C> root = query.from(entityClass);
             if (!selections.isEmpty())
             {
@@ -332,12 +332,7 @@ public class QueryCriteria<C, R> implements Criteria<C, R>
         }
     }
 
-    private void add(QueryProcessor<C> proc)
-    {
-        processors.add(proc);
-    }
-
-    private void addOrderBy(SingularAttribute<? super C, ?> att, OrderDirection orderDirection)
+    private <P> void addOrderBy(SingularAttribute<? super C, P> att, OrderDirection
orderDirection)
     {
         orderByProcessor.add(att, orderDirection);
     }
@@ -352,11 +347,12 @@ public class QueryCriteria<C, R> implements Criteria<C, R>
         return result.toArray(new Selection<?>[] {});
     }
 
-    private CriteriaQuery<?> createCriteriaQuery(CriteriaBuilder builder)
+    @SuppressWarnings("unchecked")
+    private CriteriaQuery<R> createCriteriaQuery(CriteriaBuilder builder)
     {
         if (resultClass.getName().startsWith("java.lang"))
         {
-            return builder.createQuery();
+            return (CriteriaQuery<R>) builder.createQuery();
         }
         else
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2acb0b76/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
index 6ae8538..d03575f 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/criteria/processor/OrderBy.java
@@ -30,24 +30,24 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-public class OrderBy<P, V> implements QueryProcessor<P>
+public class OrderBy<P> implements QueryProcessor<P>
 {
 
-    private final List<OrderByDefinition> orderByDefinitions = new ArrayList<OrderByDefinition>();
+    private final List<OrderByDefinition<?>> orderByDefinitions = new ArrayList<OrderByDefinition<?>>();
 
-    public void add(SingularAttribute<? super P, V> att, OrderDirection dir)
+    public <V> void add(SingularAttribute<? super P, V> att, OrderDirection dir)
     {
-        orderByDefinitions.add(new OrderByDefinition(att, dir));
+        orderByDefinitions.add(new OrderByDefinition<V>(att, dir));
     }
 
     @Override
     public <R> void process(CriteriaQuery<R> query, CriteriaBuilder builder,
Path<P> path)
     {
         List<Order> orders = new ArrayList<Order>();
-        Iterator<OrderByDefinition> iterator = orderByDefinitions.iterator();
+        Iterator<OrderByDefinition<?>> iterator = orderByDefinitions.iterator();
         while (iterator.hasNext())
         {
-            OrderByDefinition orderByDefinition = iterator.next();
+            OrderByDefinition<?> orderByDefinition = iterator.next();
             switch (orderByDefinition.getDir())
             {
                 case ASC:
@@ -60,7 +60,7 @@ public class OrderBy<P, V> implements QueryProcessor<P>
         query.orderBy(orders);
     }
 
-    private class OrderByDefinition
+    private class OrderByDefinition<V>
     {
         private final SingularAttribute<? super P, V> att;
         private final OrderDirection dir;
@@ -94,7 +94,7 @@ public class OrderBy<P, V> implements QueryProcessor<P>
             }
 
             @SuppressWarnings("unchecked")
-            OrderByDefinition that = (OrderByDefinition) o;
+            OrderByDefinition<V> that = (OrderByDefinition<V>) o;
 
             if (att != null ? !att.equals(that.att) : that.att != null)
             {


Mime
View raw message