Upgraded to JCache 0.11 for Spring Framework 4.0 RC1
Unfortunately, the JCache API changed quite a bit since 0.6. We're building against a snapshot of JCache 0.11 now, tracking its way to final after the Public Review Ballot.
This commit is contained in:
@@ -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.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.cache.jcache;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.cache.Status;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -28,6 +26,8 @@ import org.springframework.util.Assert;
|
||||
* {@link org.springframework.cache.Cache} implementation on top of a
|
||||
* {@link javax.cache.Cache} instance.
|
||||
*
|
||||
* <p>Note: This class has been updated for JCache 0.11, as of Spring 4.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
*/
|
||||
@@ -56,9 +56,6 @@ public class JCacheCache implements Cache {
|
||||
*/
|
||||
public JCacheCache(javax.cache.Cache<?,?> jcache, boolean allowNullValues) {
|
||||
Assert.notNull(jcache, "Cache must not be null");
|
||||
Status status = jcache.getStatus();
|
||||
Assert.isTrue(Status.STARTED.equals(status),
|
||||
"A 'started' cache is required - current cache is " + status.toString());
|
||||
this.cache = jcache;
|
||||
this.allowNullValues = allowNullValues;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -19,16 +19,17 @@ package org.springframework.cache.jcache;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Status;
|
||||
import javax.cache.Caching;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.cache.CacheManager} implementation
|
||||
* backed by a JCache {@link javax.cache.CacheManager}.
|
||||
*
|
||||
* <p>Note: This class has been updated for JCache 0.11, as of Spring 4.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
*/
|
||||
@@ -87,16 +88,20 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage
|
||||
return this.allowNullValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.cacheManager == null) {
|
||||
this.cacheManager = Caching.getCachingProvider().getCacheManager();
|
||||
}
|
||||
super.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Collection<Cache> loadCaches() {
|
||||
Assert.notNull(this.cacheManager, "A backing CacheManager is required");
|
||||
Status status = this.cacheManager.getStatus();
|
||||
Assert.isTrue(Status.STARTED.equals(status),
|
||||
"A 'started' JCache CacheManager is required - current cache is " + status.toString());
|
||||
|
||||
Collection<Cache> caches = new LinkedHashSet<Cache>();
|
||||
for (javax.cache.Cache<?,?> jcache : this.cacheManager.getCaches()) {
|
||||
for (String cacheName : this.cacheManager.getCacheNames()) {
|
||||
javax.cache.Cache jcache = this.cacheManager.getCache(cacheName);
|
||||
caches.add(new JCacheCache(jcache, this.allowNullValues));
|
||||
}
|
||||
return caches;
|
||||
|
||||
@@ -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.
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.cache.jcache;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -29,15 +32,19 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* obtaining a pre-defined CacheManager by name through the standard
|
||||
* JCache {@link javax.cache.Caching} class.
|
||||
*
|
||||
* <p>Note: This class has been updated for JCache 0.11, as of Spring 4.0.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
* @see javax.cache.Caching#getCacheManager()
|
||||
* @see javax.cache.Caching#getCacheManager(String)
|
||||
* @see javax.cache.Caching#getCachingProvider()
|
||||
* @see javax.cache.spi.CachingProvider#getCacheManager()
|
||||
*/
|
||||
public class JCacheManagerFactoryBean
|
||||
implements FactoryBean<CacheManager>, BeanClassLoaderAware, InitializingBean, DisposableBean {
|
||||
|
||||
private String cacheManagerName = Caching.DEFAULT_CACHE_MANAGER_NAME;
|
||||
private URI cacheManagerUri;
|
||||
|
||||
private Properties cacheManagerProperties;
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
@@ -45,12 +52,20 @@ public class JCacheManagerFactoryBean
|
||||
|
||||
|
||||
/**
|
||||
* Specify the name of the desired CacheManager.
|
||||
* Default is JCache's default.
|
||||
* @see Caching#DEFAULT_CACHE_MANAGER_NAME
|
||||
* Specify the URI for the desired CacheManager.
|
||||
* Default is {@code null} (i.e. JCache's default).
|
||||
*/
|
||||
public void setCacheManagerName(String cacheManagerName) {
|
||||
this.cacheManagerName = cacheManagerName;
|
||||
public void setCacheManagerUri(URI cacheManagerUri) {
|
||||
this.cacheManagerUri = cacheManagerUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify properties for the to-be-created CacheManager.
|
||||
* Default is {@code null} (i.e. no special properties to apply).
|
||||
* @see javax.cache.spi.CachingProvider#getCacheManager(URI, ClassLoader, Properties)
|
||||
*/
|
||||
public void setCacheManagerProperties(Properties cacheManagerProperties) {
|
||||
this.cacheManagerProperties = cacheManagerProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,9 +75,9 @@ public class JCacheManagerFactoryBean
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
this.cacheManager = (this.beanClassLoader != null ?
|
||||
Caching.getCacheManager(this.beanClassLoader, this.cacheManagerName) :
|
||||
Caching.getCacheManager(this.cacheManagerName));
|
||||
CachingProvider provider = Caching.getCachingProvider();
|
||||
this.cacheManager = provider.getCacheManager(
|
||||
this.cacheManagerUri, this.beanClassLoader, this.cacheManagerProperties);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +99,7 @@ public class JCacheManagerFactoryBean
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.cacheManager.shutdown();
|
||||
this.cacheManager.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user