You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2010/11/19 20:48:49 UTC
svn commit: r1036988 - in /openjpa/trunk:
openjpa-kernel/src/main/java/org/apache/openjpa/datacache/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/...
Author: curtisr7
Date: Fri Nov 19 19:48:49 2010
New Revision: 1036988
URL: http://svn.apache.org/viewvc?rev=1036988&view=rev
Log:
OPENJPA-1892: Fix NPE in DataCacheStoreManager.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.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=1036988&r1=1036987&r2=1036988&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 Fri Nov 19 19:48:49 2010
@@ -392,9 +392,14 @@ public class DataCacheStoreManager
&& ((fetch.getCacheStoreMode() == DataCacheStoreMode.USE && !alreadyCached)
|| (fetch.getCacheStoreMode() == DataCacheStoreMode.REFRESH));
if (updateCache) {
- cacheStateManager(cache, sm, data);
- if (stats.isEnabled()) {
- ((CacheStatisticsSPI) stats).newPut(sm.getMetaData().getDescribedType());
+ // It is possible that the "cacheability" of the provided SM changed after hitting the DB. This can happen
+ // when we are operating against an Entity that is in some sort of inheritance structure.
+ cache = _mgr.selectCache(sm);
+ if (cache != null) {
+ cacheStateManager(cache, sm, data);
+ if (stats.isEnabled()) {
+ ((CacheStatisticsSPI) stats).newPut(sm.getMetaData().getDescribedType());
+ }
}
}
return fromDatabase || alreadyCached;
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java?rev=1036988&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java Fri Nov 19 19:48:49 2010
@@ -0,0 +1,65 @@
+/*
+ * 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.cache.jpa;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.cache.jpa.model.ChildUncacheable;
+import org.apache.openjpa.persistence.cache.jpa.model.ParentUnspecifiedEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * This test was added for https://issues.apache.org/jira/browse/OPENJPA-1892.
+ *
+ * The key to this test is that the ChildUncacheable is uncacheable and ParentUnspecifiedEntity is cacheable. In the
+ * case were we pass the root Entity in em.find(ParentUnspecifiedEntity.class, 1) AND the id we passed corresponds to
+ * the child Entity we shouldn't be caching this result.
+ *
+ */
+public class TestCacheModeDisableSelectiveInheritance extends SingleEMFTestCase {
+ Object[] params =
+ new Object[] { ChildUncacheable.class, ParentUnspecifiedEntity.class, CLEAR_TABLES,
+ "javax.persistence.sharedCache.mode", "DISABLE_SELECTIVE", "openjpa.DataCache", "true" };
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp(params);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+
+ }
+
+ public void testSimpleFind() throws Exception {
+ EntityManager em = emf.createEntityManager();
+ try {
+ ChildUncacheable c = new ChildUncacheable();
+ em.getTransaction().begin();
+ em.persist(c);
+ em.getTransaction().commit();
+ assertEquals(c, em.find(ChildUncacheable.class, c.getId()));
+ em.clear();
+ assertEquals(c.getId(), em.find(ChildUncacheable.class, c.getId()).getId());
+
+ } finally {
+ em.close();
+ }
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelectiveInheritance.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java?rev=1036988&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java Fri Nov 19 19:48:49 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.cache.jpa.model;
+
+import javax.persistence.Basic;
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+
+@Entity
+@Cacheable(value = false)
+public class ChildUncacheable extends ParentUnspecifiedEntity {
+ @Basic
+ String child;
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ChildUncacheable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.java?rev=1036988&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.java Fri Nov 19 19:48:49 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.cache.jpa.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class ParentUnspecifiedEntity {
+ @Id
+ @Column(name = "ID")
+ protected int id;
+
+ @Version
+ @Column(name = "VERSN")
+ protected int version;
+
+ protected String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/ParentUnspecifiedEntity.java
------------------------------------------------------------------------------
svn:eol-style = native