openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1033637 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
Date Wed, 10 Nov 2010 18:34:35 GMT
Author: curtisr7
Date: Wed Nov 10 18:34:35 2010
New Revision: 1033637

URL: http://svn.apache.org/viewvc?rev=1033637&view=rev
Log:
OPENJPA-1882: Fix DataCacheStoreManager NPE.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
  (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?rev=1033637&r1=1033636&r2=1033637&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
Wed Nov 10 18:34:35 2010
@@ -281,9 +281,9 @@ public class DataCacheStoreManager
 
     public boolean exists(OpenJPAStateManager sm, Object edata) {
         DataCache cache = _mgr.selectCache(sm);
-        CacheStatistics stats = cache.getStatistics();
+        CacheStatistics stats = (cache == null) ? null : cache.getStatistics();
         if (cache != null && !isLocking(null) && cache.contains(sm.getObjectId())){
-            if (stats.isEnabled()) {
+            if (stats != null && stats.isEnabled()) {
                 // delay this call ONLY if stats collection is enabled
                 Class<?> cls = sm.getMetaData().getDescribedType();
                 ((CacheStatisticsSPI)stats).newGet(cls, false);
@@ -291,7 +291,7 @@ public class DataCacheStoreManager
             return true;
         }
         // If isLocking(null)==true && cache.contains(..) == true... probably shouldn't
count?
-        if (stats.isEnabled()) {
+        if (stats != null && stats.isEnabled()) {
             // delay this call ONLY if stats collection is enabled
             Class<?> cls = sm.getMetaData().getDescribedType();
             ((CacheStatisticsSPI)stats).newGet(cls, false);
@@ -322,14 +322,13 @@ public class DataCacheStoreManager
     public boolean syncVersion(OpenJPAStateManager sm, Object edata) {
         DataCache cache = _mgr.selectCache(sm);
         FetchConfiguration fc = sm.getContext().getFetchConfiguration();
-        CacheStatistics stats = cache.getStatistics();
+        CacheStatistics stats = (cache == null) ? null : cache.getStatistics();
         if (cache == null || sm.isEmbedded() || fc.getCacheRetrieveMode() == DataCacheRetrieveMode.BYPASS)
{
-            if(stats.isEnabled()){
-                ((CacheStatisticsSPI)stats).newGet(sm.getMetaData().getDescribedType(), false);
+            if (stats != null && stats.isEnabled()) {
+                ((CacheStatisticsSPI) stats).newGet(sm.getMetaData().getDescribedType(),
false);
             }
             return super.syncVersion(sm, edata);
         }
-        
         DataCachePCData data;
         Object version = null;
         data = cache.get(sm.getObjectId());
@@ -338,7 +337,7 @@ public class DataCacheStoreManager
 
         // if we have a cached version update from there
         if (version != null) {
-            if(stats.isEnabled()){
+            if (stats != null && stats.isEnabled()) {
                 ((CacheStatisticsSPI)stats).newGet(data.getType(), true);
             }
             if (!version.equals(sm.getVersion())) {

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java?rev=1033637&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
Wed Nov 10 18:34:35 2010
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.datacache;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.datacache.DataCacheManager;
+import org.apache.openjpa.datacache.DataCacheStoreManager;
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.kernel.DelegatingStoreManager;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.persistence.EntityManagerImpl;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * 
+ * This test was added for OPENJPA-1882.
+ * <p>
+ * When caching is enabled and a given type isn't being cached, make sure calling exists/syncVersion
with that type
+ * doesn't result in a NPE.
+ * 
+ */
+public class TestDataCacheStoreManager extends SingleEMFTestCase {
+    Object[] p =
+        new Object[] { CLEAR_TABLES, CachedEntityStatistics.class, "openjpa.DataCache", "true(EnableStatistics=true)",
+            "openjpa.QueryCache", "true", };
+
+    private EntityManager em;
+    private DataCacheStoreManager dsm;
+    private DataCacheManager dcm;
+    private OpenJPAStateManager sm;
+
+    public void setUp() {
+        super.setUp(p);
+
+        em = emf.createEntityManager();
+        dcm = emf.getConfiguration().getDataCacheManagerInstance();
+        dsm =
+            (DataCacheStoreManager) ((DelegatingStoreManager) ((EntityManagerImpl) em).getBroker().getStoreManager())
+                .getDelegate();
+
+        em.getTransaction().begin();
+        CachedEntityStatistics p = new CachedEntityStatistics();
+        em.persist(p);
+        em.getTransaction().commit();
+
+        dcm.stopCaching(CachedEntityStatistics.class.getName());
+
+        sm = (OpenJPAStateManager) ((PersistenceCapable) p).pcGetStateManager();
+    }
+
+    public void tearDown() throws Exception {
+        dcm.startCaching(CachedEntityStatistics.class.getName());
+        em.close();
+
+        super.tearDown();
+    }
+
+    public void testExists() {
+        dsm.exists(sm, null);
+    }
+
+    public void testsyncVersion() {
+        dsm.syncVersion(sm, null);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestDataCacheStoreManager.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message