Merge branch '3.1.x'

This commit is contained in:
Chris Beams
2011-12-22 14:55:10 +01:00
74 changed files with 8670 additions and 8634 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.cache.aspectj; package org.springframework.cache.aspectj;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext;
@@ -30,4 +32,10 @@ public class AspectJAnnotationTest extends AbstractAnnotationTest {
protected ApplicationContext getApplicationContext() { protected ApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml"); return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml");
} }
@Test
public void testKeyStrategy() throws Exception {
AnnotationCacheAspect aspect = ctx.getBean("org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
}
} }

View File

@@ -0,0 +1,23 @@
/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import org.springframework.cache.interceptor.DefaultKeyGenerator;
public class SomeKeyGenerator extends DefaultKeyGenerator {
}

View File

@@ -23,7 +23,9 @@
<bean id="annotationSource" class="org.springframework.cache.annotation.AnnotationCacheOperationSource"/> <bean id="annotationSource" class="org.springframework.cache.annotation.AnnotationCacheOperationSource"/>
--> -->
<cache:annotation-driven mode="aspectj"/> <cache:annotation-driven mode="aspectj" key-generator="keyGenerator"/>
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches"> <property name="caches">

View File

@@ -76,7 +76,8 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
* Registers a * Registers a
* <pre> * <pre>
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf"> * <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
* <property name="cacheManagerBeanName" value="cacheManager"/> * <property name="cacheManager" ref="cacheManager"/>
* <property name="keyGenerator" ref="keyGenerator"/>
* </bean> * </bean>
* *
* </pre> * </pre>
@@ -89,6 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME); def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf"); def.setFactoryMethodName("aspectOf");
parseCacheManagerProperty(element, def); parseCacheManagerProperty(element, def);
CacheNamespaceHandler.parseKeyGenerator(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME)); parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME));
} }
} }

View File

@@ -97,6 +97,7 @@ class LazyParamAwareEvaluationContext extends StandardEvaluationContext {
// save arguments as indexed variables // save arguments as indexed variables
for (int i = 0; i < this.args.length; i++) { for (int i = 0; i < this.args.length; i++) {
setVariable("a" + i, this.args[i]);
setVariable("p" + i, this.args[i]); setVariable("p" + i, this.args[i]);
} }

View File

@@ -116,7 +116,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
return counter.getAndIncrement(); return counter.getAndIncrement();
} }
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(value = "secondary", key = "#p0"), @CacheEvict(value = "primary", key = "#p0 + 'A'") }) @Caching(evict = { @CacheEvict("primary"), @CacheEvict(value = "secondary", key = "#a0"), @CacheEvict(value = "primary", key = "#p0 + 'A'") })
public Object multiEvict(Object arg1) { public Object multiEvict(Object arg1) {
return counter.getAndIncrement(); return counter.getAndIncrement();
} }
@@ -126,7 +126,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
return counter.getAndIncrement(); return counter.getAndIncrement();
} }
@Caching(cacheable = { @Cacheable(value = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") }) @Caching(cacheable = { @Cacheable(value = "primary", condition = "#a0 == 3") }, evict = { @CacheEvict("secondary") })
public Object multiConditionalCacheAndEvict(Object arg1) { public Object multiConditionalCacheAndEvict(Object arg1) {
return counter.getAndIncrement(); return counter.getAndIncrement();
} }

View File

@@ -195,10 +195,10 @@ public Book findBook(String name)]]></programlisting>
<entry><screen>#root.targetClass</screen></entry> <entry><screen>#root.targetClass</screen></entry>
</row> </row>
<row> <row>
<entry>params</entry> <entry>args</entry>
<entry>root object</entry> <entry>root object</entry>
<entry>The arguments (as array) used for invoking the target</entry> <entry>The arguments (as array) used for invoking the target</entry>
<entry><screen>#root.params[0]</screen></entry> <entry><screen>#root.args[0]</screen></entry>
</row> </row>
<row> <row>
<entry>caches</entry> <entry>caches</entry>
@@ -207,12 +207,12 @@ public Book findBook(String name)]]></programlisting>
<entry><screen>#root.caches[0].name</screen></entry> <entry><screen>#root.caches[0].name</screen></entry>
</row> </row>
<row> <row>
<entry><emphasis>parameter name</emphasis></entry> <entry><emphasis>argument name</emphasis></entry>
<entry>evaluation context</entry> <entry>evaluation context</entry>
<entry>Name of any of the method parameter. If for some reason the names are not available (ex: no debug information), <entry>Name of any of the method argument. If for some reason the names are not available (ex: no debug information),
the parameter names are also available under the <literal><![CDATA[p<#arg>]]></literal> where the argument names are also available under the <literal><![CDATA[a<#arg>]]></literal> where
<emphasis><![CDATA[#arg]]></emphasis> stands for the parameter index (starting from 0).</entry> <emphasis><![CDATA[#arg]]></emphasis> stands for the argument index (starting from 0).</entry>
<entry><screen>iban</screen> or <screen>p0</screen></entry> <entry><screen>iban</screen> or <screen>a0</screen> (one can also use <screen>p0</screen> or <literal><![CDATA[p<#arg>]]></literal> notation as an alias).</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>