From a0455744186072d73040fe307c1e74f18a4b33d6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 10 Jun 2020 11:19:52 +0200 Subject: [PATCH] Polishing --- .../ReflectiveAspectJAdvisorFactory.java | 13 ++- .../AspectJPrecedenceComparator.java | 12 +- .../aop/config/AopNamespaceHandler.java | 6 +- .../beans/CachedIntrospectionResults.java | 11 +- .../beans/factory/annotation/Lookup.java | 13 +-- .../factory/support/AbstractBeanFactory.java | 2 +- .../cache/caffeine/CaffeineCache.java | 7 +- .../cache/ehcache/EhCacheCache.java | 4 +- .../cache/ehcache/EhCacheCacheManager.java | 3 +- .../cache/jcache/JCacheCache.java | 11 +- .../cache/jcache/JCacheCacheManager.java | 20 ++-- .../cache/concurrent/ConcurrentMapCache.java | 6 +- .../concurrent/ConcurrentMapCacheManager.java | 6 +- .../cache/support/NoOpCache.java | 5 +- .../cache/support/NoOpCacheManager.java | 6 +- .../MethodValidationInterceptor.java | 5 +- .../MethodValidationPostProcessor.java | 4 +- .../cache/CacheReproTests.java | 7 +- .../concurrent/ConcurrentMapCacheTests.java | 11 +- .../jdbc/core/JdbcOperations.java | 29 +++-- .../NamedParameterJdbcOperations.java | 110 +++++++++--------- .../DataSourceTransactionManager.java | 5 +- .../orm/jpa/JpaTransactionManager.java | 14 +-- .../reactive/MockServerHttpRequest.java | 13 +-- .../springframework/http/RequestEntity.java | 5 +- .../ServerSentEventHttpMessageReader.java | 10 +- .../ServerSentEventHttpMessageWriter.java | 27 ++--- .../DefaultServerHttpRequestBuilder.java | 6 +- .../reactive/ReactorServerHttpRequest.java | 3 +- .../reactive/ServerHttpRequestDecorator.java | 5 +- .../reactive/ServletServerHttpRequest.java | 5 +- .../reactive/UndertowServerHttpRequest.java | 3 +- .../web/util/DefaultUriBuilderFactory.java | 103 ++++++++-------- .../web/util/UriBuilderFactory.java | 6 +- .../reactive/test/MockServerHttpRequest.java | 13 +-- .../DelegatingWebFluxConfiguration.java | 5 +- .../function/client/DefaultWebClient.java | 3 +- src/docs/asciidoc/core/core-expressions.adoc | 35 +++--- 38 files changed, 284 insertions(+), 268 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 760c6dc976e2..db6898f31024 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -76,9 +76,8 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto new InstanceComparator<>( Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class), (Converter) method -> { - AspectJAnnotation annotation = - AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); - return (annotation != null ? annotation.getAnnotation() : null); + AspectJAnnotation ann = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); + return (ann != null ? ann.getAnnotation() : null); }); Comparator methodNameComparator = new ConvertingComparator<>(Method::getName); METHOD_COMPARATOR = adviceKindComparator.thenComparing(methodNameComparator); @@ -153,8 +152,10 @@ private List getAdvisorMethods(Class aspectClass) { if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) { methods.add(method); } - }); - methods.sort(METHOD_COMPARATOR); + }, ReflectionUtils.USER_DECLARED_METHODS); + if (methods.size() > 1) { + methods.sort(METHOD_COMPARATOR); + } return methods; } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java index 64066f7c04e5..d013cda2c986 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -138,14 +138,8 @@ private String getAspectName(Advisor anAdvisor) { } private int getAspectDeclarationOrder(Advisor anAdvisor) { - AspectJPrecedenceInformation precedenceInfo = - AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor); - if (precedenceInfo != null) { - return precedenceInfo.getDeclarationOrder(); - } - else { - return 0; - } + AspectJPrecedenceInformation precedenceInfo = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor); + return (precedenceInfo != null ? precedenceInfo.getDeclarationOrder() : 0); } } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceHandler.java b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceHandler.java index 99eb2fa6f594..fa6cc80a1f3c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceHandler.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2020 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. @@ -61,12 +61,12 @@ public class AopNamespaceHandler extends NamespaceHandlerSupport { */ @Override public void init() { - // In 2.0 XSD as well as in 2.1 XSD. + // In 2.0 XSD as well as in 2.5+ XSDs registerBeanDefinitionParser("config", new ConfigBeanDefinitionParser()); registerBeanDefinitionParser("aspectj-autoproxy", new AspectJAutoProxyBeanDefinitionParser()); registerBeanDefinitionDecorator("scoped-proxy", new ScopedProxyBeanDefinitionDecorator()); - // Only in 2.0 XSD: moved to context namespace as of 2.1 + // Only in 2.0 XSD: moved to context namespace in 2.5+ registerBeanDefinitionParser("spring-configured", new SpringConfiguredBeanDefinitionParser()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index 60bdff343fd2..440f4517af8c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -43,9 +43,9 @@ * Internal class that caches JavaBeans {@link java.beans.PropertyDescriptor} * information for a Java class. Not intended for direct use by application code. * - *

Necessary for own caching of descriptors within the application's - * ClassLoader, rather than rely on the JDK's system-wide BeanInfo cache - * (in order to avoid leaks on ClassLoader shutdown). + *

Necessary for Spring's own caching of bean descriptors within the application + * {@link ClassLoader}, rather than relying on the JDK's system-wide {@link BeanInfo} + * cache (in order to avoid leaks on individual application shutdown in a shared JVM). * *

Information is cached statically, so we don't need to create new * objects of this class for every JavaBean we manipulate. Hence, this class @@ -97,7 +97,7 @@ public class CachedIntrospectionResults { SpringProperties.getFlag(IGNORE_BEANINFO_PROPERTY_NAME); /** Stores the BeanInfoFactory instances */ - private static List beanInfoFactories = SpringFactoriesLoader.loadFactories( + private static final List beanInfoFactories = SpringFactoriesLoader.loadFactories( BeanInfoFactory.class, CachedIntrospectionResults.class.getClassLoader()); private static final Log logger = LogFactory.getLog(CachedIntrospectionResults.class); @@ -163,7 +163,6 @@ public static void clearClassLoader(@Nullable ClassLoader classLoader) { * @return the corresponding CachedIntrospectionResults * @throws BeansException in case of introspection failure */ - @SuppressWarnings("unchecked") static CachedIntrospectionResults forClass(Class beanClass) throws BeansException { CachedIntrospectionResults results = strongClassCache.get(beanClass); if (results != null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java index 495354aa20c6..0fca4f3316a0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2020 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. @@ -41,12 +41,11 @@ * regular constructors: i.e. lookup methods cannot get replaced on beans returned * from factory methods where we cannot dynamically provide a subclass for them. * - *

Concrete limitations in typical Spring configuration scenarios: - * When used with component scanning or any other mechanism that filters out abstract - * beans, provide stub implementations of your lookup methods to be able to declare - * them as concrete classes. And please remember that lookup methods won't work on - * beans returned from {@code @Bean} methods in configuration classes; you'll have - * to resort to {@code @Inject Provider} or the like instead. + *

Recommendations for typical Spring configuration scenarios: + * When a concrete class may be needed in certain scenarios, consider providing stub + * implementations of your lookup methods. And please remember that lookup methods + * won't work on beans returned from {@code @Bean} methods in configuration classes; + * you'll have to resort to {@code @Inject Provider} or the like instead. * * @author Juergen Hoeller * @since 4.1 diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 9197a6ec6985..5085d1e02557 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -884,7 +884,7 @@ public List getBeanPostProcessors() { /** * Return whether this factory holds a InstantiationAwareBeanPostProcessor - * that will get applied to singleton beans on shutdown. + * that will get applied to singleton beans on creation. * @see #addBeanPostProcessor * @see org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor */ diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java index e50364f51ba7..b59ed1aebeff 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -35,6 +35,7 @@ * @author Juergen Hoeller * @author Stephane Nicoll * @since 4.3 + * @see CaffeineCacheManager */ public class CaffeineCache extends AbstractValueAdaptingCache { @@ -159,10 +160,10 @@ public LoadFunction(Callable valueLoader) { @Override public Object apply(Object o) { try { - return toStoreValue(valueLoader.call()); + return toStoreValue(this.valueLoader.call()); } catch (Exception ex) { - throw new ValueRetrievalException(o, valueLoader, ex); + throw new ValueRetrievalException(o, this.valueLoader, ex); } } } diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java index 9403026f1f59..fc17e8796641 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -34,6 +34,7 @@ * @author Juergen Hoeller * @author Stephane Nicoll * @since 3.1 + * @see EhCacheCacheManager */ public class EhCacheCache implements Cache { @@ -95,7 +96,6 @@ public T get(Object key, Callable valueLoader) { this.cache.releaseWriteLockOnKey(key); } } - } private T loadValue(Object key, Callable valueLoader) { diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java index 709404e6f2dc..f3e58a55b288 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -34,6 +34,7 @@ * @author Juergen Hoeller * @author Stephane Nicoll * @since 3.1 + * @see EhCacheCache */ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java index 64ce416acacd..4dd0ac437b62 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -28,13 +28,14 @@ /** * {@link org.springframework.cache.Cache} implementation on top of a - * {@link javax.cache.Cache} instance. + * {@link Cache javax.cache.Cache} instance. * *

Note: This class has been updated for JCache 1.0, as of Spring 4.0. * * @author Juergen Hoeller * @author Stephane Nicoll * @since 3.2 + * @see JCacheCacheManager */ public class JCacheCache extends AbstractValueAdaptingCache { @@ -42,7 +43,7 @@ public class JCacheCache extends AbstractValueAdaptingCache { /** - * Create an {@link org.springframework.cache.jcache.JCacheCache} instance. + * Create a {@code JCacheCache} instance. * @param jcache backing JCache Cache instance */ public JCacheCache(Cache jcache) { @@ -50,7 +51,7 @@ public JCacheCache(Cache jcache) { } /** - * Create an {@link org.springframework.cache.jcache.JCacheCache} instance. + * Create a {@code JCacheCache} instance. * @param jcache backing JCache Cache instance * @param allowNullValues whether to accept and convert null values for this cache */ @@ -128,7 +129,7 @@ public T process(MutableEntry entry, Object... arguments) throws } catch (Exception ex) { throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " + - "to compute value for key '" + entry.getKey() + "'", ex); + "to compute value for key '" + entry.getKey() + "'", ex); } entry.setValue(toStoreValue(value)); return value; diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java index 8f52be60e2d8..e564c5c60f67 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -28,13 +28,14 @@ /** * {@link org.springframework.cache.CacheManager} implementation - * backed by a JCache {@link javax.cache.CacheManager}. + * backed by a JCache {@link CacheManager javax.cache.CacheManager}. * *

Note: This class has been updated for JCache 1.0, as of Spring 4.0. * * @author Juergen Hoeller * @author Stephane Nicoll * @since 3.2 + * @see JCacheCache */ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager { @@ -45,15 +46,18 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage /** - * Create a new JCacheCacheManager, setting the target JCache CacheManager - * through the {@link #setCacheManager} bean property. + * Create a new {@code JCacheCacheManager} without a backing JCache + * {@link CacheManager javax.cache.CacheManager}. + *

The backing JCache {@code javax.cache.CacheManager} can be set via the + * {@link #setCacheManager} bean property. */ public JCacheCacheManager() { } /** - * Create a new JCacheCacheManager for the given backing JCache. - * @param cacheManager the backing JCache {@link javax.cache.CacheManager} + * Create a new {@code JCacheCacheManager} for the given backing JCache + * {@link CacheManager javax.cache.CacheManager}. + * @param cacheManager the backing JCache {@code javax.cache.CacheManager} */ public JCacheCacheManager(CacheManager cacheManager) { this.cacheManager = cacheManager; @@ -61,14 +65,14 @@ public JCacheCacheManager(CacheManager cacheManager) { /** - * Set the backing JCache {@link javax.cache.CacheManager}. + * Set the backing JCache {@link CacheManager javax.cache.CacheManager}. */ public void setCacheManager(@Nullable CacheManager cacheManager) { this.cacheManager = cacheManager; } /** - * Return the backing JCache {@link javax.cache.CacheManager}. + * Return the backing JCache {@link CacheManager javax.cache.CacheManager}. */ @Nullable public CacheManager getCacheManager() { diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index b92d6e7eefce..905f2c252b6c 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -141,7 +141,7 @@ protected Object lookup(Object key) { @Override @Nullable public T get(Object key, Callable valueLoader) { - return (T) fromStoreValue(this.store.computeIfAbsent(key, r -> { + return (T) fromStoreValue(this.store.computeIfAbsent(key, k -> { try { return toStoreValue(valueLoader.call()); } @@ -191,7 +191,7 @@ protected Object toStoreValue(@Nullable Object userValue) { } private Object serializeValue(SerializationDelegate serialization, Object storeValue) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream out = new ByteArrayOutputStream(1024); try { serialization.serialize(storeValue, out); return out.toByteArray(); diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java index 817ebf387195..aea913288d8b 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -190,9 +190,7 @@ private void recreateCaches() { */ protected Cache createConcurrentMapCache(String name) { SerializationDelegate actualSerialization = (isStoreByValue() ? this.serialization : null); - return new ConcurrentMapCache(name, new ConcurrentHashMap<>(256), - isAllowNullValues(), actualSerialization); - + return new ConcurrentMapCache(name, new ConcurrentHashMap<>(256), isAllowNullValues(), actualSerialization); } } diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java index 04f5e66cdf8d..69cf6498c82b 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -30,6 +30,7 @@ * @author Costin Leau * @author Stephane Nicoll * @since 4.3.4 + * @see NoOpCacheManager */ public class NoOpCache implements Cache { @@ -37,7 +38,7 @@ public class NoOpCache implements Cache { /** - * Create a {@link NoOpCache} instance with the specified name + * Create a {@link NoOpCache} instance with the specified name. * @param name the name of the cache */ public NoOpCache(String name) { diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java index c0510e8c1718..0b3137b88512 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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,7 +37,7 @@ * @author Costin Leau * @author Stephane Nicoll * @since 3.1 - * @see CompositeCacheManager + * @see NoOpCache */ public class NoOpCacheManager implements CacheManager { @@ -55,7 +55,7 @@ public class NoOpCacheManager implements CacheManager { public Cache getCache(String name) { Cache cache = this.caches.get(name); if (cache == null) { - this.caches.putIfAbsent(name, new NoOpCache(name)); + this.caches.computeIfAbsent(name, key -> new NoOpCache(name)); synchronized (this.cacheNames) { this.cacheNames.add(name); } diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java index c3e09d18ed22..98ae871ef777 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -49,7 +49,7 @@ * at the type level of the containing target class, applying to all public service methods * of that class. By default, JSR-303 will validate against its default group only. * - *

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider. + *

As of Spring 5.0, this functionality requires a Bean Validation 1.1+ provider. * * @author Juergen Hoeller * @since 3.1 @@ -86,7 +86,6 @@ public MethodValidationInterceptor(Validator validator) { @Override - @SuppressWarnings("unchecked") public Object invoke(MethodInvocation invocation) throws Throwable { // Avoid Validator invocation on FactoryBean.getObjectType/isSingleton if (isFactoryBeanMetadataMethod(invocation.getMethod())) { diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java index c37dcb3b3eab..0eb4635ddaa3 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -49,7 +49,7 @@ * inline constraint annotations. Validation groups can be specified through {@code @Validated} * as well. By default, JSR-303 will validate against its default group only. * - *

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider. + *

As of Spring 5.0, this functionality requires a Bean Validation 1.1+ provider. * * @author Juergen Hoeller * @since 3.1 diff --git a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java index b9aa6f800815..3b5a59d2815b 100644 --- a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java +++ b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -60,7 +60,7 @@ public class CacheReproTests { @Test - public void spr11124MultipleAnnotations() throws Exception { + public void spr11124MultipleAnnotations() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11124Config.class); Spr11124Service bean = context.getBean(Spr11124Service.class); bean.single(2); @@ -71,7 +71,7 @@ public void spr11124MultipleAnnotations() throws Exception { } @Test - public void spr11249PrimitiveVarargs() throws Exception { + public void spr11249PrimitiveVarargs() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11249Config.class); Spr11249Service bean = context.getBean(Spr11249Service.class); Object result = bean.doSomething("op", 2, 3); @@ -397,7 +397,6 @@ public Optional findById(String id) { public TestBean insertItem(TestBean item) { return item; } - } diff --git a/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java b/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java index ca360917605e..96463af8b386 100644 --- a/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java +++ b/spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -35,8 +35,7 @@ * @author Juergen Hoeller * @author Stephane Nicoll */ -public class ConcurrentMapCacheTests - extends AbstractValueAdaptingCacheTests { +public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests { protected ConcurrentMap nativeCache; @@ -48,12 +47,11 @@ public class ConcurrentMapCacheTests @Before - public void setUp() throws Exception { + public void setup() { this.nativeCache = new ConcurrentHashMap<>(); this.cache = new ConcurrentMapCache(CACHE_NAME, this.nativeCache, true); this.nativeCacheNoNull = new ConcurrentHashMap<>(); - this.cacheNoNull = new ConcurrentMapCache(CACHE_NAME_NO_NULL, - this.nativeCacheNoNull, false); + this.cacheNoNull = new ConcurrentMapCache(CACHE_NAME_NO_NULL, this.nativeCacheNoNull, false); this.cache.clear(); } @@ -72,6 +70,7 @@ protected ConcurrentMap getNativeCache() { return this.nativeCache; } + @Test public void testIsStoreByReferenceByDefault() { assertFalse(this.cache.isStoreByValue()); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java index 207031504f6a..dc559b03d525 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -100,7 +100,7 @@ public interface JdbcOperations { * @param rse a callback that will extract all rows of results * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem executing the query - * @see #query(String, Object[], ResultSetExtractor) + * @see #query(String, ResultSetExtractor, Object...) */ @Nullable T query(String sql, ResultSetExtractor rse) throws DataAccessException; @@ -114,7 +114,7 @@ public interface JdbcOperations { * @param sql the SQL query to execute * @param rch a callback that will extract results, one row at a time * @throws DataAccessException if there is any problem executing the query - * @see #query(String, Object[], RowCallbackHandler) + * @see #query(String, RowCallbackHandler, Object...) */ void query(String sql, RowCallbackHandler rch) throws DataAccessException; @@ -128,7 +128,7 @@ public interface JdbcOperations { * @param rowMapper a callback that will map one object per row * @return the result List, containing mapped objects * @throws DataAccessException if there is any problem executing the query - * @see #query(String, Object[], RowMapper) + * @see #query(String, RowMapper, Object...) */ List query(String sql, RowMapper rowMapper) throws DataAccessException; @@ -146,7 +146,7 @@ public interface JdbcOperations { * @throws IncorrectResultSizeDataAccessException if the query does not * return exactly one row * @throws DataAccessException if there is any problem executing the query - * @see #queryForObject(String, Object[], RowMapper) + * @see #queryForObject(String, RowMapper, Object...) */ @Nullable T queryForObject(String sql, RowMapper rowMapper) throws DataAccessException; @@ -166,7 +166,7 @@ public interface JdbcOperations { * @throws IncorrectResultSizeDataAccessException if the query does not return * exactly one row, or does not return exactly one column in that row * @throws DataAccessException if there is any problem executing the query - * @see #queryForObject(String, Object[], Class) + * @see #queryForObject(String, Class, Object...) */ @Nullable T queryForObject(String sql, Class requiredType) throws DataAccessException; @@ -184,7 +184,7 @@ public interface JdbcOperations { * @throws IncorrectResultSizeDataAccessException if the query does not * return exactly one row * @throws DataAccessException if there is any problem executing the query - * @see #queryForMap(String, Object[]) + * @see #queryForMap(String, Object...) * @see ColumnMapRowMapper */ Map queryForMap(String sql) throws DataAccessException; @@ -201,7 +201,7 @@ public interface JdbcOperations { * (for example, {@code Integer.class}) * @return a List of objects that match the specified element type * @throws DataAccessException if there is any problem executing the query - * @see #queryForList(String, Object[], Class) + * @see #queryForList(String, Class, Object...) * @see SingleColumnRowMapper */ List queryForList(String sql, Class elementType) throws DataAccessException; @@ -218,7 +218,7 @@ public interface JdbcOperations { * @param sql the SQL query to execute * @return an List that contains a Map per row * @throws DataAccessException if there is any problem executing the query - * @see #queryForList(String, Object[]) + * @see #queryForList(String, Object...) */ List> queryForList(String sql) throws DataAccessException; @@ -237,7 +237,7 @@ public interface JdbcOperations { * @return a SqlRowSet representation (possibly a wrapper around a * {@code javax.sql.rowset.CachedRowSet}) * @throws DataAccessException if there is any problem executing the query - * @see #queryForRowSet(String, Object[]) + * @see #queryForRowSet(String, Object...) * @see SqlRowSetResultSetExtractor * @see javax.sql.rowset.CachedRowSet */ @@ -323,7 +323,8 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem */ @Nullable - T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException; + T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) + throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of arguments @@ -466,7 +467,8 @@ public interface JdbcOperations { * @return the result List, containing mapped objects * @throws DataAccessException if the query fails */ - List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper rowMapper) throws DataAccessException; + List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper rowMapper) + throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -903,6 +905,7 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @param sql the SQL statement to execute * @param batchArgs the List of Object arrays containing the batch of arguments for the query * @return an array containing the numbers of rows affected by each update in the batch + * @throws DataAccessException if there is any problem issuing the update */ int[] batchUpdate(String sql, List batchArgs) throws DataAccessException; @@ -913,6 +916,7 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @param argTypes the SQL types of the arguments * (constants from {@code java.sql.Types}) * @return an array containing the numbers of rows affected by each update in the batch + * @throws DataAccessException if there is any problem issuing the update */ int[] batchUpdate(String sql, List batchArgs, int[] argTypes) throws DataAccessException; @@ -926,6 +930,7 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @param pss the ParameterizedPreparedStatementSetter to use * @return an array containing for each batch another array containing the numbers of rows affected * by each update in the batch + * @throws DataAccessException if there is any problem issuing the update * @since 3.1 */ int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java index 4739d3c7d976..d37abe95c129 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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,7 +62,7 @@ public interface NamedParameterJdbcOperations { * and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy. *

The callback action can return a result object, for example a * domain object or a collection of domain objects. - * @param sql SQL to execute + * @param sql the SQL to execute * @param paramSource container of arguments to bind to the query * @param action callback object that specifies the action * @return a result object returned by the action, or {@code null} @@ -80,7 +80,7 @@ T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallb * and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy. *

The callback action can return a result object, for example a * domain object or a collection of domain objects. - * @param sql SQL to execute + * @param sql the SQL to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param action callback object that specifies the action @@ -99,7 +99,7 @@ T execute(String sql, Map paramMap, PreparedStatementCallback * and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy. *

The callback action can return a result object, for example a * domain object or a collection of domain objects. - * @param sql SQL to execute + * @param sql the SQL to execute * @param action callback object that specifies the action * @return a result object returned by the action, or {@code null} * @throws DataAccessException if there is any problem @@ -111,7 +111,7 @@ T execute(String sql, Map paramMap, PreparedStatementCallback * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, reading the ResultSet with a * ResultSetExtractor. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param rse object that will extract results * @return an arbitrary result object, as returned by the ResultSetExtractor @@ -125,12 +125,12 @@ T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rs * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, reading the ResultSet with a * ResultSetExtractor. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param rse object that will extract results * @return an arbitrary result object, as returned by the ResultSetExtractor - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ @Nullable T query(String sql, Map paramMap, ResultSetExtractor rse) @@ -142,10 +142,10 @@ T query(String sql, Map paramMap, ResultSetExtractor rse) *

Note: In contrast to the JdbcOperations method with the same signature, * this query variant always uses a PreparedStatement. It is effectively * equivalent to a query call with an empty parameter Map. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param rse object that will extract results * @return an arbitrary result object, as returned by the ResultSetExtractor - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ @Nullable T query(String sql, ResultSetExtractor rse) throws DataAccessException; @@ -154,7 +154,7 @@ T query(String sql, Map paramMap, ResultSetExtractor rse) * Query given SQL to create a prepared statement from SQL and a list of * arguments to bind to the query, reading the ResultSet on a per-row basis * with a RowCallbackHandler. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param rch object that will extract results, one row at a time * @throws DataAccessException if the query fails @@ -166,11 +166,11 @@ void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) * Query given SQL to create a prepared statement from SQL and a list of * arguments to bind to the query, reading the ResultSet on a per-row basis * with a RowCallbackHandler. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param rch object that will extract results, one row at a time - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ void query(String sql, Map paramMap, RowCallbackHandler rch) throws DataAccessException; @@ -180,9 +180,9 @@ void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) *

Note: In contrast to the JdbcOperations method with the same signature, * this query variant always uses a PreparedStatement. It is effectively * equivalent to a query call with an empty parameter Map. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param rch object that will extract results, one row at a time - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ void query(String sql, RowCallbackHandler rch) throws DataAccessException; @@ -190,11 +190,11 @@ void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, mapping each row to a Java object * via a RowMapper. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param rowMapper object that will map one object per row * @return the result List, containing mapped objects - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ List query(String sql, SqlParameterSource paramSource, RowMapper rowMapper) throws DataAccessException; @@ -203,12 +203,12 @@ List query(String sql, SqlParameterSource paramSource, RowMapper rowMa * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, mapping each row to a Java object * via a RowMapper. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param rowMapper object that will map one object per row * @return the result List, containing mapped objects - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ List query(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException; @@ -219,10 +219,10 @@ List query(String sql, Map paramMap, RowMapper rowMapper) *

Note: In contrast to the JdbcOperations method with the same signature, * this query variant always uses a PreparedStatement. It is effectively * equivalent to a query call with an empty parameter Map. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param rowMapper object that will map one object per row * @return the result List, containing mapped objects - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ List query(String sql, RowMapper rowMapper) throws DataAccessException; @@ -230,7 +230,7 @@ List query(String sql, Map paramMap, RowMapper rowMapper) * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, mapping a single result row to a * Java object via a RowMapper. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param rowMapper object that will map one object per row * @return the single mapped object (may be {@code null} if the given @@ -238,7 +238,7 @@ List query(String sql, Map paramMap, RowMapper rowMapper) * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row, or does not return exactly * one column in that row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ @Nullable T queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper) @@ -248,7 +248,7 @@ T queryForObject(String sql, SqlParameterSource paramSource, RowMapper ro * Query given SQL to create a prepared statement from SQL and a list * of arguments to bind to the query, mapping a single result row to a * Java object via a RowMapper. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param rowMapper object that will map one object per row @@ -257,7 +257,7 @@ T queryForObject(String sql, SqlParameterSource paramSource, RowMapper ro * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row, or does not return exactly * one column in that row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails */ @Nullable T queryForObject(String sql, Map paramMap, RowMapper rowMapper) @@ -268,14 +268,14 @@ T queryForObject(String sql, Map paramMap, RowMapper rowMapper * list of arguments to bind to the query, expecting a result object. *

The query is expected to be a single row/single column query; the returned * result will be directly mapped to the corresponding object type. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param requiredType the type that the result object is expected to match * @return the result object of the required type, or {@code null} in case of SQL NULL * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row, or does not return exactly * one column in that row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) */ @Nullable @@ -287,7 +287,7 @@ T queryForObject(String sql, SqlParameterSource paramSource, Class requir * list of arguments to bind to the query, expecting a result object. *

The query is expected to be a single row/single column query; the returned * result will be directly mapped to the corresponding object type. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param requiredType the type that the result object is expected to match @@ -295,7 +295,7 @@ T queryForObject(String sql, SqlParameterSource paramSource, Class requir * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row, or does not return exactly * one column in that row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) */ @Nullable @@ -307,12 +307,12 @@ T queryForObject(String sql, Map paramMap, Class requiredType) * list of arguments to bind to the query, expecting a result Map. *

The query is expected to be a single row query; the result row will be * mapped to a Map (one entry for each column, using the column name as the key). - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @return the result Map (one entry for each column, using the column name as the key) * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String) * @see org.springframework.jdbc.core.ColumnMapRowMapper */ @@ -326,13 +326,13 @@ T queryForObject(String sql, Map paramMap, Class requiredType) * one of the queryForObject() methods. *

The query is expected to be a single row query; the result row will be * mapped to a Map (one entry for each column, using the column name as the key). - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @return the result Map (one entry for each column, using the column name as the key) * @throws org.springframework.dao.IncorrectResultSizeDataAccessException * if the query does not return exactly one row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String) * @see org.springframework.jdbc.core.ColumnMapRowMapper */ @@ -343,12 +343,12 @@ T queryForObject(String sql, Map paramMap, Class requiredType) * list of arguments to bind to the query, expecting a result list. *

The results will be mapped to a List (one entry for each row) of * result objects, each of them matching the specified element type. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @param elementType the required type of element in the result list * (for example, {@code Integer.class}) * @return a List of objects that match the specified element type - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class) * @see org.springframework.jdbc.core.SingleColumnRowMapper */ @@ -360,13 +360,13 @@ List queryForList(String sql, SqlParameterSource paramSource, Class el * list of arguments to bind to the query, expecting a result list. *

The results will be mapped to a List (one entry for each row) of * result objects, each of them matching the specified element type. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @param elementType the required type of element in the result list * (for example, {@code Integer.class}) * @return a List of objects that match the specified element type - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class) * @see org.springframework.jdbc.core.SingleColumnRowMapper */ @@ -380,10 +380,10 @@ List queryForList(String sql, Map paramMap, Class elementTy * Maps (one entry for each column, using the column name as the key). * Each element in the list will be of the form returned by this interface's * {@code queryForMap} methods. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @return a List that contains a Map per row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String) */ List> queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException; @@ -395,11 +395,11 @@ List queryForList(String sql, Map paramMap, Class elementTy * Maps (one entry for each column, using the column name as the key). * Each element in the list will be of the form returned by this interface's * {@code queryForMap} methods. - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @return a List that contains a Map per row - * @throws org.springframework.dao.DataAccessException if the query fails + * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String) */ List> queryForList(String sql, Map paramMap) throws DataAccessException; @@ -413,11 +413,11 @@ List queryForList(String sql, Map paramMap, Class elementTy * be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} * class is used, which is part of JDK 1.5+ and also available separately as part of * Sun's JDBC RowSet Implementations download (rowset.jar). - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramSource container of arguments to bind to the query * @return a SqlRowSet representation (possibly a wrapper around a * {@code javax.sql.rowset.CachedRowSet}) - * @throws org.springframework.dao.DataAccessException if there is any problem executing the query + * @throws DataAccessException if there is any problem executing the query * @see org.springframework.jdbc.core.JdbcTemplate#queryForRowSet(String) * @see org.springframework.jdbc.core.SqlRowSetResultSetExtractor * @see javax.sql.rowset.CachedRowSet @@ -433,12 +433,12 @@ List queryForList(String sql, Map paramMap, Class elementTy * be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} * class is used, which is part of JDK 1.5+ and also available separately as part of * Sun's JDBC RowSet Implementations download (rowset.jar). - * @param sql SQL query to execute + * @param sql the SQL query to execute * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @return a SqlRowSet representation (possibly a wrapper around a * {@code javax.sql.rowset.CachedRowSet}) - * @throws org.springframework.dao.DataAccessException if there is any problem executing the query + * @throws DataAccessException if there is any problem executing the query * @see org.springframework.jdbc.core.JdbcTemplate#queryForRowSet(String) * @see org.springframework.jdbc.core.SqlRowSetResultSetExtractor * @see javax.sql.rowset.CachedRowSet @@ -447,31 +447,31 @@ List queryForList(String sql, Map paramMap, Class elementTy /** * Issue an update via a prepared statement, binding the given arguments. - * @param sql SQL containing named parameters + * @param sql the SQL containing named parameters * @param paramSource container of arguments and SQL types to bind to the query * @return the number of rows affected - * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update + * @throws DataAccessException if there is any problem issuing the update */ int update(String sql, SqlParameterSource paramSource) throws DataAccessException; /** * Issue an update via a prepared statement, binding the given arguments. - * @param sql SQL containing named parameters + * @param sql the SQL containing named parameters * @param paramMap map of parameters to bind to the query * (leaving it to the PreparedStatement to guess the corresponding SQL type) * @return the number of rows affected - * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update + * @throws DataAccessException if there is any problem issuing the update */ int update(String sql, Map paramMap) throws DataAccessException; /** * Issue an update via a prepared statement, binding the given arguments, * returning generated keys. - * @param sql SQL containing named parameters + * @param sql the SQL containing named parameters * @param paramSource container of arguments and SQL types to bind to the query - * @param generatedKeyHolder KeyHolder that will hold the generated keys + * @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys * @return the number of rows affected - * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update + * @throws DataAccessException if there is any problem issuing the update * @see MapSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ @@ -481,12 +481,12 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol /** * Issue an update via a prepared statement, binding the given arguments, * returning generated keys. - * @param sql SQL containing named parameters + * @param sql the SQL containing named parameters * @param paramSource container of arguments and SQL types to bind to the query - * @param generatedKeyHolder KeyHolder that will hold the generated keys + * @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys * @param keyColumnNames names of the columns that will have keys generated for them * @return the number of rows affected - * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update + * @throws DataAccessException if there is any problem issuing the update * @see MapSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ @@ -498,6 +498,7 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol * @param sql the SQL statement to execute * @param batchValues the array of Maps containing the batch of arguments for the query * @return an array containing the numbers of rows affected by each update in the batch + * @throws DataAccessException if there is any problem issuing the update */ int[] batchUpdate(String sql, Map[] batchValues); @@ -506,6 +507,7 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol * @param sql the SQL statement to execute * @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query * @return an array containing the numbers of rows affected by each update in the batch + * @throws DataAccessException if there is any problem issuing the update */ int[] batchUpdate(String sql, SqlParameterSource[] batchArgs); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java index 0ce9f4125b9e..d62d3f7b8c42 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java @@ -194,7 +194,7 @@ protected DataSource obtainDataSource() { * through an explicit statement on the transactional connection: * "SET TRANSACTION READ ONLY" as understood by Oracle, MySQL and Postgres. *

The exact treatment, including any SQL statement executed on the connection, - * can be customized through through {@link #prepareTransactionalConnection}. + * can be customized through {@link #prepareTransactionalConnection}. *

This mode of read-only handling goes beyond the {@link Connection#setReadOnly} * hint that Spring applies by default. In contrast to that standard JDBC hint, * "SET TRANSACTION READ ONLY" enforces an isolation-level-like connection mode @@ -249,9 +249,6 @@ protected boolean isExistingTransaction(Object transaction) { return (txObject.hasConnectionHolder() && txObject.getConnectionHolder().isTransactionActive()); } - /** - * This implementation sets the isolation level but ignores the timeout. - */ @Override protected void doBegin(Object transaction, TransactionDefinition definition) { DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java index 154d624feb7e..6a03f82f3e9e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -420,7 +420,7 @@ public int getTimeout() { conHolder.setTimeoutInSeconds(timeoutToUse); } if (logger.isDebugEnabled()) { - logger.debug("Exposing JPA transaction as JDBC transaction [" + conHandle + "]"); + logger.debug("Exposing JPA transaction as JDBC [" + conHandle + "]"); } TransactionSynchronizationManager.bindResource(getDataSource(), conHolder); txObject.setConnectionHolder(conHolder); @@ -537,9 +537,9 @@ protected void doCommit(DefaultTransactionStatus status) { } catch (RollbackException ex) { if (ex.getCause() instanceof RuntimeException) { - DataAccessException dex = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause()); - if (dex != null) { - throw dex; + DataAccessException dae = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause()); + if (dae != null) { + throw dae; } } throw new TransactionSystemException("Could not commit JPA transaction", ex); @@ -606,9 +606,9 @@ protected void doCleanupAfterCompletion(Object transaction) { getJpaDialect().releaseJdbcConnection(conHandle, txObject.getEntityManagerHolder().getEntityManager()); } - catch (Exception ex) { + catch (Throwable ex) { // Just log it, to keep a transaction-related exception. - logger.error("Could not close JDBC connection after transaction", ex); + logger.error("Failed to release JDBC connection after transaction", ex); } } } diff --git a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java index 6282ed4e04d9..77d91c4d7061 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -97,8 +97,8 @@ public InetSocketAddress getRemoteAddress() { return this.remoteAddress; } - @Nullable @Override + @Nullable protected SslInfo initSslInfo() { return this.sslInfo; } @@ -342,9 +342,9 @@ public interface BaseBuilder> { * @see BodyBuilder#body(String) */ MockServerHttpRequest build(); - } + /** * A builder that adds a body to the request. */ @@ -383,7 +383,6 @@ public interface BodyBuilder extends BaseBuilder { * @return the built request entity */ MockServerHttpRequest body(String body); - } @@ -391,7 +390,6 @@ private static class DefaultBodyBuilder implements BodyBuilder { private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory(); - private final HttpMethod method; private final URI url; @@ -411,7 +409,6 @@ private static class DefaultBodyBuilder implements BodyBuilder { @Nullable private SslInfo sslInfo; - public DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; this.url = url; @@ -558,13 +555,11 @@ private void applyCookiesIfNecessary() { private URI getUrlToUse() { MultiValueMap params = this.queryParamsBuilder.buildAndExpand().encode().getQueryParams(); - if (!params.isEmpty()) { return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri(); } - return this.url; } } -} \ No newline at end of file +} diff --git a/spring-web/src/main/java/org/springframework/http/RequestEntity.java b/spring-web/src/main/java/org/springframework/http/RequestEntity.java index a1a3a7ff8a08..0cbbdecb18f9 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -60,8 +60,11 @@ * @author Arjen Poutsma * @author Sebastien Deleuze * @since 4.1 + * @param the body type * @see #getMethod() * @see #getUrl() + * @see org.springframework.web.client.RestOperations#exchange(RequestEntity, Class) + * @see ResponseEntity */ public class RequestEntity extends HttpEntity { diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java index c025cfd07de5..d6aad897cff1 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -46,12 +46,12 @@ */ public class ServerSentEventHttpMessageReader implements HttpMessageReader { + private static final ResolvableType STRING_TYPE = ResolvableType.forClass(String.class); + private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory(); private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly(); - private static final ResolvableType STRING_TYPE = ResolvableType.forClass(String.class); - @Nullable private final Decoder decoder; @@ -130,7 +130,7 @@ else if (line.startsWith("event:")) { sseBuilder.event(line.substring(6)); } else if (line.startsWith("retry:")) { - sseBuilder.retry(Duration.ofMillis(Long.valueOf(line.substring(6)))); + sseBuilder.retry(Duration.ofMillis(Long.parseLong(line.substring(6)))); } else if (line.startsWith(":")) { comment = (comment != null ? comment : new StringBuilder()); @@ -143,7 +143,7 @@ else if (line.startsWith(":")) { if (shouldWrap) { if (comment != null) { - sseBuilder.comment(comment.toString().substring(0, comment.length() - 1)); + sseBuilder.comment(comment.substring(0, comment.length() - 1)); } return decodedData.map(o -> { sseBuilder.data(o); diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java index 37b8cc950ea3..7dc59972bc96 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -38,6 +38,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * {@code HttpMessageWriter} for {@code "text/event-stream"} responses. @@ -135,7 +136,7 @@ private Flux> encode(Publisher input, ResolvableType el writeField("retry", retry.toMillis(), sb); } if (comment != null) { - sb.append(':').append(comment.replaceAll("\\n", "\n:")).append("\n"); + sb.append(':').append(StringUtils.replace(comment, "\n", "\n:")).append("\n"); } if (data != null) { sb.append("data:"); @@ -147,24 +148,24 @@ private Flux> encode(Publisher input, ResolvableType el }); } - private void writeField(String fieldName, Object fieldValue, StringBuilder stringBuilder) { - stringBuilder.append(fieldName); - stringBuilder.append(':'); - stringBuilder.append(fieldValue.toString()); - stringBuilder.append("\n"); + private void writeField(String fieldName, Object fieldValue, StringBuilder sb) { + sb.append(fieldName); + sb.append(':'); + sb.append(fieldValue.toString()); + sb.append("\n"); } @SuppressWarnings("unchecked") - private Flux encodeData(@Nullable T data, ResolvableType valueType, + private Flux encodeData(@Nullable T dataValue, ResolvableType valueType, MediaType mediaType, DataBufferFactory factory, Map hints) { - if (data == null) { + if (dataValue == null) { return Flux.empty(); } - if (data instanceof String) { - String text = (String) data; - return Flux.from(encodeText(text.replaceAll("\\n", "\ndata:") + "\n", mediaType, factory)); + if (dataValue instanceof String) { + String text = (String) dataValue; + return Flux.from(encodeText(StringUtils.replace(text, "\n", "\ndata:") + "\n", mediaType, factory)); } if (this.encoder == null) { @@ -172,7 +173,7 @@ private Flux encodeData(@Nullable T data, ResolvableType valueTy } return ((Encoder) this.encoder) - .encode(Mono.just(data), factory, valueType, mediaType, hints) + .encode(Mono.just(dataValue), factory, valueType, mediaType, hints) .concatWith(encodeText("\n", mediaType, factory)); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java index 43a92aff2e03..bbc3beb3bf9d 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -215,14 +215,14 @@ protected MultiValueMap initCookies() { return this.cookies; } - @Nullable @Override + @Nullable public InetSocketAddress getRemoteAddress() { return this.remoteAddress; } - @Nullable @Override + @Nullable protected SslInfo initSslInfo() { return this.sslInfo; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index c9e86e3bcf05..1cc8f79fb258 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -155,6 +155,7 @@ public InetSocketAddress getRemoteAddress() { return this.request.remoteAddress(); } + @Override @Nullable protected SslInfo initSslInfo() { SslHandler sslHandler = this.request.context().channel().pipeline().get(SslHandler.class); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java index 34cf412feeee..dc38cda37c5b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -92,12 +92,13 @@ public MultiValueMap getCookies() { } @Override + @Nullable public InetSocketAddress getRemoteAddress() { return getDelegate().getRemoteAddress(); } - @Nullable @Override + @Nullable public SslInfo getSslInfo() { return getDelegate().getSslInfo(); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java index dedaf44466a2..a79aa3f54a40 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -42,6 +42,7 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -168,10 +169,12 @@ protected MultiValueMap initCookies() { } @Override + @NonNull public InetSocketAddress getRemoteAddress() { return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort()); } + @Override @Nullable protected SslInfo initSslInfo() { X509Certificate[] certificates = getX509Certificates(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java index 4ef141635a42..3e603ed175a9 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -102,6 +102,7 @@ protected MultiValueMap initCookies() { } @Override + @Nullable public InetSocketAddress getRemoteAddress() { return this.exchange.getSourceAddress(); } diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index b6660fe8fdef..ca70a4e581fa 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,55 +39,6 @@ */ public class DefaultUriBuilderFactory implements UriBuilderFactory { - /** - * Enum to represent multiple URI encoding strategies. - * @see #setEncodingMode - */ - public enum EncodingMode { - - /** - * Pre-encode the URI template first, then strictly encode URI variables - * when expanded, with the following rules: - *
    - *
  • For the URI template replace only non-ASCII and illegal - * (within a given URI component type) characters with escaped octets. - *
  • For URI variables do the same and also replace characters with - * reserved meaning. - *
- *

For most cases, this mode is most likely to give the expected - * result because in treats URI variables as opaque data to be fully - * encoded, while {@link #URI_COMPONENT} by comparison is useful only - * if intentionally expanding URI variables with reserved characters. - * @since 5.0.8 - * @see UriComponentsBuilder#encode() - */ - TEMPLATE_AND_VALUES, - - /** - * Does not encode the URI template and instead applies strict encoding - * to URI variables via {@link UriUtils#encodeUriVariables} prior to - * expanding them into the template. - * @see UriUtils#encodeUriVariables(Object...) - * @see UriUtils#encodeUriVariables(Map) - */ - VALUES_ONLY, - - /** - * Expand URI variables first, and then encode the resulting URI - * component values, replacing only non-ASCII and illegal - * (within a given URI component type) characters, but not characters - * with reserved meaning. - * @see UriComponents#encode() - */ - URI_COMPONENT, - - /** - * No encoding should be applied. - */ - NONE - } - - @Nullable private final UriComponentsBuilder baseUri; @@ -194,16 +145,19 @@ public boolean shouldParsePath() { // UriTemplateHandler + @Override public URI expand(String uriTemplate, Map uriVars) { return uriString(uriTemplate).build(uriVars); } + @Override public URI expand(String uriTemplate, Object... uriVars) { return uriString(uriTemplate).build(uriVars); } // UriBuilderFactory + @Override public UriBuilder uriString(String uriTemplate) { return new DefaultUriBuilder(uriTemplate); } @@ -214,6 +168,55 @@ public UriBuilder builder() { } + /** + * Enum to represent multiple URI encoding strategies. + * @see #setEncodingMode + */ + public enum EncodingMode { + + /** + * Pre-encode the URI template first, then strictly encode URI variables + * when expanded, with the following rules: + *

    + *
  • For the URI template replace only non-ASCII and illegal + * (within a given URI component type) characters with escaped octets. + *
  • For URI variables do the same and also replace characters with + * reserved meaning. + *
+ *

For most cases, this mode is most likely to give the expected + * result because in treats URI variables as opaque data to be fully + * encoded, while {@link #URI_COMPONENT} by comparison is useful only + * if intentionally expanding URI variables with reserved characters. + * @since 5.0.8 + * @see UriComponentsBuilder#encode() + */ + TEMPLATE_AND_VALUES, + + /** + * Does not encode the URI template and instead applies strict encoding + * to URI variables via {@link UriUtils#encodeUriVariables} prior to + * expanding them into the template. + * @see UriUtils#encodeUriVariables(Object...) + * @see UriUtils#encodeUriVariables(Map) + */ + VALUES_ONLY, + + /** + * Expand URI variables first, and then encode the resulting URI + * component values, replacing only non-ASCII and illegal + * (within a given URI component type) characters, but not characters + * with reserved meaning. + * @see UriComponents#encode() + */ + URI_COMPONENT, + + /** + * No encoding should be applied. + */ + NONE + } + + /** * {@link DefaultUriBuilderFactory} specific implementation of UriBuilder. */ diff --git a/spring-web/src/main/java/org/springframework/web/util/UriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/UriBuilderFactory.java index c1d7698123f7..ddd5f5dd8335 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriBuilderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.util; /** @@ -22,13 +23,14 @@ * * @author Rossen Stoyanchev * @since 5.0 + * @see DefaultUriBuilderFactory */ public interface UriBuilderFactory extends UriTemplateHandler { /** * Initialize a builder with the given URI template. * @param uriTemplate the URI template to use - * @return the URI builder instance + * @return the builder instance */ UriBuilder uriString(String uriTemplate); diff --git a/spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java b/spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java index adc862161b1a..b9c32d82caa4 100644 --- a/spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java +++ b/spring-web/src/test/java/org/springframework/mock/http/server/reactive/test/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -97,8 +97,8 @@ public InetSocketAddress getRemoteAddress() { return this.remoteAddress; } - @Nullable @Override + @Nullable protected SslInfo initSslInfo() { return this.sslInfo; } @@ -342,9 +342,9 @@ public interface BaseBuilder> { * @see BodyBuilder#body(String) */ MockServerHttpRequest build(); - } + /** * A builder that adds a body to the request. */ @@ -383,7 +383,6 @@ public interface BodyBuilder extends BaseBuilder { * @return the built request entity */ MockServerHttpRequest body(String body); - } @@ -391,7 +390,6 @@ private static class DefaultBodyBuilder implements BodyBuilder { private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory(); - private final HttpMethod method; private final URI url; @@ -411,7 +409,6 @@ private static class DefaultBodyBuilder implements BodyBuilder { @Nullable private SslInfo sslInfo; - public DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; this.url = url; @@ -558,13 +555,11 @@ private void applyCookiesIfNecessary() { private URI getUrlToUse() { MultiValueMap params = this.queryParamsBuilder.buildAndExpand().encode().getQueryParams(); - if (!params.isEmpty()) { return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri(); } - return this.url; } } -} \ No newline at end of file +} diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java index 65601ad6b417..f754040fa71c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -42,6 +42,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport private final WebFluxConfigurerComposite configurers = new WebFluxConfigurerComposite(); + @Autowired(required = false) public void setConfigurers(List configurers) { if (!CollectionUtils.isEmpty(configurers)) { @@ -49,6 +50,7 @@ public void setConfigurers(List configurers) { } } + @Override protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { this.configurers.configureContentTypeResolver(builder); @@ -100,4 +102,5 @@ protected MessageCodesResolver getMessageCodesResolver() { protected void configureViewResolvers(ViewResolverRegistry registry) { this.configurers.configureViewResolvers(registry); } + } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index a76a06938e6a..42a0add6c5c9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -134,7 +134,6 @@ public RequestBodyUriSpec method(HttpMethod httpMethod) { return methodInternal(httpMethod); } - @SuppressWarnings("unchecked") private RequestBodyUriSpec methodInternal(HttpMethod httpMethod) { return new DefaultRequestBodyUriSpec(httpMethod); } diff --git a/src/docs/asciidoc/core/core-expressions.adoc b/src/docs/asciidoc/core/core-expressions.adoc index 5405dfa2f908..ed7c1610284b 100644 --- a/src/docs/asciidoc/core/core-expressions.adoc +++ b/src/docs/asciidoc/core/core-expressions.adoc @@ -393,8 +393,8 @@ More and more types of expression will be compilable in the future. [[expressions-beandef]] == Expressions in bean definitions -SpEL expressions can be used with XML or annotation-based configuration metadata for -defining ``BeanDefinition``s. In both cases the syntax to define the expression is of the +You can use SpEL expressions with XML-based or annotation-based configuration metadata for +defining `BeanDefinition` instances. In both cases, the syntax to define the expression is of the form `#{ }`. @@ -402,7 +402,8 @@ form `#{ }`. [[expressions-beandef-xml-based]] === XML configuration -A property or constructor-arg value can be set using expressions as shown below. +A property or constructor argument value can be set by using expressions, as the following +example shows: [source,xml,indent=0] [subs="verbatim"] @@ -414,10 +415,14 @@ A property or constructor-arg value can be set using expressions as shown below. ---- -The variable `systemProperties` is predefined, so you can use it in your expressions as -shown below. Note that you do not have to prefix the predefined variable with the `#` -symbol in this context. +All beans in the application context are available as predefined variables with their +common bean name. This includes standard context beans such as `environment` (of type +`org.springframework.core.env.Environment`) as well as `systemProperties` and +`systemEnvironment` (of type `Map`) for access to the runtime environment. +The following example shows access to the `systemProperties` bean as a SpEL variable: + +==== [source,xml,indent=0] [subs="verbatim"] ---- @@ -428,8 +433,11 @@ symbol in this context. ---- -You can also refer to other bean properties by name, for example. +Note that you do not have to prefix the predefined variable with the `#` symbol here. +You can also refer to other bean properties by name, as the following example shows: + +==== [source,xml,indent=0] [subs="verbatim"] ---- @@ -451,10 +459,10 @@ You can also refer to other bean properties by name, for example. [[expressions-beandef-annotation-based]] === Annotation config -The `@Value` annotation can be placed on fields, methods and method/constructor -parameters to specify a default value. +To specify a default value, you can place the `@Value` annotation on fields, methods, +and method or constructor parameters. -Here is an example to set the default value of a field variable. +The following example sets the default value of a field variable: [source,java,indent=0] [subs="verbatim,quotes"] @@ -475,7 +483,7 @@ Here is an example to set the default value of a field variable. } ---- -The equivalent but on a property setter method is shown below. +The following example shows the equivalent but on a property setter method: [source,java,indent=0] [subs="verbatim,quotes"] @@ -496,7 +504,8 @@ The equivalent but on a property setter method is shown below. } ---- -Autowired methods and constructors can also use the `@Value` annotation. +Autowired methods and constructors can also use the `@Value` annotation, as the following +examples show: [source,java,indent=0] [subs="verbatim,quotes"] @@ -1129,7 +1138,7 @@ The following example shows how to use the Elvis operator: ---- ExpressionParser parser = new SpelExpressionParser(); - String name = parser.parseExpression("name?:'Unknown'").getValue(String.class); + String name = parser.parseExpression("name?:'Unknown'").getValue(new Inventor(), String.class); System.out.println(name); // 'Unknown' ----