openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r802104 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/...
Date Fri, 07 Aug 2009 17:43:49 GMT
Author: ppoddar
Date: Fri Aug  7 17:43:48 2009
New Revision: 802104

URL: http://svn.apache.org/viewvc?rev=802104&view=rev
Log:
OPENJPA-1180: Parameter indexing for CriteriaQuery is the order of their registraion

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java?rev=802104&r1=802103&r2=802104&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
Fri Aug  7 17:43:48 2009
@@ -1497,14 +1497,14 @@
         sq.select(cb.max(e2.get(Employee_.empId)));
         Predicate p1 = cb.equal(e.get(Employee_.empId), empid); 
         Predicate p2 = cb.equal(d.get(Dependent_.id).get(DependentId_.empid), sq);
-        Predicate p3 = cb.gt(d.get(Dependent_.id).get(DependentId_.effDate).as(Long.class),
minDate.as(Long.class));
-        Predicate p4 = cb.lt(d.get(Dependent_.id).get(DependentId_.effDate).as(Long.class),
maxDate.as(Long.class));
+        Predicate p3 = cb.greaterThan(d.get(Dependent_.id).get(DependentId_.effDate), minDate);
+        Predicate p4 = cb.lessThan(d.get(Dependent_.id).get(DependentId_.effDate), maxDate);
         
         q.where(cb.and(cb.and(cb.and(p1, p2), p3), p4));
         
         assertEquivalence(q, jpql, 
             new String[]{"empid", "minDate", "maxDate"}, 
-            new Object[]{101L, new Date(100).getTime(), new Date(100000).getTime()});
+            new Object[]{101L, new Date(100), new Date(100000)});
     }
     
     public void testCorrelatedNestedSubquery1() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java?rev=802104&r1=802103&r2=802104&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
Fri Aug  7 17:43:48 2009
@@ -207,12 +207,11 @@
           assertEquivalence(q, jpql); 
      }
       
-    @AllowFailure
     public void testParameters() {
         String jpql = "SELECT c FROM Customer c Where c.status = :stat";
         CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
         Root<Customer> c = q.from(Customer.class);
-        ParameterExpression<Integer> param = cb.parameter(Integer.class);
+        ParameterExpression<Integer> param = cb.parameter(Integer.class, "stat");
         param.alias("stat");
         q.select(c).where(cb.equal(c.get("status"), param));
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java?rev=802104&r1=802103&r2=802104&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Fri Aug  7 17:43:48 2009
@@ -1033,7 +1033,8 @@
             return;
         }
         if (!Filters.canConvert(v.getClass(), param.getJavaType(), true)) {
-            throw new IllegalArgumentException(_loc.get("param-no-convert", param, v).getMessage());
+            throw new IllegalArgumentException(_loc.get("param-type-mismatch", new Object[]{
+                param, getQueryString(), v, v.getClass().getName(), param.getJavaType().getName()}).getMessage());
         }
     }
     

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java?rev=802104&r1=802103&r2=802104&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Fri Aug  7 17:43:48 2009
@@ -28,7 +28,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedSet;
 import java.util.Stack;
+import java.util.TreeSet;
 
 import javax.persistence.Tuple;
 import javax.persistence.criteria.AbstractQuery;
@@ -73,7 +75,7 @@
     private Set<Root<?>>        _roots;
     private PredicateImpl       _where;
     private List<Order>         _orders;
-    private Set<ParameterExpression<?>> _params;
+    private LinkedMap/*<ParameterExpression<?>, Class<?>>*/ _params;
     private List<Selection<?>>  _selections;
     private List<Expression<?>> _groups;
     private PredicateImpl       _having;
@@ -198,14 +200,15 @@
      */
     public void registerParameter(ParameterExpressionImpl<?> p) {
         if (_params == null)
-            _params = new HashSet<ParameterExpression<?>>();
-        if (_params.add(p)) {
-            p.setIndex(_params.size()-1);
+            _params = new LinkedMap/*<ParameterExpression<?>, Class<?>*/();
+        if (!_params.containsKey(p)) {
+            p.setIndex(_params.size());
+            _params.put(p, p.getJavaType());
         }
     }
     
     public Set<ParameterExpression<?>> getParameters() {
-        return _params == null ? Collections.EMPTY_SET : Collections.unmodifiableSet(_params);
+        return _params == null ? Collections.EMPTY_SET : _params.keySet();
     }
 
     /**
@@ -332,13 +335,7 @@
      * Empty map if no parameter has been declared. 
      */
     public LinkedMap getParameterTypes() {
-        if (_params == null)
-            return StoreQuery.EMPTY_PARAMS;
-        LinkedMap  parameterTypes = new LinkedMap();
-        for (ParameterExpression<?> p : _params) {
-            parameterTypes.put(p, p.getJavaType());
-        }
-        return parameterTypes;
+        return _params == null ? StoreQuery.EMPTY_PARAMS : _params;
     }
     
     /**



Mime
View raw message