From 687d350b575847c8969d0c278c122cb901f3ffca Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 10 Aug 2018 18:00:17 +0200 Subject: [PATCH] Polishing --- .../autoproxy/AbstractAutoProxyCreator.java | 6 +-- .../factory/annotation/InjectionMetadata.java | 11 ++-- .../support/DefaultListableBeanFactory.java | 16 +++--- .../event/GenericApplicationListener.java | 12 +++-- .../event/SmartApplicationListener.java | 12 +++-- .../transaction/TransactionStatus.java | 14 ++--- .../DefaultTransactionAttribute.java | 5 +- .../support/DefaultTransactionStatus.java | 53 ++++++++++--------- .../support/SimpleTransactionStatus.java | 15 +++--- 9 files changed, 77 insertions(+), 67 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index 6a8fc97da4..904c765053 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -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. @@ -412,7 +412,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport // Found a matching TargetSource. if (logger.isDebugEnabled()) { logger.debug("TargetSourceCreator [" + tsc + - " found custom TargetSource for bean with name '" + beanName + "'"); + "] found custom TargetSource for bean with name '" + beanName + "'"); } return ts; } @@ -553,7 +553,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * Subclasses may choose to implement this: for example, * to change the interfaces exposed. *

The default implementation is empty. - * @param proxyFactory ProxyFactory that is already configured with + * @param proxyFactory a ProxyFactory that is already configured with * TargetSource and interfaces and will be used to create the proxy * immediately after this method returns */ diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index af64331ce9..6f9caba818 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -80,9 +80,8 @@ public class InjectionMetadata { Collection elementsToIterate = (this.checkedElements != null ? this.checkedElements : this.injectedElements); if (!elementsToIterate.isEmpty()) { - boolean debug = logger.isDebugEnabled(); for (InjectedElement element : elementsToIterate) { - if (debug) { + if (logger.isDebugEnabled()) { logger.debug("Processing injected element of bean '" + beanName + "': " + element); } element.inject(target, beanName, pvs); @@ -109,7 +108,10 @@ public class InjectionMetadata { } - public static abstract class InjectedElement { + /** + * A single injected element. + */ + public abstract static class InjectedElement { protected final Member member; @@ -216,6 +218,7 @@ public class InjectionMetadata { } /** + * Clear property skipping for this element. * @since 3.2.13 */ protected void clearPropertySkipping(PropertyValues pvs) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index d53d3d4baf..c3ea84a0f9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -541,29 +541,29 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public String[] getBeanNamesForAnnotation(Class annotationType) { - List results = new ArrayList(); + List result = new ArrayList(); for (String beanName : this.beanDefinitionNames) { BeanDefinition beanDefinition = getBeanDefinition(beanName); if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { - results.add(beanName); + result.add(beanName); } } for (String beanName : this.manualSingletonNames) { - if (!results.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { - results.add(beanName); + if (!result.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { + result.add(beanName); } } - return StringUtils.toStringArray(results); + return StringUtils.toStringArray(result); } @Override public Map getBeansWithAnnotation(Class annotationType) { String[] beanNames = getBeanNamesForAnnotation(annotationType); - Map results = new LinkedHashMap(beanNames.length); + Map result = new LinkedHashMap(beanNames.length); for (String beanName : beanNames) { - results.put(beanName, getBean(beanName)); + result.put(beanName, getBean(beanName)); } - return results; + return result; } /** diff --git a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java index cfe7f457a9..8bd2d2dba7 100644 --- a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -23,23 +23,27 @@ import org.springframework.core.ResolvableType; /** * Extended variant of the standard {@link ApplicationListener} interface, - * exposing further metadata such as the supported event type. + * exposing further metadata such as the supported event and source type. * - *

As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with - * proper handling of generics-based event. + *

As of Spring Framework 4.2, this interface supersedes the Class-based + * {@link SmartApplicationListener} with full handling of generic event types. * * @author Stephane Nicoll * @since 4.2 + * @see SmartApplicationListener + * @see GenericApplicationListenerAdapter */ public interface GenericApplicationListener extends ApplicationListener, Ordered { /** * Determine whether this listener actually supports the given event type. + * @param eventType the event type (never {@code null}) */ boolean supportsEventType(ResolvableType eventType); /** * Determine whether this listener actually supports the given source type. + * @param sourceType the source type, or {@code null} if no source */ boolean supportsSourceType(Class sourceType); diff --git a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java index 5d50920754..3a737169ed 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -22,25 +22,27 @@ import org.springframework.core.Ordered; /** * Extended variant of the standard {@link ApplicationListener} interface, - * exposing further metadata such as the supported event type. + * exposing further metadata such as the supported event and source type. * - *

Users are strongly advised to use the {@link GenericApplicationListener} - * interface instead as it provides an improved detection of generics-based - * event types. + *

For full introspection of generic event types, consider implementing + * the {@link GenericApplicationListener} interface instead. * * @author Juergen Hoeller * @since 3.0 * @see GenericApplicationListener + * @see GenericApplicationListenerAdapter */ public interface SmartApplicationListener extends ApplicationListener, Ordered { /** * Determine whether this listener actually supports the given event type. + * @param eventType the event type (never {@code null}) */ boolean supportsEventType(Class eventType); /** * Determine whether this listener actually supports the given source type. + * @param sourceType the source type, or {@code null} if no source */ boolean supportsSourceType(Class sourceType); diff --git a/spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java b/spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java index 54112784ca..b2865a70d9 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java @@ -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. @@ -25,7 +25,7 @@ import java.io.Flushable; * and to programmatically request a rollback (instead of throwing * an exception that causes an implicit rollback). * - *

Derives from the SavepointManager interface to provide access + *

Includes the {@link SavepointManager} interface to provide access * to savepoint management facilities. Note that savepoint management * is only available if supported by the underlying transaction manager. * @@ -39,9 +39,9 @@ import java.io.Flushable; public interface TransactionStatus extends SavepointManager, Flushable { /** - * Return whether the present transaction is new (else participating - * in an existing transaction, or potentially not running in an - * actual transaction in the first place). + * Return whether the present transaction is new; otherwise participating + * in an existing transaction, or potentially not running in an actual + * transaction in the first place. */ boolean isNewTransaction(); @@ -50,9 +50,9 @@ public interface TransactionStatus extends SavepointManager, Flushable { * that is, has been created as nested transaction based on a savepoint. *

This method is mainly here for diagnostic purposes, alongside * {@link #isNewTransaction()}. For programmatic handling of custom - * savepoints, use SavepointManager's operations. + * savepoints, use the operations provided by {@link SavepointManager}. * @see #isNewTransaction() - * @see #createSavepoint + * @see #createSavepoint() * @see #rollbackToSavepoint(Object) * @see #releaseSavepoint(Object) */ diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java index fc45334c03..2771a62e97 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java @@ -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. @@ -17,6 +17,7 @@ package org.springframework.transaction.interceptor; import org.springframework.transaction.support.DefaultTransactionDefinition; +import org.springframework.util.StringUtils; /** * Spring's common transaction attribute implementation. @@ -136,7 +137,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im */ protected final StringBuilder getAttributeDescription() { StringBuilder result = getDefinitionDescription(); - if (this.qualifier != null) { + if (StringUtils.hasText(this.qualifier)) { result.append("; '").append(this.qualifier).append("'"); } return result; diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java index 22f6f46acc..8bd2257095 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java @@ -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. @@ -62,14 +62,14 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { /** - * Create a new DefaultTransactionStatus instance. - * @param transaction underlying transaction object that can hold - * state for the internal transaction implementation - * @param newTransaction if the transaction is new, - * else participating in an existing transaction - * @param newSynchronization if a new transaction synchronization - * has been opened for the given transaction - * @param readOnly whether the transaction is read-only + * Create a new {@code DefaultTransactionStatus} instance. + * @param transaction underlying transaction object that can hold state + * for the internal transaction implementation + * @param newTransaction if the transaction is new, otherwise participating + * in an existing transaction + * @param newSynchronization if a new transaction synchronization has been + * opened for the given transaction + * @param readOnly whether the transaction is marked as read-only * @param debug should debug logging be enabled for the handling of this transaction? * Caching it in here can prevent repeated calls to ask the logging system whether * debug logging should be enabled. @@ -124,9 +124,9 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { } /** - * Return whether the progress of this transaction is debugged. This is used - * by AbstractPlatformTransactionManager as an optimization, to prevent repeated - * calls to logger.isDebug(). Not really intended for client code. + * Return whether the progress of this transaction is debugged. This is used by + * {@link AbstractPlatformTransactionManager} as an optimization, to prevent repeated + * calls to {@code logger.isDebugEnabled()}. Not really intended for client code. */ public boolean isDebug() { return this.debug; @@ -146,11 +146,11 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { //--------------------------------------------------------------------- /** - * Determine the rollback-only flag via checking both the transaction object, - * provided that the latter implements the {@link SmartTransactionObject} interface. - *

Will return "true" if the transaction itself has been marked rollback-only - * by the transaction coordinator, for example in case of a timeout. - * @see SmartTransactionObject#isRollbackOnly + * Determine the rollback-only flag via checking the transaction object, provided + * that the latter implements the {@link SmartTransactionObject} interface. + *

Will return {@code true} if the global transaction itself has been marked + * rollback-only by the transaction coordinator, for example in case of a timeout. + * @see SmartTransactionObject#isRollbackOnly() */ @Override public boolean isGlobalRollbackOnly() { @@ -159,8 +159,9 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { } /** - * Delegate the flushing to the transaction object, - * provided that the latter implements the {@link SmartTransactionObject} interface. + * Delegate the flushing to the transaction object, provided that the latter + * implements the {@link SmartTransactionObject} interface. + * @see SmartTransactionObject#flush() */ @Override public void flush() { @@ -170,23 +171,25 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { } /** - * This implementation exposes the SavepointManager interface + * This implementation exposes the {@link SavepointManager} interface * of the underlying transaction object, if any. + * @throws NestedTransactionNotSupportedException if savepoints are not supported + * @see #isTransactionSavepointManager() */ @Override protected SavepointManager getSavepointManager() { if (!isTransactionSavepointManager()) { throw new NestedTransactionNotSupportedException( - "Transaction object [" + getTransaction() + "] does not support savepoints"); + "Transaction object [" + this.transaction + "] does not support savepoints"); } return (SavepointManager) getTransaction(); } /** - * Return whether the underlying transaction implements the - * SavepointManager interface. - * @see #getTransaction - * @see org.springframework.transaction.SavepointManager + * Return whether the underlying transaction implements the {@link SavepointManager} + * interface and therefore supports savepoints. + * @see #getTransaction() + * @see #getSavepointManager() */ public boolean isTransactionSavepointManager() { return (getTransaction() instanceof SavepointManager); diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionStatus.java b/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionStatus.java index 2788b8f728..51e8d4e32f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionStatus.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionStatus.java @@ -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. @@ -18,10 +18,8 @@ package org.springframework.transaction.support; /** * A simple {@link org.springframework.transaction.TransactionStatus} - * implementation. - * - *

Derives from {@link AbstractTransactionStatus} and adds an explicit - * {@link #isNewTransaction() "newTransaction"} flag. + * implementation. Derives from {@link AbstractTransactionStatus} and + * adds an explicit {@link #isNewTransaction() "newTransaction"} flag. * *

This class is not used by any of Spring's pre-built * {@link org.springframework.transaction.PlatformTransactionManager} @@ -32,8 +30,7 @@ package org.springframework.transaction.support; * * @author Juergen Hoeller * @since 1.2.3 - * @see #SimpleTransactionStatus(boolean) - * @see TransactionCallback + * @see TransactionCallback#doInTransaction */ public class SimpleTransactionStatus extends AbstractTransactionStatus { @@ -41,7 +38,7 @@ public class SimpleTransactionStatus extends AbstractTransactionStatus { /** - * Create a new instance of the {@link SimpleTransactionStatus} class, + * Create a new {@code SimpleTransactionStatus} instance, * indicating a new transaction. */ public SimpleTransactionStatus() { @@ -49,7 +46,7 @@ public class SimpleTransactionStatus extends AbstractTransactionStatus { } /** - * Create a new instance of the {@link SimpleTransactionStatus} class. + * Create a new {@code SimpleTransactionStatus} instance. * @param newTransaction whether to indicate a new transaction */ public SimpleTransactionStatus(boolean newTransaction) {