Polishing

This commit is contained in:
Juergen Hoeller 2017-02-16 14:20:40 +01:00
parent 7ed4884eaa
commit b0ef80c3ff
30 changed files with 203 additions and 238 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@ -1478,8 +1478,10 @@ public class BeanDefinitionParserDelegate {
/**
* Get the namespace URI for the supplied node. The default implementation uses {@link Node#getNamespaceURI}.
* Subclasses may override the default implementation to provide a different namespace identification mechanism.
* Get the namespace URI for the supplied node.
* <p>The default implementation uses {@link Node#getNamespaceURI}.
* Subclasses may override the default implementation to provide a
* different namespace identification mechanism.
* @param node the node
*/
public String getNamespaceURI(Node node) {
@ -1487,8 +1489,10 @@ public class BeanDefinitionParserDelegate {
}
/**
* Ges the local name for the supplied {@link Node}. The default implementation calls {@link Node#getLocalName}.
* Subclasses may override the default implementation to provide a different mechanism for getting the local name.
* Get the local name for the supplied {@link Node}.
* <p>The default implementation calls {@link Node#getLocalName}.
* Subclasses may override the default implementation to provide a
* different mechanism for getting the local name.
* @param node the {@code Node}
*/
public String getLocalName(Node node) {

View File

@ -197,6 +197,20 @@ class ConfigurationClassParser {
processConfigurationClass(new ConfigurationClass(metadata, beanName));
}
/**
* Validate each {@link ConfigurationClass} object.
* @see ConfigurationClass#validate
*/
public void validate() {
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
configClass.validate(this.problemReporter);
}
}
public Set<ConfigurationClass> getConfigurationClasses() {
return this.configurationClasses.keySet();
}
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
@ -390,6 +404,7 @@ class ConfigurationClassParser {
return beanMethods;
}
/**
* Process the given <code>@PropertySource</code> annotation metadata.
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
@ -608,30 +623,15 @@ class ConfigurationClassParser {
return false;
}
/**
* Validate each {@link ConfigurationClass} object.
* @see ConfigurationClass#validate
*/
public void validate() {
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
configClass.validate(this.problemReporter);
}
}
public Set<ConfigurationClass> getConfigurationClasses() {
return this.configurationClasses.keySet();
}
ImportRegistry getImportRegistry() {
return this.importStack;
}
/**
* Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
*/
public SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
AnnotationMetadata metadata = configurationClass.getMetadata();
if (metadata instanceof StandardAnnotationMetadata) {
return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
@ -642,7 +642,7 @@ class ConfigurationClassParser {
/**
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
*/
public SourceClass asSourceClass(Class<?> classType) throws IOException {
SourceClass asSourceClass(Class<?> classType) throws IOException {
try {
// Sanity test that we can read annotations, if not fall back to ASM
classType.getAnnotations();
@ -657,8 +657,8 @@ class ConfigurationClassParser {
/**
* Factory method to obtain {@link SourceClass}s from class names.
*/
public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>();
private Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>(classNames.length);
for (String className : classNames) {
annotatedClasses.add(asSourceClass(className));
}
@ -668,7 +668,7 @@ class ConfigurationClassParser {
/**
* Factory method to obtain a {@link SourceClass} from a class name.
*/
public SourceClass asSourceClass(String className) throws IOException {
SourceClass asSourceClass(String className) throws IOException {
if (className.startsWith("java")) {
// Never use ASM for core java types
try {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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,8 @@ import org.springframework.util.ClassUtils;
*/
public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME = "org.glassfish.api.deployment.InstrumentableClassLoader";
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME =
"org.glassfish.api.deployment.InstrumentableClassLoader";
private final ClassLoader classLoader;
@ -57,16 +58,10 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
Class<?> instrumentableLoaderClass;
try {
instrumentableLoaderClass = classLoader.loadClass(INSTRUMENTABLE_LOADER_CLASS_NAME);
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException(
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
}
try {
this.addTransformerMethod = instrumentableLoaderClass.getMethod("addTransformer", ClassFileTransformer.class);
this.copyMethod = instrumentableLoaderClass.getMethod("copy");
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException(
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
}
@ -97,7 +92,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex);
}
}
@ -115,7 +110,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish copy method", ex);
}
}

View File

@ -78,7 +78,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
this.translatorClass = classLoader.loadClass(TRANSLATOR_NAME);
this.addTranslator = this.target.getClass().getMethod("addTranslator", this.translatorClass);
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException(
"Could not initialize JBoss LoadTimeWeaver because the JBoss 6 API classes are not available", ex);
}
@ -92,7 +92,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
try {
this.addTranslator.invoke(this.target, adapterInstance);
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not add transformer on JBoss 6 ClassLoader " + this.classLoader, ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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.
@ -78,10 +78,7 @@ class JBossMCTranslatorAdapter implements InvocationHandler {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(getClass().getName());
builder.append(" for transformer: ");
builder.append(this.transformer);
return builder.toString();
return getClass().getName() + " for transformer: " + this.transformer;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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,22 +43,32 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
private final Object delegatingTransformer;
public JBossModulesAdapter(ClassLoader loader) {
this.classLoader = loader;
public JBossModulesAdapter(ClassLoader classLoader) {
this.classLoader = classLoader;
try {
Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer");
Field transformer = ReflectionUtils.findField(classLoader.getClass(), "transformer");
if (transformer == null) {
throw new IllegalArgumentException("Could not find 'transformer' field on JBoss ClassLoader: " +
classLoader.getClass().getName());
}
transformer.setAccessible(true);
this.delegatingTransformer = transformer.get(loader);
this.delegatingTransformer = transformer.get(classLoader);
if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " +
throw new IllegalStateException(
"Transformer not of the expected type DelegatingClassFileTransformer: " +
this.delegatingTransformer.getClass().getName());
}
this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
"addTransformer", ClassFileTransformer.class);
if (this.addTransformer == null) {
throw new IllegalArgumentException(
"Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " +
this.delegatingTransformer.getClass().getName());
}
this.addTransformer.setAccessible(true);
}
catch (Exception ex) {
throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex);
catch (Throwable ex) {
throw new IllegalStateException("Could not initialize JBoss LoadTimeWeaver", ex);
}
}
@ -67,7 +77,7 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
try {
this.addTransformer.invoke(this.delegatingTransformer, transformer);
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not add transformer on JBoss 7 ClassLoader " + this.classLoader, ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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,7 +76,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
}
this.copyMethod = copyMethod;
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException(
"Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available", ex);
}
@ -91,7 +91,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex);
}
}
@ -109,7 +109,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat copy method", ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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,7 +28,6 @@ import java.util.List;
import org.springframework.util.Assert;
/**
*
* Reflective wrapper around a WebSphere 7+ class loader. Used to
* encapsulate the classloader-specific methods (discovered and
* called through reflection) from the load-time weaver.
@ -45,6 +44,7 @@ class WebSphereClassLoaderAdapter {
private static final String PLUGINS_FIELD = "preDefinePlugins";
private ClassLoader classLoader;
private Class<?> wsPreProcessorClass;
@ -68,13 +68,13 @@ class WebSphereClassLoaderAdapter {
this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD);
this.transformerList.setAccessible(true);
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException(
"Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex);
}
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) {
throw new IllegalArgumentException("ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]");
throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME);
}
this.classLoader = classLoader;
}
@ -95,7 +95,7 @@ class WebSphereClassLoaderAdapter {
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex);
}
}
@ -111,7 +111,7 @@ class WebSphereClassLoaderAdapter {
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.instrument.classloading.websphere;
import java.lang.instrument.ClassFileTransformer;
@ -46,7 +47,7 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
this.transformer = transformer;
ClassLoader classLoader = transformer.getClass().getClassLoader();
// first force the full class loading of the weaver by invoking transformation on a dummy class
// First force the full class loading of the weaver by invoking transformation on a dummy class
try {
String dummyClass = Dummy.class.getName().replace('.', '/');
byte[] bytes = FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream(dummyClass + ".class"));
@ -81,17 +82,14 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
protected byte[] transform(String className, byte[] classfileBuffer, CodeSource codeSource, ClassLoader classLoader)
throws Exception {
// NB: WebSphere passes className as "." without class while the transformer expects a VM, "/" format
// NB: WebSphere passes className as "." without class while the transformer expects a VM "/" format
byte[] result = transformer.transform(classLoader, className.replace('.', '/'), null, null, classfileBuffer);
return (result != null ? result : classfileBuffer);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(getClass().getName());
builder.append(" for transformer: ");
builder.append(this.transformer);
return builder.toString();
return getClass().getName() + " for transformer: " + this.transformer;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -172,7 +172,7 @@ public class AnnotatedElementUtils {
*/
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty");
Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return getMetaAnnotationTypes(element, AnnotationUtils.getAnnotation(element, annotationName));
}
@ -232,7 +232,7 @@ public class AnnotatedElementUtils {
*/
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty");
Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return hasMetaAnnotationTypes(element, null, annotationName);
}
@ -290,7 +290,7 @@ public class AnnotatedElementUtils {
*/
public static boolean isAnnotated(AnnotatedElement element, String annotationName) {
Assert.notNull(element, "AnnotatedElement must not be null");
Assert.hasLength(annotationName, "annotationName must not be null or empty");
Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
return Boolean.TRUE.equals(searchWithGetSemantics(element, null, annotationName, alwaysTrueAnnotationProcessor));
}
@ -391,7 +391,7 @@ public class AnnotatedElementUtils {
public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element,
String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) {
Assert.hasLength(annotationName, "annotationName must not be null or empty");
Assert.hasLength(annotationName, "'annotationName' must not be null or empty");
AnnotationAttributes attributes = searchWithGetSemantics(element, null, annotationName,
new MergedAnnotationAttributesProcessor(classValuesAsString, nestedAnnotationsAsMap));
AnnotationUtils.postProcessAnnotationAttributes(element, attributes, classValuesAsString, nestedAnnotationsAsMap);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -233,10 +233,7 @@ public class CallableStatementCreatorFactory {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=[");
sb.append(callString).append("]; parameters=").append(this.inParameters);
return sb.toString();
return "CallableStatementCreator: sql=[" + callString + "]; parameters=" + this.inParameters;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@ -306,10 +306,7 @@ public class PreparedStatementCreatorFactory {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("PreparedStatementCreatorFactory.PreparedStatementCreatorImpl: sql=[");
sb.append(sql).append("]; parameters=").append(this.parameters);
return sb.toString();
return "PreparedStatementCreator: sql=[" + sql + "]; parameters=" + this.parameters;
}
}

View File

@ -45,8 +45,8 @@ public interface CallMetaDataProvider {
* This is only called for databases that are supported. This initialization
* can be turned off by specifying that column meta data should not be used.
* @param databaseMetaData used to retrieve database specific information
* @param catalogName name of catalog to use or null
* @param schemaName name of schema name to use or null
* @param catalogName name of catalog to use (or {@code null} if none)
* @param schemaName name of schema name to use (or {@code null} if none)
* @param procedureName name of the stored procedure
* @throws SQLException in case of initialization failure
* @see org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess()

View File

@ -79,8 +79,8 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
/**
* Constructor used to initialize with provided database meta data.
* @param databaseMetaData meta data to be used
* Constructor used to initialize with provided database metadata.
* @param databaseMetaData metadata to be used
*/
protected GenericTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
this.userName = databaseMetaData.getUserName();
@ -308,7 +308,7 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
}
/**
* Method supporting the metedata processing for a table.
* Method supporting the metadata processing for a table.
*/
private void locateTableAndProcessMetaData(
DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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,8 +23,8 @@ import java.util.List;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
/**
* Interface specifying the API to be implemented by a class providing table metedata. This is intended for internal use
* by the Simple JDBC classes.
* Interface specifying the API to be implemented by a class providing table metadata.
* This is intended for internal use by the Simple JDBC classes.
*
* @author Thomas Risberg
* @since 2.5
@ -32,45 +32,37 @@ import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
public interface TableMetaDataProvider {
/**
* Initialize using the database metedata provided
* @param databaseMetaData
* @throws SQLException
* Initialize using the database metadata provided.
* @param databaseMetaData used to retrieve database specific information
* @throws SQLException in case of initialization failure
*/
void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException;
/**
* Initialize using provided database metadata, table and column information. This initalization can be
* turned off by specifying that column meta data should not be used.
* Initialize using provided database metadata, table and column information.
* This initialization can be turned off by specifying that column meta data should not be used.
* @param databaseMetaData used to retrieve database specific information
* @param catalogName name of catalog to use or null
* @param schemaName name of schema name to use or null
* @param catalogName name of catalog to use (or {@code null} if none)
* @param schemaName name of schema name to use (or {@code null} if none)
* @param tableName name of the table
* @throws SQLException
* @throws SQLException in case of initialization failure
*/
void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName)
void initializeWithTableColumnMetaData(
DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName)
throws SQLException;
/**
* Get the table name formatted based on metadata information. This could include altering the case.
*
* @param tableName
* @return table name formatted
*/
String tableNameToUse(String tableName);
/**
* Get the catalog name formatted based on metadata information. This could include altering the case.
*
* @param catalogName
* @return catalog name formatted
*/
String catalogNameToUse(String catalogName);
/**
* Get the schema name formatted based on metadata information. This could include altering the case.
*
* @param schemaName
* @return schema name formatted
*/
String schemaNameToUse(String schemaName);
@ -78,9 +70,6 @@ public interface TableMetaDataProvider {
* Provide any modification of the catalog name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used or
* providing a base catalog if none is provided.
*
* @param catalogName
* @return catalog name to use
*/
String metaDataCatalogNameToUse(String catalogName) ;
@ -88,9 +77,6 @@ public interface TableMetaDataProvider {
* Provide any modification of the schema name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used or
* providing a base schema if none is provided.
*
* @param schemaName
* @return schema name to use
*/
String metaDataSchemaNameToUse(String schemaName) ;
@ -100,15 +86,15 @@ public interface TableMetaDataProvider {
boolean isTableColumnMetaDataUsed();
/**
* Does this database support the JDBC 3.0 feature of retreiving generated keys
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}
* Does this database support the JDBC 3.0 feature of retrieving generated keys
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
*/
boolean isGetGeneratedKeysSupported();
/**
* Does this database support a simple quey to retrieve the generated key whe the JDBC 3.0 feature
* of retreiving generated keys is not supported
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}
* Does this database support a simple query to retrieve the generated key when
* the JDBC 3.0 feature of retrieving generated keys is not supported?
* @see #isGetGeneratedKeysSupported()
*/
boolean isGetGeneratedKeysSimulated();
@ -118,7 +104,7 @@ public interface TableMetaDataProvider {
String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName);
/**
* Does this database support a column name String array for retreiving generated keys
* Does this database support a column name String array for retrieving generated keys
* {@link java.sql.Connection#createStruct(String, Object[])}
*/
boolean isGeneratedKeysColumnNameArraySupported();
@ -133,4 +119,5 @@ public interface TableMetaDataProvider {
* Set the {@link NativeJdbcExtractor} to use to retrieve the native connection if necessary
*/
void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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,9 +42,9 @@ public class TableMetaDataProviderFactory {
/**
* Create a TableMetaDataProvider based on the database metedata
* @param dataSource used to retrieve metedata
* @param context the class that holds configuration and metedata
* Create a TableMetaDataProvider based on the database metadata.
* @param dataSource used to retrieve metadata
* @param context the class that holds configuration and metadata
* @return instance of the TableMetaDataProvider implementation to be used
*/
public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) {
@ -52,9 +52,9 @@ public class TableMetaDataProviderFactory {
}
/**
* Create a TableMetaDataProvider based on the database metedata
* @param dataSource used to retrieve metedata
* @param context the class that holds configuration and metedata
* Create a TableMetaDataProvider based on the database metadata.
* @param dataSource used to retrieve metadata
* @param context the class that holds configuration and metadata
* @param nativeJdbcExtractor the NativeJdbcExtractor to be used
* @return instance of the TableMetaDataProvider implementation to be used
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -75,9 +75,8 @@ public interface SimpleJdbcInsertOperations {
/**
* Include synonyms for the column meta data lookups via JDBC.
* Note: this is only necessary to include for Oracle since other
* databases supporting synonyms seems to include the synonyms
* automatically.
* <p>Note: This is only necessary to include for Oracle since other databases
* supporting synonyms seems to include the synonyms automatically.
* @return the instance of this SimpleJdbcInsert
*/
SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData();
@ -85,7 +84,7 @@ public interface SimpleJdbcInsertOperations {
/**
* Use a the provided NativeJdbcExtractor during the column meta data
* lookups via JDBC.
* Note: this is only necessary to include when running with a connection pool
* <p>Note: This is only necessary to include when running with a connection pool
* that wraps the meta data connection and when using a database like Oracle
* where it is necessary to access the native connection to include synonyms.
* @return the instance of this SimpleJdbcInsert

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -85,7 +85,7 @@ public class JdbcBeanDefinitionReader {
/**
* Set the JdbcTemplate to be used by this bean factory.
* Contains settings for DataSource, SQLExceptionTranslator, NativeJdbcExtractor, etc.
* Contains settings for DataSource, SQLExceptionTranslator, etc.
*/
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -26,7 +26,8 @@ import java.sql.Connection;
* native JDBC Connection such as Oracle's OracleConnection. Spring's
* {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter}
* automatically detects such proxies before delegating to the actual
* unwrapping for a specific connection pool.
* unwrapping for a specific connection pool. Alternatively, all such
* connections also support JDBC 4.0's {@link Connection#unwrap}.
*
* @author Juergen Hoeller
* @since 1.1

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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.
@ -54,7 +54,7 @@ import org.springframework.core.Constants;
* without paying a performance penalty if no actual data access happens.
*
* <p>This DataSource proxy gives you behavior analogous to JTA and a
* transactional JNDI DataSource (as provided by the J2EE server), even
* transactional JNDI DataSource (as provided by the Java EE server), even
* with a local transaction strategy like DataSourceTransactionManager or
* HibernateTransactionManager. It does not add value with Spring's
* JtaTransactionManager as transaction strategy.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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,9 +39,6 @@ import org.springframework.util.ObjectUtils;
* <p>If client code will call {@code close()} in the assumption of a pooled
* Connection, like when using persistence tools, set "suppressClose" to "true".
* This will return a close-suppressing proxy instead of the physical Connection.
* Be aware that you will not be able to cast this to a native
* {@code OracleConnection} or the like anymore; you need to use a
* {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor} then.
*
* <p>This is primarily intended for testing. For example, it enables easy testing
* outside an application server, for code that expects to work on a DataSource.
@ -53,10 +50,8 @@ import org.springframework.util.ObjectUtils;
* @see #getConnection()
* @see java.sql.Connection#close()
* @see DataSourceUtils#releaseConnection
* @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
*/
public class SingleConnectionDataSource extends DriverManagerDataSource
implements SmartDataSource, DisposableBean {
public class SingleConnectionDataSource extends DriverManagerDataSource implements SmartDataSource, DisposableBean {
/** Create a close-suppressing proxy? */
private boolean suppressClose;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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.
@ -31,7 +31,7 @@ import org.springframework.util.Assert;
/**
* Proxy for a target JDBC {@link javax.sql.DataSource}, adding awareness of
* Spring-managed transactions. Similar to a transactional JNDI DataSource
* as provided by a J2EE server.
* as provided by a Java EE server.
*
* <p>Data access code that should remain unaware of Spring's data access support
* can work with this proxy to seamlessly participate in Spring-managed transactions.
@ -51,7 +51,7 @@ import org.springframework.util.Assert;
* Connection. If not within a transaction, normal DataSource behavior applies.
*
* <p>This proxy allows data access code to work with the plain JDBC API and still
* participate in Spring-managed transactions, similar to JDBC code in a J2EE/JTA
* participate in Spring-managed transactions, similar to JDBC code in a Java EE/JTA
* environment. However, if possible, use Spring's DataSourceUtils, JdbcTemplate or
* JDBC operation objects to get transaction participation even without a proxy for
* the target DataSource, avoiding the need to define such a proxy in the first place.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -95,12 +95,12 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
Class<?> wsrraFactoryClass = getClass().getClassLoader().loadClass("com.ibm.websphere.rsadapter.WSRRAFactory");
this.newJdbcConnSpecMethod = wsrraFactoryClass.getMethod("createJDBCConnectionSpec", (Class<?>[]) null);
this.wsDataSourceGetConnectionMethod =
this.wsDataSourceClass.getMethod("getConnection", new Class<?>[] {jdbcConnSpecClass});
this.wsDataSourceClass.getMethod("getConnection", jdbcConnSpecClass);
this.setTransactionIsolationMethod =
jdbcConnSpecClass.getMethod("setTransactionIsolation", new Class<?>[] {int.class});
this.setReadOnlyMethod = jdbcConnSpecClass.getMethod("setReadOnly", new Class<?>[] {Boolean.class});
this.setUserNameMethod = jdbcConnSpecClass.getMethod("setUserName", new Class<?>[] {String.class});
this.setPasswordMethod = jdbcConnSpecClass.getMethod("setPassword", new Class<?>[] {String.class});
jdbcConnSpecClass.getMethod("setTransactionIsolation", int.class);
this.setReadOnlyMethod = jdbcConnSpecClass.getMethod("setReadOnly", Boolean.class);
this.setUserNameMethod = jdbcConnSpecClass.getMethod("setUserName", String.class);
this.setPasswordMethod = jdbcConnSpecClass.getMethod("setPassword", String.class);
}
catch (Exception ex) {
throw new IllegalStateException(
@ -144,7 +144,7 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
}
/**
* Create a WebSphere {@code JDBCConnectionSpec} object for the given charateristics.
* Create a WebSphere {@code JDBCConnectionSpec} object for the given characteristics.
* <p>The default implementation uses reflection to apply the given settings.
* Can be overridden in subclasses to customize the JDBCConnectionSpec object
* (<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/rsadapter/JDBCConnectionSpec.html">JDBCConnectionSpec javadoc</a>;

View File

@ -422,7 +422,7 @@ public abstract class JdbcUtils {
/**
* Extract a common name for the database in use even if various drivers/platforms provide varying names.
* @param source the name as provided in database metedata
* @param source the name as provided in database metadata
* @return the common name to be used
*/
public static String commonDatabaseName(String source) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@ -143,10 +143,9 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithStaticSql() throws Exception {
doTestStrings(false, null, null, null, null, new JdbcTemplateCallback() {
doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, rch);
}
});
@ -154,10 +153,9 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception {
doTestStrings(false, 10, 20, 30, null, new JdbcTemplateCallback() {
doTestStrings(10, 20, 30, null, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, rch);
}
});
@ -165,10 +163,9 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithEmptyPreparedStatementSetter() throws Exception {
doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() {
doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, (PreparedStatementSetter) null, rch);
}
});
@ -177,10 +174,9 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithPreparedStatementSetter() throws Exception {
final Integer argument = 99;
doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() {
doTestStrings(null, null, null, argument, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
@ -193,10 +189,9 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithEmptyPreparedStatementArgs() throws Exception {
doTestStrings(true, null, null, null, null, new JdbcTemplateCallback() {
doTestStrings(null, null, null, null, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, (Object[]) null, rch);
}
});
@ -205,26 +200,22 @@ public class JdbcTemplateTests {
@Test
public void testStringsWithPreparedStatementArgs() throws Exception {
final Integer argument = 99;
doTestStrings(true, null, null, null, argument, new JdbcTemplateCallback() {
doTestStrings(null, null, null, argument, new JdbcTemplateCallback() {
@Override
public void doInJdbcTemplate(JdbcTemplate template, String sql,
RowCallbackHandler rch) {
public void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch) {
template.query(sql, new Object[] { argument }, rch);
}
});
}
private void doTestStrings(
boolean usePreparedStatement,
Integer fetchSize, Integer maxRows, Integer queryTimeout, Object argument,
JdbcTemplateCallback jdbcTemplateCallback)
throws Exception {
private void doTestStrings(Integer fetchSize, Integer maxRows, Integer queryTimeout,
Object argument, JdbcTemplateCallback jdbcTemplateCallback) throws Exception {
String sql = "SELECT FORENAME FROM CUSTMR";
String[] results = { "rod", "gary", " portia" };
class StringHandler implements RowCallbackHandler {
private List<String> list = new LinkedList<String>();
private List<String> list = new LinkedList<>();
@Override
public void processRow(ResultSet rs) throws SQLException {
this.list.add(rs.getString(1));
@ -740,9 +731,8 @@ public class JdbcTemplateTests {
@Test
public void testBatchUpdateWithListOfObjectArrays() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
final List<Object[]> ids = new ArrayList<Object[]>();
final List<Object[]> ids = new ArrayList<>();
ids.add(new Object[] {100});
ids.add(new Object[] {200});
final int[] rowsAffected = new int[] { 1, 2 };
@ -768,7 +758,7 @@ public class JdbcTemplateTests {
@Test
public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
final List<Object[]> ids = new ArrayList<Object[]>();
final List<Object[]> ids = new ArrayList<>();
ids.add(new Object[] {100});
ids.add(new Object[] {200});
final int[] sqlTypes = new int[] {Types.NUMERIC};
@ -851,13 +841,15 @@ public class JdbcTemplateTests {
@Test
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty()
throws Exception {
throws SQLException {
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(true);
}
@Test
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet()
throws Exception {
throws SQLException {
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(false);
}
@ -867,6 +859,7 @@ public class JdbcTemplateTests {
*/
private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty)
throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
@ -1098,7 +1091,6 @@ public class JdbcTemplateTests {
@Test
public void testNativeJdbcExtractorInvoked() throws Exception {
final Statement statement2 = mock(Statement.class);
given(statement2.executeQuery(anyString())).willReturn(this.resultSet);
@ -1246,7 +1238,7 @@ public class JdbcTemplateTests {
given(this.callableStatement.execute()).willReturn(true);
given(this.callableStatement.getUpdateCount()).willReturn(-1);
List<SqlParameter> params = new ArrayList<SqlParameter>();
List<SqlParameter> params = new ArrayList<>();
params.add(new SqlReturnResultSet("", new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) {
@ -1286,7 +1278,7 @@ public class JdbcTemplateTests {
assertTrue("now it should have been set to case insensitive",
this.template.isResultsMapCaseInsensitive());
List<SqlParameter> params = new ArrayList<SqlParameter>();
List<SqlParameter> params = new ArrayList<>();
params.add(new SqlOutParameter("a", 12));
Map<String, Object> out = this.template.call(new CallableStatementCreator() {
@ -1311,6 +1303,7 @@ public class JdbcTemplateTests {
given(this.connection.getMetaData()).willReturn(databaseMetaData);
}
private static class PlainNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
@Override
@ -1320,7 +1313,7 @@ public class JdbcTemplateTests {
}
private static interface JdbcTemplateCallback {
private interface JdbcTemplateCallback {
void doInJdbcTemplate(JdbcTemplate template, String sql, RowCallbackHandler rch);
}
@ -1329,6 +1322,7 @@ public class JdbcTemplateTests {
private static class Dispatcher implements PreparedStatementCreator, SqlProvider {
private int id;
private String sql;
public Dispatcher(int id, String sql) {
@ -1348,4 +1342,5 @@ public class JdbcTemplateTests {
return this.sql;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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,7 +34,7 @@ import org.springframework.util.Assert;
* @see org.springframework.aop.framework.AopProxyUtils
* @see ReflectionTestUtils
*/
public class AopTestUtils {
public abstract class AopTestUtils {
/**
* Get the <em>target</em> object of the supplied {@code candidate} object.
@ -42,22 +42,22 @@ public class AopTestUtils {
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
* be returned; otherwise, the {@code candidate} will be returned
* <em>as is</em>.
* @param candidate the instance to check (potentially a Spring AOP proxy);
* never {@code null}
* @return the target object or the {@code candidate}; never {@code null}
* @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null})
* @return the target object or the {@code candidate} (never {@code null})
* @throws IllegalStateException if an error occurs while unwrapping a proxy
* @see Advised#getTargetSource()
* @see #getUltimateTargetObject
*/
@SuppressWarnings("unchecked")
public static <T> T getTargetObject(Object candidate) {
Assert.notNull(candidate, "candidate must not be null");
Assert.notNull(candidate, "Candidate must not be null");
try {
if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) ((Advised) candidate).getTargetSource().getTarget();
}
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Failed to unwrap proxied object", ex);
}
return (T) candidate;
@ -71,23 +71,22 @@ public class AopTestUtils {
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
* nested proxies will be returned; otherwise, the {@code candidate}
* will be returned <em>as is</em>.
* @param candidate the instance to check (potentially a Spring AOP proxy);
* never {@code null}
* @return the ultimate target object or the {@code candidate}; never
* {@code null}
* @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null})
* @return the target object or the {@code candidate} (never {@code null})
* @throws IllegalStateException if an error occurs while unwrapping a proxy
* @see Advised#getTargetSource()
* @see org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass
*/
@SuppressWarnings("unchecked")
public static <T> T getUltimateTargetObject(Object candidate) {
Assert.notNull(candidate, "candidate must not be null");
Assert.notNull(candidate, "Candidate must not be null");
try {
if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
}
}
catch (Exception ex) {
catch (Throwable ex) {
throw new IllegalStateException("Failed to unwrap proxied object", ex);
}
return (T) candidate;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -50,9 +50,9 @@ import org.springframework.http.HttpStatus;
*
* @author Arjen Poutsma
* @author Sam Brannen
* @since 3.0
* @see org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
* @see javax.servlet.http.HttpServletResponse#sendError(int, String)
* @since 3.0
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)

View File

@ -47,10 +47,10 @@ import org.springframework.web.servlet.support.RequestContextUtils;
* <li>{@link Principal}
* <li>{@link InputStream}
* <li>{@link Reader}
* <li>{@link HttpMethod} (as of Spring 4.0)</li>
* <li>{@link HttpMethod} (as of Spring 4.0)
* <li>{@link Locale}
* <li>{@link TimeZone} (as of Spring 4.0)
* <li>{@link java.time.ZoneId} (as of Spring 4.0 and Java 8)</li>
* <li>{@link java.time.ZoneId} (as of Spring 4.0 and Java 8)
* </ul>
*
* @author Arjen Poutsma

View File

@ -75,11 +75,9 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void servletRequest() throws Exception {
MethodParameter servletRequestParameter = new MethodParameter(method, 0);
assertTrue("ServletRequest not supported", resolver.supportsParameter(servletRequestParameter));
boolean isSupported = resolver.supportsParameter(servletRequestParameter);
Object result = resolver.resolveArgument(servletRequestParameter, mavContainer, webRequest, null);
assertTrue("ServletRequest not supported", isSupported);
assertSame("Invalid result", servletRequest, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
}
@ -88,12 +86,11 @@ public class ServletRequestMethodArgumentResolverTests {
public void session() throws Exception {
MockHttpSession session = new MockHttpSession();
servletRequest.setSession(session);
MethodParameter sessionParameter = new MethodParameter(method, 2);
assertTrue("Session not supported", resolver.supportsParameter(sessionParameter));
boolean isSupported = resolver.supportsParameter(sessionParameter);
Object result = resolver.resolveArgument(sessionParameter, mavContainer, webRequest, null);
assertTrue("Session not supported", isSupported);
assertSame("Invalid result", session, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
}
@ -107,8 +104,8 @@ public class ServletRequestMethodArgumentResolverTests {
}
};
servletRequest.setUserPrincipal(principal);
MethodParameter principalParameter = new MethodParameter(method, 3);
MethodParameter principalParameter = new MethodParameter(method, 3);
assertTrue("Principal not supported", resolver.supportsParameter(principalParameter));
Object result = resolver.resolveArgument(principalParameter, null, webRequest, null);
@ -119,8 +116,8 @@ public class ServletRequestMethodArgumentResolverTests {
public void locale() throws Exception {
Locale locale = Locale.ENGLISH;
servletRequest.addPreferredLocale(locale);
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@ -132,8 +129,8 @@ public class ServletRequestMethodArgumentResolverTests {
Locale locale = Locale.ENGLISH;
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(locale));
MethodParameter localeParameter = new MethodParameter(method, 4);
MethodParameter localeParameter = new MethodParameter(method, 4);
assertTrue("Locale not supported", resolver.supportsParameter(localeParameter));
Object result = resolver.resolveArgument(localeParameter, null, webRequest, null);
@ -143,7 +140,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void timeZone() throws Exception {
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@ -155,8 +151,8 @@ public class ServletRequestMethodArgumentResolverTests {
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE,
new FixedLocaleResolver(Locale.US, timeZone));
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
MethodParameter timeZoneParameter = new MethodParameter(method, 8);
assertTrue("TimeZone not supported", resolver.supportsParameter(timeZoneParameter));
Object result = resolver.resolveArgument(timeZoneParameter, null, webRequest, null);
@ -166,7 +162,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void zoneId() throws Exception {
MethodParameter zoneIdParameter = new MethodParameter(method, 9);
assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter));
Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null);
@ -189,7 +184,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void inputStream() throws Exception {
MethodParameter inputStreamParameter = new MethodParameter(method, 5);
assertTrue("InputStream not supported", resolver.supportsParameter(inputStreamParameter));
Object result = resolver.resolveArgument(inputStreamParameter, null, webRequest, null);
@ -199,7 +193,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void reader() throws Exception {
MethodParameter readerParameter = new MethodParameter(method, 6);
assertTrue("Reader not supported", resolver.supportsParameter(readerParameter));
Object result = resolver.resolveArgument(readerParameter, null, webRequest, null);
@ -209,7 +202,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void webRequest() throws Exception {
MethodParameter webRequestParameter = new MethodParameter(method, 7);
assertTrue("WebRequest not supported", resolver.supportsParameter(webRequestParameter));
Object result = resolver.resolveArgument(webRequestParameter, null, webRequest, null);
@ -219,7 +211,6 @@ public class ServletRequestMethodArgumentResolverTests {
@Test
public void httpMethod() throws Exception {
MethodParameter httpMethodParameter = new MethodParameter(method, 10);
assertTrue("HttpMethod not supported", resolver.supportsParameter(httpMethodParameter));
Object result = resolver.resolveArgument(httpMethodParameter, null, webRequest, null);
@ -241,4 +232,4 @@ public class ServletRequestMethodArgumentResolverTests {
HttpMethod p10) {
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -33,7 +33,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import static org.junit.Assert.*;
/**
* Test fixture with {@link org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver}.
* Test fixture with {@link ServletResponseMethodArgumentResolver}.
*
* @author Arjen Poutsma
*/
@ -49,6 +49,7 @@ public class ServletResponseMethodArgumentResolverTests {
private MockHttpServletResponse servletResponse;
@Before
public void setUp() throws Exception {
resolver = new ServletResponseMethodArgumentResolver();
@ -58,10 +59,10 @@ public class ServletResponseMethodArgumentResolverTests {
webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse);
}
@Test
public void servletResponse() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null);
@ -69,8 +70,7 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled());
}
// SPR-8983
@Test // SPR-8983
public void servletResponseNoMavContainer() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
@ -82,7 +82,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test
public void outputStream() throws Exception {
MethodParameter outputStreamParameter = new MethodParameter(method, 1);
assertTrue("OutputStream not supported", resolver.supportsParameter(outputStreamParameter));
Object result = resolver.resolveArgument(outputStreamParameter, mavContainer, webRequest, null);
@ -93,7 +92,6 @@ public class ServletResponseMethodArgumentResolverTests {
@Test
public void writer() throws Exception {
MethodParameter writerParameter = new MethodParameter(method, 2);
assertTrue("Writer not supported", resolver.supportsParameter(writerParameter));
Object result = resolver.resolveArgument(writerParameter, mavContainer, webRequest, null);
@ -101,7 +99,9 @@ public class ServletResponseMethodArgumentResolverTests {
assertTrue(mavContainer.isRequestHandled());
}
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
@SuppressWarnings("unused")
public void supportedParams(ServletResponse p0, OutputStream p1, Writer p2) {
}
}
}