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 2012/10/09 15:47:39 UTC
svn commit: r1396037 - in /openjpa/trunk:
openjpa-kernel/src/main/java/org/apache/openjpa/datacache/
openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/
openjp...
Author: curtisr7
Date: Tue Oct 9 13:47:38 2012
New Revision: 1396037
URL: http://svn.apache.org/viewvc?rev=1396037&view=rev
Log:
OPENJPA-1532: Enable shared-cache-mode to turn on datacache without needing openjpa.DataCache configuration. Patch contributed by Helen Xu.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java (with props)
Modified:
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java Tue Oct 9 13:47:38 2012
@@ -523,20 +523,32 @@ public abstract class AbstractDataCache
public void setTypes(Set<String> types) {
_includedTypes = types;
+ if (log.isWarnEnabled())
+ log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types",
+ DataCacheMode.ENABLE_SELECTIVE.toString()}));
}
public void setTypes(String types) {
_includedTypes =
StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays.asList(Strings.split(types, ";", 0)));
+ if (log.isWarnEnabled())
+ log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types",
+ DataCacheMode.ENABLE_SELECTIVE.toString()}));
}
public void setExcludedTypes(Set<String> types) {
_excludedTypes = types;
+ if (log.isWarnEnabled())
+ log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes",
+ DataCacheMode.DISABLE_SELECTIVE.toString()}));
}
public void setExcludedTypes(String types) {
_excludedTypes =
StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays.asList(Strings.split(types, ";", 0)));
+ if (log.isWarnEnabled())
+ log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes",
+ DataCacheMode.DISABLE_SELECTIVE.toString()}));
}
public DataCache selectCache(OpenJPAStateManager sm) {
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=1396037&r1=1396036&r2=1396037&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 Tue Oct 9 13:47:38 2012
@@ -143,7 +143,7 @@ public class DataCacheStoreManager
continue;
mods = getModifications(modMap, cache);
- data = newPCData(sm);
+ data = newPCData(sm, cache);
data.store(sm);
mods.additions.add(new PCDataHolder(data, sm));
CacheStatistics stats = cache.getStatistics();
@@ -178,7 +178,7 @@ public class DataCacheStoreManager
// dirty, but maybe it got dropped from the cache in the
// interim
if (data == null) {
- data = newPCData(sm);
+ data = newPCData(sm, cache);
data.store(sm);
mods.newUpdates.add(new PCDataHolder(data, sm));
} else {
@@ -420,7 +420,7 @@ public class DataCacheStoreManager
// initial load of the data.
boolean isNew = data == null;
if (isNew) {
- data = newPCData(sm);
+ data = newPCData(sm, cache);
}
data.store(sm);
if (isNew) {
@@ -626,7 +626,7 @@ public class DataCacheStoreManager
isNew = data == null;
if (isNew)
- data = newPCData(sm);
+ data = newPCData(sm, cache);
if (fields == null)
data.store(sm);
else
@@ -780,15 +780,15 @@ public class DataCacheStoreManager
_ctx.getConfiguration().getRemoteCommitEventManager()
.fireLocalStaleNotification(oid);
}
-
+
/**
* Create a new cacheable instance for the given state manager.
*/
- private DataCachePCData newPCData(OpenJPAStateManager sm) {
+ private DataCachePCData newPCData(OpenJPAStateManager sm, DataCache cache) {
ClassMetaData meta = sm.getMetaData();
if (_gen != null)
return (DataCachePCData) _gen.generatePCData(sm.getObjectId(), meta);
- return new DataCachePCDataImpl(sm.fetchObjectId(), meta, _mgr.selectCache(sm).getName());
+ return new DataCachePCDataImpl(sm.fetchObjectId(), meta, cache.getName());
}
/**
Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties Tue Oct 9 13:47:38 2012
@@ -113,5 +113,7 @@ partition-cache-default-partition: You h
partition in the configuration "{0}". The partition name matches the default \
name reserved by OpenJPA for internal use and hence can not be used.
invalid-types-excluded-types: Failed to configure openjpa.DataCache Types, ExcludedTypes. \
- Types "{0}" were found in both lists, but can only appear one of the lists.
-
\ No newline at end of file
+ Types "{0}" were found in both lists, but can only appear one of the lists.
+recommend_jpa2_caching: You have specified the openjpa.DataCache property "{0}", but using that \
+ property is not recommended. Please utilize the JPA 2.0 shared-cache-mode element "{1}" \
+ in conjunction with the javax.persistence.Cacheable annotation instead.
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java Tue Oct 9 13:47:38 2012
@@ -203,28 +203,30 @@ public abstract class AbstractCacheModeT
*
*/
public void testRetrieveModeUse() {
- assertNoSql(new Action() {
- public void run() {
- EntityManager em = getEntityManagerFactory().createEntityManager();
- em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.USE);
- for (Class<?> cls : getExpectedInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
- assertNotNull(em.find(cls, 1));
+ if (getCacheEnabled()) {
+ assertNoSql(new Action() {
+ public void run() {
+ EntityManager em = getEntityManagerFactory().createEntityManager();
+ em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.USE);
+ for (Class<?> cls : getExpectedInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
+ assertNotNull(em.find(cls, 1));
+ }
+ em.close();
}
- em.close();
- }
- });
- assertSqlInc(new Action() {
- public void run() {
- EntityManager em = getEntityManagerFactory().createEntityManager();
- em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.USE);
- for (Class<?> cls : getExpectedNotInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
- assertNotNull(em.find(cls, 1));
+ });
+ assertSqlInc(new Action() {
+ public void run() {
+ EntityManager em = getEntityManagerFactory().createEntityManager();
+ em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.USE);
+ for (Class<?> cls : getExpectedNotInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
+ assertNotNull(em.find(cls, 1));
+ }
+ em.close();
}
- em.close();
- }
- }, getExpectedNotInCache().length);
+ }, getExpectedNotInCache().length);
+ }
}
public void updateAndFind(Class<? extends CacheEntity> classToUpdate, int idToUpdate,
@@ -404,45 +406,50 @@ public abstract class AbstractCacheModeT
}
public void testResultsFromQueryAreInCache() {
- // clear cache
- getEntityManagerFactory().getStoreCache().evictAll();
- getEntityManagerFactory().getQueryResultCache().evictAll();
-
- EntityManager em = getEntityManagerFactory().createEntityManager();
- String query;
- for(Class<?> cls : persistentTypes) {
- query = "Select e from " + getAlias(cls) + " e";
- List<?> res = em.createQuery(query).getResultList();
- assertNotNull(String.format("Expected to find some results when running query %s",query), res);
- assertTrue(String.format("Expected more than 0 results running query %s",query),res.size() != 0 ) ;
- }
- for(Class<?> cls : getExpectedInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
- }
-
- for(Class<?> cls : getExpectedNotInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
+ if (getCacheEnabled()) {
+ // clear cache
+ getEntityManagerFactory().getStoreCache().evictAll();
+ getEntityManagerFactory().getQueryResultCache().evictAll();
+
+ EntityManager em = getEntityManagerFactory().createEntityManager();
+ String query;
+ for(Class<?> cls : persistentTypes) {
+ query = "Select e from " + getAlias(cls) + " e";
+ List<?> res = em.createQuery(query).getResultList();
+ assertNotNull(String.format("Expected to find some results when running query %s",query), res);
+ assertTrue(String.format("Expected more than 0 results running query %s",query),res.size() != 0 ) ;
+ }
+ for(Class<?> cls : getExpectedInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
+ }
+
+ for(Class<?> cls : getExpectedNotInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
+ }
+ em.close();
}
- em.close();
}
public void testResultsFromFindAreInCache() {
- // clear cache
- getEntityManagerFactory().getStoreCache().evictAll();
- getEntityManagerFactory().getQueryResultCache().evictAll();
+ if (getCacheEnabled()) {
+ // clear cache
+ getEntityManagerFactory().getStoreCache().evictAll();
+ getEntityManagerFactory().getQueryResultCache().evictAll();
+
+ EntityManager em = getEntityManagerFactory().createEntityManager();
+ for(Class<?> cls : persistentTypes) {
+ assertNotNull(String.format("Expected to find %s::%d from database or from cache", cls, 1),
+ em.find(cls, 1));
+ }
+ for(Class<?> cls : getExpectedInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
+ }
- EntityManager em = getEntityManagerFactory().createEntityManager();
- for(Class<?> cls : persistentTypes) {
- assertNotNull(String.format("Expected to find %s::%d from database or from cache", cls, 1),em.find(cls, 1));
- }
- for(Class<?> cls : getExpectedInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, true);
- }
-
- for(Class<?> cls : getExpectedNotInCache()) {
- assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
+ for(Class<?> cls : getExpectedNotInCache()) {
+ assertCached(getEntityManagerFactory().getCache(), cls, 1, false);
+ }
+ em.close();
}
- em.close();
}
private String getAlias(Class<?> cls) {
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java Tue Oct 9 13:47:38 2012
@@ -66,9 +66,7 @@ public abstract class AbstractCacheTestC
public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName,
Map<String, Object> additionalProperties) {
- Map<String, Object> propertiesMap = getPropertiesMap("openjpa.DataCache", "true",
- "openjpa.QueryCache", "true",
- "openjpa.RemoteCommitProvider", "sjvm", persistentTypes,
+ Map<String, Object> propertiesMap = getPropertiesMap( persistentTypes,
"openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() });
if (additionalProperties != null) {
Set<String> keys = additionalProperties.keySet();
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,28 @@
+/*
+ * 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 org.apache.openjpa.datacache.ConcurrentDataCache;
+
+public class DataCacheTestExtension extends ConcurrentDataCache {
+
+ private static final long serialVersionUID = 1L;
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java Tue Oct 9 13:47:38 2012
@@ -23,13 +23,19 @@ import java.util.List;
import javax.persistence.Cache;
+import org.apache.openjpa.datacache.ConcurrentDataCache;
import org.apache.openjpa.lib.jdbc.JDBCListener;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.FilteringJDBCListener;
+/*
+ * When shared-cache-mode is set to ALL, all entities will be cached.
+ * If the DataCache is not configured, the default values will be used.
+ * For example, CacheSize will be set to default value 1000.
+ */
public class TestCacheModeAll extends AbstractCacheModeTestCase {
- private static Cache cache = null;
+ protected static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
@@ -41,6 +47,11 @@ public class TestCacheModeAll extends Ab
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-all",null);
assertNotNull(emf);
+ ConcurrentDataCache dataCache = (ConcurrentDataCache) emf.getConfiguration()
+ .getDataCacheManagerInstance().getDataCache("default");
+ assertNotNull(dataCache);
+ assertEquals(1000, dataCache.getCacheSize());
+ assertEquals("true", emf.getConfiguration().getDataCache());
cache = emf.getCache();
assertNotNull(cache);
}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,56 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.datacache.ConcurrentDataCache;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+/*
+ * When shared-cache-mode is set to ALL, all entities will be cached no matter
+ * what is the customized DataCache setting. The other DataCache
+ * config settings like CacheSize will be used to config the data cache.
+ */
+public class TestCacheModeAllDataCacheCustomized extends TestCacheModeAll {
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("openjpa.DataCache",
+ "org.apache.openjpa.persistence.cache.jpa.DataCacheTestExtension(CacheSize=5000, "
+ + "ExcludedTypes=org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)");
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-all", props);
+ assertNotNull(emf);
+ ConcurrentDataCache dataCache =
+ (ConcurrentDataCache) emf.getConfiguration().getDataCacheManagerInstance().getDataCache("default");
+ assertNotNull(dataCache);
+ assertEquals(5000, dataCache.getCacheSize());
+ assertEquals("org.apache.openjpa.persistence.cache.jpa.DataCacheTestExtension(CacheSize=5000, "
+ + "ExcludedTypes=org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)", emf
+ .getConfiguration().getDataCache());
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,57 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.datacache.ConcurrentDataCache;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+/*
+ * When shared-cache-mode is set to ALL, all entities will be cached no matter
+ * what is DataCache Types/ExcludedTypes setting. The other DataCache
+ * config settings like CacheSize will be used to config the data cache.
+ */
+public class TestCacheModeAllDataCacheTrue extends TestCacheModeAll {
+
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("openjpa.DataCache", "true(CacheSize=5000, "
+ + "ExcludedTypes=org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)");
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-all", props);
+ assertNotNull(emf);
+ ConcurrentDataCache dataCache =
+ (ConcurrentDataCache) emf.getConfiguration().getDataCacheManagerInstance().getDataCache("default");
+ assertNotNull(dataCache);
+ assertEquals(5000, dataCache.getCacheSize());
+ assertEquals("true(CacheSize=5000, ExcludedTypes="
+ + "org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)", emf.getConfiguration()
+ .getDataCache());
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java Tue Oct 9 13:47:38 2012
@@ -35,7 +35,7 @@ import org.apache.openjpa.persistence.te
public class TestCacheModeDisableSelective extends AbstractCacheModeTestCase {
- private static Cache cache = null;
+ protected static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
@@ -49,6 +49,7 @@ public class TestCacheModeDisableSelecti
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-disable", null);
assertNotNull(emf);
+ assertEquals("true", emf.getConfiguration().getDataCache());
cache = emf.getCache();
assertNotNull(cache);
}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java Tue Oct 9 13:47:38 2012
@@ -18,6 +18,9 @@
*/
package org.apache.openjpa.persistence.cache.jpa;
+/*
+ * When both shared-cache-mode and dataCache are not set, caching will be off.
+ */
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +44,7 @@ public class TestCacheModeEmpty extends
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-empty", null);
assertNotNull(emf);
+ assertEquals("false", emf.getConfiguration().getDataCache());
cache = emf.getCache();
assertNotNull(cache);
}
@@ -59,15 +63,15 @@ public class TestCacheModeEmpty extends
}
public void testCacheables() {
- assertCacheables(cache, true);
+ assertCacheables(cache, false);
}
public void testUncacheables() {
- assertUncacheables(cache, true);
+ assertUncacheables(cache, false);
}
public void testUnspecified() {
- assertUnspecified(cache, true);
+ assertUnspecified(cache, false);
}
@Override
@@ -79,4 +83,9 @@ public class TestCacheModeEmpty extends
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
+
+ @Override
+ public boolean getCacheEnabled() {
+ return false;
+ }
}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,52 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+/*
+ * When ENABLE_SELECTIVE is set for the shared-cache-mode element and an entity is marked as cacheable(true),
+ * the entity will be cached even though DataCache ExcludedTypes indicate it should be excluded
+ * since shared-cache-mode take the precedence.
+ */
+public class TestCacheModeEnableSelectedDataCacheTrue extends TestCacheModeEnableSelective{
+
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String,Object> props = new HashMap<String,Object>();
+ //exclude types will be ignored since shared cache mode take precedence
+ props.put("openjpa.DataCache", "true(ExcludedTypes=" +
+ "org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity)");
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-enable", props);
+ assertNotNull(emf);
+ assertEquals("true(ExcludedTypes=" +
+ "org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity)",
+ emf.getConfiguration().getDataCache());
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java Tue Oct 9 13:47:38 2012
@@ -35,7 +35,7 @@ import org.apache.openjpa.persistence.te
public class TestCacheModeEnableSelective extends AbstractCacheModeTestCase {
- private static Cache cache = null;
+ protected static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
@@ -49,6 +49,7 @@ public class TestCacheModeEnableSelectiv
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-enable", null);
assertNotNull(emf);
+ assertEquals("true", emf.getConfiguration().getDataCache());
cache = emf.getCache();
assertNotNull(cache);
}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java Tue Oct 9 13:47:38 2012
@@ -32,9 +32,7 @@ public class TestCacheModeInvalid extend
public void testInvalidElement() {
boolean exceptionCaught = false;
try {
- Map<String, Object> propertiesMap = getPropertiesMap("openjpa.DataCache", "true",
- "openjpa.QueryCache", "true",
- "openjpa.RemoteCommitProvider", "sjvm", persistentTypes,
+ Map<String, Object> propertiesMap = getPropertiesMap(persistentTypes,
"openjpa.jdbc.JDBCListeners", new JDBCListener [] { getListener() });
emf = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory("cache-mode-invalid",
"META-INF/caching-persistence-invalid.xml", propertiesMap );
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java Tue Oct 9 13:47:38 2012
@@ -27,9 +27,12 @@ import org.apache.openjpa.lib.jdbc.JDBCL
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.FilteringJDBCListener;
+/*
+ * When shared-cache-mode is NONE and dataCache is not set, caching will be off.
+ */
public class TestCacheModeNone extends AbstractCacheModeTestCase {
- private static Cache cache = null;
+ protected static Cache cache = null;
private static List<String> sql = new ArrayList<String>();
private static JDBCListener listener;
@@ -40,6 +43,7 @@ public class TestCacheModeNone extends A
public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-none",null);
+ assertEquals("false", emf.getConfiguration().getDataCache());
assertNotNull(emf);
cache = emf.getCache();
assertNotNull(cache);
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,47 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public class TestCacheModeNoneDataCacheCustomized extends TestCacheModeNone {
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("openjpa.DataCache",
+ "org.apache.openjpa.persistence.cache.jpa.DataCacheTestExtension(CacheSize=5000, "
+ + "ExcludedTypes=org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)");
+
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-none", props);
+ assertNotNull(emf);
+ assertEquals("org.apache.openjpa.persistence.cache.jpa.DataCacheTestExtension(CacheSize=5000, "
+ + "ExcludedTypes=org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity)", emf
+ .getConfiguration().getDataCache());
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,47 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+/*
+ * Caching is off when shared cache mode is set to NONE no matter
+ * dataCache is set to true or not.
+ * */
+public class TestCacheModeNoneDataCacheTrue extends TestCacheModeNone{
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String,Object> props = new HashMap<String,Object>();
+ props.put("openjpa.DataCache", "true");
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-none",props);
+ assertNotNull(emf);
+ assertEquals("true", emf.getConfiguration().getDataCache());
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java Tue Oct 9 13:47:38 2012
@@ -27,6 +27,9 @@ import org.apache.openjpa.lib.jdbc.JDBCL
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.FilteringJDBCListener;
+/*
+ * When shared-cache-mode is UNSPECIFIED and dataCache is not set, caching will be off.
+ */
public class TestCacheModeUnspecified extends AbstractCacheModeTestCase {
private static Cache cache = null;
@@ -41,6 +44,7 @@ public class TestCacheModeUnspecified ex
if (emf == null) {
emf = createEntityManagerFactory("cache-mode-unspecified", null);
assertNotNull(emf);
+ assertEquals("false", emf.getConfiguration().getDataCache());
cache = emf.getCache();
assertNotNull(cache);
}
@@ -59,15 +63,15 @@ public class TestCacheModeUnspecified ex
}
public void testCacheables() {
- assertCacheables(cache, true);
+ assertCacheables(cache, false);
}
public void testUncacheables() {
- assertUncacheables(cache, true);
+ assertUncacheables(cache, false);
}
public void testUnspecified() {
- assertUnspecified(cache, true);
+ assertUnspecified(cache, false);
}
@Override
@@ -79,4 +83,9 @@ public class TestCacheModeUnspecified ex
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
+
+ @Override
+ public boolean getCacheEnabled() {
+ return false;
+ }
}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java?rev=1396037&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java Tue Oct 9 13:47:38 2012
@@ -0,0 +1,90 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.Cache;
+
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.FilteringJDBCListener;
+
+/*
+ * When shared-cache-mode is UNSPECIFIED and dataCache is true, caching will be on.
+ */
+public class TestCacheModeUnspecifiedDataCacheTrue extends AbstractCacheModeTestCase{
+ private static Cache cache = null;
+ private static List<String> sql = new ArrayList<String>();
+ private static JDBCListener listener;
+
+ private static Class<?>[] expectedInCache = persistentTypes;
+ private static Class<?>[] expectedNotInCache = {};
+
+ @Override
+ public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+ Map<String,Object> props = new HashMap<String,Object>();
+ props.put("openjpa.DataCache", "true");
+ props.put("openjpa.RemoteCommitProvider", "sjvm");
+ if (emf == null) {
+ emf = createEntityManagerFactory("cache-mode-unspecified", props);
+ assertNotNull(emf);
+ cache = emf.getCache();
+ assertNotNull(cache);
+ }
+ return emf;
+ }
+
+ public JDBCListener getListener() {
+ if (listener == null) {
+ listener = new FilteringJDBCListener(getSql());
+ }
+ return listener;
+ }
+
+ public List<String> getSql() {
+ return sql;
+ }
+
+ public void testCacheables() {
+ assertCacheables(cache, true);
+ }
+
+ public void testUncacheables() {
+ assertUncacheables(cache, true);
+ }
+
+ public void testUnspecified() {
+ assertUnspecified(cache, true);
+ }
+
+ @Override
+ protected Class<?>[] getExpectedInCache() {
+ return expectedInCache;
+ }
+
+ @Override
+ protected Class<?>[] getExpectedNotInCache() {
+ return expectedNotInCache;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java Tue Oct 9 13:47:38 2012
@@ -29,6 +29,9 @@ import org.apache.openjpa.lib.jdbc.JDBCL
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.FilteringJDBCListener;
+/*
+ * When sharedCache.mode is UNSPECIFIED and dataCache is not set, caching will be off.
+ */
public class TestPropertyCacheModeUnspecified extends AbstractCacheModeTestCase {
private static Cache cache = null;
@@ -63,15 +66,15 @@ public class TestPropertyCacheModeUnspec
}
public void testCacheables() {
- assertCacheables(cache, true);
+ assertCacheables(cache, false);
}
public void testUncacheables() {
- assertUncacheables(cache, true);
+ assertUncacheables(cache, false);
}
public void testUnspecified() {
- assertUnspecified(cache, true);
+ assertUnspecified(cache, false);
}
@Override
@@ -83,4 +86,9 @@ public class TestPropertyCacheModeUnspec
protected Class<?>[] getExpectedNotInCache() {
return expectedNotInCache;
}
+
+ @Override
+ public boolean getCacheEnabled() {
+ return false;
+ }
}
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java Tue Oct 9 13:47:38 2012
@@ -699,11 +699,28 @@ public class PersistenceProductDerivatio
// those.
if (conf instanceof OpenJPAConfiguration) {
OpenJPAConfiguration oconf = (OpenJPAConfiguration) conf;
- // If the datacache is enabled, make sure we have a RemoteCommitProvider
- String dc = oconf.getDataCache();
+ String dataCache = oconf.getDataCache();
+ String sharedDataCacheMode = oconf.getDataCacheMode();
+
+ if (DataCacheMode.NONE.toString().equals(sharedDataCacheMode)
+ && dataCache != null && !"false".equals(dataCache)) {
+ Log log = conf.getConfigurationLog();
+ if (log.isWarnEnabled()) {
+ log.warn(_loc.get("shared-cache-mode-take-precedence", dataCache));
+ }
+ }
+
+ if ((dataCache == null || "false".equals(dataCache))
+ && !DataCacheMode.NONE.toString().equals(sharedDataCacheMode)
+ && !DataCacheMode.UNSPECIFIED.toString().equals(sharedDataCacheMode)){
+ oconf.setDataCache("true");
+ }
+
+ // If the datacache is enabled, make sure we have a RemoteCommitProvider
String rcp = oconf.getRemoteCommitProvider();
+ dataCache = oconf.getDataCache();
// If the datacache is set and is something other than false
- if (dc != null && !"false".equals(dc)) {
+ if (dataCache != null && !"false".equals(dataCache)) {
// If RCP is null or empty, set it to sjvm.
if (rcp == null || "".equals(rcp)) {
oconf.setRemoteCommitProvider("sjvm");
Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties (original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties Tue Oct 9 13:47:38 2012
@@ -254,3 +254,5 @@ managed PersistenceUnit "{0}". Each Enti
connection will not be released until the EntityManager is closed. If the application uses container managed \
EntityManagers this property should not be used because these EntityManagers may remain open for extended periods of \
time.
+shared-cache-mode-take-precedence: The DataCache is set to {0} while the shared-cache-mode Element or \
+javax.persistence.sharedCache.mode property is set to NONE. The shared-cache-mode take the precedence and caching will be disabled.
Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml?rev=1396037&r1=1396036&r2=1396037&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_caching.xml Tue Oct 9 13:47:38 2012
@@ -134,6 +134,16 @@ a distributed environment, as caches in
Data Cache Configuration
</title>
<para>
+There are two ways to enable the basic single-factory cache. One is using
+<link linkend="openjpa.DataCache"><literal>openjpa.DataCache</literal></link>
+property, the other is using JPA standard shared-cache-mode element or the
+javax.persistence.sharedCache.mode property.
+ </para>
+ <section id="ref_guide_data_cache">
+ <title>
+ openjpa.DataCache Configuration
+ </title>
+ <para>
To enable the basic single-factory cache set the
<link linkend="openjpa.DataCache"><literal>openjpa.DataCache</literal></link>
property to <literal>true</literal>:
@@ -352,11 +362,70 @@ an UPDATE or DELETE statement. The defau
<para>
<programlisting><property name="openjpa.DataCache" value="true(EvictOnBulkUpdate=false)"/></programlisting>
</para>
- </example>
+ </example>
+</section>
+<section id="ref_guide_shared_cache_mode_integration">
+ <title>
+ Integration with JPA standard shared cache mode
+ </title>
+ <para>
+ JPA 2.0 specification introduced the standard data cache configuration through the shared-cache-mode element or javax.persistence.
+sharedCache.mode property.
+ </para>
+ <para>
+ When only the shared cache mode is configured to turn on the caching, the default data cache setting will be used. For example the
+ cache size will be set to default 1000.
+ </para>
+ <para>
+ When the shared cache mode and openjpa.DataCache are both configured, the JPA standard shared cache mode
+ configuration takes the precedence.
+ </para>
+ <para>
+ If the shared cache mode is to turn on the caching, the cache setting configured through openjpa.DataCache
+ , like cacheSize and SoftReferenceSize, will be used to initialize or manage the cache. The Types and ExcludeTypes
+ property in openjpa.DataCache will be ingnored since the shared cache mode in conjunction with the javax.persistence.Cacheable
+ annotation already defines what will be cached.
+ </para>
+ <example id="shared-cache-mode-none">
+ <para>
+<programlisting>
+<property name="openjpa.DataCache" value="true"/>
+<property name="javax.persistence.sharedCache.mode" value="NONE"/>
+</programlisting>
+ </para>
+ <para>
+ When the shared cache mode is set to NONE, the data cache will be disabled no matter how openjpa.DataCache is configured.
+ </para>
+ </example>
+
+ <example id="shared-cache-mode-all">
+ <para>
+<programlisting>
+<property name="openjpa.DataCache" value="true(ExcludedTypes=foo.bar.Person;foo.bar.Employee)"/>
+<property name="javax.persistence.sharedCache.mode" value="ALL"/>
+</programlisting>
+ </para>
+ <para>
+ When the shared cache mode is set to ALL, all entities will be cached no matter how openjpa.DataCache is configured.
+ </para>
+ </example>
+
+ <example id="shared-cache-mode-enable-selective">
+ <para>
+<programlisting>
+<property name="openjpa.DataCache" value="true(ExcludedTypes=foo.bar.Person;foo.bar.Employee)"/>
+<property name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE"/>
+</programlisting>
+ </para>
+ <para>
+ When the shared cache mode set to ENABLE_SELECTIVE, the entities with Cacheable(true) anotation will be cached.
+ ExcludedTypes will be ignored.
+ </para>
+ </example>
+</section>
<section id="ref_guide_cache_distribution">
<title>Distributing instances across cache partitions</title>
<para>
-
OpenJPA also supports a partitioned cache configuration where the cached
instances can be distributed across partitions by an application-defined
policy. Each partition behaves as a data cache by itself, identified by its name and can