openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1798237 - in /openjpa/branches/2.2.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/
Date Fri, 09 Jun 2017 15:50:06 GMT
Author: jgrassel
Date: Fri Jun  9 15:50:06 2017
New Revision: 1798237

URL: http://svn.apache.org/viewvc?rev=1798237&view=rev
Log:
OPENJPA-2698: Query cache incorrectly handles parameters for BETWEEN expressions (commit on
wdazeys behalf)

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

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=1798237&r1=1798236&r2=1798237&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Fri Jun  9 15:50:06 2017
@@ -1120,13 +1120,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.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java?rev=1798237&r1=1798236&r2=1798237&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/Employee.java
Fri Jun  9 15:50:06 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.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java?rev=1798237&r1=1798236&r2=1798237&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
Fri Jun  9 15:50:06 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;
@@ -86,6 +89,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";
@@ -147,6 +156,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);
@@ -319,6 +331,26 @@ public class TestPreparedQueryCache exte
         
     }
     
+    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());
+    }
     
     public void testRepeatedParameterInSubqueryInDifferentOrderSubQLast() {
         OpenJPAEntityManager em = emf.createEntityManager();



Mime
View raw message