Polishing

This commit is contained in:
Juergen Hoeller
2020-06-10 11:19:52 +02:00
parent 7f87eb56d9
commit a045574418
38 changed files with 284 additions and 268 deletions
@@ -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, Annotation>) method -> {
AspectJAnnotation<?> annotation =
AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
return (annotation != null ? annotation.getAnnotation() : null);
AspectJAnnotation<?> ann = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
return (ann != null ? ann.getAnnotation() : null);
});
Comparator<Method> methodNameComparator = new ConvertingComparator<>(Method::getName);
METHOD_COMPARATOR = adviceKindComparator.thenComparing(methodNameComparator);
@@ -153,8 +152,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
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;
}
@@ -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 @@ class AspectJPrecedenceComparator implements Comparator<Advisor> {
}
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);
}
}
@@ -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());
}
@@ -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 @@ import org.springframework.util.StringUtils;
* Internal class that caches JavaBeans {@link java.beans.PropertyDescriptor}
* information for a Java class. Not intended for direct use by application code.
*
* <p>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).
* <p>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).
*
* <p>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<BeanInfoFactory> beanInfoFactories = SpringFactoriesLoader.loadFactories(
private static final List<BeanInfoFactory> beanInfoFactories = SpringFactoriesLoader.loadFactories(
BeanInfoFactory.class, CachedIntrospectionResults.class.getClassLoader());
private static final Log logger = LogFactory.getLog(CachedIntrospectionResults.class);
@@ -163,7 +163,6 @@ public class CachedIntrospectionResults {
* @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) {
@@ -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 @@ import java.lang.annotation.Target;
* regular constructors: i.e. lookup methods cannot get replaced on beans returned
* from factory methods where we cannot dynamically provide a subclass for them.
*
* <p><b>Concrete limitations in typical Spring configuration scenarios:</b>
* 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<TargetBean>} or the like instead.
* <p><b>Recommendations for typical Spring configuration scenarios:</b>
* 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<TargetBean>} or the like instead.
*
* @author Juergen Hoeller
* @since 4.1
@@ -884,7 +884,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
/**
* 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
*/
@@ -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 @@ import org.springframework.util.Assert;
* @author Juergen Hoeller
* @author Stephane Nicoll
* @since 4.3
* @see CaffeineCacheManager
*/
public class CaffeineCache extends AbstractValueAdaptingCache {
@@ -159,10 +160,10 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
@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);
}
}
}
@@ -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 @@ import org.springframework.util.Assert;
* @author Juergen Hoeller
* @author Stephane Nicoll
* @since 3.1
* @see EhCacheCacheManager
*/
public class EhCacheCache implements Cache {
@@ -95,7 +96,6 @@ public class EhCacheCache implements Cache {
this.cache.releaseWriteLockOnKey(key);
}
}
}
private <T> T loadValue(Object key, Callable<T> valueLoader) {
@@ -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 @@ import org.springframework.util.Assert;
* @author Juergen Hoeller
* @author Stephane Nicoll
* @since 3.1
* @see EhCacheCache
*/
public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManager {
@@ -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 @@ import org.springframework.util.Assert;
/**
* {@link org.springframework.cache.Cache} implementation on top of a
* {@link javax.cache.Cache} instance.
* {@link Cache javax.cache.Cache} instance.
*
* <p>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<Object, Object> jcache) {
@@ -50,7 +51,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
* @param allowNullValues whether to accept and convert null values for this cache
*/
@@ -128,7 +129,7 @@ public class JCacheCache extends AbstractValueAdaptingCache {
}
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;
@@ -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 @@ import org.springframework.util.Assert;
/**
* {@link org.springframework.cache.CacheManager} implementation
* backed by a JCache {@link javax.cache.CacheManager}.
* backed by a JCache {@link CacheManager javax.cache.CacheManager}.
*
* <p>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}.
* <p>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 class JCacheCacheManager extends AbstractTransactionSupportingCacheManage
/**
* 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() {
@@ -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 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
@Override
@Nullable
public <T> T get(Object key, Callable<T> 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 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
}
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();
@@ -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 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
*/
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);
}
}
@@ -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 @@ import org.springframework.util.Assert;
* @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) {
@@ -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 @@ import org.springframework.lang.Nullable;
* @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);
}
@@ -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 @@ import org.springframework.validation.annotation.Validated;
* 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.
*
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.
* <p>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 class MethodValidationInterceptor implements MethodInterceptor {
@Override
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable {
// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
if (isFactoryBeanMetadataMethod(invocation.getMethod())) {
@@ -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 @@ import org.springframework.validation.annotation.Validated;
* inline constraint annotations. Validation groups can be specified through {@code @Validated}
* as well. By default, JSR-303 will validate against its default group only.
*
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.
* <p>As of Spring 5.0, this functionality requires a Bean Validation 1.1+ provider.
*
* @author Juergen Hoeller
* @since 3.1
@@ -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 class CacheReproTests {
}
@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 class CacheReproTests {
public TestBean insertItem(TestBean item) {
return item;
}
}
@@ -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 @@ import static org.junit.Assert.*;
* @author Juergen Hoeller
* @author Stephane Nicoll
*/
public class ConcurrentMapCacheTests
extends AbstractValueAdaptingCacheTests<ConcurrentMapCache> {
public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<ConcurrentMapCache> {
protected ConcurrentMap<Object, Object> 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 @@ public class ConcurrentMapCacheTests
return this.nativeCache;
}
@Test
public void testIsStoreByReferenceByDefault() {
assertFalse(this.cache.isStoreByValue());
@@ -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> T query(String sql, ResultSetExtractor<T> 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...)
*/
<T> List<T> query(String sql, RowMapper<T> 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> T queryForObject(String sql, RowMapper<T> 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> T queryForObject(String sql, Class<T> 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<String, Object> 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
*/
<T> List<T> queryForList(String sql, Class<T> 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<Map<String, Object>> 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> T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException;
<T> T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> 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
*/
<T> List<T> query(String sql, @Nullable PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException;
<T> List<T> query(String sql, @Nullable PreparedStatementSetter pss, RowMapper<T> rowMapper)
throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -903,6 +905,7 @@ public interface JdbcOperations {
* @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<Object[]> batchArgs) throws DataAccessException;
@@ -913,6 +916,7 @@ public interface JdbcOperations {
* @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<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
@@ -926,6 +930,7 @@ public interface JdbcOperations {
* @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
*/
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
@@ -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.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
* 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> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
@@ -142,10 +142,10 @@ public interface NamedParameterJdbcOperations {
* <p>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> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
@@ -154,7 +154,7 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
* 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<String, ?> paramMap, RowCallbackHandler rch) throws DataAccessException;
@@ -180,9 +180,9 @@ public interface NamedParameterJdbcOperations {
* <p>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 @@ public interface NamedParameterJdbcOperations {
* 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
*/
<T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
throws DataAccessException;
@@ -203,12 +203,12 @@ public interface NamedParameterJdbcOperations {
* 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
*/
<T> List<T> query(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
throws DataAccessException;
@@ -219,10 +219,10 @@ public interface NamedParameterJdbcOperations {
* <p>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
*/
<T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException;
@@ -230,7 +230,7 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
* @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> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
@@ -248,7 +248,7 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
* @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> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
@@ -268,14 +268,14 @@ public interface NamedParameterJdbcOperations {
* list of arguments to bind to the query, expecting a result object.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* list of arguments to bind to the query, expecting a result object.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* @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 @@ public interface NamedParameterJdbcOperations {
* list of arguments to bind to the query, expecting a result Map.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* one of the queryForObject() methods.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* list of arguments to bind to the query, expecting a result list.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* list of arguments to bind to the query, expecting a result list.
* <p>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 @@ public interface NamedParameterJdbcOperations {
* 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<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException;
@@ -395,11 +395,11 @@ public interface NamedParameterJdbcOperations {
* 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<Map<String, Object>> queryForList(String sql, Map<String, ?> paramMap) throws DataAccessException;
@@ -413,11 +413,11 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
* 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 @@ public interface NamedParameterJdbcOperations {
/**
* 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<String, ?> 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 @@ public interface NamedParameterJdbcOperations {
/**
* 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 @@ public interface NamedParameterJdbcOperations {
* @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<String, ?>[] batchValues);
@@ -506,6 +507,7 @@ public interface NamedParameterJdbcOperations {
* @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);
@@ -194,7 +194,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
* through an explicit statement on the transactional connection:
* "SET TRANSACTION READ ONLY" as understood by Oracle, MySQL and Postgres.
* <p>The exact treatment, including any SQL statement executed on the connection,
* can be customized through through {@link #prepareTransactionalConnection}.
* can be customized through {@link #prepareTransactionalConnection}.
* <p>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 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
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;
@@ -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 class JpaTransactionManager extends AbstractPlatformTransactionManager
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 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
}
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 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
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);
}
}
}
@@ -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 class MockServerHttpRequest extends AbstractServerHttpRequest {
return this.remoteAddress;
}
@Nullable
@Override
@Nullable
protected SslInfo initSslInfo() {
return this.sslInfo;
}
@@ -342,9 +342,9 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest build();
}
/**
* A builder that adds a body to the request.
*/
@@ -383,7 +383,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @return the built request entity
*/
MockServerHttpRequest body(String body);
}
@@ -391,7 +390,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
private final HttpMethod method;
private final URI url;
@@ -411,7 +409,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
@Nullable
private SslInfo sslInfo;
public DefaultBodyBuilder(HttpMethod method, URI url) {
this.method = method;
this.url = url;
@@ -558,13 +555,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private URI getUrlToUse() {
MultiValueMap<String, String> params =
this.queryParamsBuilder.buildAndExpand().encode().getQueryParams();
if (!params.isEmpty()) {
return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri();
}
return this.url;
}
}
}
}
@@ -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 @@ import org.springframework.util.ObjectUtils;
* @author Arjen Poutsma
* @author Sebastien Deleuze
* @since 4.1
* @param <T> the body type
* @see #getMethod()
* @see #getUrl()
* @see org.springframework.web.client.RestOperations#exchange(RequestEntity, Class)
* @see ResponseEntity
*/
public class RequestEntity<T> extends HttpEntity<T> {
@@ -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 @@ import org.springframework.lang.Nullable;
*/
public class ServerSentEventHttpMessageReader implements HttpMessageReader<Object> {
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 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
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 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
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);
@@ -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.ServerHttpRequest;
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 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
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 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
});
}
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 <T> Flux<DataBuffer> encodeData(@Nullable T data, ResolvableType valueType,
private <T> Flux<DataBuffer> encodeData(@Nullable T dataValue, ResolvableType valueType,
MediaType mediaType, DataBufferFactory factory, Map<String, Object> 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 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
}
return ((Encoder<T>) this.encoder)
.encode(Mono.just(data), factory, valueType, mediaType, hints)
.encode(Mono.just(dataValue), factory, valueType, mediaType, hints)
.concatWith(encodeText("\n", mediaType, factory));
}
@@ -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 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
return this.cookies;
}
@Nullable
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return this.remoteAddress;
}
@Nullable
@Override
@Nullable
protected SslInfo initSslInfo() {
return this.sslInfo;
}
@@ -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 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
return this.request.remoteAddress();
}
@Override
@Nullable
protected SslInfo initSslInfo() {
SslHandler sslHandler = this.request.context().channel().pipeline().get(SslHandler.class);
@@ -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 class ServerHttpRequestDecorator implements ServerHttpRequest {
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return getDelegate().getRemoteAddress();
}
@Nullable
@Override
@Nullable
public SslInfo getSslInfo() {
return getDelegate().getSslInfo();
}
@@ -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.core.io.buffer.DefaultDataBufferFactory;
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 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
@NonNull
public InetSocketAddress getRemoteAddress() {
return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort());
}
@Override
@Nullable
protected SslInfo initSslInfo() {
X509Certificate[] certificates = getX509Certificates();
@@ -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 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return this.exchange.getSourceAddress();
}
@@ -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 @@ import org.springframework.util.StringUtils;
*/
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:
* <ul>
* <li>For the URI template replace <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters with escaped octets.
* <li>For URI variables do the same and also replace characters with
* reserved meaning.
* </ul>
* <p>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 <em>only</em> 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 class DefaultUriBuilderFactory implements UriBuilderFactory {
// UriTemplateHandler
@Override
public URI expand(String uriTemplate, Map<String, ?> 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 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:
* <ul>
* <li>For the URI template replace <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters with escaped octets.
* <li>For URI variables do the same and also replace characters with
* reserved meaning.
* </ul>
* <p>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 <em>only</em> 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.
*/
@@ -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 @@ package org.springframework.web.util;
*
* @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);
@@ -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 class MockServerHttpRequest extends AbstractServerHttpRequest {
return this.remoteAddress;
}
@Nullable
@Override
@Nullable
protected SslInfo initSslInfo() {
return this.sslInfo;
}
@@ -342,9 +342,9 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest build();
}
/**
* A builder that adds a body to the request.
*/
@@ -383,7 +383,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @return the built request entity
*/
MockServerHttpRequest body(String body);
}
@@ -391,7 +390,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
private final HttpMethod method;
private final URI url;
@@ -411,7 +409,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
@Nullable
private SslInfo sslInfo;
public DefaultBodyBuilder(HttpMethod method, URI url) {
this.method = method;
this.url = url;
@@ -558,13 +555,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private URI getUrlToUse() {
MultiValueMap<String, String> params =
this.queryParamsBuilder.buildAndExpand().encode().getQueryParams();
if (!params.isEmpty()) {
return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri();
}
return this.url;
}
}
}
}
@@ -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<WebFluxConfigurer> configurers) {
if (!CollectionUtils.isEmpty(configurers)) {
@@ -49,6 +50,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
}
}
@Override
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
this.configurers.configureContentTypeResolver(builder);
@@ -100,4 +102,5 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
protected void configureViewResolvers(ViewResolverRegistry registry) {
this.configurers.configureViewResolvers(registry);
}
}
@@ -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 @@ class DefaultWebClient implements WebClient {
return methodInternal(httpMethod);
}
@SuppressWarnings("unchecked")
private RequestBodyUriSpec methodInternal(HttpMethod httpMethod) {
return new DefaultRequestBodyUriSpec(httpMethod);
}
+22 -13
View File
@@ -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 `#{ <expression string> }`.
@@ -402,7 +402,8 @@ form `#{ <expression string> }`.
[[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.
</bean>
----
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<String, Object>`) 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.
</bean>
----
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'
----