openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r924055 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/
Date Tue, 16 Mar 2010 23:41:36 GMT
Author: faywang
Date: Tue Mar 16 23:41:36 2010
New Revision: 924055

URL: http://svn.apache.org/viewvc?rev=924055&view=rev
Log:
OPENJPA-1577: disable query cache when user-defined field strategy is used.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryImpl.java
    openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryImpl.java?rev=924055&r1=924054&r2=924055&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryImpl.java
Tue Mar 16 23:41:36 2010
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.MappingRepository;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.sql.LogicalUnion;
@@ -177,6 +178,10 @@ public class PreparedQueryImpl implement
         SQLBuffer buffer = selector.getSQL();
         if (buffer == null)
             return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql",
_id).getMessage());;
+        boolean useFieldStrategy = isUsingFieldStrategy(); 
+        if (useFieldStrategy)
+            return new PreparedQueryCacheImpl.StrongExclusion(_id, 
+                _loc.get("exclude-user-strategy", _id).getMessage());;
         setTargetQuery(buffer.getSQL());
         setParameters(buffer.getParameters());
         setUserParameterPositions(buffer.getUserParameters());
@@ -253,7 +258,28 @@ public class PreparedQueryImpl implement
         }
         return false;
     }
+    
+    private boolean isUsingFieldStrategy() {
+        for (int i = 0; i < _exps.length; i++) {
+            if (isUsingFieldStrategy(_exps[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
 
+    private boolean isUsingFieldStrategy(QueryExpressions exp) {
+        if (exp == null)
+            return false;
+        List<FieldMetaData> fmds = exp.getParameterizedFields();
+        if (fmds == null || fmds.isEmpty())
+            return false;
+        for (FieldMetaData fmd : fmds) {
+            if (((FieldMapping)fmd).getMappingInfo().getStrategy() != null)
+                return true;
+        }
+        return false;
+    }
     
     /**
      * Merge the given user parameters with its own parameter. The given map

Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=924055&r1=924054&r2=924055&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
Tue Mar 16 23:41:36 2010
@@ -166,4 +166,6 @@ exclude-not-select-rop: Query "{0}" is n
 exclude-not-executor: Query "{0}" is not cached because it was not executed on a \
     data store.    
 exclude-externalized-param: Query "{0}" is not cached because some parameterized \
-    field values are externalized.  
\ No newline at end of file
+    field values are externalized.  
+exclude-user-strategy: This query "{0}" is not cached because some parameterized \
+    field value depends on user-defined field strategy.        
\ No newline at end of file

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java?rev=924055&r1=924054&r2=924055&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestNonstandardMappingAnnotations.java
Tue Mar 16 23:41:36 2010
@@ -21,6 +21,8 @@ package org.apache.openjpa.persistence.j
 import java.awt.*;
 import java.util.Map;
 
+import javax.persistence.Query;
+
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.Discriminator;
@@ -327,5 +329,17 @@ public class TestNonstandardMappingAnnot
         assertEquals("name1", pc.getName());
         assertEquals(1.0, pc.getPoint().getX());
         assertEquals(2.0, pc.getPoint().getY());
+        
+        for (int i = 0; i < 2; i++) {
+            Query query = em.createQuery("select s from NonstandardMappingEntity4 s where
s.point = :point");
+            query.setParameter("point", new Point(1, 2));
+            java.util.List<NonstandardMappingEntity4> list = query.getResultList();
+            for (NonstandardMappingEntity4 pc1 : list) {
+                assertEquals(1.0, pc1.getPoint().getX());
+                assertEquals(2.0, pc1.getPoint().getY());
+            }
+            em.clear();
+        }
+        
         em.close();
     }}



Mime
View raw message