Polishing
This commit is contained in:
parent
2938a95435
commit
6b82a6c38c
|
|
@ -983,7 +983,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 (potentially {@code null} or empty)
|
||||
* @param array the original {@code String} array (potentially empty)
|
||||
* @return the resulting array (of the same size) with trimmed elements
|
||||
*/
|
||||
public static String[] trimArrayElements(String[] array) {
|
||||
|
|
|
|||
|
|
@ -156,14 +156,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 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.
|
||||
|
|
@ -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 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 +58,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);
|
||||
|
||||
List<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);
|
||||
|
|
|
|||
|
|
@ -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 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);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue