You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/03/16 11:45:46 UTC
[1/2] cayenne git commit: CAY-2259 use "untyped" caches for storage
in JCacheQueryCache implementation
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 <st...@gmail.com>
Authored: Thu Mar 16 12:21:48 2017 +0300
Committer: Nikita Timofeev <st...@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:
[2/2] cayenne git commit: Make CacheGroupHandler optional in
CacheInvalidationModuleBuilder
Posted by nt...@apache.org.
Make CacheGroupHandler optional in CacheInvalidationModuleBuilder
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/8ef8f122
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/8ef8f122
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/8ef8f122
Branch: refs/heads/master
Commit: 8ef8f12218c48487dbe711a8e5cfe831b1c96a9e
Parents: 17db3b1
Author: Nikita Timofeev <st...@gmail.com>
Authored: Thu Mar 16 14:44:12 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Thu Mar 16 14:44:12 2017 +0300
----------------------------------------------------------------------
.../cache/CacheInvalidationModuleBuilder.java | 15 +++++++++++++--
.../lifecycle/unit/CacheInvalidationCase.java | 2 +-
2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/8ef8f122/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/cache/CacheInvalidationModuleBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/cache/CacheInvalidationModuleBuilder.java b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/cache/CacheInvalidationModuleBuilder.java
index 881444d..92d7993 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/cache/CacheInvalidationModuleBuilder.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/cache/CacheInvalidationModuleBuilder.java
@@ -22,7 +22,6 @@ package org.apache.cayenne.lifecycle.cache;
import java.util.Collection;
import java.util.HashSet;
-import org.apache.cayenne.configuration.Constants;
import org.apache.cayenne.configuration.server.ServerModule;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.ListBuilder;
@@ -40,6 +39,8 @@ public class CacheInvalidationModuleBuilder {
private Collection<InvalidationHandler> handlerInstances;
+ private boolean noCacheGroupsHandler;
+
public static CacheInvalidationModuleBuilder builder() {
return new CacheInvalidationModuleBuilder();
}
@@ -53,6 +54,14 @@ public class CacheInvalidationModuleBuilder {
this.handlerInstances = new HashSet<>();
}
+ /**
+ * Disable {@link CacheGroupsHandler} based on {@link CacheGroups} annotation.
+ */
+ public CacheInvalidationModuleBuilder noCacheGroupsHandler() {
+ noCacheGroupsHandler = true;
+ return this;
+ }
+
public CacheInvalidationModuleBuilder invalidationHandler(Class<? extends InvalidationHandler> handlerType) {
handlerTypes.add(handlerType);
return this;
@@ -69,7 +78,9 @@ public class CacheInvalidationModuleBuilder {
public void configure(Binder binder) {
ListBuilder<InvalidationHandler> handlers = contributeInvalidationHandler(binder);
- handlers.add(CacheGroupsHandler.class);
+ if(!noCacheGroupsHandler) {
+ handlers.add(CacheGroupsHandler.class);
+ }
handlers.addAll(handlerInstances);
for(Class<? extends InvalidationHandler> handlerType : handlerTypes) {
http://git-wip-us.apache.org/repos/asf/cayenne/blob/8ef8f122/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/unit/CacheInvalidationCase.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/unit/CacheInvalidationCase.java b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/unit/CacheInvalidationCase.java
index 2d17220..1350ce4 100644
--- a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/unit/CacheInvalidationCase.java
+++ b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/unit/CacheInvalidationCase.java
@@ -25,7 +25,6 @@ import org.apache.cayenne.Persistent;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.configuration.server.ServerRuntimeBuilder;
import org.apache.cayenne.di.Module;
-import org.apache.cayenne.lifecycle.cache.CacheGroups;
import org.apache.cayenne.lifecycle.cache.CacheInvalidationModuleBuilder;
import org.apache.cayenne.lifecycle.cache.InvalidationFunction;
import org.apache.cayenne.lifecycle.cache.InvalidationHandler;
@@ -53,6 +52,7 @@ public class CacheInvalidationCase {
protected ServerRuntimeBuilder configureCayenne() {
Module cacheInvalidationModule = CacheInvalidationModuleBuilder
.builder()
+ .noCacheGroupsHandler()
.invalidationHandler(G1InvalidationHandler.class)
.build();