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/11/05 21:46:42 UTC
svn commit: r1405947 - in /openjpa/branches/2.2.x:
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/jp...
Author: curtisr7
Date: Mon Nov 5 20:46:41 2012
New Revision: 1405947
URL: http://svn.apache.org/viewvc?rev=1405947&view=rev
Log:
OPENJPA-1532: Merged changes from trunk. Make shared-cache-mode element enable DataCache.
Added:
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/DataCacheTestExtension.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheCustomized.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAllDataCacheTrue.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelectedDataCacheTrue.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheCustomized.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNoneDataCacheTrue.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java
- copied unchanged from r1396037, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecifiedDataCacheTrue.java
Modified:
openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java
openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
openjpa/branches/2.2.x/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
openjpa/branches/2.2.x/openjpa-project/src/doc/manual/ref_guide_caching.xml
Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java (original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractDataCache.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java (original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties (original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/resources/org/apache/openjpa/datacache/localizer.properties Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheModeTestCase.java Mon Nov 5 20:46:41 2012
@@ -206,28 +206,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,
@@ -407,45 +409,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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractCacheTestCase.java Mon Nov 5 20:46:41 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();
Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java Mon Nov 5 20:46:41 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);
}
Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEmpty.java Mon Nov 5 20:46:41 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;
+ }
}
Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeInvalid.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java Mon Nov 5 20:46:41 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);
Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeUnspecified.java Mon Nov 5 20:46:41 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;
+ }
}
Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestPropertyCacheModeUnspecified.java Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java (original)
+++ openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java Mon Nov 5 20:46:41 2012
@@ -698,11 +698,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/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties (original)
+++ openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties Mon Nov 5 20:46:41 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/branches/2.2.x/openjpa-project/src/doc/manual/ref_guide_caching.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-project/src/doc/manual/ref_guide_caching.xml?rev=1405947&r1=1405946&r2=1405947&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-project/src/doc/manual/ref_guide_caching.xml (original)
+++ openjpa/branches/2.2.x/openjpa-project/src/doc/manual/ref_guide_caching.xml Mon Nov 5 20:46:41 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