Browse Source

Polishing

pull/1946/head
Juergen Hoeller 7 years ago
parent
commit
951b39cc7a
  1. 4
      spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
  2. 10
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java
  3. 16
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  4. 12
      spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.java
  5. 12
      spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java
  6. 14
      spring-tx/src/main/java/org/springframework/transaction/TransactionStatus.java
  7. 7
      spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java
  8. 53
      spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java
  9. 15
      spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionStatus.java

4
spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

@ -419,7 +419,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
// Found a matching TargetSource. // Found a matching TargetSource.
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("TargetSourceCreator [" + tsc + logger.debug("TargetSourceCreator [" + tsc +
" found custom TargetSource for bean with name '" + beanName + "'"); "] found custom TargetSource for bean with name '" + beanName + "'");
} }
return ts; return ts;
} }
@ -561,7 +561,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* Subclasses may choose to implement this: for example, * Subclasses may choose to implement this: for example,
* to change the interfaces exposed. * to change the interfaces exposed.
* <p>The default implementation is empty. * <p>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 * TargetSource and interfaces and will be used to create the proxy
* immediately after this method returns * immediately after this method returns
*/ */

10
spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,9 +83,8 @@ public class InjectionMetadata {
Collection<InjectedElement> elementsToIterate = Collection<InjectedElement> elementsToIterate =
(checkedElements != null ? checkedElements : this.injectedElements); (checkedElements != null ? checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) { if (!elementsToIterate.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (InjectedElement element : elementsToIterate) { for (InjectedElement element : elementsToIterate) {
if (debug) { if (logger.isDebugEnabled()) {
logger.debug("Processing injected element of bean '" + beanName + "': " + element); logger.debug("Processing injected element of bean '" + beanName + "': " + element);
} }
element.inject(target, beanName, pvs); element.inject(target, beanName, pvs);
@ -94,6 +93,7 @@ public class InjectionMetadata {
} }
/** /**
* Clear property skipping for the contained elements.
* @since 3.2.13 * @since 3.2.13
*/ */
public void clear(@Nullable PropertyValues pvs) { public void clear(@Nullable PropertyValues pvs) {
@ -113,6 +113,9 @@ public class InjectionMetadata {
} }
/**
* A single injected element.
*/
public abstract static class InjectedElement { public abstract static class InjectedElement {
protected final Member member; protected final Member member;
@ -226,6 +229,7 @@ public class InjectionMetadata {
} }
/** /**
* Clear property skipping for this element.
* @since 3.2.13 * @since 3.2.13
*/ */
protected void clearPropertySkipping(@Nullable PropertyValues pvs) { protected void clearPropertySkipping(@Nullable PropertyValues pvs) {

16
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -538,29 +538,29 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override @Override
public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) { public String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType) {
List<String> results = new ArrayList<>(); List<String> result = new ArrayList<>();
for (String beanName : this.beanDefinitionNames) { for (String beanName : this.beanDefinitionNames) {
BeanDefinition beanDefinition = getBeanDefinition(beanName); BeanDefinition beanDefinition = getBeanDefinition(beanName);
if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) {
results.add(beanName); result.add(beanName);
} }
} }
for (String beanName : this.manualSingletonNames) { for (String beanName : this.manualSingletonNames) {
if (!results.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { if (!result.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) {
results.add(beanName); result.add(beanName);
} }
} }
return StringUtils.toStringArray(results); return StringUtils.toStringArray(result);
} }
@Override @Override
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) { public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) {
String[] beanNames = getBeanNamesForAnnotation(annotationType); String[] beanNames = getBeanNamesForAnnotation(annotationType);
Map<String, Object> results = new LinkedHashMap<>(beanNames.length); Map<String, Object> result = new LinkedHashMap<>(beanNames.length);
for (String beanName : beanNames) { for (String beanName : beanNames) {
results.put(beanName, getBean(beanName)); result.put(beanName, getBean(beanName));
} }
return results; return result;
} }
/** /**

12
spring-context/src/main/java/org/springframework/context/event/GenericApplicationListener.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,23 +24,27 @@ import org.springframework.lang.Nullable;
/** /**
* Extended variant of the standard {@link ApplicationListener} interface, * 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.
* *
* <p>As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with * <p>As of Spring Framework 4.2, this interface supersedes the Class-based
* proper handling of generics-based event. * {@link SmartApplicationListener} with full handling of generic event types.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 4.2 * @since 4.2
* @see SmartApplicationListener
* @see GenericApplicationListenerAdapter
*/ */
public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered { public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
/** /**
* Determine whether this listener actually supports the given event type. * Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/ */
boolean supportsEventType(ResolvableType eventType); boolean supportsEventType(ResolvableType eventType);
/** /**
* Determine whether this listener actually supports the given source type. * Determine whether this listener actually supports the given source type.
* @param sourceType the source type, or {@code null} if no source
*/ */
boolean supportsSourceType(@Nullable Class<?> sourceType); boolean supportsSourceType(@Nullable Class<?> sourceType);

12
spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,25 +23,27 @@ import org.springframework.lang.Nullable;
/** /**
* Extended variant of the standard {@link ApplicationListener} interface, * 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.
* *
* <p>Users are <bold>strongly advised</bold> to use the {@link GenericApplicationListener} * <p>For full introspection of generic event types, consider implementing
* interface instead as it provides an improved detection of generics-based * the {@link GenericApplicationListener} interface instead.
* event types.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.0 * @since 3.0
* @see GenericApplicationListener * @see GenericApplicationListener
* @see GenericApplicationListenerAdapter
*/ */
public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered { public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {
/** /**
* Determine whether this listener actually supports the given event type. * Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/ */
boolean supportsEventType(Class<? extends ApplicationEvent> eventType); boolean supportsEventType(Class<? extends ApplicationEvent> eventType);
/** /**
* Determine whether this listener actually supports the given source type. * Determine whether this listener actually supports the given source type.
* @param sourceType the source type, or {@code null} if no source
*/ */
boolean supportsSourceType(@Nullable Class<?> sourceType); boolean supportsSourceType(@Nullable Class<?> sourceType);

14
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * and to programmatically request a rollback (instead of throwing
* an exception that causes an implicit rollback). * an exception that causes an implicit rollback).
* *
* <p>Derives from the SavepointManager interface to provide access * <p>Includes the {@link SavepointManager} interface to provide access
* to savepoint management facilities. Note that savepoint management * to savepoint management facilities. Note that savepoint management
* is only available if supported by the underlying transaction manager. * is only available if supported by the underlying transaction manager.
* *
@ -39,9 +39,9 @@ import java.io.Flushable;
public interface TransactionStatus extends SavepointManager, Flushable { public interface TransactionStatus extends SavepointManager, Flushable {
/** /**
* Return whether the present transaction is new (else participating * Return whether the present transaction is new; otherwise participating
* in an existing transaction, or potentially not running in an * in an existing transaction, or potentially not running in an actual
* actual transaction in the first place). * transaction in the first place.
*/ */
boolean isNewTransaction(); boolean isNewTransaction();
@ -50,9 +50,9 @@ public interface TransactionStatus extends SavepointManager, Flushable {
* that is, has been created as nested transaction based on a savepoint. * that is, has been created as nested transaction based on a savepoint.
* <p>This method is mainly here for diagnostic purposes, alongside * <p>This method is mainly here for diagnostic purposes, alongside
* {@link #isNewTransaction()}. For programmatic handling of custom * {@link #isNewTransaction()}. For programmatic handling of custom
* savepoints, use SavepointManager's operations. * savepoints, use the operations provided by {@link SavepointManager}.
* @see #isNewTransaction() * @see #isNewTransaction()
* @see #createSavepoint * @see #createSavepoint()
* @see #rollbackToSavepoint(Object) * @see #rollbackToSavepoint(Object)
* @see #releaseSavepoint(Object) * @see #releaseSavepoint(Object)
*/ */

7
spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.transaction.interceptor;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.StringUtils;
/** /**
* Spring's common transaction attribute implementation. * Spring's common transaction attribute implementation.
@ -82,7 +83,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
* to process this specific transaction. * to process this specific transaction.
* @since 3.0 * @since 3.0
*/ */
public void setQualifier(String qualifier) { public void setQualifier(@Nullable String qualifier) {
this.qualifier = qualifier; this.qualifier = qualifier;
} }
@ -141,7 +142,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
*/ */
protected final StringBuilder getAttributeDescription() { protected final StringBuilder getAttributeDescription() {
StringBuilder result = getDefinitionDescription(); StringBuilder result = getDefinitionDescription();
if (this.qualifier != null) { if (StringUtils.hasText(this.qualifier)) {
result.append("; '").append(this.qualifier).append("'"); result.append("; '").append(this.qualifier).append("'");
} }
return result; return result;

53
spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -66,14 +66,14 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
/** /**
* Create a new DefaultTransactionStatus instance. * Create a new {@code DefaultTransactionStatus} instance.
* @param transaction underlying transaction object that can hold * @param transaction underlying transaction object that can hold state
* state for the internal transaction implementation * for the internal transaction implementation
* @param newTransaction if the transaction is new, * @param newTransaction if the transaction is new, otherwise participating
* else participating in an existing transaction * in an existing transaction
* @param newSynchronization if a new transaction synchronization * @param newSynchronization if a new transaction synchronization has been
* has been opened for the given transaction * opened for the given transaction
* @param readOnly whether the transaction is read-only * @param readOnly whether the transaction is marked as read-only
* @param debug should debug logging be enabled for the handling of this transaction? * @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 * Caching it in here can prevent repeated calls to ask the logging system whether
* debug logging should be enabled. * debug logging should be enabled.
@ -130,9 +130,9 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
} }
/** /**
* Return whether the progress of this transaction is debugged. This is used * Return whether the progress of this transaction is debugged. This is used by
* by AbstractPlatformTransactionManager as an optimization, to prevent repeated * {@link AbstractPlatformTransactionManager} as an optimization, to prevent repeated
* calls to logger.isDebug(). Not really intended for client code. * calls to {@code logger.isDebugEnabled()}. Not really intended for client code.
*/ */
public boolean isDebug() { public boolean isDebug() {
return this.debug; return this.debug;
@ -153,11 +153,11 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/** /**
* Determine the rollback-only flag via checking both the transaction object, * Determine the rollback-only flag via checking the transaction object, provided
* provided that the latter implements the {@link SmartTransactionObject} interface. * that the latter implements the {@link SmartTransactionObject} interface.
* <p>Will return "true" if the transaction itself has been marked rollback-only * <p>Will return {@code true} if the global transaction itself has been marked
* by the transaction coordinator, for example in case of a timeout. * rollback-only by the transaction coordinator, for example in case of a timeout.
* @see SmartTransactionObject#isRollbackOnly * @see SmartTransactionObject#isRollbackOnly()
*/ */
@Override @Override
public boolean isGlobalRollbackOnly() { public boolean isGlobalRollbackOnly() {
@ -166,8 +166,9 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
} }
/** /**
* Delegate the flushing to the transaction object, * Delegate the flushing to the transaction object, provided that the latter
* provided that the latter implements the {@link SmartTransactionObject} interface. * implements the {@link SmartTransactionObject} interface.
* @see SmartTransactionObject#flush()
*/ */
@Override @Override
public void flush() { public void flush() {
@ -177,24 +178,26 @@ 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. * of the underlying transaction object, if any.
* @throws NestedTransactionNotSupportedException if savepoints are not supported
* @see #isTransactionSavepointManager()
*/ */
@Override @Override
protected SavepointManager getSavepointManager() { protected SavepointManager getSavepointManager() {
Object transaction = this.transaction; Object transaction = this.transaction;
if (!(transaction instanceof SavepointManager)) { if (!(transaction instanceof SavepointManager)) {
throw new NestedTransactionNotSupportedException( throw new NestedTransactionNotSupportedException(
"Transaction object [" + this.transaction + "] does not support savepoints"); "Transaction object [" + this.transaction + "] does not support savepoints");
} }
return (SavepointManager) transaction; return (SavepointManager) transaction;
} }
/** /**
* Return whether the underlying transaction implements the * Return whether the underlying transaction implements the {@link SavepointManager}
* SavepointManager interface. * interface and therefore supports savepoints.
* @see #getTransaction * @see #getTransaction()
* @see org.springframework.transaction.SavepointManager * @see #getSavepointManager()
*/ */
public boolean isTransactionSavepointManager() { public boolean isTransactionSavepointManager() {
return (this.transaction instanceof SavepointManager); return (this.transaction instanceof SavepointManager);

15
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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} * A simple {@link org.springframework.transaction.TransactionStatus}
* implementation. * implementation. Derives from {@link AbstractTransactionStatus} and
* * adds an explicit {@link #isNewTransaction() "newTransaction"} flag.
* <p>Derives from {@link AbstractTransactionStatus} and adds an explicit
* {@link #isNewTransaction() "newTransaction"} flag.
* *
* <p>This class is not used by any of Spring's pre-built * <p>This class is not used by any of Spring's pre-built
* {@link org.springframework.transaction.PlatformTransactionManager} * {@link org.springframework.transaction.PlatformTransactionManager}
@ -32,8 +30,7 @@ package org.springframework.transaction.support;
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.2.3 * @since 1.2.3
* @see #SimpleTransactionStatus(boolean) * @see TransactionCallback#doInTransaction
* @see TransactionCallback
*/ */
public class SimpleTransactionStatus extends AbstractTransactionStatus { 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. * indicating a new transaction.
*/ */
public SimpleTransactionStatus() { 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 * @param newTransaction whether to indicate a new transaction
*/ */
public SimpleTransactionStatus(boolean newTransaction) { public SimpleTransactionStatus(boolean newTransaction) {

Loading…
Cancel
Save