You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/10/20 22:47:13 UTC

svn commit: r827788 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/ openjpa-persisten...

Author: ppoddar
Date: Tue Oct 20 20:47:12 2009
New Revision: 827788

URL: http://svn.apache.org/viewvc?rev=827788&view=rev
Log:
OPENJPA-1334: Support instance-based cache partition
move type-based cache eligibility logic to DataCacheManager from ClassMetaData.
Calibrate tests to new eligibility policy

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/DataCacheManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.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/TestCacheModeUnspecified.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestExtensionAnnotations.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

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=827788&r1=827787&r2=827788&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 20 20:47:12 2009
@@ -74,9 +74,6 @@
     private String _name = null;
     private boolean _closed = false;
     private String _schedule = null;
-    
-    protected Set<String> _includedTypes;
-    protected Set<String> _excludedTypes;
 
     public String getName() {
         return _name;
@@ -437,6 +434,26 @@
      */
     protected abstract boolean unpinInternal(Object oid);
     
+    /**
+     * 
+     */
+    public DataCache getPartition(String name, boolean create) {
+        if (StringUtils.equals(_name, name))
+            return this;
+        return null;
+    }
+
+    /**
+     * 
+     */
+    public Set<String> getPartitionNames() {
+        return Collections.emptySet();
+    }
+    
+    public boolean isPartitioned() {
+        return false;
+    }
+
     public CacheStatistics getStatistics() {
     	return stats;
     }
@@ -469,66 +486,4 @@
 		}
 	}
     
