commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1593769 - /commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.java
Date Sun, 11 May 2014 10:46:35 GMT
Author: rmannibucau
Date: Sun May 11 10:46:35 2014
New Revision: 1593769

URL: http://svn.apache.org/r1593769
Log:
configuration from openjpa properties for jcache datacache

Modified:
    commons/proper/jcs/trunk/commons-jcs-jcache-openjpa/src/main/java/org/apache/commons/jcs/jcache/openjpa/OpenJPAJCacheDataCacheManager.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=1593769&r1=1593768&r2=1593769&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 10:46:35 2014
@@ -30,7 +30,10 @@ import javax.cache.configuration.Mutable
 import javax.cache.expiry.CreatedExpiryPolicy;
 import javax.cache.expiry.Duration;
 import javax.cache.expiry.ExpiryPolicy;
+import javax.cache.integration.CacheLoader;
+import javax.cache.integration.CacheWriter;
 import javax.cache.spi.CachingProvider;
+import java.util.Map;
 import java.util.Properties;
 
 public class OpenJPAJCacheDataCacheManager extends DataCacheManagerImpl
@@ -43,8 +46,20 @@ public class OpenJPAJCacheDataCacheManag
     {
         super.initialize(conf, dataCache, queryCache);
         provider = Caching.getCachingProvider();
-        cacheManager = provider.getCacheManager(
-                provider.getDefaultURI(), provider.getDefaultClassLoader(), new Properties());
// todo get props
+
+        final Properties properties = new Properties();
+        final Map<String, Object> props = conf.toProperties(false);
+        if (props != null)
+        {
+            for (final Map.Entry<?, ?> entry : props.entrySet())
+            {
+                if (entry.getKey() != null && entry.getValue() != null)
+                {
+                    properties.setProperty(entry.getKey().toString(), entry.getValue().toString());
+                }
+            }
+        }
+        cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(),
properties);
     }
 
     @Override
@@ -57,14 +72,37 @@ public class OpenJPAJCacheDataCacheManag
 
     Cache<Object, Object> getOrCreateCache(final String prefix, final String entity)
     {
-        final String name = entity;
-        final String internalName = prefix + name;
+        final String internalName = prefix + entity;
         Cache<Object, Object> cache = cacheManager.getCache(internalName);
         if (cache == null)
         {
-            cache = cacheManager.createCache(internalName,
-                    new MutableConfiguration<Object, Object>().setStoreByValue(false)
-                            .setExpiryPolicyFactory(new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new
CreatedExpiryPolicy(Duration.FIVE_MINUTES))));
+            final Properties properties = cacheManager.getProperties();
+            final MutableConfiguration<Object, Object> configuration = new MutableConfiguration<Object,
Object>()
+                    .setStoreByValue("true".equalsIgnoreCase(properties.getProperty("jcache.store-by-value",
"false")));
+
+            configuration.setReadThrough("true".equals(properties.getProperty("jcache.read-through",
"false")));
+            configuration.setWriteThrough("true".equals(properties.getProperty("jcache.write-through",
"false")));
+            if (configuration.isReadThrough())
+            {
+                configuration.setCacheLoaderFactory(new FactoryBuilder.ClassFactory<CacheLoader<Object,
Object>>(properties.getProperty("jcache.cache-loader-factory")));
+            }
+            if (configuration.isWriteThrough())
+            {
+                configuration.setCacheWriterFactory(new FactoryBuilder.ClassFactory<CacheWriter<Object,
Object>>(properties.getProperty("jcache.cache-writer-factory")));
+            }
+            final String expirtyPolicy = properties.getProperty("jcache.expiry-policy-factory");
+            if (expirtyPolicy != null)
+            {
+                configuration.setExpiryPolicyFactory(new FactoryBuilder.ClassFactory<ExpiryPolicy>(expirtyPolicy));
+            }
+            else
+            {
+                configuration.setExpiryPolicyFactory(new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new
CreatedExpiryPolicy(Duration.FIVE_MINUTES)));
+            }
+            configuration.setManagementEnabled("true".equals(properties.getProperty("jcache.management-enabled",
"false")));
+            configuration.setStatisticsEnabled("true".equals(properties.getProperty("jcache.statistics-enabled",
"false")));
+
+            cache = cacheManager.createCache(internalName, configuration);
         }
         return cache;
     }



Mime
View raw message