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 2010/02/11 18:38:11 UTC

svn commit: r909091 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestCacheExclusions.java

Author: ppoddar
Date: Thu Feb 11 17:37:53 2010
New Revision: 909091

URL: http://svn.apache.org/viewvc?rev=909091&view=rev
Log:
OPENJPA-1334: Emulate 1.2 versions IncludedTypes/ExcludedTypes functionality via new distribution policy mechanics

Modified:
    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/datacache/TestCacheExclusions.java

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=909091&r1=909090&r2=909091&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 Thu Feb 11 17:37:53 2010
@@ -152,8 +152,7 @@
     private int _resMode = MODE_NONE;
 
     private Class<?> _type = Object.class;
-    private final Map<String,FieldMetaData> _fieldMap = 
-    	new TreeMap<String,FieldMetaData>();
+    private final Map<String,FieldMetaData> _fieldMap = new TreeMap<String,FieldMetaData>();
     private Map<String,FieldMetaData> _supFieldMap = null;
     private boolean _defSupFields = false;
     private Collection<String> _staticFields = null;
@@ -183,6 +182,9 @@
     private String _seqName = DEFAULT_STRING;
     private SequenceMetaData _seqMeta = null;
     private String _cacheName = DEFAULT_STRING; // null implies @DataCache(enabled=false)
+    private boolean _dataCacheEnabled = false;     // true implies the class has been annotated by the user or name of
+                                                // the cache is explicitly set by the user to a null string
+
     private Boolean _cacheEnabled = null;       // denotes status of JPA 2 @Cacheable annotation
     private int _cacheTimeout = Integer.MIN_VALUE;
     private Boolean _detachable = null;
@@ -1429,7 +1431,7 @@
         }
         return _cacheName;
     }
-
+    
     /**
      * Set the cache name for this class. 
      * 
@@ -1437,6 +1439,16 @@
      */
     public void setDataCacheName(String name) {
         _cacheName = name;
+        if (name != null)
+            _dataCacheEnabled = true;
+    }
+    
+    /**
+     * Affirms true if this receiver is annotated with @DataCache and is not disabled. 
+     * A separate state variable is necessary besides the name of the cache defaulted to a special string.
+     */
+    public boolean getDataCacheEnabled() {
+        return _dataCacheEnabled;
     }
 
     /**
@@ -2430,6 +2442,7 @@
         if (_cacheTimeout == Integer.MIN_VALUE)
             _cacheTimeout = meta.getDataCacheTimeout();
         _cacheEnabled = meta.getCacheEnabled();
+        _dataCacheEnabled = meta.getDataCacheEnabled();
         if (_detachable == null)
             _detachable = meta._detachable;
         if (DEFAULT_STRING.equals(_detachState))

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=909091&r1=909090&r2=909091&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 Thu Feb 11 17:37:53 2010
@@ -28,9 +28,10 @@
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 import org.apache.openjpa.persistence.StoreCache;
+import org.apache.openjpa.persistence.test.AbstractCachedEMFTestCase;
 import org.apache.openjpa.persistence.test.PersistenceTestCase;
 
-public class TestCacheExclusions extends PersistenceTestCase {
+public class TestCacheExclusions extends AbstractCachedEMFTestCase {
 
     private OpenJPAEntityManagerFactorySPI emf = null;
 
@@ -80,12 +81,10 @@
             for (ClassMapping mapping : ((ClassMapping[]) emf
                 .getConfiguration().getMetaDataRepositoryInstance()
                 .getMetaDatas())) {
-                if (mapping.getTable() != null) {
-                    Query q =
-                        em.createNativeQuery("DROP TABLE "
-                            + mapping.getTable().getName());
-                    q.executeUpdate();
-                }
+                Query q =
+                    em.createNativeQuery("DROP TABLE "
+                        + mapping.getTable().getName());
+                q.executeUpdate();
             }
             em.getTransaction().commit();
             em.close();
@@ -107,7 +106,7 @@
         getEntityManagerFactoryCacheSettings(new Class[] { Item.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, true, true);
+        assertCacheContents(cache, false, false, true);
     }
 
     public void testCacheItemsAndPurchases() {
@@ -115,7 +114,7 @@
             Purchase.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, true, true);
+        assertCacheContents(cache, true, false, true);
     }
 
     public void testCacheItemsAndOrders() {
@@ -123,7 +122,7 @@
             Order.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, true, true);
+        assertCacheContents(cache, false, true, true);
     }
 
     public void testCachePurchasesAndOrders() {
@@ -131,7 +130,7 @@
             Order.class }, null);
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, true, true, true);
+        assertCacheContents(cache, true, true, false);
     }
 
     public void testExcludePurchases() {
@@ -169,7 +168,7 @@
             Item.class }, new Class[] { Purchase.class });
         populate();
         StoreCache cache = emf.getStoreCache();
-        assertCacheContents(cache, false, true, true);
+        assertCacheContents(cache, false, false, true);
     }
 
     public OpenJPAEntityManagerFactorySPI getEntityManagerFactoryCacheSettings(
@@ -193,21 +192,17 @@
             excludes.setLength(excludes.length() - 1); // remove last semicolon
         }
         StringBuilder dataCacheSettings = new StringBuilder();
-        dataCacheSettings.append("default");
-        
-        StringBuilder policySettings = new StringBuilder();
-        if (includes.length() > 0 || excludes.length() > 0) {
-            policySettings.append("type-based(");
-            policySettings.append(includes);
-            if (includes.length() > 0 && excludes.length() > 0) {
-                policySettings.append(",");
-            }
-            policySettings.append(excludes);
-            policySettings.append(")");
+        boolean hasIncludeOrExclude = includes.length() > 0 || excludes.length() > 0;
+        dataCacheSettings.append(hasIncludeOrExclude ? "type-based(" : "default");
+        if (hasIncludeOrExclude) {
+            dataCacheSettings.append(includes);
+            if (includes.length() > 0 && excludes.length() > 0) 
+                dataCacheSettings.append(",");
+            dataCacheSettings.append(excludes);
+            dataCacheSettings.append(")");
         }
         Map<String, String> props = new HashMap<String, String>();
-        props.put("openjpa.DataCacheManager", dataCacheSettings.toString());
-        props.put("openjpa.CacheDistributionPolicy", policySettings.toString());
+        props.put("openjpa.CacheDistributionPolicy", dataCacheSettings.toString());
         props.put("openjpa.DataCache", "true");
         props.put("openjpa.RemoteCommitProvider", "sjvm");
         props.put("openjpa.MetaDataFactory", "jpa(Types="