You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rm...@apache.org on 2014/05/11 13:53:12 UTC

svn commit: r1593781 - in /commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src: main/java/org/apache/commons/jcs/jcache/openjpa/ test/java/org/apache/commons/jcs/jcache/openjpa/

Author: rmannibucau
Date: Sun May 11 11:53:12 2014
New Revision: 1593781

URL: http://svn.apache.org/r1593781
Log:
allowing to configure jcs uri and auto adjusting querycache and datacache if manager is jcache

Modified:
    commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java
    commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDerivation.java
    commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/test/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheTest.java

Modified: commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java?rev=1593781&r1=1593780&r2=1593781&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java Sun May 11 11:53:12 2014
@@ -33,6 +33,7 @@ import javax.cache.expiry.ExpiryPolicy;
 import javax.cache.integration.CacheLoader;
 import javax.cache.integration.CacheWriter;
 import javax.cache.spi.CachingProvider;
+import java.net.URI;
 import java.util.Map;
 import java.util.Properties;
 
@@ -59,7 +60,9 @@ public class OpenJPAJCacheDataCacheManag
                 }
             }
         }
-        cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), properties);
+
+        final String uri = properties.getProperty("jcache.uri", provider.getDefaultURI().toString());
+        cacheManager = provider.getCacheManager(URI.create(uri), provider.getDefaultClassLoader(), properties);
     }
 
     @Override

Modified: commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDerivation.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDerivation.java?rev=1593781&r1=1593780&r2=1593781&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDerivation.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDerivation.java Sun May 11 11:53:12 2014
@@ -23,25 +23,53 @@ import org.apache.openjpa.conf.OpenJPACo
 import org.apache.openjpa.event.SingleJVMRemoteCommitProvider;
 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.Configurations;
+
+import java.util.Map;
 
 public class OpenJPAJCacheDerivation extends AbstractProductDerivation
 {
+    private static final String JCACHE_NAME = "jcache";
+
     @Override
-    public boolean beforeConfigurationLoad(Configuration conf)
+    public boolean beforeConfigurationLoad(final Configuration conf)
     {
         if (OpenJPAConfiguration.class.isInstance(conf)) {
             final OpenJPAConfigurationImpl oconf = OpenJPAConfigurationImpl.class.cast(conf);
-            oconf.dataCacheManagerPlugin.setAlias("jcache", OpenJPAJCacheDataCacheManager.class.getName());
-            oconf.dataCachePlugin.setAlias("jcache", OpenJPAJCacheDataCache.class.getName());
-            oconf.queryCachePlugin.setAlias("jcache", OpenJPAJCacheQueryCache.class.getName());
-            oconf.remoteProviderPlugin.setAlias("none", SingleJVMRemoteCommitProvider .class.getName());
+            oconf.dataCacheManagerPlugin.setAlias(JCACHE_NAME, OpenJPAJCacheDataCacheManager.class.getName());
+            oconf.dataCachePlugin.setAlias(JCACHE_NAME, OpenJPAJCacheDataCache.class.getName());
+            oconf.queryCachePlugin.setAlias(JCACHE_NAME, OpenJPAJCacheQueryCache.class.getName());
+        }
+        return super.beforeConfigurationLoad(conf);
+    }
+
+    @Override
+    public boolean beforeConfigurationConstruct(final ConfigurationProvider cp)
+    {
+        final Map<?, ?> props = cp.getProperties();
+        final Object dcm = Configurations.getProperty("DataCacheManager", props);
+        if (dcm != null && JCACHE_NAME.equals(dcm))
+        {
+            if (Configurations.getProperty("DataCache", props) == null)
+            {
+                cp.addProperty("openjpa.DataCache", JCACHE_NAME);
+            }
+            if (Configurations.getProperty("QueryCache", props) == null)
+            {
+                cp.addProperty("openjpa.QueryCache", JCACHE_NAME);
+            }
+            if (Configurations.getProperty("RemoteCommitProvider", props) == null)
+            {
+                cp.addProperty("openjpa.RemoteCommitProvider", SingleJVMRemoteCommitProvider.class.getName());
+            }
         }
-        return false;
+        return super.beforeConfigurationConstruct(cp);
     }
 
     @Override
     public int getType()
     {
-        return 0;
+        return TYPE_FEATURE;
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/test/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/test/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheTest.java?rev=1593781&r1=1593780&r2=1593781&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/test/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheTest.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/test/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheTest.java Sun May 11 11:53:12 2014
@@ -51,9 +51,11 @@ public class OpenJPAJCacheDataCacheTest
         setProperty("openjpa.ConnectionURL", "jdbc:derby:memory:test;create=true");
         setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema");
         setProperty("openjpa.DataCacheManager", "jcache");
-        setProperty("openjpa.DataCache", "jcache");
-        setProperty("openjpa.QueryCache", "jcache");
         setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
+
+        // implicit
+        // setProperty("openjpa.DataCache", "jcache");
+        // setProperty("openjpa.QueryCache", "jcache");
     }};
 
     @Test