openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r807662 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ 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/a...
Date Tue, 25 Aug 2009 15:08:17 GMT
Author: mikedd
Date: Tue Aug 25 15:08:16 2009
New Revision: 807662

URL: http://svn.apache.org/viewvc?rev=807662&view=rev
Log:
OPENJPA-1264: 
Enable shared-cache-mode persistence.xml element. 

Added:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/model/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml   (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.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/test/AbstractPersistenceTestCase.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/MetaDataTag.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.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/conf/OpenJPAConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java?rev=807662&r1=807661&r2=807662&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java Tue Aug 25 15:08:16 2009
@@ -23,6 +23,7 @@
 
 import org.apache.openjpa.datacache.DataCache;
 import org.apache.openjpa.datacache.DataCacheManager;
+import org.apache.openjpa.datacache.DataCacheMode;
 import org.apache.openjpa.ee.ManagedRuntime;
 import org.apache.openjpa.enhance.RuntimeUnenhancedClassesModes;
 import org.apache.openjpa.event.BrokerFactoryEventManager;
@@ -1830,4 +1831,20 @@
      * @return EncryptionProvider
      */
     public EncryptionProvider getEncryptionProvider();
+    
+    
+    /**
+     * Set the {@link DataCacheMode}
+     * 
+     * @param mode One of the Sting constants from {@link DataCacheMode}
+     * @since 2.0.0
+     */
+    public void setDataCacheMode(String mode);
+
+    /**
+     * Return the String constant that matches the {@link DataCacheMode}
+     * @return DataCacheMode
+     * @since 2.0.0
+     */
+    public String getDataCacheMode();
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=807662&r1=807661&r2=807662&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java Tue Aug 25 15:08:16 2009
@@ -27,6 +27,7 @@
 import org.apache.openjpa.datacache.ConcurrentQueryCache;
 import org.apache.openjpa.datacache.DataCacheManager;
 import org.apache.openjpa.datacache.DataCacheManagerImpl;
+import org.apache.openjpa.datacache.DataCacheMode;
 import org.apache.openjpa.ee.ManagedRuntime;
 import org.apache.openjpa.enhance.RuntimeUnenhancedClassesModes;
 import org.apache.openjpa.event.BrokerFactoryEventManager;
@@ -172,6 +173,7 @@
     public ObjectValue writeBehindCachePlugin;
     public ObjectValue writeBehindCacheManagerPlugin;
     public ObjectValue writeBehindCallbackPlugin;
+    public StringValue dataCacheMode; 
     public BooleanValue dynamicEnhancementAgent;
     
     // custom values
@@ -634,6 +636,10 @@
         writeBehindCallbackPlugin.setAliases(aliases);
         writeBehindCallbackPlugin.setDefault(aliases[0]);
         writeBehindCallbackPlugin.setString(aliases[0]);
+        
+        dataCacheMode = addString(DataCacheMode.class.getSimpleName());
+        dataCacheMode.setDefault(DataCacheMode.UNSPECIFIED.toString());
+        dataCacheMode.set(DataCacheMode.UNSPECIFIED.toString());
 
         if (derivations)
             ProductDerivations.beforeConfigurationLoad(this);
@@ -1782,5 +1788,13 @@
             encryptionProvider.instantiate(EncryptionProvider.class, this);
         return (EncryptionProvider) encryptionProvider.get();
     }
