diff --git a/build.gradle b/build.gradle index 293206a5f1..e4ebdd0ce3 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,6 @@ configure(allprojects) { project -> maven { url "http://repo.spring.io/libs-release" } maven { url "http://repo.spring.io/milestone" } // for AspectJ 1.8.0.M1 maven { url "https://repository.apache.org/content/repositories/releases" } // tomcat 8 - // maven { url "https://repository.apache.org/content/repositories/snapshots" } // tomcat 8 snapshots maven { url "https://maven.java.net/content/repositories/releases" } // javax.websocket, tyrus maven { url "https://oss.sonatype.org/content/repositories/releases" } // javax.cache } @@ -506,7 +505,7 @@ project("spring-context-support") { optional(project(":spring-jdbc")) // for Quartz support optional(project(":spring-tx")) // for Quartz support optional("javax.mail:mail:1.4.7") - optional("javax.cache:cache-api:1.0.0-PFD") + optional("javax.cache:cache-api:1.0.0-RC1") optional("com.google.guava:guava:14.0.1") optional("net.sf.ehcache:ehcache-core:2.6.5") optional("org.quartz-scheduler:quartz:1.8.6") { diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java index 72ae884a20..048581cfec 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java @@ -50,12 +50,12 @@ public class EhCacheCache implements Cache { @Override - public String getName() { + public final String getName() { return this.cache.getName(); } @Override - public Ehcache getNativeCache() { + public final Ehcache getNativeCache() { return this.cache; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java index 80ca887b9c..b6b538fa82 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag } /** - * Create a new EhCacheCacheManager for the given backing EhCache. + * Create a new EhCacheCacheManager for the given backing EhCache CacheManager. * @param cacheManager the backing EhCache {@link net.sf.ehcache.CacheManager} */ public EhCacheCacheManager(net.sf.ehcache.CacheManager cacheManager) { @@ -71,15 +71,16 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag @Override protected Collection loadCaches() { - Assert.notNull(this.cacheManager, "A backing EhCache CacheManager is required"); - Status status = this.cacheManager.getStatus(); + net.sf.ehcache.CacheManager cacheManager = getCacheManager(); + Assert.notNull(cacheManager, "A backing EhCache CacheManager is required"); + Status status = cacheManager.getStatus(); Assert.isTrue(Status.STATUS_ALIVE.equals(status), "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); - String[] names = this.cacheManager.getCacheNames(); + String[] names = cacheManager.getCacheNames(); Collection caches = new LinkedHashSet(names.length); for (String name : names) { - caches.add(new EhCacheCache(this.cacheManager.getEhcache(name))); + caches.add(new EhCacheCache(cacheManager.getEhcache(name))); } return caches; } @@ -90,7 +91,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag if (cache == null) { // check the EhCache cache again // (in case the cache was added at runtime) - Ehcache ehcache = this.cacheManager.getEhcache(name); + Ehcache ehcache = getCacheManager().getEhcache(name); if (ehcache != null) { cache = new EhCacheCache(ehcache); addCache(cache); diff --git a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java index f7525e598c..24b634935e 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java @@ -67,16 +67,16 @@ public class GuavaCache implements Cache { @Override - public String getName() { + public final String getName() { return this.name; } @Override - public com.google.common.cache.Cache getNativeCache() { + public final com.google.common.cache.Cache getNativeCache() { return this.cache; } - public boolean isAllowNullValues() { + public final boolean isAllowNullValues() { return this.allowNullValues; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCacheManager.java index cc08695006..2f83f5567b 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCacheManager.java @@ -26,7 +26,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilderSpec; import com.google.common.cache.CacheLoader; -import org.springframework.beans.factory.DisposableBean; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.util.Assert; @@ -49,7 +48,7 @@ import org.springframework.util.Assert; * @since 4.0 * @see GuavaCache */ -public class GuavaCacheManager implements CacheManager, DisposableBean { +public class GuavaCacheManager implements CacheManager { private final ConcurrentMap cacheMap = new ConcurrentHashMap(16); @@ -59,6 +58,8 @@ public class GuavaCacheManager implements CacheManager, DisposableBean { private CacheLoader cacheLoader; + private boolean allowNullValues = true; + /** * Construct a dynamic GuavaCacheManager, @@ -133,6 +134,24 @@ public class GuavaCacheManager implements CacheManager, DisposableBean { this.cacheLoader = cacheLoader; } + /** + * Specify whether to accept and convert {@code null} values for all caches + * in this cache manager. + *

Default is "true", despite Guava itself not supporting {@code null} values. + * An internal holder object will be used to store user-level {@code null}s. + */ + public void setAllowNullValues(boolean allowNullValues) { + this.allowNullValues = allowNullValues; + } + + /** + * Return whether this cache manager accepts and converts {@code null} values + * for all of its caches. + */ + public boolean isAllowNullValues() { + return this.allowNullValues; + } + @Override public Collection getCacheNames() { @@ -160,7 +179,7 @@ public class GuavaCacheManager implements CacheManager, DisposableBean { * @return the Spring GuavaCache adapter (or a decorator thereof) */ protected Cache createGuavaCache(String name) { - return new GuavaCache(name, createNativeGuavaCache(name)); + return new GuavaCache(name, createNativeGuavaCache(name), isAllowNullValues()); } /** @@ -177,12 +196,4 @@ public class GuavaCacheManager implements CacheManager, DisposableBean { } } - - @Override - public void destroy() { - for (Cache cache : this.cacheMap.values()) { - - } - } - } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java index c95cd6618f..b988be59e3 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java @@ -26,7 +26,7 @@ import org.springframework.util.Assert; * {@link org.springframework.cache.Cache} implementation on top of a * {@link javax.cache.Cache} instance. * - *

Note: This class has been updated for JCache 0.11, as of Spring 4.0. + *

Note: This class has been updated for JCache 1.0, as of Spring 4.0. * * @author Juergen Hoeller * @since 3.2 @@ -35,8 +35,7 @@ public class JCacheCache implements Cache { private static final Object NULL_HOLDER = new NullHolder(); - @SuppressWarnings("rawtypes") - private final javax.cache.Cache cache; + private final javax.cache.Cache cache; private final boolean allowNullValues; @@ -45,7 +44,7 @@ public class JCacheCache implements Cache { * Create an {@link org.springframework.cache.jcache.JCacheCache} instance. * @param jcache backing JCache Cache instance */ - public JCacheCache(javax.cache.Cache jcache) { + public JCacheCache(javax.cache.Cache jcache) { this(jcache, true); } @@ -54,7 +53,7 @@ public class JCacheCache implements Cache { * @param jcache backing JCache Cache instance * @param allowNullValues whether to accept and convert null values for this cache */ - public JCacheCache(javax.cache.Cache jcache, boolean allowNullValues) { + public JCacheCache(javax.cache.Cache jcache, boolean allowNullValues) { Assert.notNull(jcache, "Cache must not be null"); this.cache = jcache; this.allowNullValues = allowNullValues; @@ -62,21 +61,20 @@ public class JCacheCache implements Cache { @Override - public String getName() { + public final String getName() { return this.cache.getName(); } @Override - public javax.cache.Cache getNativeCache() { + public final javax.cache.Cache getNativeCache() { return this.cache; } - public boolean isAllowNullValues() { + public final boolean isAllowNullValues() { return this.allowNullValues; } @Override - @SuppressWarnings("unchecked") public ValueWrapper get(Object key) { Object value = this.cache.get(key); return (value != null ? new SimpleValueWrapper(fromStoreValue(value)) : null); @@ -93,13 +91,11 @@ public class JCacheCache implements Cache { } @Override - @SuppressWarnings("unchecked") public void put(Object key, Object value) { this.cache.put(key, toStoreValue(value)); } @Override - @SuppressWarnings("unchecked") public void evict(Object key) { this.cache.remove(key); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java index 71d41b6a5d..46574013a0 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java @@ -28,7 +28,7 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM * {@link org.springframework.cache.CacheManager} implementation * backed by a JCache {@link javax.cache.CacheManager}. * - *

Note: This class has been updated for JCache 0.11, as of Spring 4.0. + *

Note: This class has been updated for JCache 1.0, as of Spring 4.0. * * @author Juergen Hoeller * @since 3.2 @@ -71,17 +71,17 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage } /** - * Specify whether to accept and convert null values for all caches + * Specify whether to accept and convert {@code null} values for all caches * in this cache manager. - *

Default is "true", despite JSR-107 itself not supporting null values. - * An internal holder object will be used to store user-level null values. + *

Default is "true", despite JSR-107 itself not supporting {@code null} values. + * An internal holder object will be used to store user-level {@code null}s. */ public void setAllowNullValues(boolean allowNullValues) { this.allowNullValues = allowNullValues; } /** - * Return whether this cache manager accepts and converts null values + * Return whether this cache manager accepts and converts {@code null} values * for all of its caches. */ public boolean isAllowNullValues() { @@ -90,8 +90,8 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage @Override public void afterPropertiesSet() { - if (this.cacheManager == null) { - this.cacheManager = Caching.getCachingProvider().getCacheManager(); + if (getCacheManager() == null) { + setCacheManager(Caching.getCachingProvider().getCacheManager()); } super.afterPropertiesSet(); } @@ -100,9 +100,9 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage @Override protected Collection loadCaches() { Collection caches = new LinkedHashSet(); - for (String cacheName : this.cacheManager.getCacheNames()) { - javax.cache.Cache jcache = this.cacheManager.getCache(cacheName); - caches.add(new JCacheCache(jcache, this.allowNullValues)); + for (String cacheName : getCacheManager().getCacheNames()) { + javax.cache.Cache jcache = getCacheManager().getCache(cacheName); + caches.add(new JCacheCache(jcache, isAllowNullValues())); } return caches; } @@ -111,11 +111,10 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage public Cache getCache(String name) { Cache cache = super.getCache(name); if (cache == null) { - // check the JCache cache again - // (in case the cache was added at runtime) - javax.cache.Cache jcache = this.cacheManager.getCache(name); + // Check the JCache cache again (in case the cache was added at runtime) + javax.cache.Cache jcache = getCacheManager().getCache(name); if (jcache != null) { - cache = new JCacheCache(jcache, this.allowNullValues); + cache = new JCacheCache(jcache, isAllowNullValues()); addCache(cache); } } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java index a7787ac8fc..e8455931d0 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheManagerFactoryBean.java @@ -32,7 +32,7 @@ import org.springframework.beans.factory.InitializingBean; * obtaining a pre-defined CacheManager by name through the standard * JCache {@link javax.cache.Caching} class. * - *

Note: This class has been updated for JCache 0.11, as of Spring 4.0. + *

Note: This class has been updated for JCache 1.0, as of Spring 4.0. * * @author Juergen Hoeller * @since 3.2 diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index 7294b5bd63..58b384bac9 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -87,16 +87,16 @@ public class ConcurrentMapCache implements Cache { @Override - public String getName() { + public final String getName() { return this.name; } @Override - public ConcurrentMap getNativeCache() { + public final ConcurrentMap getNativeCache() { return this.store; } - public boolean isAllowNullValues() { + public final boolean isAllowNullValues() { return this.allowNullValues; } diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java index 6c87d7832b..5f69a828e5 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java @@ -47,6 +47,8 @@ public class ConcurrentMapCacheManager implements CacheManager { private boolean dynamic = true; + private boolean allowNullValues = true; + /** * Construct a dynamic ConcurrentMapCacheManager, @@ -78,6 +80,25 @@ public class ConcurrentMapCacheManager implements CacheManager { } } + /** + * Specify whether to accept and convert {@code null} values for all caches + * in this cache manager. + *

Default is "true", despite ConcurrentHashMap itself not supporting {@code null} + * values. An internal holder object will be used to store user-level {@code null}s. + */ + public void setAllowNullValues(boolean allowNullValues) { + this.allowNullValues = allowNullValues; + } + + /** + * Return whether this cache manager accepts and converts {@code null} values + * for all of its caches. + */ + public boolean isAllowNullValues() { + return this.allowNullValues; + } + + @Override public Collection getCacheNames() { return Collections.unmodifiableSet(this.cacheMap.keySet()); @@ -104,7 +125,7 @@ public class ConcurrentMapCacheManager implements CacheManager { * @return the ConcurrentMapCache (or a decorator thereof) */ protected Cache createConcurrentMapCache(String name) { - return new ConcurrentMapCache(name); + return new ConcurrentMapCache(name, isAllowNullValues()); } }