svn commit: r1793616 - in /openjpa/branches/2.4.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1793616 - in /openjpa/branches/2.4.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/

ilgrosso
Author: ilgrosso
Date: Wed May  3 06:42:52 2017
New Revision: 1793616

URL: http://svn.apache.org/viewvc?rev=1793616&view=rev
Log:
[OPENJPA-2698] Applying the provided patch

Modified:
    openjpa/branches/2.4.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java
    openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java

Modified: openjpa/branches/2.4.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=1793616&r1=1793615&r2=1793616&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java (original)
+++ openjpa/branches/2.4.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java Wed May  3 06:42:52 2017
@@ -1137,13 +1137,14 @@ public class JPQLExpressionBuilder
                 return factory.divide(val1, val2);
 
             case JJTBETWEEN: // x.field [NOT] BETWEEN 5 AND 10
-                val1 = getValue(child(node, 0, 3));
+                Value val_min = getValue(child(node, 0, 3));
+                Value val_max = getValue(child(node, 0, 3));
                 val2 = getValue(child(node, 1, 3));
                 val3 = getValue(child(node, 2, 3));
-                setImplicitTypes(val1, val2, null);
-                setImplicitTypes(val1, val3, null);
-                return evalNot(not, and(factory.greaterThanEqual(val1, val2),
-                    factory.lessThanEqual(val1, val3)));
+                setImplicitTypes(val_min, val2, null);
+                setImplicitTypes(val_max, val3, null);
+                return evalNot(not, and(factory.greaterThanEqual(val_min, val2),
+                    factory.lessThanEqual(val_max, val3)));
 
             case JJTIN: // x.field [NOT] IN ('a', 'b', 'c')
                         // TYPE(x...) [NOT] IN (entityTypeLiteral1,...)

Modified: openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java?rev=1793616&r1=1793615&r2=1793616&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java (original)
+++ openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java Wed May  3 06:42:52 2017
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.persistence.jdbc.sqlcache;
 
+import java.util.Date;
+
 import javax.persistence.*;
 
 @Entity
@@ -45,6 +47,10 @@ public class Employee {
  @Enumerated(EnumType.ORDINAL)
  private Category hireStatus;
 
+ private Date startDate;
+
+ private Date endDate;
+
  public boolean isManager() {
         return isManager;
     }
@@ -97,4 +103,19 @@ public class Employee {
         return status;
     }
 
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
 }

Modified: openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java?rev=1793616&r1=1793615&r2=1793616&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java (original)
+++ openjpa/branches/2.4.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java Wed May  3 06:42:52 2017
@@ -20,7 +20,10 @@ package org.apache.openjpa.persistence.j
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -84,6 +87,12 @@ public class TestPreparedQueryCache exte
     public static final int[]    START_YEARS      = {1900, 2000, 2010 };
  public static final String[] DEPARTMENT_NAMES = {"Marketing", "Sales", "Engineering" };
     public static final String[] EMPLOYEE_NAMES   = {"Tom", "Dick", "Harray" };
+    public static final Date[] EMPLOYEE_START_DATES = {new GregorianCalendar(2017, Calendar.FEBRUARY, 12).getTime(),
+     new GregorianCalendar(2014, Calendar.JANUARY, 1).getTime(),
+     new GregorianCalendar(2014, Calendar.JANUARY, 1).getTime()};
+    public static final Date[] EMPLOYEE_END_DATES = {new GregorianCalendar(2999, Calendar.JANUARY, 1).getTime(),
+     new GregorianCalendar(2999, Calendar.JANUARY, 1).getTime(),
+     new GregorianCalendar(2016, Calendar.DECEMBER, 31).getTime()};
  public static final String[] CITY_NAMES       = {"Tulsa", "Durban", "Harlem"};
 
     public static final String EXCLUDED_QUERY_1 = "select count(p) from Company p";
@@ -145,6 +154,9 @@ public class TestPreparedQueryCache exte
             for (int k = 0; k < EMPLOYEE_NAMES.length; k++) {
                 Employee emp = new Employee();
                 emp.setName(EMPLOYEE_NAMES[k]);
+                emp.setStartDate(EMPLOYEE_START_DATES[k]);
+                emp.setEndDate(EMPLOYEE_END_DATES[k]);
+
                 Address addr = new Address();
                 addr.setCity(CITY_NAMES[k]);
                     em.persist(emp);
@@ -1323,6 +1335,26 @@ public class TestPreparedQueryCache exte
         return stats.get(N/2);
     }  
     
+    public void testRepeatedQueryInBetweenParameters() {
+     OpenJPAEntityManager em = emf.createEntityManager();
+     em.clear();
+
+     String jpql1 = "SELECT e FROM Employee e";
+     int employeeSize = em.createQuery(jpql1, Employee.class).getResultList().size();
+
+     String jpql2 = "SELECT e FROM Employee e WHERE :baseDate between e.startDate AND e.endDate";
+     TypedQuery<Employee> q1 = em.createQuery(jpql2, Employee.class);
+     q1.setParameter("baseDate", new GregorianCalendar(2016, Calendar.JUNE, 1).getTime());
+     int count2016 = (int)(employeeSize * ((double)2/3));
+
+ assertEquals(count2016, q1.getResultList().size());
+
+ TypedQuery<Employee> q2 = em.createQuery(jpql2, Employee.class);
+     q2.setParameter("baseDate", new GregorianCalendar(2017, Calendar.JUNE, 1).getTime());
+     int count2017 = (int)(employeeSize * ((double)2/3));
+
+ assertEquals(count2017, q2.getResultList().size());
+    }
     
     void parameterize(Query q, Object[] params) {
         if (params == null)