Polishing
This commit is contained in:
@@ -412,8 +412,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessBeforeInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessBeforeInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
@@ -427,8 +427,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessAfterInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessAfterInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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,6 +19,7 @@ package org.springframework.cache.annotation;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -68,8 +69,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
|
||||
*/
|
||||
public AnnotationCacheOperationSource(boolean publicMethodsOnly) {
|
||||
this.publicMethodsOnly = publicMethodsOnly;
|
||||
this.annotationParsers = new LinkedHashSet<>(1);
|
||||
this.annotationParsers.add(new SpringCacheAnnotationParser());
|
||||
this.annotationParsers = Collections.singleton(new SpringCacheAnnotationParser());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +89,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
|
||||
public AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers) {
|
||||
this.publicMethodsOnly = true;
|
||||
Assert.notEmpty(annotationParsers, "At least one CacheAnnotationParser needs to be specified");
|
||||
Set<CacheAnnotationParser> parsers = new LinkedHashSet<>(annotationParsers.length);
|
||||
Collections.addAll(parsers, annotationParsers);
|
||||
this.annotationParsers = parsers;
|
||||
this.annotationParsers = new LinkedHashSet<>(Arrays.asList(annotationParsers));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,23 +105,22 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Collection<CacheOperation> findCacheOperations(final Class<?> clazz) {
|
||||
protected Collection<CacheOperation> findCacheOperations(Class<?> clazz) {
|
||||
return determineCacheOperations(parser -> parser.parseCacheAnnotations(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Collection<CacheOperation> findCacheOperations(final Method method) {
|
||||
protected Collection<CacheOperation> findCacheOperations(Method method) {
|
||||
return determineCacheOperations(parser -> parser.parseCacheAnnotations(method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the cache operation(s) for the given {@link CacheOperationProvider}.
|
||||
* <p>This implementation delegates to configured
|
||||
* {@link CacheAnnotationParser}s for parsing known annotations into
|
||||
* Spring's metadata attribute class.
|
||||
* <p>Can be overridden to support custom annotations that carry
|
||||
* caching metadata.
|
||||
* {@link CacheAnnotationParser CacheAnnotationParsers}
|
||||
* for parsing known annotations into Spring's metadata attribute class.
|
||||
* <p>Can be overridden to support custom annotations that carry caching metadata.
|
||||
* @param provider the cache operation provider to use
|
||||
* @return the configured caching operations, or {@code null} if none found
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.context.annotation.Role;
|
||||
* to enable proxy-based annotation-driven cache management.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see EnableCaching
|
||||
* @see CachingConfigurationSelector
|
||||
@@ -41,8 +42,7 @@ public class ProxyCachingConfiguration extends AbstractCachingConfiguration {
|
||||
@Bean(name = CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public BeanFactoryCacheOperationSourceAdvisor cacheAdvisor() {
|
||||
BeanFactoryCacheOperationSourceAdvisor advisor =
|
||||
new BeanFactoryCacheOperationSourceAdvisor();
|
||||
BeanFactoryCacheOperationSourceAdvisor advisor = new BeanFactoryCacheOperationSourceAdvisor();
|
||||
advisor.setCacheOperationSource(cacheOperationSource());
|
||||
advisor.setAdvice(cacheInterceptor());
|
||||
if (this.enableCaching != null) {
|
||||
|
||||
@@ -228,8 +228,8 @@ public class AnnotatedElementUtils {
|
||||
return hasMetaAnnotationTypes(element, null, annotationName);
|
||||
}
|
||||
|
||||
private static boolean hasMetaAnnotationTypes(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName) {
|
||||
private static boolean hasMetaAnnotationTypes(
|
||||
AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType, @Nullable String annotationName) {
|
||||
|
||||
return Boolean.TRUE.equals(
|
||||
searchWithGetSemantics(element, annotationType, annotationName, new SimpleAnnotationProcessor<Boolean>() {
|
||||
@@ -1007,7 +1007,7 @@ public class AnnotatedElementUtils {
|
||||
|
||||
if (containerType != null && !processor.aggregates()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Searches for repeatable annotations must supply an aggregating Processor");
|
||||
"Searches for repeatable annotations must supply an aggregating Processor");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -982,7 +982,7 @@ public abstract class StringUtils {
|
||||
/**
|
||||
* Trim the elements of the given {@code String} array,
|
||||
* calling {@code String.trim()} on each of them.
|
||||
* @param array the original {@code String} array
|
||||
* @param array the original {@code String} array (potentially empty)
|
||||
* @return the resulting array (of the same size) with trimmed elements
|
||||
*/
|
||||
public static String[] trimArrayElements(@Nullable String[] array) {
|
||||
@@ -1001,7 +1001,7 @@ public abstract class StringUtils {
|
||||
/**
|
||||
* Remove duplicate strings from the given array.
|
||||
* <p>As of 4.2, it preserves the original order, as it uses a {@link LinkedHashSet}.
|
||||
* @param array the {@code String} array
|
||||
* @param array the {@code String} array (potentially empty)
|
||||
* @return an array without duplicates, in natural sort order
|
||||
*/
|
||||
public static String[] removeDuplicateStrings(String[] array) {
|
||||
@@ -1009,18 +1009,15 @@ public abstract class StringUtils {
|
||||
return array;
|
||||
}
|
||||
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
for (String element : array) {
|
||||
set.add(element);
|
||||
}
|
||||
Set<String> set = new LinkedHashSet<>(Arrays.asList(array));
|
||||
return toStringArray(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a {@code String} at the first occurrence of the delimiter.
|
||||
* Does not include the delimiter in the result.
|
||||
* @param toSplit the string to split
|
||||
* @param delimiter to split the string up with
|
||||
* @param toSplit the string to split (potentially {@code null} or empty)
|
||||
* @param delimiter to split the string up with (potentially {@code null} or empty)
|
||||
* @return a two element array with index 0 being before the delimiter, and
|
||||
* index 1 being after the delimiter (neither element includes the delimiter);
|
||||
* or {@code null} if the delimiter wasn't found in the given input {@code String}
|
||||
@@ -1099,7 +1096,7 @@ public abstract class StringUtils {
|
||||
* delimiter characters. Each of those characters can be used to separate
|
||||
* tokens. A delimiter is always a single character; for multi-character
|
||||
* delimiters, consider using {@link #delimitedListToStringArray}.
|
||||
* @param str the {@code String} to tokenize
|
||||
* @param str the {@code String} to tokenize (potentially {@code null} or empty)
|
||||
* @param delimiters the delimiter characters, assembled as a {@code String}
|
||||
* (each of the characters is individually considered as a delimiter)
|
||||
* @return an array of the tokens
|
||||
@@ -1118,7 +1115,7 @@ public abstract class StringUtils {
|
||||
* delimiter characters. Each of those characters can be used to separate
|
||||
* tokens. A delimiter is always a single character; for multi-character
|
||||
* delimiters, consider using {@link #delimitedListToStringArray}.
|
||||
* @param str the {@code String} to tokenize
|
||||
* @param str the {@code String} to tokenize (potentially {@code null} or empty)
|
||||
* @param delimiters the delimiter characters, assembled as a {@code String}
|
||||
* (each of the characters is individually considered as a delimiter)
|
||||
* @param trimTokens trim the tokens via {@link String#trim()}
|
||||
@@ -1158,7 +1155,7 @@ public abstract class StringUtils {
|
||||
* but it will still be considered as a single delimiter string, rather
|
||||
* than as bunch of potential delimiter characters, in contrast to
|
||||
* {@link #tokenizeToStringArray}.
|
||||
* @param str the input {@code String}
|
||||
* @param str the input {@code String} (potentially {@code null} or empty)
|
||||
* @param delimiter the delimiter between elements (this is a single delimiter,
|
||||
* rather than a bunch individual delimiter characters)
|
||||
* @return an array of the tokens in the list
|
||||
@@ -1175,7 +1172,7 @@ public abstract class StringUtils {
|
||||
* but it will still be considered as a single delimiter string, rather
|
||||
* than as bunch of potential delimiter characters, in contrast to
|
||||
* {@link #tokenizeToStringArray}.
|
||||
* @param str the input {@code String}
|
||||
* @param str the input {@code String} (potentially {@code null} or empty)
|
||||
* @param delimiter the delimiter between elements (this is a single delimiter,
|
||||
* rather than a bunch individual delimiter characters)
|
||||
* @param charsToDelete a set of characters to delete; useful for deleting unwanted
|
||||
@@ -1217,7 +1214,7 @@ public abstract class StringUtils {
|
||||
/**
|
||||
* Convert a comma delimited list (e.g., a row from a CSV file) into an
|
||||
* array of strings.
|
||||
* @param str the input {@code String}
|
||||
* @param str the input {@code String} (potentially {@code null} or empty)
|
||||
* @return an array of strings, or the empty array in case of empty input
|
||||
*/
|
||||
public static String[] commaDelimitedListToStringArray(@Nullable String str) {
|
||||
@@ -1228,23 +1225,19 @@ public abstract class StringUtils {
|
||||
* Convert a comma delimited list (e.g., a row from a CSV file) into a set.
|
||||
* <p>Note that this will suppress duplicates, and as of 4.2, the elements in
|
||||
* the returned set will preserve the original order in a {@link LinkedHashSet}.
|
||||
* @param str the input {@code String}
|
||||
* @param str the input {@code String} (potentially {@code null} or empty)
|
||||
* @return a set of {@code String} entries in the list
|
||||
* @see #removeDuplicateStrings(String[])
|
||||
*/
|
||||
public static Set<String> commaDelimitedListToSet(@Nullable String str) {
|
||||
Set<String> set = new LinkedHashSet<>();
|
||||
String[] tokens = commaDelimitedListToStringArray(str);
|
||||
for (String token : tokens) {
|
||||
set.add(token);
|
||||
}
|
||||
return set;
|
||||
return new LinkedHashSet<>(Arrays.asList(tokens));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link Collection} to a delimited {@code String} (e.g. CSV).
|
||||
* <p>Useful for {@code toString()} implementations.
|
||||
* @param coll the {@code Collection} to convert
|
||||
* @param coll the {@code Collection} to convert (potentially {@code null} or empty)
|
||||
* @param delim the delimiter to use (typically a ",")
|
||||
* @param prefix the {@code String} to start each element with
|
||||
* @param suffix the {@code String} to end each element with
|
||||
@@ -1271,7 +1264,7 @@ public abstract class StringUtils {
|
||||
/**
|
||||
* Convert a {@code Collection} into a delimited {@code String} (e.g. CSV).
|
||||
* <p>Useful for {@code toString()} implementations.
|
||||
* @param coll the {@code Collection} to convert
|
||||
* @param coll the {@code Collection} to convert (potentially {@code null} or empty)
|
||||
* @param delim the delimiter to use (typically a ",")
|
||||
* @return the delimited {@code String}
|
||||
*/
|
||||
@@ -1282,17 +1275,17 @@ public abstract class StringUtils {
|
||||
/**
|
||||
* Convert a {@code Collection} into a delimited {@code String} (e.g., CSV).
|
||||
* <p>Useful for {@code toString()} implementations.
|
||||
* @param coll the {@code Collection} to convert
|
||||
* @param coll the {@code Collection} to convert (potentially {@code null} or empty)
|
||||
* @return the delimited {@code String}
|
||||
*/
|
||||
public static String collectionToCommaDelimitedString(Collection<?> coll) {
|
||||
public static String collectionToCommaDelimitedString(@Nullable Collection<?> coll) {
|
||||
return collectionToDelimitedString(coll, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@code String} array into a delimited {@code String} (e.g. CSV).
|
||||
* <p>Useful for {@code toString()} implementations.
|
||||
* @param arr the array to display
|
||||
* @param arr the array to display (potentially {@code null} or empty)
|
||||
* @param delim the delimiter to use (typically a ",")
|
||||
* @return the delimited {@code String}
|
||||
*/
|
||||
@@ -1318,7 +1311,7 @@ public abstract class StringUtils {
|
||||
* Convert a {@code String} array into a comma delimited {@code String}
|
||||
* (i.e., CSV).
|
||||
* <p>Useful for {@code toString()} implementations.
|
||||
* @param arr the array to display
|
||||
* @param arr the array to display (potentially {@code null} or empty)
|
||||
* @return the delimited {@code String}
|
||||
*/
|
||||
public static String arrayToCommaDelimitedString(@Nullable Object[] arr) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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,6 +19,7 @@ package org.springframework.transaction.annotation;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
@@ -86,13 +87,18 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa
|
||||
*/
|
||||
public AnnotationTransactionAttributeSource(boolean publicMethodsOnly) {
|
||||
this.publicMethodsOnly = publicMethodsOnly;
|
||||
this.annotationParsers = new LinkedHashSet<>(2);
|
||||
this.annotationParsers.add(new SpringTransactionAnnotationParser());
|
||||
if (jta12Present) {
|
||||
this.annotationParsers.add(new JtaTransactionAnnotationParser());
|
||||
if (jta12Present || ejb3Present) {
|
||||
this.annotationParsers = new LinkedHashSet<>(4);
|
||||
this.annotationParsers.add(new SpringTransactionAnnotationParser());
|
||||
if (jta12Present) {
|
||||
this.annotationParsers.add(new JtaTransactionAnnotationParser());
|
||||
}
|
||||
if (ejb3Present) {
|
||||
this.annotationParsers.add(new Ejb3TransactionAnnotationParser());
|
||||
}
|
||||
}
|
||||
if (ejb3Present) {
|
||||
this.annotationParsers.add(new Ejb3TransactionAnnotationParser());
|
||||
else {
|
||||
this.annotationParsers = Collections.singleton(new SpringTransactionAnnotationParser());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +119,7 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa
|
||||
public AnnotationTransactionAttributeSource(TransactionAnnotationParser... annotationParsers) {
|
||||
this.publicMethodsOnly = true;
|
||||
Assert.notEmpty(annotationParsers, "At least one TransactionAnnotationParser needs to be specified");
|
||||
Set<TransactionAnnotationParser> parsers = new LinkedHashSet<>(annotationParsers.length);
|
||||
Collections.addAll(parsers, annotationParsers);
|
||||
this.annotationParsers = parsers;
|
||||
this.annotationParsers = new LinkedHashSet<>(Arrays.asList(annotationParsers));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,14 +152,13 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa
|
||||
* for parsing known annotations into Spring's metadata attribute class.
|
||||
* Returns {@code null} if it's not transactional.
|
||||
* <p>Can be overridden to support custom annotations that carry transaction metadata.
|
||||
* @param ae the annotated method or class
|
||||
* @return TransactionAttribute the configured transaction attribute,
|
||||
* or {@code null} if none was found
|
||||
* @param element the annotated method or class
|
||||
* @return the configured transaction attribute, or {@code null} if none was found
|
||||
*/
|
||||
@Nullable
|
||||
protected TransactionAttribute determineTransactionAttribute(AnnotatedElement ae) {
|
||||
protected TransactionAttribute determineTransactionAttribute(AnnotatedElement element) {
|
||||
for (TransactionAnnotationParser annotationParser : this.annotationParsers) {
|
||||
TransactionAttribute attr = annotationParser.parseTransactionAnnotation(ae);
|
||||
TransactionAttribute attr = annotationParser.parseTransactionAnnotation(element);
|
||||
if (attr != null) {
|
||||
return attr;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -37,8 +37,8 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
|
||||
javax.ejb.TransactionAttribute ann = ae.getAnnotation(javax.ejb.TransactionAttribute.class);
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) {
|
||||
javax.ejb.TransactionAttribute ann = element.getAnnotation(javax.ejb.TransactionAttribute.class);
|
||||
if (ann != null) {
|
||||
return parseTransactionAnnotation(ann);
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar
|
||||
return new Ejb3TransactionAttribute(ann.value());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || other instanceof Ejb3TransactionAnnotationParser);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -40,9 +40,9 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
|
||||
AnnotationAttributes attributes =
|
||||
AnnotatedElementUtils.getMergedAnnotationAttributes(ae, javax.transaction.Transactional.class);
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) {
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(
|
||||
element, javax.transaction.Transactional.class);
|
||||
if (attributes != null) {
|
||||
return parseTransactionAnnotation(attributes);
|
||||
}
|
||||
@@ -57,23 +57,23 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars
|
||||
|
||||
protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
|
||||
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
|
||||
|
||||
rbta.setPropagationBehaviorName(
|
||||
RuleBasedTransactionAttribute.PREFIX_PROPAGATION + attributes.getEnum("value").toString());
|
||||
ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<>();
|
||||
Class<?>[] rbf = attributes.getClassArray("rollbackOn");
|
||||
for (Class<?> rbRule : rbf) {
|
||||
RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
|
||||
ArrayList<RollbackRuleAttribute> rollbackrules = new ArrayList<>();
|
||||
for (Class<?> rbRule : attributes.getClassArray("rollbackOn")) {
|
||||
rollbackrules.add(new RollbackRuleAttribute(rbRule));
|
||||
}
|
||||
Class<?>[] nrbf = attributes.getClassArray("dontRollbackOn");
|
||||
for (Class<?> rbRule : nrbf) {
|
||||
NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
for (Class<?> rbRule : attributes.getClassArray("dontRollbackOn")) {
|
||||
rollbackrules.add(new NoRollbackRuleAttribute(rbRule));
|
||||
}
|
||||
rbta.getRollbackRules().addAll(rollBackRules);
|
||||
rbta.setRollbackRules(rollbackrules);
|
||||
|
||||
return rbta;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || other instanceof JtaTransactionAnnotationParser);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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,6 +19,7 @@ package org.springframework.transaction.annotation;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
@@ -40,9 +41,9 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
|
||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) {
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(
|
||||
ae, Transactional.class, false, false);
|
||||
element, Transactional.class, false, false);
|
||||
if (attributes != null) {
|
||||
return parseTransactionAnnotation(attributes);
|
||||
}
|
||||
@@ -57,6 +58,7 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP
|
||||
|
||||
protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
|
||||
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
|
||||
|
||||
Propagation propagation = attributes.getEnum("propagation");
|
||||
rbta.setPropagationBehavior(propagation.value());
|
||||
Isolation isolation = attributes.getEnum("isolation");
|
||||
@@ -64,31 +66,26 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP
|
||||
rbta.setTimeout(attributes.getNumber("timeout").intValue());
|
||||
rbta.setReadOnly(attributes.getBoolean("readOnly"));
|
||||
rbta.setQualifier(attributes.getString("value"));
|
||||
ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<>();
|
||||
Class<?>[] rbf = attributes.getClassArray("rollbackFor");
|
||||
for (Class<?> rbRule : rbf) {
|
||||
RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
|
||||
List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
|
||||
for (Class<?> rbRule : attributes.getClassArray("rollbackFor")) {
|
||||
rollbackRules.add(new RollbackRuleAttribute(rbRule));
|
||||
}
|
||||
String[] rbfc = attributes.getStringArray("rollbackForClassName");
|
||||
for (String rbRule : rbfc) {
|
||||
RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
for (String rbRule : attributes.getStringArray("rollbackForClassName")) {
|
||||
rollbackRules.add(new RollbackRuleAttribute(rbRule));
|
||||
}
|
||||
Class<?>[] nrbf = attributes.getClassArray("noRollbackFor");
|
||||
for (Class<?> rbRule : nrbf) {
|
||||
NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
for (Class<?> rbRule : attributes.getClassArray("noRollbackFor")) {
|
||||
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
|
||||
}
|
||||
String[] nrbfc = attributes.getStringArray("noRollbackForClassName");
|
||||
for (String rbRule : nrbfc) {
|
||||
NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
|
||||
rollBackRules.add(rule);
|
||||
for (String rbRule : attributes.getStringArray("noRollbackForClassName")) {
|
||||
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
|
||||
}
|
||||
rbta.getRollbackRules().addAll(rollBackRules);
|
||||
rbta.setRollbackRules(rollbackRules);
|
||||
|
||||
return rbta;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || other instanceof SpringTransactionAnnotationParser);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -39,16 +39,14 @@ public interface TransactionAnnotationParser {
|
||||
|
||||
/**
|
||||
* Parse the transaction attribute for the given method or class,
|
||||
* based on a known annotation type.
|
||||
* <p>This essentially parses a known transaction annotation into Spring's
|
||||
* metadata attribute class. Returns {@code null} if the method/class
|
||||
* is not transactional.
|
||||
* @param ae the annotated method or class
|
||||
* @return TransactionAttribute the configured transaction attribute,
|
||||
* or {@code null} if none was found
|
||||
* based on an annotation type understood by this parser.
|
||||
* <p>This essentially parses a known transaction annotation into Spring's metadata
|
||||
* attribute class. Returns {@code null} if the method/class is not transactional.
|
||||
* @param element the annotated method or class
|
||||
* @return the configured transaction attribute, or {@code null} if none found
|
||||
* @see AnnotationTransactionAttributeSource#determineTransactionAttribute
|
||||
*/
|
||||
@Nullable
|
||||
TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae);
|
||||
TransactionAttribute parseTransactionAnnotation(AnnotatedElement element);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user