Polishing

This commit is contained in:
Juergen Hoeller
2018-01-19 19:35:02 +01:00
parent a73d9bbed5
commit 8b5a013423
12 changed files with 108 additions and 128 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1384,8 +1384,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
catch (ClassNotFoundException ex) {
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
}
catch (LinkageError ex) {
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
catch (LinkageError err) {
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
}
}

View File

@@ -22,7 +22,6 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.cache.CacheManager;
/**
* Proxy factory bean for simplified declarative caching handling.
@@ -54,7 +53,7 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
/**
* Set the sources used to find cache operations.
* Set one or more sources to find cache operations.
* @see CacheInterceptor#setCacheOperationSources
*/
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
@@ -62,42 +61,9 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
}
/**
* Set the default {@link KeyGenerator} that this cache aspect should delegate to
* if no specific key generator has been set for the operation.
* <p>The default is a {@link SimpleKeyGenerator}.
* @since 5.0.3
* @see CacheInterceptor#setKeyGenerator
*/
public void setKeyGenerator(KeyGenerator keyGenerator) {
this.cacheInterceptor.setKeyGenerator(keyGenerator);
}
/**
* Set the default {@link CacheResolver} that this cache aspect should delegate
* to if no specific cache resolver has been set for the operation.
* <p>The default resolver resolves the caches against their names and the
* default cache manager.
* @since 5.0.3
* @see CacheInterceptor#setCacheResolver
*/
public void setCacheResolver(CacheResolver cacheResolver) {
this.cacheInterceptor.setCacheResolver(cacheResolver);
}
/**
* Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
* Replace the current {@link CacheResolver}, if any.
* @since 5.0.3
* @see CacheInterceptor#setCacheManager
*/
public void setCacheManager(CacheManager cacheManager) {
this.cacheInterceptor.setCacheManager(cacheManager);
}
/**
* Set a pointcut, i.e a bean that can cause conditional invocation
* of the CacheInterceptor depending on method and attributes passed.
* Note: Additional interceptors are always invoked.
* Set a pointcut, i.e. a bean that triggers conditional invocation of the
* {@link CacheInterceptor} depending on the method and attributes passed.
* <p>Note: Additional interceptors are always invoked.
* @see #setPreInterceptors
* @see #setPostInterceptors
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,8 @@ import org.springframework.util.StringUtils;
* @see ResourceBundleMessageSource
* @see java.util.ResourceBundle
*/
public class ReloadableResourceBundleMessageSource extends AbstractResourceBasedMessageSource implements ResourceLoaderAware {
public class ReloadableResourceBundleMessageSource extends AbstractResourceBasedMessageSource
implements ResourceLoaderAware {
private static final String PROPERTIES_SUFFIX = ".properties";
@@ -99,15 +100,15 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
private ResourceLoader resourceLoader = new DefaultResourceLoader();
/** Cache to hold filename lists per Locale */
// Cache to hold filename lists per Locale
private final ConcurrentMap<String, Map<Locale, List<String>>> cachedFilenames =
new ConcurrentHashMap<String, Map<Locale, List<String>>>();
/** Cache to hold already loaded properties per filename */
// Cache to hold already loaded properties per filename
private final ConcurrentMap<String, PropertiesHolder> cachedProperties =
new ConcurrentHashMap<String, PropertiesHolder>();
/** Cache to hold merged loaded properties per locale */
// Cache to hold merged loaded properties per locale
private final ConcurrentMap<Locale, PropertiesHolder> cachedMergedProperties =
new ConcurrentHashMap<Locale, PropertiesHolder>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -387,9 +387,13 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
}
@Override
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime) {
public boolean needsReload(
String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime) {
if (super.needsReload(baseName, locale, format, loader, bundle, loadTime)) {
cachedBundleMessageFormats.remove(bundle);
synchronized (cachedBundleMessageFormats) {
cachedBundleMessageFormats.remove(bundle);
}
return true;
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,6 +67,7 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
setBeanClassLoader(beanClassLoader);
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
@@ -84,8 +85,10 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
else {
try {
this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
logger.info("Using a reflective load-time weaver for class loader: " +
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
if (logger.isInfoEnabled()) {
logger.info("Using a reflective load-time weaver for class loader: " +
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
}
}
catch (IllegalStateException ex) {
throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
@@ -106,24 +109,26 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
String name = classLoader.getClass().getName();
try {
if (name.startsWith("weblogic")) {
return new WebLogicLoadTimeWeaver(classLoader);
if (name.startsWith("org.apache.catalina")) {
return new TomcatLoadTimeWeaver(classLoader);
}
else if (name.startsWith("org.glassfish")) {
return new GlassFishLoadTimeWeaver(classLoader);
}
else if (name.startsWith("org.apache.catalina")) {
return new TomcatLoadTimeWeaver(classLoader);
}
else if (name.startsWith("org.jboss")) {
return new JBossLoadTimeWeaver(classLoader);
}
else if (name.startsWith("com.ibm")) {
return new WebSphereLoadTimeWeaver(classLoader);
}
else if (name.startsWith("weblogic")) {
return new WebLogicLoadTimeWeaver(classLoader);
}
}
catch (IllegalStateException ex) {
logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
catch (Exception ex) {
if (logger.isInfoEnabled()) {
logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
}
}
return null;
}
@@ -131,8 +136,10 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
@Override
public void destroy() {
if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
logger.info("Removing all registered transformers for class loader: " +
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
if (logger.isInfoEnabled()) {
logger.info("Removing all registered transformers for class loader: " +
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
}
((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@ import java.util.List;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.springframework.util.StringUtils;
/**
* {@link CommandLinePropertySource} implementation backed by a JOpt {@link OptionSet}.
*
@@ -84,13 +86,13 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
public String[] getPropertyNames() {
List<String> names = new ArrayList<String>();
for (OptionSpec<?> spec : this.source.specs()) {
List<String> aliases = new ArrayList<String>(spec.options());
List<String> aliases = spec.options();
if (!aliases.isEmpty()) {
// Only the longest name is used for enumerating
names.add(aliases.get(aliases.size() - 1));
}
}
return names.toArray(new String[names.size()]);
return StringUtils.toStringArray(names);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -149,10 +149,8 @@ public class CodeFlow implements Opcodes {
* Return the descriptor for the item currently on top of the stack (in the current scope).
*/
public String lastDescriptor() {
if (this.compilationScopes.peek().isEmpty()) {
return null;
}
return this.compilationScopes.peek().get(this.compilationScopes.peek().size() - 1);
ArrayList<String> scopes = this.compilationScopes.peek();
return (!scopes.isEmpty() ? scopes.get(scopes.size() - 1) : null);
}
/**
@@ -161,7 +159,7 @@ public class CodeFlow implements Opcodes {
* @param mv the visitor into which new instructions should be inserted
*/
public void unboxBooleanIfNecessary(MethodVisitor mv) {
if (lastDescriptor().equals("Ljava/lang/Boolean")) {
if ("Ljava/lang/Boolean".equals(lastDescriptor())) {
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
}
}

View File

@@ -70,9 +70,8 @@ public class FunctionReference extends SpelNodeImpl {
if (value == TypedValue.NULL) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
}
// Two possibilities: a lambda function or a Java static method registered as a function
if (!(value.getValue() instanceof Method)) {
// Two possibilities: a lambda function or a Java static method registered as a function
throw new SpelEvaluationException(
SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
}
@@ -96,11 +95,13 @@ public class FunctionReference extends SpelNodeImpl {
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
Object[] functionArgs = getArguments(state);
if (!method.isVarArgs() && method.getParameterCount() != functionArgs.length) {
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, method.getParameterCount());
if (!method.isVarArgs()) {
int declaredParamCount = method.getParameterTypes().length;
if (declaredParamCount != functionArgs.length) {
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, declaredParamCount);
}
}
// Only static methods can be called in this way
if (!Modifier.isStatic(method.getModifiers())) {
throw new SpelEvaluationException(getStartPosition(),
SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,43 +51,43 @@ import org.springframework.util.StringUtils;
*/
public class CallMetaDataContext {
/** Logger available to subclasses */
// Logger available to subclasses
protected final Log logger = LogFactory.getLog(getClass());
/** name of procedure to call **/
// Name of procedure to call
private String procedureName;
/** name of catalog for call **/
// Name of catalog for call
private String catalogName;
/** name of schema for call **/
// Name of schema for call
private String schemaName;
/** List of SqlParameter objects to be used in call execution */
// List of SqlParameter objects to be used in call execution
private List<SqlParameter> callParameters = new ArrayList<SqlParameter>();
/** Actual name to use for the return value in the output map */
// Actual name to use for the return value in the output map
private String actualFunctionReturnName;
/** Set of in parameter names to exclude use for any not listed */
// Set of in parameter names to exclude use for any not listed
private Set<String> limitedInParameterNames = new HashSet<String>();
/** List of SqlParameter names for out parameters */
// List of SqlParameter names for out parameters
private List<String> outParameterNames = new ArrayList<String>();
/** Indicates whether this is a procedure or a function **/
// Indicates whether this is a procedure or a function
private boolean function = false;
/** Indicates whether this procedure's return value should be included **/
// Indicates whether this procedure's return value should be included
private boolean returnValueRequired = false;
/** Should we access call parameter meta data info or not */
// Should we access call parameter meta data info or not
private boolean accessCallParameterMetaData = true;
/** Should we bind parameter by name **/
// Should we bind parameter by name
private boolean namedBinding;
/** The provider of call meta data */
// The provider of call meta data
private CallMetaDataProvider metaDataProvider;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,34 +44,34 @@ import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
*/
public class TableMetaDataContext {
/** Logger available to subclasses */
// Logger available to subclasses
protected final Log logger = LogFactory.getLog(getClass());
/** Name of table for this context */
// Name of table for this context
private String tableName;
/** Name of catalog for this context */
// Name of catalog for this context
private String catalogName;
/** Name of schema for this context */
// Name of schema for this context
private String schemaName;
/** List of columns objects to be used in this context */
// List of columns objects to be used in this context
private List<String> tableColumns = new ArrayList<String>();
/** should we access insert parameter meta data info or not */
// Should we access insert parameter meta data info or not
private boolean accessTableColumnMetaData = true;
/** should we override default for including synonyms for meta data lookups */
// Should we override default for including synonyms for meta data lookups
private boolean overrideIncludeSynonymsDefault = false;
/** the provider of table meta data */
// The provider of table meta data
private TableMetaDataProvider metaDataProvider;
/** are we using generated key columns */
// Are we using generated key columns
private boolean generatedKeyColumnsUsed = false;
/** NativeJdbcExtractor to be used to retrieve the native connection */
// NativeJdbcExtractor to be used to retrieve the native connection
NativeJdbcExtractor nativeJdbcExtractor;
@@ -204,8 +204,8 @@ public class TableMetaDataContext {
*/
public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) {
List<Object> values = new ArrayList<Object>();
// for parameter source lookups we need to provide caseinsensitive lookup support since the
// database metadata is not necessarily providing case sensitive column names
// For parameter source lookups we need to provide case-insensitive lookup support since the
// database metadata is not necessarily providing case-sensitive column names
Map<String, String> caseInsensitiveParameterNames =
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource);
for (String column : this.tableColumns) {
@@ -224,9 +224,8 @@ public class TableMetaDataContext {
}
else {
if (caseInsensitiveParameterNames.containsKey(lowerCaseName)) {
values.add(
SqlParameterSourceUtils.getTypedValue(parameterSource,
caseInsensitiveParameterNames.get(lowerCaseName)));
values.add(SqlParameterSourceUtils.getTypedValue(
parameterSource, caseInsensitiveParameterNames.get(lowerCaseName)));
}
else {
values.add(null);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,6 +70,20 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
}
}
/**
* Derives a default SQL type from the corresponding property type.
* @see org.springframework.jdbc.core.StatementCreatorUtils#javaTypeToSqlParameterType
*/
@Override
public int getSqlType(String paramName) {
int sqlType = super.getSqlType(paramName);
if (sqlType != TYPE_UNKNOWN) {
return sqlType;
}
Class<?> propType = this.beanWrapper.getPropertyType(paramName);
return StatementCreatorUtils.javaTypeToSqlParameterType(propType);
}
/**
* Provide access to the property names of the wrapped bean.
* Uses support provided in the {@link PropertyAccessor} interface.
@@ -89,18 +103,4 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
return this.propertyNames;
}
/**
* Derives a default SQL type from the corresponding property type.
* @see org.springframework.jdbc.core.StatementCreatorUtils#javaTypeToSqlParameterType
*/
@Override
public int getSqlType(String paramName) {
int sqlType = super.getSqlType(paramName);
if (sqlType != TYPE_UNKNOWN) {
return sqlType;
}
Class<?> propType = this.beanWrapper.getPropertyType(paramName);
return StatementCreatorUtils.javaTypeToSqlParameterType(propType);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,13 +94,15 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
if (this.mostSpecificMethod != null) {
return this.mostSpecificMethod;
}
else if (AopUtils.isAopProxy(this.bean)) {
Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean);
return AopUtils.getMostSpecificMethod(getMethod(), target);
}
else {
return getMethod();
Method method = getMethod();
if (method != null) {
Object bean = getBean();
if (AopUtils.isAopProxy(bean)) {
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
method = AopUtils.getMostSpecificMethod(method, targetClass);
}
}
return method;
}
/**