cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1355386 - in /cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/query/ test/java/org/apache/cayenne/ test/resources/
Date Fri, 29 Jun 2012 13:51:20 GMT
Author: oltka
Date: Fri Jun 29 13:51:19 2012
New Revision: 1355386

URL: http://svn.apache.org/viewvc?rev=1355386&view=rev
Log:
CAY-1715 Passing parameters to mapped EJBQL queries

(cherry picked from commit 5331a60e02460f09484cd714f3edf8c73640b647)

Modified:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/NamedQuery.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextNamedQueryCachingTest.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/NamedQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/NamedQuery.java?rev=1355386&r1=1355385&r2=1355386&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/NamedQuery.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/NamedQuery.java
Fri Jun 29 13:51:19 2012
@@ -22,6 +22,7 @@ package org.apache.cayenne.query;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -126,6 +127,13 @@ public class NamedQuery extends Indirect
 
         if (query instanceof ParameterizedQuery) {
             query = ((ParameterizedQuery) query).createQuery(normalizedParameters());
+        } else if (query instanceof EJBQLQuery) {
+            
+            Iterator it = normalizedParameters().entrySet().iterator();
+            while (it.hasNext()) {
+                Map.Entry pairs = (Map.Entry)it.next();
+                ((EJBQLQuery)query).setParameter((String) pairs.getKey(), pairs.getValue());
+            }
         }
 
         return query;

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextNamedQueryCachingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextNamedQueryCachingTest.java?rev=1355386&r1=1355385&r2=1355386&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextNamedQueryCachingTest.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextNamedQueryCachingTest.java
Fri Jun 29 13:51:19 2012
@@ -104,7 +104,7 @@ public class CayenneContextNamedQueryCac
                 assertSame(result1, result2);
             }
         });
-
+        
         final List<?> result3 = context.performQuery(q2);
         assertNotSame(result1, result3);
         assertEquals(1, result3.size());
@@ -119,5 +119,15 @@ public class CayenneContextNamedQueryCac
                 assertSame(result1, result5);
             }
         });
+    
+    }
+    
+    public void testLocalCacheEJBQLQueryParameterized() throws Exception {
+        
+        createThreeMtTable1sDataSet();
+        NamedQuery query = new NamedQuery("ParameterizedEJBQLMtQuery", Collections.singletonMap("g",
"g1"));
+        
+        List<?> r1 = context.performQuery(query);
+        assertEquals(1, r1.size());
     }
 }

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml?rev=1355386&r1=1355385&r2=1355386&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
Fri Jun 29 13:51:19 2012
@@ -242,6 +242,10 @@
 	<query name="MtQueryWithLocalCache" factory="org.apache.cayenne.map.SelectQueryBuilder"
root="obj-entity" root-name="MtTable1">
 		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="LOCAL_CACHE"/>
 	</query>
+	<query name="ParameterizedEJBQLMtQuery" factory="org.apache.cayenne.map.EjbqlBuilder">
+		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="LOCAL_CACHE"/>
+		<ejbql><![CDATA[select a from MtTable1 a where a.globalAttribute1 = :g]]></ejbql>
+	</query>
 	<query name="ParameterizedMtQueryWithLocalCache" factory="org.apache.cayenne.map.SelectQueryBuilder"
root="obj-entity" root-name="MtTable1">
 		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="LOCAL_CACHE"/>
 		<qualifier><![CDATA[globalAttribute1 = $g]]></qualifier>



Mime
View raw message