openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r980963 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
Date Fri, 30 Jul 2010 21:02:05 GMT
Author: curtisr7
Date: Fri Jul 30 21:02:04 2010
New Revision: 980963

URL: http://svn.apache.org/viewvc?rev=980963&view=rev
Log:
OPENJPA-1727: Fix QueryCache eviction when returning an empty result and using the TIMESTAMP
eviction policy.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java?rev=980963&r1=980962&r2=980963&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
Fri Jul 30 21:02:04 2010
@@ -124,11 +124,11 @@ public class QueryCacheStoreQuery
         // get the cached data
         QueryResult res = _cache.get(qk);
 
-        if (res == null)
-            return null;        
-        if (res.isEmpty())
-            return Collections.emptyList();
-
+        
+        if (res == null) {
+            return null;
+        }
+               
         // this if block is invoked if the evictOnTimestamp is set to true
         if (_cache instanceof AbstractQueryCache) {
             AbstractQueryCache qcache = (AbstractQueryCache) _cache;
@@ -152,6 +152,10 @@ public class QueryCacheStoreQuery
                 }
             }
         }
+      
+        if (res.isEmpty()) {
+            return Collections.emptyList();
+        }
 
         int projs = getContext().getProjectionAliases().length;
         if (projs == 0) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java?rev=980963&r1=980962&r2=980963&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/cache/TestQueryTimestampEviction.java
Fri Jul 30 21:02:04 2010
@@ -18,22 +18,64 @@
  */
 package org.apache.openjpa.persistence.jdbc.query.cache;
 
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Query;
 
 import org.apache.openjpa.datacache.ConcurrentQueryCache;
 import org.apache.openjpa.datacache.QueryCache;
-import org.apache.openjpa.datacache.TypesChangedEvent;
 import org.apache.openjpa.datacache.AbstractQueryCache.EvictPolicy;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.embed.attrOverrides.TestAssocOverridesXML.SQLListener;
 
 public class TestQueryTimestampEviction extends AbstractQueryCacheTest {
+    private List<String> _sql = new ArrayList<String>();
+    
     public void setUp() throws Exception {
         super.setUp(
                 "openjpa.DataCache", "true",
                 "openjpa.QueryCache", "true(CacheSize=1000, EvictPolicy='timestamp')",
-                "openjpa.RemoteCommitProvider", "sjvm");
+                "openjpa.RemoteCommitProvider", "sjvm",
+                "openjpa.jdbc.JDBCListeners",new JDBCListener[] { new SQLListener() });
     }
 
+    public void testEmptyResultTimeout() {
+        // Not all databases support GenerationType.IDENTITY column(s)
+        if (!((JDBCConfiguration) emf.getConfiguration()).getDBDictionaryInstance().supportsAutoAssign)
{
+            return;
+        }
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        String query = "select p from PartBase p where p.cost > ?1";
+        // execute a query that needs to return zero results
+        Query q = em.createQuery(query);
+        q.setParameter(1, 100000);
+        List l = q.getResultList();
+        assertEquals(0, l.size());     
+
+        // Create a new Entity that has the PartBase accesspath. Has a newer timestamp than
our query
+        em.getTransaction().begin();
+        em.persist(new PartBase());
+        em.getTransaction().commit();
+
+        // Make sure that our sql listener is working
+        assertTrue(_sql.size() > 0);
+        _sql.clear();
+        
+        q = em.createQuery(query);
+        q.setParameter(1, 100000);
+        q.getResultList();
+        
+        // Make sure that we execute sql. This means that the query was properly kicked out
of the cache.
+        assertEquals(1, _sql.size());
+        em.close();
+
+    }
+    
     /**
      * Verify that the persistent unit property configuration is enabling
      * the TIMESTAMP Eviction Policy.
@@ -87,5 +129,15 @@ public class TestQueryTimestampEviction 
             fail("The thread is still waiting on a writeLock()!");
         }
     }
+
+    public class SQLListener extends AbstractJDBCListener {
+
+        @Override
+        public void beforeExecuteStatement(JDBCEvent event) {
+            if (event.getSQL() != null && _sql != null) {
+                _sql.add(event.getSQL());
+            }
+        }
+    }
 }
 



Mime
View raw message