cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/2] cayenne git commit: CAY-2259 use "untyped" caches for storage in JCacheQueryCache implementation
Date Thu, 16 Mar 2017 11:45:46 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master e68d4640f -> 8ef8f1221


CAY-2259 use "untyped" caches for storage in JCacheQueryCache implementation


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/17db3b14
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/17db3b14
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/17db3b14

Branch: refs/heads/master
Commit: 17db3b1400f2986500e9bcaa206719bd9604be06
Parents: e68d464
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Mar 16 12:21:48 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Mar 16 12:21:48 2017 +0300

----------------------------------------------------------------------
 .../jcache/JCacheConfigurationFactory.java      |  2 +-
 .../JCacheDefaultConfigurationFactory.java      |  5 ++-
 .../cayenne/jcache/JCacheModuleProvider.java    |  5 ++-
 .../apache/cayenne/jcache/JCacheQueryCache.java | 33 ++++++++------------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 5 files changed, 21 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/17db3b14/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheConfigurationFactory.java
b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheConfigurationFactory.java
index e13c33a..8ca9f1f 100644
--- a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheConfigurationFactory.java
+++ b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheConfigurationFactory.java
@@ -30,6 +30,6 @@ import javax.cache.configuration.Configuration;
  */
 public interface JCacheConfigurationFactory {
 
-    Configuration<String, List> create(String cacheGroup);
+    Configuration<Object, Object> create(String cacheGroup);
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/17db3b14/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheDefaultConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheDefaultConfigurationFactory.java
b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheDefaultConfigurationFactory.java
index fa1d611..3cdde49 100644
--- a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheDefaultConfigurationFactory.java
+++ b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheDefaultConfigurationFactory.java
@@ -41,8 +41,7 @@ import javax.cache.expiry.Duration;
  */
 public class JCacheDefaultConfigurationFactory implements JCacheConfigurationFactory {
 
-    private final Configuration<String, List> configuration = new MutableConfiguration<String,
List>()
-            .setTypes(String.class, List.class)
+    private final Configuration<Object, Object> configuration = new MutableConfiguration<>()
             .setStoreByValue(false)
             .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
 
@@ -50,7 +49,7 @@ public class JCacheDefaultConfigurationFactory implements JCacheConfigurationFac
      * @param cacheGroup is unused by default configuration factory
      * @return cache configuration
      */
-    public Configuration<String, List> create(String cacheGroup) {
+    public Configuration<Object, Object> create(String cacheGroup) {
         return configuration;
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/17db3b14/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheModuleProvider.java
----------------------------------------------------------------------
diff --git a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheModuleProvider.java
b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheModuleProvider.java
index 34f9cca..f1f9d40 100644
--- a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheModuleProvider.java
+++ b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheModuleProvider.java
@@ -22,6 +22,7 @@ package org.apache.cayenne.jcache;
 import java.util.Collection;
 import java.util.Collections;
 
+import org.apache.cayenne.configuration.server.ServerModule;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.ModuleProvider;
 
@@ -40,8 +41,10 @@ public class JCacheModuleProvider implements ModuleProvider {
         return JCacheModule.class;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public Collection<Class<? extends Module>> overrides() {
-        return Collections.emptyList();
+        Collection modules = Collections.singletonList(ServerModule.class);
+        return modules;
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/17db3b14/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
----------------------------------------------------------------------
diff --git a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
index 90e059a..d10a83c 100644
--- a/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
+++ b/cayenne-jcache/src/main/java/org/apache/cayenne/jcache/JCacheQueryCache.java
@@ -24,31 +24,28 @@ import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.di.BeforeScopeEnd;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.QueryMetadata;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import javax.cache.Cache;
 import javax.cache.CacheException;
 import javax.cache.CacheManager;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 
 /**
  * @since 4.0
  */
 public class JCacheQueryCache implements QueryCache {
 
-    private static final Log LOGGER = LogFactory.getLog(JCacheQueryCache.class);
-
     @Inject
     protected CacheManager cacheManager;
 
     @Inject
     protected JCacheConfigurationFactory configurationFactory;
 
-    private ConcurrentMap<String, Object> seenCacheNames = new ConcurrentHashMap<>();
+    private Set<String> seenCacheNames = Collections.newSetFromMap(new ConcurrentHashMap<String,
Boolean>());
 
     @Override
     public List get(QueryMetadata metadata) {
@@ -96,17 +93,11 @@ public class JCacheQueryCache implements QueryCache {
 
     @Override
     public void clear() {
-        for(String name : seenCacheNames.keySet()) {
+        for (String name : seenCacheNames) {
             getCache(name).clear();
         }
     }
 
-    /**
-     * Returns -1 to indicate that we can't calculate the size. JCache and EhCache can potentially
have a complex topology
-     * that can not be meaningfully described by a single int. Use other means (like provider-specific
JMX) to monitor cache.
-     *
-     * @return -1
-     */
     @Override
     @Deprecated
     public int size() {
@@ -117,13 +108,14 @@ public class JCacheQueryCache implements QueryCache {
         return createIfAbsent(cacheName(metadata));
     }
 
+    @SuppressWarnings("unchecked")
     protected Cache<String, List> createIfAbsent(String cacheName) {
 
         Cache<String, List> cache = getCache(cacheName);
         if (cache == null) {
 
             try {
-                cache = cacheManager.createCache(cacheName, configurationFactory.create(cacheName));
+                cache = createCache(cacheName);
             } catch (CacheException e) {
                 // someone else just created this cache?
                 cache = getCache(cacheName);
@@ -133,14 +125,18 @@ public class JCacheQueryCache implements QueryCache {
                 }
             }
 
-            seenCacheNames.put(cacheName, 1);
+            seenCacheNames.add(cacheName);
         }
 
         return cache;
     }
 
+    protected Cache createCache(String cacheName) {
+        return cacheManager.createCache(cacheName, configurationFactory.create(cacheName));
+    }
+
     protected Cache<String, List> getCache(String name) {
-        return cacheManager.getCache(name, String.class, List.class);
+        return cacheManager.getCache(name);
     }
 
     protected String cacheName(QueryMetadata metadata) {
@@ -150,13 +146,10 @@ public class JCacheQueryCache implements QueryCache {
             return cacheGroup;
         }
 
-        // no explicit cache groups
+        // no explicit cache group
         return JCacheConstants.DEFAULT_CACHE_NAME;
     }
 
-    /**
-     * Shuts down CacheManager
-     */
     @BeforeScopeEnd
     public void shutdown() {
         cacheManager.close();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/17db3b14/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 12c9533..e168b10 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -17,6 +17,7 @@ CAY-1873 Move DataDomain cache configuration from the Modeler and into DI
 CAY-2258 DI: type-safe binding of List and Map
 CAY-2266 Move EventBridge implementations into autoloadable modules
 CAY-2267 Contribute lifecycle events listeners via DI
+CAY-2259 QueryCache: support for referencing type-safe caches
 
 Bug Fixes:
 


Mime
View raw message