-    public Set<String> getTypes() {
-        return _includedTypes;
-    }
-    
-    public Set<String> getExcludedTypes() {
-        return _excludedTypes;
-    }
-    
-    public boolean isExcludedType(String type) {
-        if (_excludedTypes != null) {
-            if (_excludedTypes.contains(type)) {
-                return true;
-            }
-        }
-        if (_includedTypes != null) {
-             if (!_includedTypes.contains(type)) {
-                 return true;
-             }
-        }
-        return false;
-    }
-
-    public void setTypes(Set<String> types) {
-        _includedTypes = types;
-    }
-
-    public void setTypes(String types) {
-        _includedTypes =
-            StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays
-                .asList(Strings.split(types, ";", 0)));
-    }
-
-    public void setExcludedTypes(Set<String> types) {
-        _excludedTypes = types;
-    }
-
-    public void setExcludedTypes(String types) {
-        _excludedTypes =
-            StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays
-                .asList(Strings.split(types, ";", 0)));
-    }
-    
-    /**
-     * 
-     */
-    public DataCache getPartition(String name, boolean create) {
-        if (StringUtils.equals(_name, name))
-            return this;
-        return null;
-    }
-
-    /**
-     * 
-     */
-    public Set<String> getPartitionNames() {
-        return Collections.emptySet();
-    }
-    
-    public boolean isPartitioned() {
-        return false;
-    }
-
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java Tue Oct 20 20:47:12 2009
@@ -25,9 +25,13 @@
 /**
  * Manages the system's data and query caches. You can
  * retrieve the data cache manager from the {@link OpenJPAConfiguration}.
+ * <br>
+ * Decides eligibility to cache for managed types.
+ * 
  *
  * @author Abe White
  * @author Patrick Linskey
+ * @author Pinaki Poddar
  */
 public interface DataCacheManager {
 
@@ -79,15 +83,33 @@
      *  
      * @param sm the managed proxy instance
      * @return the cache that will store the state of the given managed instance.
+     * 
      * @since 2.0.0
      */
-    public DataCache selectCache(OpenJPAStateManager sm);
+    public DataCache selectCache(final OpenJPAStateManager sm);
     
     /**
-     * Return the policy that suggests the cache where a managed entity state is stored.  
+     * Return the user-specific policy that <em>suggests</em> the cache where a managed entity state is stored.  
+     * 
      * @since 2.0.0
      */
     public CacheDistributionPolicy getDistributionPolicy();
+    
+    /**
+     * Set the types that are explicitly excluded from being cached.
+     * 
+     * @param typeNames semicolon separated fully qualified class names.
+     * @since 2.0.0
+     */
+    public void setExcludedTypes(String typeNames);
+    
+    /**
+     * Set the types that are explicitly included to be cached.
+     * 
+     * @param typeNames semicolon separated fully qualified class names.
+     * @since 2.0.0
+     */
+    public void setIncludedTypes(String typeNames);
 
     /**
      * Close all caches.

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java Tue Oct 20 20:47:12 2009
@@ -18,28 +18,45 @@
  */
 package org.apache.openjpa.datacache;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.enhance.PCDataGenerator;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.lib.conf.ObjectValue;
 import org.apache.openjpa.lib.util.Closeable;
+import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.util.ImplHelper;
 
+import serp.util.Strings;
+
 /**
- * Default data cache manager.
- *
+ * Default data cache manager provides handle to utilities {@linkplain PCDataGenerator}, {@linkplain DataCacheScheduler}
+ * and {@linkplain CacheDistributionPolicy} for the cache operation. This implementation also determines whether a
+ * managed type is eligible to cache.
+ * 
  * @author Abe White
  * @author Patrick Linskey
+ * @author Pinaki Poddar
  */
 public class DataCacheManagerImpl
     implements Closeable, DataCacheManager {
 
+    private OpenJPAConfiguration _conf;
     private DataCache _cache = null;
     private QueryCache _queryCache = null;
     private DataCachePCDataGenerator _pcGenerator = null;
     private DataCacheScheduler _scheduler = null;
     private CacheDistributionPolicy _policy = new CacheDistributionPolicy.Default();
+    private Set<String> _excludedTypes;
+    private Set<String> _includedTypes;
 
     public void initialize(OpenJPAConfiguration conf, ObjectValue dataCache, ObjectValue queryCache) {
+        _conf = conf;
         _cache = (DataCache) dataCache.instantiate(DataCache.class, conf);
         if (_cache == null)
             return;
@@ -65,6 +82,9 @@
 
     /**
      * Returns the named cache. 
+     * If the given name is name or the name of the cache plugin then returns the main cache.
+     * Otherwise, {@linkplain DataCache#getPartition(String, boolean) delegates} to the main cache
+     * to obtain a partition.   
      */
     public DataCache getDataCache(String name, boolean create) {
         if (name == null || (_cache != null && name.equals(_cache.getName())))
@@ -93,21 +113,132 @@
             _scheduler.stop();
     }
 
+    /**
+     * Select cache for the given managed instance.
+     * If type based verification affirms the type to be cached then the instance based policy 
+     * is called to determine the target cache.  
+     */
     public DataCache selectCache(OpenJPAStateManager sm) {
-        if (sm == null)
-            return null;
-        if (_cache instanceof AbstractDataCache 
-        && ((AbstractDataCache)_cache).isExcludedType(sm.getMetaData().getDescribedType().getName()))
+        if (sm == null || !isCachable(sm.getMetaData()))
             return null;
         String name = _policy.selectCache(sm, null);
         return name == null ? null : getDataCache(name);
     }
     
+    /**
+     * Gets the instance-based cache distribution policy, if configured. 
+     */
     public CacheDistributionPolicy getDistributionPolicy() {
         return _policy;
     }
     
+    /**
+     * Sets the instance-based cache distribution policy. 
+     */
     public void setDistributionPolicy(CacheDistributionPolicy policy) {
         _policy = policy;
     }
+    
+    /**
+     * Affirms if the given type is eligible for cache.
+     */
+    public boolean isCachable(ClassMetaData meta) {
+        Boolean isCachable = isCacheableByPlugin(meta);
+        if (isCachable == null) {
+            isCachable = isCacheableByMode(meta);
+            if (isCachable == null) {
+                isCachable = isCacheableByType(meta);
+            }
+        }
+        return isCachable;
+    }
+    
+    /**
+     * Affirms the given class is eligible to be cached according to the cache mode
+     * and the cache enable flag on the given metadata.
+     *  
+     * @return TRUE or FALSE if  cache mode is configured. null otherwise.
+     */
+    private Boolean isCacheableByMode(ClassMetaData meta) { 
+        switch (DataCacheMode.valueOf(_conf.getDataCacheMode())) {
+          case ALL: // include everything, regardless of annotation or xml configuration
+              return true;
+          case NONE: // exclude everything, regardless of annotation of xml configuration
+              return false;
+          case ENABLE_SELECTIVE: // cache only those entities which were explicitly enabled
+              return Boolean.TRUE.equals(meta.getCacheEnabled());
+          case DISABLE_SELECTIVE: // exclude *only* the entities which are explicitly excluded 
+              return !Boolean.FALSE.equals(meta.getCacheEnabled());
+          case UNSPECIFIED:
+          default: // not determined by mode 
+              return null; 
+      }
+    }
+    
+    /**
+     * Is the given type cacheable by its own flag.
+     * The flag being unset (null) implies TRUE.
+     *  
+     * @see ClassMetaData#getCacheEnabled()
+     */
+    private Boolean isCacheableByType(ClassMetaData meta) {
+        return meta.getCacheEnabled() == null || meta.getCacheEnabled();
+    }
+    
+    /**
+     * Is the given type cacheable by excludeTypes/includeTypes plug-in properties.
+     *  
+     * @param meta the given type
+     * @return TRUE or FALSE if the type has appeared in the plug-in property.
+     * null otherwise.
+     */
+    private Boolean isCacheableByPlugin(ClassMetaData meta) {
+        String className = meta.getDescribedType().getName();
+        if (_excludedTypes != null && _excludedTypes.contains(className)) {  
+            return Boolean.FALSE;
+        } 
+        if (_includedTypes != null && _includedTypes.contains(className)) {
+            return Boolean.TRUE;
+        }
+        return null;
+    }
+
+    /**
+     * Gets the excluded types, if configured.
+     */
+    public Set<String> getExcludedTypes() {
+        return _excludedTypes;
+    }
+    
+    /**
+     * Sets excluded types from a semicolon separated list of type names.
+     */
+    public void setExcludedTypes(String types) {
+        _excludedTypes = parseNames(types);
+    }
+
+    /**
+     * Gets the included types, if configured.
+     */
+    public Set<String> getIncludedTypes() {
+        return _excludedTypes;
+    }
+    
+    /**
+     * Sets included types from a semicolon separated list of type names.
+     */
+    public void setIncludedTypes(String types) {
+        _includedTypes = parseNames(types);
+    }
+    
+    private Set<String> parseNames(String types) {
+        if (StringUtils.isEmpty(types))
+            return Collections.emptySet();
+        String[] names = Strings.split(types, ";", 0);
+        Set<String> set = new HashSet<String>();
+        set.addAll(Arrays.asList(names));
+        
+        return  Collections.unmodifiableSet(set);
+    }
+
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java Tue Oct 20 20:47:12 2009
@@ -214,7 +214,6 @@
     private boolean _abstract = false;
     private Boolean _hasAbstractPKField = null;
     private Boolean _hasPKFieldsFromAbstractClass = null;
-    private Boolean _isCacheable = null;
     
     /**
      * Constructor. Supply described type and repository.
@@ -1412,11 +1411,12 @@
     }
 
     /**
-     * The name of the datacache to use for this class. If this class is not
-     * eligible for caching based its annotation or the cache configuration
-     * null will be returned.
+     * The name of the data cache that stores the managed instance of this class, by default.
+     * This can be overwritten by per-instance basis {@linkplain CacheDistributionPolicy cache distribution policy}. 
+     * 
+     * @return If this class is disabled from cache or no name has been set then returns 
+     * {@linkplain DataCache#NAME_DEFAULT default} data cache name. 
      * 
-     * @return The cache name, or null if this type should not be cached.
      */
     public String getDataCacheName() {
         if (DEFAULT_STRING.equals(_cacheName)) {
@@ -1425,15 +1425,15 @@
             } else {
                 _cacheName = DataCache.NAME_DEFAULT;
             }
-            if (!isCacheable(_cacheName)) {
-                _cacheName = null;
-            }
         }
         return _cacheName;
     }
 
     /**
-     * Set the cache name for this class. Set to null to disable caching.
+     * Set the cache name for this class. 
+     * 
+     * @param can not be null. To disable cache use {@linkplain ClassMetaData#setCacheEnabled(boolean, boolean)} 
+     * instead. 
      */
     public void setDataCacheName(String name) {
         _cacheName = name;
@@ -2429,6 +2429,7 @@
             _cacheName = meta.getDataCacheName();
         if (_cacheTimeout == Integer.MIN_VALUE)
             _cacheTimeout = meta.getDataCacheTimeout();
+        _cacheEnabled = meta.getCacheEnabled();
         if (_detachable == null)
             _detachable = meta._detachable;
         if (DEFAULT_STRING.equals(_detachState))
@@ -2589,137 +2590,6 @@
     }
 
     /**
-     * Determine whether this Type should be included in the DataCache (if one
-     * is provided) based on the DataCache's configuration.
-     * 
-     * @return true if the DataCache will accept this type, otherwise false.
-     */
-    private boolean isConfiguredForCaching() {
-        if (_isCacheable != null) {
-            return _isCacheable.booleanValue();
-        }
-
-        setIsCacheable(true, false);
-        return _isCacheable.booleanValue();
-    }
-
-    /**
-     * <p>
-     * Set whether or not the class represented by this ClassMetaData object should be included in the datacache. The
-     * arguments provided are *hints* as to whether the class should be included in the datacache, and can be overridden
-     * by the configuration set in openjpa.Datacache.
-     * </p>
-     * 
-     * <p>
-     * Rules for this determination are:
-     * </p>
-     * <ol>
-     * <li>If the class shows up in the list of excluded types, it does not get cached, period.</li>
-     * <li>If the class does not show up in the excluded types, but the included types field is set (ie, has at least
-     * one class), then:
-     * <ol>
-     * <li>If the class is listed in the include list, then it gets cached</li>
-     * <li>If the class is set as cacheable by the @Datacache annotation, it gets cached</li>
-     * <li>If neither a or b are true, then the class does not get cached</li>
-     * </ol>
-     * </li>
-     * <li>If neither the include or exclude lists are defined, then go along with the value passed into the argument,
-     * which is either the default value (true) or whatever was set with the @Datacache annotation</li>
-     * </ol>
-     * 
-     * @param isCacheable
-     *            Hint whether this class should be included in the datacache. Default behavior is yes, though the 
-     *            @Datacache annotation can specify if it should not be cached.
-     * @param annotationOverride
-     *            Whether this hint originated from the @Datacache annotation or whether this is the default "yes" hint.
-     *            The origination of the hint influences the decision making process in rule #2b.
-     */
-    public void setIsCacheable(boolean isCacheable, boolean annotationOverride) {
-        Options dataCacheOptions = getDataCacheOptions();
-        Set excludedTypes = extractDataCacheClassListing(dataCacheOptions.getProperty("ExcludedTypes", null));
-        Set types = extractDataCacheClassListing(dataCacheOptions.getProperty("Types", null));
-
-        String className = getDescribedType().getName();
-        if (excludedTypes != null && excludedTypes.contains(className)) {
-            // Rule #1
-            _isCacheable = Boolean.FALSE;
-        } else if (types != null) {
-            // Rule #2
-            if ((annotationOverride && isCacheable) || (types.contains(className))) {
-                _isCacheable = Boolean.TRUE;
-            } else {
-                _isCacheable = Boolean.FALSE;
-            }
-        } else {
-            // Rule #3
-            _isCacheable = isCacheable ? Boolean.TRUE : Boolean.FALSE;
-        }
-    }
-
-    /**
-     * Extract all of the DataCache plugin options from the configuration
-     */
-    private Options getDataCacheOptions() {
-        String dataCacheConfig = getRepository().getConfiguration().getDataCache();
-        Options dataCacheOptions = Configurations.parseProperties(Configurations.getProperties(dataCacheConfig));
-        return dataCacheOptions;
-    }
-
-    /**
-     * Tool to extract classes defined in the datacache include and exclude list into individual entries in a Set.
-     */
-    private final Set extractDataCacheClassListing(String classList) {
-        if (classList == null || classList.length() == 0)
-            return null;
-
-        HashSet returnSet = new HashSet();
-        String[] entries = classList.split(";");
-        for (int index = 0; index < entries.length; index++) {
-            returnSet.add(entries[index]);
-        }
-
-        return returnSet;
-    }
-
-    private boolean isCacheable(String candidateCacheName) { 
-        boolean rval;
-        switch(DataCacheMode.valueOf(_repos.getConfiguration().getDataCacheMode())) {
-          case ALL:
-              // include everything, regardless of annotation or xml configuration
-              rval = true;
-              break;
-          case NONE:
-              // excluded everything, regardless of annotation of xml configuration
-              rval = false;
-              break;
-          case ENABLE_SELECTIVE:
-              // cache only those entities which were specifically enabled
-              if(getCacheEnabled() == null) { 
-                  rval = false; 
-              }
-              else { 
-                  rval = getCacheEnabled();
-              }
-              break;
-          case DISABLE_SELECTIVE:
-              // exclude *only* the entities which are explicitly excluded. 
-              if(getCacheEnabled() == null) { 
-                  rval = true; 
-              }
-              else { 
-                  rval = getCacheEnabled();
-              }
-              break;
-          case UNSPECIFIED:
-          default:
-              // behavior from previous releases. 
-              rval = isConfiguredForCaching(); 
-      }
-      return rval;
-        
-    }
-    
-    /**
      * Convenience method to determine if the pcType modeled by
      * this ClassMetaData object is both abstract and declares PKFields. This
      * method is used by the PCEnhancer to determine if special handling is
@@ -2792,10 +2662,24 @@
         return _hasPKFieldsFromAbstractClass.booleanValue();
     }
     
-    public void setCacheEnabled(Boolean enabled) { 
+    /**
+     * Sets the eligibility status of this class for cache.
+     * To set enable from true to false, overwrite flag must be true.
+     */
+    public void setCacheEnabled(boolean enabled, boolean overwrite) { 
+        if (Boolean.TRUE.equals(_cacheEnabled) && enabled == false && !overwrite) {
+            getRepository().getConfiguration().getConfigurationLog().warn(_loc.get("cache-enable-overwrite"));
+            return;
+        }
         _cacheEnabled = enabled;
     }
     
+    /**
+     * Returns tri-state status on whether this class has been enabled for caching.
+     * 
+     * @return TRUE or FALSE denote the class has been explicitly enabled or disabled for caching.
+     * null denotes that no status for caching has been set. 
+     */
     public Boolean getCacheEnabled() { 
         return _cacheEnabled;
     }

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=827788&r1=827787&r2=827788&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 20 20:47:12 2009
@@ -25,6 +25,13 @@
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedCachableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
 
 public class TestCacheModeEmpty extends AbstractCacheModeTestCase {
     private static OpenJPAEntityManagerFactorySPI emf = null;
@@ -32,8 +39,10 @@
     private static List<String> sql = new ArrayList<String>();
     private static JDBCListener listener;
     
-    private static Class<?>[] expectedInCache = persistentTypes;
-    private static Class<?>[] expectedNotInCache = {};
+    private static Class<?>[] expectedInCache = {CacheableEntity.class, UnspecifiedEntity.class, 
+        NegatedUncacheableEntity.class, XmlCacheableEntity.class};
+    private static Class<?>[] expectedNotInCache = {UncacheableEntity.class, NegatedCachableEntity.class,
+        XmlUncacheableEntity.class};
 
     @Override
     public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
@@ -62,7 +71,7 @@
     }
 
     public void testUncacheables() {
-        assertUncacheables(cache, true);
+        assertUncacheables(cache, false);
     }
 
     public void testUnspecified() {

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=827788&r1=827787&r2=827788&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 20 20:47:12 2009
@@ -25,6 +25,13 @@
 
 import org.apache.openjpa.lib.jdbc.JDBCListener;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.cache.jpa.model.CacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedCachableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.NegatedUncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UncacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.UnspecifiedEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlCacheableEntity;
+import org.apache.openjpa.persistence.cache.jpa.model.XmlUncacheableEntity;
 
 public class TestCacheModeUnspecified extends AbstractCacheModeTestCase {
     private static OpenJPAEntityManagerFactorySPI emf = null;
@@ -32,8 +39,10 @@
     private static List<String> sql = new ArrayList<String>();
     private static JDBCListener listener;
     
-    private static Class<?>[] expectedInCache = persistentTypes;
-    private static Class<?>[] expectedNotInCache = {};
+    private static Class<?>[] expectedInCache = {CacheableEntity.class, UnspecifiedEntity.class, 
+        NegatedUncacheableEntity.class, XmlCacheableEntity.class};
+    private static Class<?>[] expectedNotInCache = {UncacheableEntity.class, NegatedCachableEntity.class,
+        XmlUncacheableEntity.class};
 
     @Override
     public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
@@ -62,7 +71,7 @@
     }
 
     public void testUncacheables() {
-        assertUncacheables(cache, true);
+        assertUncacheables(cache, false);
     }
 
     public void testUnspecified() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java Tue Oct 20 20:47:12 2009
@@ -106,7 +106,7 @@
         getEntityManagerFactoryCacheSettings(new Class[] { Item.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, false, false, true);
+        assertCacheContents(cache, true, true, true);
     }
 
     public void testCacheItemsAndPurchases() {
@@ -114,7 +114,7 @@
             Purchase.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, false, true);
+        assertCacheContents(cache, true, true, true);
     }
 
     public void testCacheItemsAndOrders() {
@@ -122,7 +122,7 @@
             Order.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, false, true, true);
+        assertCacheContents(cache, true, true, true);
     }
 
     public void testCachePurchasesAndOrders() {
@@ -130,7 +130,7 @@
             Order.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, true, false);
+        assertCacheContents(cache, true, true, true);
     }
 
     public void testExcludePurchases() {
@@ -168,14 +168,14 @@
             Item.class }, new Class[] { Purchase.class });
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, false, false, true);
+        assertCacheContents(cache, false, true, true);
     }
 
     public OpenJPAEntityManagerFactorySPI getEntityManagerFactoryCacheSettings(
         Class<?>[] includedTypes, Class<?>[] excludedTypes) {
         StringBuilder includes = new StringBuilder();
         if (includedTypes != null && includedTypes.length > 0) {
-            includes.append("Types=");
+            includes.append("IncludedTypes=");
             for (Class<?> c : includedTypes) {
                 includes.append(c.getName());
                 includes.append(_tSep);
@@ -192,7 +192,7 @@
             excludes.setLength(excludes.length() - 1); // remove last semicolon
         }
         StringBuilder dataCacheSettings = new StringBuilder();
-        dataCacheSettings.append("true");
+        dataCacheSettings.append("default");
         if (includes.length() > 0 || excludes.length() > 0) {
             dataCacheSettings.append("(");
             dataCacheSettings.append(includes);
@@ -203,7 +203,8 @@
             dataCacheSettings.append(")");
         }
         Map<String, String> props = new HashMap<String, String>();
-        props.put("openjpa.DataCache", dataCacheSettings.toString());
+        props.put("openjpa.DataCacheManager", dataCacheSettings.toString());
+        props.put("openjpa.DataCache", "true");
         props.put("openjpa.RemoteCommitProvider", "sjvm");
         props.put("openjpa.MetaDataFactory", "jpa(Types="
             + Item.class.getName() + _tSep + Purchase.class.getName() + _tSep

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestExtensionAnnotations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestExtensionAnnotations.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestExtensionAnnotations.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestExtensionAnnotations.java Tue Oct 20 20:47:12 2009
@@ -21,6 +21,7 @@
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FetchGroup;
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.UpdateStrategies;
@@ -51,8 +52,13 @@
         assertEquals("system", _mapping.getIdentitySequenceName());
     }
 
+    /**
+     * {@linkplain ClassMetaData#getDataCacheName()} now returns non-null name even for types that 
+     * have data cache disabled.
+     * To test whether a type is disabled for caching, use {@linkplain ClassMetaData#getCacheEnabled()}. 
+     */
     public void testDataCache() {
-        assertNull(_mapping.getDataCacheName());
+        assertFalse(_mapping.getCacheEnabled());
     }
 
     public void testFetchGroups() {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java Tue Oct 20 20:47:12 2009
@@ -820,20 +820,10 @@
         if (cache.timeout() != Integer.MIN_VALUE) {
             meta.setDataCacheTimeout(cache.timeout());
         }
-        if (!StringUtils.isEmpty(cache.name())) {
-            meta.setDataCacheName(cache.name());
-            if(cache.enabled()) {
-                meta.setCacheEnabled(true);
-            }
-        }
-        else if (cache.enabled()) {
-            meta.setDataCacheName(org.apache.openjpa.datacache.DataCache.NAME_DEFAULT);
-            meta.setCacheEnabled(true); 
-        } else {
-            meta.setDataCacheName(null);
-            meta.setCacheEnabled(false);
-        }
-        meta.setIsCacheable(cache.enabled(), true);
+        String cacheName = cache.name();
+        if (!StringUtils.isEmpty(cacheName))
+            meta.setDataCacheName(cacheName);
+        meta.setCacheEnabled(cache.enabled(), false);
     }
 
     private void parseManagedInterface(ClassMetaData meta,
@@ -1235,7 +1225,7 @@
      * Parse @Cache.
      */
     private void parseCache(ClassMetaData meta, Cacheable cacheable) {
-        meta.setCacheEnabled(cacheable.value());
+        meta.setCacheEnabled(cacheable.value(), false);
     }
 
     /**

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=827788&r1=827787&r2=827788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java Tue Oct 20 20:47:12 2009
@@ -104,8 +104,7 @@
     protected static final String ELEM_CASCADE_DET = "cascade-detach";
     protected static final String ELEM_PU_META = "persistence-unit-metadata";
     protected static final String ELEM_PU_DEF = "persistence-unit-defaults";
-    protected static final String ELEM_XML_MAP_META_COMPLETE =
-        "xml-mapping-metadata-complete";
+    protected static final String ELEM_XML_MAP_META_COMPLETE = "xml-mapping-metadata-complete";
     protected static final String ELEM_DELIM_IDS = "delimited-identifiers";
 
     private static final Map<String, Object> _elems =
@@ -907,8 +906,8 @@
             }
         }
         
-        if(attrs.getValue("cacheable") != null) { 
-            meta.setCacheEnabled(Boolean.valueOf(attrs.getValue("cacheable")));
+        if (attrs.getValue("cacheable") != null) { 
+            meta.setCacheEnabled(Boolean.valueOf(attrs.getValue("cacheable")), true);
         }
         
         if (isMappingMode())