+
+    public void setDataCacheMode(String mode) {
+        this.dataCacheMode.setString(mode);
+    }
+
+    public String getDataCacheMode() {
+        return dataCacheMode.getString();
+    }
 }
 

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java (added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.datacache;
+
+public enum DataCacheMode {
+    /**
+     * <p>All entities are cached regardless of annotations or xml configuration.</p>
+     */
+    ALL,
+    /**
+     * <p>No entities are cached regardless of annotations or xml configuration.</p>
+     */
+    NONE,
+    /**
+     * <p>
+     * <b>Only</b> the entities which are configured to be in the cache will be
+     * cached. Entities which do not specify whether they are cacheable will be
+     * excluded
+     * </p>
+     * <p>
+     * AKA opt-in.
+     * </p>
+     */
+    ENABLE_SELECTIVE,
+    /**
+     * <p>
+     * All entities except those which are explicitly excluded will be cached.
+     * </p>
+     * <p>
+     * AKA opt-out
+     * </p>
+     */
+    DISABLE_SELECTIVE,
+    /**
+     * <p>
+     * Default value. In this case OpenJPA will behave as it did in previous
+     * releases, and will take into account the includedTypes and excludedTypes
+     * optional parameters on the <literal>openjpa.DataCache</literal>
+     * configuration property.
+     * </p>
+     */
+    UNSPECIFIED
+}

Propchange: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=807662&r1=807661&r2=807662&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 Aug 25 15:08:16 2009
@@ -40,6 +40,7 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.datacache.AbstractDataCache;
 import org.apache.openjpa.datacache.DataCache;
+import org.apache.openjpa.datacache.DataCacheMode;
 import org.apache.openjpa.enhance.PCRegistry;
 import org.apache.openjpa.enhance.Reflection;
 import org.apache.openjpa.enhance.PersistenceCapable;
@@ -183,6 +184,7 @@
     private String _seqName = DEFAULT_STRING;
     private SequenceMetaData _seqMeta = null;
     private String _cacheName = DEFAULT_STRING;
+    private Boolean _cacheEnabled = null;
     private int _cacheTimeout = Integer.MIN_VALUE;
     private Boolean _detachable = null;
     private String _detachState = DEFAULT_STRING;
@@ -1415,14 +1417,13 @@
      */
     public String getDataCacheName() {
         if (DEFAULT_STRING.equals(_cacheName)) {
-            if (_super != null) {
+            if (_super != null && StringUtils.isNotEmpty(getPCSuperclassMetaData().getDataCacheName())) {
                 _cacheName = getPCSuperclassMetaData().getDataCacheName();
-            }
-            else {
+            } else {
                 _cacheName = DataCache.NAME_DEFAULT;
             }
-            if(!isCacheable(_cacheName)) { 
-               _cacheName = null; 
+            if (!isCacheable(_cacheName)) {
+                _cacheName = null;
             }
         }
         return _cacheName;
@@ -1462,10 +1463,10 @@
      */
     public DataCache getDataCache() {
         String name = getDataCacheName();
-        if (name == null)
+        if (name == null) {
             return null;
-        return _repos.getConfiguration().getDataCacheManagerInstance().
-            getDataCache(name, true);
+        }
+        return _repos.getConfiguration().getDataCacheManagerInstance().getDataCache(name, true);
     }
 
     /**
@@ -1729,8 +1730,9 @@
 
         // are we the target of an embedded value?
         if (embed) {
-            if (recursiveEmbed(_owner))
+            if (recursiveEmbed(_owner)) {
                 throw new MetaDataException(_loc.get("recurse-embed", _owner));
+            }
 
             // copy info from the "real" metadata for this type
             ClassMetaData meta = _repos.getMetaData(_type, _loader, true);
@@ -1883,16 +1885,21 @@
             throw new MetaDataException(_loc.get("cache-timeout-invalid",
                 _type, String.valueOf(timeout)));
 
-        if (_super == null)
+        if (_super == null) {
             return;
+        }
         String cache = getDataCacheName();
-        if (cache == null)
+        if (cache == null) {
             return;
+        }
 
         String superCache = getPCSuperclassMetaData().getDataCacheName();
-        if (!StringUtils.equals(cache, superCache))
-            throw new MetaDataException(_loc.get("cache-names", new Object[]
-                { _type, cache, _super, superCache }));
+        
+        if (!StringUtils.isEmpty(superCache)) {  
+            if (!StringUtils.equals(cache, superCache)) {
+                throw new MetaDataException(_loc.get("cache-names", new Object[] { _type, cache, _super, superCache }));
+            }
+        }
     }
 
     /**
@@ -2583,11 +2590,10 @@
      * 
      * @return true if the DataCache will accept this type, otherwise false.
      */
-    private boolean isCacheable(String candidateCacheName) {
+    private boolean isConfiguredForCaching(String candidateCacheName) {
         boolean rval = true;
         DataCache cache =
-            getRepository().getConfiguration().getDataCacheManagerInstance()
-                .getDataCache(candidateCacheName);
+            getRepository().getConfiguration().getDataCacheManagerInstance().getDataCache(candidateCacheName);
         if (cache != null && (cache instanceof AbstractDataCache)) {
             AbstractDataCache adc = (AbstractDataCache) cache;
             if (!adc.isCacheableType(getDescribedType().getName()))
@@ -2596,6 +2602,44 @@
         return rval;
     }
     
+    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(candidateCacheName); 
+      }
+      return rval;
+        
+    }
+    
     /**
      * Convenience method to determine if the pcType modeled by
      * this ClassMetaData object is both abstract and declares PKFields. This
@@ -2668,5 +2712,13 @@
 
         return _hasPKFieldsFromAbstractClass.booleanValue();
     }
+    
+    public void setCacheEnabled(Boolean enabled) { 
+        _cacheEnabled = enabled;
+    }
+    
+    public Boolean getCacheEnabled() { 
+        return _cacheEnabled;
+    }
 
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,155 @@
+/*
+ * 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.lang.reflect.Modifier;
+
+import javax.persistence.Cache;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.cache.jpa.model.CacheEntity;
+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;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+
+public abstract class AbstractJPACacheTestCase extends AbstractPersistenceTestCase {
+    public abstract OpenJPAEntityManagerFactorySPI getEntityManagerFactory();
+
+    private static Class<?>[] persistentTypes =
+        { CacheableEntity.class, UncacheableEntity.class, UnspecifiedEntity.class, 
+            NegatedCachableEntity.class, NegatedUncacheableEntity.class, XmlCacheableEntity.class,
+            XmlUncacheableEntity.class };
+
+    public void populate() throws IllegalAccessException, InstantiationException {
+        EntityManager em = getEntityManagerFactory().createEntityManager();
+        em.getTransaction().begin();
+        for (Class<?> clss : persistentTypes) {
+            if (!Modifier.isAbstract(clss.getModifiers())) {
+                CacheEntity ce = (CacheEntity) clss.newInstance();
+                ce.setId(1);
+                em.persist(ce);
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public OpenJPAEntityManagerFactorySPI createEntityManagerFactory(String puName) {
+        OpenJPAEntityManagerFactorySPI emf =
+            (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(puName,
+                "META-INF/caching-persistence.xml", getPropertiesMap("openjpa.DataCache", "true",
+                    "openjpa.RemoteCommitProvider", "sjvm", persistentTypes));
+        return emf;
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        // populate once per test method in case we add more methods
+        cleanDatabase();
+        populate();
+    }
+
+    public void cleanDatabase() throws Exception {
+        EntityManager em = getEntityManagerFactory().createEntityManager();
+        em.getTransaction().begin();
+        for (Class<?> clss : persistentTypes) {
+            if (!Modifier.isAbstract(clss.getModifiers())) {
+                em.createQuery("Delete from " + clss.getSimpleName()).executeUpdate();
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    /**
+     * Assert whether the cache contains the expected results.
+     * 
+     * @param cache
+     *            The JPA Cache to verify
+     * @param expectCacheables
+     *            Whether entities with @Cacheable(true) should be in the cache
+     *            (almost always true)
+     * @param expectUncacheables
+     *            Whether entities with @Cacheable(false) should be in the cache
+     *            (almost always false)
+     * @param expectUnspecified
+     *            Whether entities with no @Cacheable annotation should be in
+     *            the cache (varies per config).
+     */
+    protected void assertCacheContents(Cache cache, boolean expectCacheables, boolean expectUncacheables,
+        boolean expectUnspecified) {
+        assertCacheables(cache, expectCacheables);
+        assertUncacheables(cache, expectUncacheables);
+        assertUnspecified(cache, expectUnspecified);
+    }
+
+    /**
+     * Assert whether the cacheable types are in the cache. This method exits on
+     * the first cache 'miss'.
+     * 
+     * @param cache
+     *            JPA Cache to verify
+     * @param expected
+     *            If true the cacheable types should be in the cache, if false
+     *            they should not be.
+     */
+    protected void assertCacheables(Cache cache, boolean expected) {
+        assertCached(cache, CacheableEntity.class, 1, expected);
+        assertCached(cache, NegatedUncacheableEntity.class, 1, expected);
+        assertCached(cache, XmlCacheableEntity.class, 1, expected);
+    }
+
+    /**
+     * Assert whether the uncacheable types are in the cache. This method exits
+     * on the first cache 'miss'.
+     * 
+     * @param cache
+     *            JPA Cache to verify
+     * @param expected
+     *            If true the uncacheable types should be in the cache, if false
+     *            they should not be.
+     */
+    protected void assertUncacheables(Cache cache, boolean expected) {
+        assertCached(cache, UncacheableEntity.class, 1, expected);
+        assertCached(cache, XmlUncacheableEntity.class, 1, expected);
+        assertCached(cache, NegatedCachableEntity.class, 1, expected);
+    }
+
+    /**
+     * Assert whether the unspecified types are in the cache. This method exits
+     * on the first cache 'miss'.
+     * 
+     * @param cache
+     *            JPA Cache to verify
+     * @param expected
+     *            If true the unspecified types should be in the cache, if false
+     *            they should not be.
+     */
+    protected void assertUnspecified(Cache cache, boolean expected) {
+        assertCached(cache, UnspecifiedEntity.class, 1, expected);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/AbstractJPACacheTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java Tue Aug 25 15:08:16 2009
@@ -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 javax.persistence.Cache;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public class TestCacheModeAll extends AbstractJPACacheTestCase {
+
+    private static OpenJPAEntityManagerFactorySPI emf = null;
+    private static Cache cache = null;
+
+    @Override
+    public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+        if (emf == null) {
+            emf = createEntityManagerFactory("cache-mode-all");
+            assertNotNull(emf);
+            cache = emf.getCache();
+            assertNotNull(cache);
+        }
+        return emf;
+    }
+
+    public void testCacheables() {
+        assertCacheables(cache, true);
+    }
+
+    public void testUncacheables() {
+        assertUncacheables(cache, true);
+    }
+
+    public void testUnspecified() {
+        assertUnspecified(cache, true);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java Tue Aug 25 15:08:16 2009
@@ -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 javax.persistence.Cache;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public class TestCacheModeDisableSelective extends AbstractJPACacheTestCase {
+
+    private static OpenJPAEntityManagerFactorySPI emf = null;
+    private static Cache cache = null;
+
+    @Override
+    public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+        if (emf == null) {
+            emf = createEntityManagerFactory("cache-mode-disable");
+            assertNotNull(emf);
+            cache = emf.getCache();
+            assertNotNull(cache);
+        }
+        return emf;
+    }
+
+    public void testCacheables() {
+        assertCacheables(cache, true);
+    }
+
+    public void testUncacheables() {
+        assertUncacheables(cache, false);
+    }
+
+    public void testUnspecified() {
+        assertUnspecified(cache, true);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeDisableSelective.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa;
+
+import javax.persistence.Cache;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public class TestCacheModeEnableSelective extends AbstractJPACacheTestCase {
+
+    private static OpenJPAEntityManagerFactorySPI emf = null;
+    private static Cache cache = null;
+
+    @Override
+    public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+        if (emf == null) {
+            emf = createEntityManagerFactory("cache-mode-enable");
+            assertNotNull(emf);
+            cache = emf.getCache();
+            assertNotNull(cache);
+        }
+        return emf;
+    }
+
+    public void testCacheables() {
+        assertCacheables(cache, true);
+    }
+
+    public void testUncacheables() {
+        assertUncacheables(cache, false);
+    }
+
+    public void testUnspecified() {
+        assertUnspecified(cache, false);
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeEnableSelective.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java Tue Aug 25 15:08:16 2009
@@ -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 javax.persistence.Cache;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+public class TestCacheModeNone extends AbstractJPACacheTestCase {
+
+    private static OpenJPAEntityManagerFactorySPI emf = null;
+    private static Cache cache = null;
+
+    @Override
+    public OpenJPAEntityManagerFactorySPI getEntityManagerFactory() {
+        if (emf == null) {
+            emf = createEntityManagerFactory("cache-mode-none");
+            assertNotNull(emf);
+            cache = emf.getCache();
+            assertNotNull(cache);
+        }
+        return emf;
+    }
+
+    public void testCacheables() {
+        assertCacheables(cache, false);
+    }
+
+    public void testUncacheables() {
+        assertUncacheables(cache, false);
+    }
+
+    public void testUnspecified() {
+        assertUnspecified(cache, false);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestCacheModeNone.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+public interface CacheEntity {
+
+    public void setId(int id);
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+@Cacheable(true)
+public class CacheableEntity  implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/CacheableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java Tue Aug 25 15:08:16 2009
@@ -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.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * Extends CacheableEntity but the cachable attribute will be negated by XML
+ * configuration
+ */
+@Entity
+public class NegatedCachableEntity implements CacheEntity  {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedCachableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java Tue Aug 25 15:08:16 2009
@@ -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.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * Extends UncacheableEntity but the cachable attribute will be negated by XML
+ * configuration.
+ */
+@Entity
+public class NegatedUncacheableEntity implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/NegatedUncacheableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+import javax.persistence.Cacheable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+@Cacheable(false)
+public class UncacheableEntity implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UncacheableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class UnspecifiedEntity implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/UnspecifiedEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * Cacheable setting will be provided by XML descriptor.  
+ */
+@Entity
+public class XmlCacheableEntity implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlCacheableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java Tue Aug 25 15:08:16 2009
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.cache.jpa.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * Cacheable setting will be provided by XML descriptor.
+ */
+@Entity
+public class XmlUncacheableEntity implements CacheEntity {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/XmlUncacheableEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html Tue Aug 25 15:08:16 2009
@@ -0,0 +1,23 @@
+<!--
+ 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.   
+-->
+<html>
+<body>
+<p><strong>Tests for the JPA Cache interface</strong></p>
+</body>
+</html>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java?rev=807662&r1=807661&r2=807662&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java Tue Aug 25 15:08:16 2009
@@ -31,6 +31,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.persistence.Cache;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
@@ -140,7 +141,13 @@
                     + "SchemaAction='drop,add')");
             } else if (props[i] instanceof Class<?>) {
                 types.add((Class<?>) props[i]);
-            } else if (props[i] != null) {
+            } 
+            else if (props[i] instanceof Class<?>[]) { 
+                for(Class<?> clss : (Class<?>[]) props[i]) { 
+                    types.add(clss);
+                }
+            }
+            else if (props[i] != null) {
                 prop = true;
             }
         }
@@ -559,5 +566,24 @@
     public String getPlatform() {
         return System.getProperty("platform", "derby");
     }
-
+    
+    /**
+     * Assert whether the Cache contains an instance of the specified class and id.
+     * 
+     * @param cache
+     *            The JPA Cache to verify
+     * @param clss
+     *            The Entity type
+     * @param id
+     *            ID of the entity
+     * @param expected
+     *            Whether the class should be found in the cache
+     */
+    protected void assertCached(Cache cache, Class<?> clss, Object id, boolean expected) {
+        if (expected) {
+            assertTrue(String.format("Expected %s:%s to exist in cache", clss, id), cache.contains(clss, id));
+        } else {
+            assertFalse(String.format("Expected %s:%s not to exist in cache", clss, id), cache.contains(clss, id));
+        }
+    }
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml Tue Aug 25 15:08:16 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
+    version="2.0">
+    <package>org.apache.openjpa.persistence.cache.jpa.model</package>
+<!--    <mapped-superclass class="BaseEntity"/>-->
+    <entity class="CacheableEntity"/>
+    <entity class="UncacheableEntity"/> 
+    <entity class="UnspecifiedEntity"/>
+    <entity class="NegatedCachableEntity" cacheable="false" />
+    <entity class="NegatedUncacheableEntity" cacheable="true"/>
+    <entity class="XmlUncacheableEntity" cacheable="false"/>
+    <entity class="XmlCacheableEntity" cacheable="true"/>
+ </entity-mappings>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-orm.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml?rev=807662&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml Tue Aug 25 15:08:16 2009
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.   
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0">
+    <!--  Caching Persistence Units -->
+    <persistence-unit name="cache-mode-all" transaction-type="RESOURCE_LOCAL">
+        <mapping-file>META-INF/caching-orm.xml</mapping-file>
+        <shared-cache-mode>ALL</shared-cache-mode>
+        <properties>
+            <!-- Connection info is passed in via system properties -->
+            <!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="cache-mode-none">
+        <mapping-file>META-INF/caching-orm.xml</mapping-file>
+        <shared-cache-mode>NONE</shared-cache-mode>
+        <properties>
+            <!-- Connection info is passed in via system properties -->
+            <!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="cache-mode-enable">
+        <mapping-file>META-INF/caching-orm.xml</mapping-file>
+        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
+        <properties>
+            <!-- Connection info is passed in via system properties -->
+            <!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="cache-mode-disable">
+        <mapping-file>META-INF/caching-orm.xml</mapping-file>
+        <shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
+        <properties>
+            <!-- Connection info is passed in via system properties -->
+            <!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="cache-mode-unspecified">
+        <mapping-file>META-INF/caching-orm.xml</mapping-file>
+        <shared-cache-mode>UNSPECIFIED</shared-cache-mode>
+        <properties>
+            <!-- Connection info is passed in via system properties -->
+            <!-- Cache configuration ie openjpa.DataCache is passed in at EMF initialization -->
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
+        </properties>
+    </persistence-unit>
+</persistence>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/caching-persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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=807662&r1=807661&r2=807662&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 Aug 25 15:08:16 2009
@@ -19,54 +19,7 @@
 package org.apache.openjpa.persistence;
 
 import static javax.persistence.GenerationType.AUTO;
-import static org.apache.openjpa.persistence.MetaDataTag.ACCESS;
-import static org.apache.openjpa.persistence.MetaDataTag.DATASTORE_ID;
-import static org.apache.openjpa.persistence.MetaDataTag.DATA_CACHE;
-import static org.apache.openjpa.persistence.MetaDataTag.DEPENDENT;
-import static org.apache.openjpa.persistence.MetaDataTag.DETACHED_STATE;
-import static org.apache.openjpa.persistence.MetaDataTag.ELEM_DEPENDENT;
-import static org.apache.openjpa.persistence.MetaDataTag.ELEM_TYPE;
-import static org.apache.openjpa.persistence.MetaDataTag.EMBEDDED_ID;
-import static org.apache.openjpa.persistence.MetaDataTag.ENTITY_LISTENERS;
-import static org.apache.openjpa.persistence.MetaDataTag.
-        EXCLUDE_DEFAULT_LISTENERS;
-import static org.apache.openjpa.persistence.MetaDataTag.
-        EXCLUDE_SUPERCLASS_LISTENERS;
-import static org.apache.openjpa.persistence.MetaDataTag.EXTERNALIZER;
-import static org.apache.openjpa.persistence.MetaDataTag.EXTERNAL_VALS;
-import static org.apache.openjpa.persistence.MetaDataTag.FACTORY;
-import static org.apache.openjpa.persistence.MetaDataTag.FETCH_GROUP;
-import static org.apache.openjpa.persistence.MetaDataTag.FETCH_GROUPS;
-import static org.apache.openjpa.persistence.MetaDataTag.FLUSH_MODE;
-import static org.apache.openjpa.persistence.MetaDataTag.GENERATED_VALUE;
-import static org.apache.openjpa.persistence.MetaDataTag.ID;
-import static org.apache.openjpa.persistence.MetaDataTag.ID_CLASS;
-import static org.apache.openjpa.persistence.MetaDataTag.INVERSE_LOGICAL;
-import static org.apache.openjpa.persistence.MetaDataTag.KEY_DEPENDENT;
-import static org.apache.openjpa.persistence.MetaDataTag.KEY_TYPE;
-import static org.apache.openjpa.persistence.MetaDataTag.LOAD_FETCH_GROUP;
-import static org.apache.openjpa.persistence.MetaDataTag.LRS;
-import static org.apache.openjpa.persistence.MetaDataTag.MANAGED_INTERFACE;
-import static org.apache.openjpa.persistence.MetaDataTag.MAPPED_BY_ID;
-import static org.apache.openjpa.persistence.MetaDataTag.MAP_KEY;
-import static org.apache.openjpa.persistence.MetaDataTag.MAP_KEY_CLASS;
-import static org.apache.openjpa.persistence.MetaDataTag.NATIVE_QUERIES;
-import static org.apache.openjpa.persistence.MetaDataTag.NATIVE_QUERY;
-import static org.apache.openjpa.persistence.MetaDataTag.ORDER_BY;
-import static org.apache.openjpa.persistence.MetaDataTag.POST_LOAD;
-import static org.apache.openjpa.persistence.MetaDataTag.POST_PERSIST;
-import static org.apache.openjpa.persistence.MetaDataTag.POST_REMOVE;
-import static org.apache.openjpa.persistence.MetaDataTag.POST_UPDATE;
-import static org.apache.openjpa.persistence.MetaDataTag.PRE_PERSIST;
-import static org.apache.openjpa.persistence.MetaDataTag.PRE_REMOVE;
-import static org.apache.openjpa.persistence.MetaDataTag.PRE_UPDATE;
-import static org.apache.openjpa.persistence.MetaDataTag.QUERIES;
-import static org.apache.openjpa.persistence.MetaDataTag.QUERY;
-import static org.apache.openjpa.persistence.MetaDataTag.READ_ONLY;
-import static org.apache.openjpa.persistence.MetaDataTag.REPLICATED;
-import static org.apache.openjpa.persistence.MetaDataTag.SEQ_GENERATOR;
-import static org.apache.openjpa.persistence.MetaDataTag.TYPE;
-import static org.apache.openjpa.persistence.MetaDataTag.VERSION;
+import static org.apache.openjpa.persistence.MetaDataTag.*;
 
 import java.io.File;
 import java.io.Serializable;
@@ -90,7 +43,10 @@
 import java.util.Stack;
 import java.util.TreeSet;
 
+import javax.persistence.Access;
+import javax.persistence.AccessType;
 import javax.persistence.Basic;
+import javax.persistence.Cacheable;
 import javax.persistence.CascadeType;
 import javax.persistence.ElementCollection;
 import javax.persistence.Embeddable;
@@ -190,6 +146,7 @@
 
     static {
         _tags.put(Access.class, ACCESS);
+        _tags.put(Cacheable.class, CACHEABLE);
         _tags.put(EmbeddedId.class, EMBEDDED_ID);
         _tags.put(EntityListeners.class, ENTITY_LISTENERS);
         _tags.put(ExcludeDefaultListeners.class, EXCLUDE_DEFAULT_LISTENERS);
@@ -653,6 +610,11 @@
                     if (isMetaDataMode())
                         parseAccess(meta, (Access)anno);
                     break;
+                case CACHEABLE: 
+                    if (isMetaDataMode()) { 
+                        parseCache(meta, (Cacheable) anno);
+                    }
+                    break;
                 default:
                     throw new UnsupportedException(_loc.get("unsupported", _cls,
                         anno.toString()));
@@ -849,15 +811,22 @@
      * Parse @DataCache.
      */
     private void parseDataCache(ClassMetaData meta, DataCache cache) {
-        if (cache.timeout() != Integer.MIN_VALUE)
+        if (cache.timeout() != Integer.MIN_VALUE) {
             meta.setDataCacheTimeout(cache.timeout());
-        if (!StringUtils.isEmpty(cache.name()))
+        }
+        if (!StringUtils.isEmpty(cache.name())) {
             meta.setDataCacheName(cache.name());
-        else if (cache.enabled())
-            meta.setDataCacheName(
-                org.apache.openjpa.datacache.DataCache.NAME_DEFAULT);
-        else
+            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);
+        }
     }
 
     private void parseManagedInterface(ClassMetaData meta,
@@ -1254,6 +1223,13 @@
      */
     protected void parseMemberMappingAnnotations(FieldMetaData fmd) {
     }
+    
+    /**
+     * Parse @Cache.
+     */
+    private void parseCache(ClassMetaData meta, Cacheable cacheable) {
+        meta.setCacheEnabled(cacheable.value());
+    }
 
     /**
      * Allow subclasses to handle unknown annotations.

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java?rev=807662&r1=807661&r2=807662&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java Tue Aug 25 15:08:16 2009
@@ -32,6 +32,7 @@
 public enum MetaDataTag {
     // sorted by XML order
     ACCESS,
+    CACHEABLE,
     MAPPED_SUPERCLASS,
     ENTITY,
     EMBEDDABLE,

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=807662&r1=807661&r2=807662&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 Aug 25 15:08:16 2009
@@ -730,6 +730,9 @@
                     if ("provider".equals(name))
                         _info.setPersistenceProviderClassName(currentText());
                     break;
+                case 's' : // shared-cache-mode
+                    _info.setSharedCacheMode(currentText());
+                    break;
                 case 'v': // validation-mode
                     _info.setValidationMode(Enum.valueOf(ValidationMode.class,
                         currentText()));

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java?rev=807662&r1=807661&r2=807662&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java Tue Aug 25 15:08:16 2009
@@ -41,6 +41,7 @@
 import javax.persistence.spi.PersistenceUnitTransactionType;
 import javax.sql.DataSource;
 
+import org.apache.openjpa.datacache.DataCacheMode;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.conf.ProductDerivations;
@@ -63,6 +64,13 @@
     public static final String VALIDATION_MODE =
         "javax.persistence.validation.mode";
     public static final String PERSISTENCE_VERSION = "PersistenceVersion";
+    
+    /**
+     * Properties key for the SHARED_CACHE_MODE. The JPA 2.0 spec
+     * SharedCacheMode maps to OpenJPA's DataCacheMode so we're using that
+     * class' simple name as the property key.
+     */
+    public static final String SHARED_CACHE_MODE=DataCacheMode.class.getSimpleName();  
 
     private static final Localizer s_loc = Localizer.forPackage
         (PersistenceUnitInfoImpl.class);
@@ -84,6 +92,7 @@
     private URL _persistenceXmlFile;
     private String _schemaVersion = "1.0";
     private ValidationMode _validationMode;
+    private SharedCacheMode _sharedCacheMode;
 
     // A persistence unit is defined by a persistence.xml file. The jar
     // file or directory whose META-INF directory contains the
@@ -299,29 +308,46 @@
                 setPersistenceProviderClassName((String) val);
             else if ("javax.persistence.transactionType".equals(key)) {
                 PersistenceUnitTransactionType ttype;
-                if (val instanceof String)
+                if (val instanceof String) {
                     ttype = Enum.valueOf(PersistenceUnitTransactionType.class, 
                         (String) val);
-                else
+                }
+                else {
                     ttype = (PersistenceUnitTransactionType) val;
+                }
                 setTransactionType(ttype);
             } else if ("javax.persistence.jtaDataSource".equals(key)) {
-                if (val instanceof String)
+                if (val instanceof String) {
                     setJtaDataSourceName((String) val);
-                else
+                }
+                else {
                     setJtaDataSource((DataSource) val);
+                }
             } else if ("javax.persistence.nonJtaDataSource".equals(key)) {
-                if (val instanceof String)
+                if (val instanceof String) {
                     setNonJtaDataSourceName((String) val);
-                else
+                }
+                else {
                     setNonJtaDataSource((DataSource) val);
+                }
             } else if (VALIDATION_MODE.equals(key)) {
-                if (val instanceof String)
+                if (val instanceof String) {
                     setValidationMode((String) val);
-                else
+                }
+                else {
                     setValidationMode((ValidationMode) val);
-            } else
+                }
+            } else if (SHARED_CACHE_MODE.equals(key)) { 
+               if(val instanceof String) { 
+                   setSharedCacheMode((String) val);
+               }
+               else {
+                   setSharedCacheMode((SharedCacheMode) val);
+               }
+            }
+            else {
                 _props.put(key, val);
+            }
         }
     }
 
@@ -465,6 +491,10 @@
             map.put(PERSISTENCE_VERSION, info.getPersistenceXMLSchemaVersion());
         }
         
+        if (info.getSharedCacheMode() != null) { 
+            put(map, added, SHARED_CACHE_MODE, info.getSharedCacheMode().toString());
+        }
+        
         return map;
     }
 
@@ -531,16 +561,6 @@
         _schemaVersion = version;
     }
 
-    public SharedCacheMode getCaching() {
-        throw new UnsupportedOperationException(
-            "JPA 2.0 - Method not yet implemented");
-    }
-    
-    public void setCaching(SharedCacheMode cache) {
-        throw new UnsupportedOperationException(
-        "JPA 2.0 - Method not yet implemented");
-    }
-
     public ValidationMode getValidationMode() {
         return _validationMode;
     }
@@ -554,6 +574,14 @@
     }
 
     public SharedCacheMode getSharedCacheMode() {
-        throw new UnsupportedOperationException("JPA 2.0 - Method not yet implemented");
+        return _sharedCacheMode;
+    }
+    
+    public void setSharedCacheMode(String mode) { 
+        setSharedCacheMode(Enum.valueOf(SharedCacheMode.class, mode.toUpperCase()));
+    }
+
+    public void setSharedCacheMode(SharedCacheMode mode) { 
+        _sharedCacheMode = mode;
     }
 }

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=807662&r1=807661&r2=807662&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 Aug 25 15:08:16 2009
@@ -897,6 +897,11 @@
                 addDeferredEmbeddableMetaData(_cls, access);
             }
         }
+        
+        if(attrs.getValue("cacheable") != null) { 
+            meta.setCacheEnabled(Boolean.valueOf(attrs.getValue("cacheable")));
+        }
+        
         if (isMappingMode())
             meta.setSourceMode(MODE_MAPPING, true);
         if (isMappingOverrideMode())



Mime
View raw message