Browse Source
SPR-8082 SPR-7833 + add support for CacheDefinitions declarations inside XML + more integration testspull/7/head
20 changed files with 497 additions and 175 deletions
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/cache" |
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
||||
xmlns:beans="http://www.springframework.org/schema/beans" |
||||
xmlns:tool="http://www.springframework.org/schema/tool" |
||||
targetNamespace="http://www.springframework.org/schema/cache" |
||||
elementFormDefault="qualified" |
||||
attributeFormDefault="unqualified"> |
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"/> |
||||
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-3.0.xsd"/> |
||||
|
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
Defines the elements used in the Spring Framework's declarative |
||||
cache management infrastructure. |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
|
||||
<xsd:element name="annotation-driven"> |
||||
<xsd:complexType> |
||||
<xsd:annotation> |
||||
<xsd:documentation source="java:org.springframework.cache.annotation.AnnotationCacheOperationDefinitionSource"><![CDATA[ |
||||
Indicates that cache configuration is defined by Java 5 |
||||
annotations on bean classes, and that proxies are automatically |
||||
to be created for the relevant annotated beans. |
||||
|
||||
The default annotations supported are Spring's @Cacheable and @CacheEvict. |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:attribute name="cache-manager" type="xsd:string" default="cacheManager"> |
||||
<xsd:annotation> |
||||
<xsd:documentation source="java:org.springframework.cache.CacheManager"><![CDATA[ |
||||
The bean name of the CacheManager that is to be used to retrieve the backing caches. |
||||
|
||||
This attribute is not required, and only needs to be specified |
||||
explicitly if the bean name of the desired CacheManager |
||||
is not 'cacheManager'. |
||||
]]></xsd:documentation> |
||||
<xsd:appinfo> |
||||
<tool:annotation kind="ref"> |
||||
<tool:expected-type type="org.springframework.cache.CacheManager"/> |
||||
</tool:annotation> |
||||
</xsd:appinfo> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
<xsd:attribute name="key-generator" type="xsd:string"> |
||||
<xsd:annotation> |
||||
<xsd:documentation source="java:org.springframework.cache.interceptor.KeyGenerator"><![CDATA[ |
||||
The bean name of the KeyGenerator that is to be used to retrieve the backing caches. |
||||
|
||||
This attribute is not required, and only needs to be specified |
||||
explicitly if the default strategy (DefaultKeyGenerator) is not sufficient. |
||||
]]></xsd:documentation> |
||||
<xsd:appinfo> |
||||
<tool:annotation kind="ref"> |
||||
<tool:expected-type type="org.springframework.cache.interceptor.KeyGenerator"/> |
||||
</tool:annotation> |
||||
</xsd:appinfo> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
<xsd:attribute name="mode" default="proxy"> |
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
Should annotated beans be proxied using Spring's AOP framework, |
||||
or should they rather be weaved with an AspectJ transaction aspect? |
||||
|
||||
AspectJ weaving requires spring-aspects.jar on the classpath, |
||||
as well as load-time weaving (or compile-time weaving) enabled. |
||||
|
||||
Note: The weaving-based aspect requires the @Cacheable and @CacheInvalidate |
||||
annotations to be defined on the concrete class. Annotations in interfaces |
||||
will not work in that case (they will rather only work with interface-based proxies)! |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:simpleType> |
||||
<xsd:restriction base="xsd:string"> |
||||
<xsd:enumeration value="proxy"/> |
||||
<xsd:enumeration value="aspectj"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
</xsd:attribute> |
||||
<xsd:attribute name="proxy-target-class" type="xsd:boolean" default="false"> |
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
Are class-based (CGLIB) proxies to be created? By default, standard |
||||
Java interface-based proxies are created. |
||||
|
||||
Note: Class-based proxies require the @Cacheable and @CacheInvalidate annotations |
||||
to be defined on the concrete class. Annotations in interfaces will not work |
||||
in that case (they will rather only work with interface-based proxies)! |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
<xsd:attribute name="order" type="xsd:int"> |
||||
<xsd:annotation> |
||||
<xsd:documentation source="java:org.springframework.core.Ordered"><![CDATA[ |
||||
Controls the ordering of the execution of the cache advisor |
||||
when multiple advice executes at a specific joinpoint. |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
|
||||
</xsd:schema> |
||||
@ -1,84 +0,0 @@
@@ -1,84 +0,0 @@
|
||||
/* |
||||
* Copyright 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.interceptor; |
||||
|
||||
import java.beans.PropertyEditorSupport; |
||||
|
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* PropertyEditor for {@link CacheOperation} objects. Accepts a String of form |
||||
* <p><tt>action,cache,key,condition</tt> |
||||
* <p>where only action and cache are required. Available definitions for action are |
||||
* <tt>cacheable</tt> and <tt>evict</tt>. |
||||
* When specifying multiple caches, use ; as a separator |
||||
* |
||||
* A typical example would be: |
||||
* <p><code>cacheable, orders;books, #p0</code> |
||||
* |
||||
* <p>The tokens need to be specified in the order above. |
||||
* |
||||
* @author Costin Leau |
||||
* |
||||
* @see org.springframework.transaction.TransactionAttributeEditor |
||||
* @see org.springframework.core.Constants |
||||
*/ |
||||
public class CacheOperationEditor extends PropertyEditorSupport { |
||||
|
||||
/** |
||||
* Format is action, cache, key, condition. |
||||
* Null or the empty string means that the method is non cacheable. |
||||
* @see java.beans.PropertyEditor#setAsText(java.lang.String) |
||||
*/ |
||||
@Override |
||||
public void setAsText(String text) throws IllegalArgumentException { |
||||
if (StringUtils.hasLength(text)) { |
||||
// tokenize it with ","
|
||||
String[] tokens = StringUtils.commaDelimitedListToStringArray(text); |
||||
if (tokens.length < 2) { |
||||
throw new IllegalArgumentException( |
||||
"too little arguments found, at least the cache action and cache name are required"); |
||||
} |
||||
|
||||
CacheOperation op; |
||||
|
||||
if ("cacheable".contains(tokens[0])) { |
||||
op = new CacheableOperation(); |
||||
} |
||||
|
||||
else if ("evict".contains(tokens[0])) { |
||||
op = new CacheEvictOperation(); |
||||
} else { |
||||
throw new IllegalArgumentException("Invalid cache action specified " + tokens[0]); |
||||
} |
||||
|
||||
op.setCacheNames(StringUtils.delimitedListToStringArray(tokens[1], ";")); |
||||
|
||||
if (tokens.length > 2) { |
||||
op.setKey(tokens[2]); |
||||
} |
||||
|
||||
if (tokens.length > 3) { |
||||
op.setCondition(tokens[3]); |
||||
} |
||||
|
||||
setValue(op); |
||||
} else { |
||||
setValue(null); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue