Commit Graph

5377 Commits

Author SHA1 Message Date
Chris Beams 81dfef90ef Sync with 3.1.x
* 3.1.x:
  Fix false negative test failure in ResourceTests
  Compensate for Eclipse vs Sun compiler discrepancy
2012-02-13 15:54:14 +01:00
Chris Beams 1d9d3e6ff7 Fix false negative test failure in ResourceTests
Prior to changes in commit 57851de88e,
AbstractResource#getFilename threw IllegalStateException unless
overridden by a subclass. Following that change, this method now throws
null instead, but ResourceTests#testAbstractResourceExceptions had not
been updated to reflect, resulting in a false negative failure. This has
now been fixed.

Issue: SPR-9043
2012-02-13 15:52:37 +01:00
Chris Beams 8e0b1c3a5f Compensate for Eclipse vs Sun compiler discrepancy
Eclipse allows autoboxing on type inference; Sun javac does not. This
means that variables assigned from calls to
AnnotationAttributes#getNumber should consistently use object wrappers
as opposed to number primitives. There was only one such instance
anyway, and has now been updated accordingly.
2012-02-13 15:37:19 +01:00
Chris Beams ee36c80ca9 Sync with 3.1.x
* 3.1.x: (61 commits)
  Compensate for changes in JDK 7 Introspector
  Avoid 'type mismatch' errors in ExtendedBeanInfo
  Polish ExtendedBeanInfo and tests
  Infer AnnotationAttributes method return types
  Minor fix in MVC reference doc chapter
  Hibernate 4.1 etc
  TypeDescriptor equals implementation accepts annotations in any order
  "setBasenames" uses varargs now (for programmatic setup; SPR-9106)
  @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992
  polishing
  clarified Resource's "getFilename" method to consistently return null
  substituteNamedParameters detects and unwraps SqlParameterValue object
  Replace spaces with tabs
  Consider security in ClassUtils#getMostSpecificMethod
  Adding null check for username being null.
  Improvements for registering custom SQL exception translators in app c
  SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera
  Minor polish in WebMvcConfigurationSupport
  Detect overridden boolean getters in ExtendedBeanInfo
  Polish ExtendedBeanInfoTests
  ...
2012-02-13 15:17:30 +01:00
Chris Beams 0a5392e37d Compensate for changes in JDK 7 Introspector
Prior to JDK 7, java.beans.Introspector registered indexed write methods
irrespective of return type, for example either of the following methods
were legal

    void setFoo(int i, Foo foo)
    Object setFoo(int i, Foo foo)

This was considered a bug and disallowed starting with JDK 7, such that
only the former signature is a candidate.

Supporting non-void returning setter methods is exactly what
ExtendedBeanInfo was designed to do, and prior to this commit, the
implementation of ExtendedBeanInfo assumed this (somewhat surprising)
behavior from the underlying Introspector, and because it worked out of
the box, took no extra steps to recognize and register these methods.
For this reason, non-void returning indexed write methods were not
registered under JDK 7+, causing test failures in ExtendedBeanInfoTests.

Now the implementation is careful to detect these methods without any
assumption about Introspector behavior, such that they are registered in
exactly the same fashion across JDK versions.

Issue: SPR-9014
2012-02-13 15:01:06 +01:00
Chris Beams b787a68f20 Avoid 'type mismatch' errors in ExtendedBeanInfo
Prior to this commit, ExtendedBeanInfo would add non-indexed write
methods without consideration for the presence of indexed read/write
methods, which is invalid per the JavaBeans spec and per the behavior
of java.beans.Introspector.  That is, a method with the signature

    void setFoo(Foo foo)

Should never be registered as a write method if the following method
signature is also present in the class

    void setFoo(int i, Foo foo)

In most cases, this oversight caused no problems, but in certain
situations where a bean actually contains such a mismatch of methods,
"type mismatch" errors were thrown when ExtendedBeanInfo attempted the
illegal addition against the underlying property descriptor.

The implementation is now more careful about checking the parameter type
of write methods -- if the property descriptor in question is an
IndexedPropertyDescriptor, i.e. has an indexed write method, then any
non-indexed write method candidate must have a single *array* parameter,
which conforms to the spec and to Introspector behavior.

Issue: SPR-8937
2012-02-13 15:01:06 +01:00
Chris Beams ef143d363e Polish ExtendedBeanInfo and tests
ExtendedBeanInfo

 - Reduce log messages from warn to debug

 - Remove now-incorrect comment indicating underlying property
   descriptors are never modified (they actually are as of SPR-8806)

ExtendedBeanInfoTests

 - Consolidate SPR-8949 tests

 - Eliminate compiler warnings

Issue: SPR-8949, SPR-8806
2012-02-13 15:01:05 +01:00
Chris Beams e25f1cbca9 Infer AnnotationAttributes method return types
- Drop 'expectedType' parameter from #getClass and #getEnum methods and
   rely on compiler inference based on type of assigned variable, e.g.

     public @interface Example {
         Color color();
         Class<? extends UserType> userType();
         int order() default 0;
     }

     AnnotationAttributes example =
        AnnotationUtils.getAnnotationAttributes(Example.class, true, true);

     Color color = example.getEnum("color");
     Class<? extends UserType> userType = example.getClass("userType");

   or in cases where there is no variable assignment (and thus no
   inference possible), use explicit generic type, e.g.

     bean.setColor(example.<Color>getEnum("color"));

 - Rename #get{Int=>Number} and update return type from int to
   <N extends Number>, allowing invocations such as:

     int order = example.getNumber("order");

These changes reduce the overall number of methods exposed by
AnnotationAttributes, while at the same time providing comprehensive
access to all possible annotation attribute types -- that is, instead of
requiring explicit #getInt, #getFloat, #getDouble methods, the
single #getNumber method is capabable of handling them all, and without
any casting required. And the obvious additional benefit is more concise
invocation as no redundant 'expectedType' parameters are required.
2012-02-13 15:01:05 +01:00
Rossen Stoyanchev 997c6c56f7 Minor fix in MVC reference doc chapter
Issues: SPR-9111
2012-02-12 19:54:17 -05:00
jhoeller caa50a1d41 Merge pull request #33 from trisberg/SQLException-translation-enhancements
SQL exception translation enhancements
2012-02-12 07:19:21 -08:00
jhoeller 6e00456e67 Merge pull request #25 from trisberg/fixes-for-SimpleJdbcInsert
Fixes for SimpleJdbcInsert [SPR-9006]
2012-02-12 07:17:15 -08:00
Juergen Hoeller a46facc2f9 Hibernate 4.1 etc 2012-02-11 19:15:42 +01:00
Juergen Hoeller 9e21d2f741 TypeDescriptor equals implementation accepts annotations in any order (SPR-9084) 2012-02-11 19:15:41 +01:00
Juergen Hoeller 9470323724 "setBasenames" uses varargs now (for programmatic setup; SPR-9106) 2012-02-11 19:15:40 +01:00
Juergen Hoeller b17d545bb7 @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992) 2012-02-11 19:15:39 +01:00
Juergen Hoeller 1bd260adaf polishing 2012-02-11 19:15:38 +01:00
Juergen Hoeller 57851de88e clarified Resource's "getFilename" method to consistently return null if resource type does not have a filename (SPR-9043) 2012-02-11 19:15:37 +01:00
Juergen Hoeller 1e1f8c912b substituteNamedParameters detects and unwraps SqlParameterValue objects (SPR-9052) 2012-02-11 19:15:35 +01:00
Rossen Stoyanchev 66bc214a79 Replace spaces with tabs 2012-02-10 18:24:58 -05:00
Chris Beams 45ad183331 Consider security in ClassUtils#getMostSpecificMethod
Recent changes in ExtendedBeanInfo involve invoking
ClassUtils#getMostSpecificMethod when determining JavaBeans get/set
pairs; if Java security settings control disallow reflective access,
this results in an AccessControlException.

This change defends against this (comparatively rare) scenario by
catching the exception and falling back to returning the method
originally supplied by the user.

This change was a result of noticing CallbacksSecurityTests failing
following the ExtendedBeanInfo modifications mentioned above

Issue: SPR-8949
2012-02-10 00:13:24 +01:00
Thomas Risberg 66012b951e Adding null check for username being null.
The username is usually not null, but it  could be for some embedded databases.

Always setting generatedKeysColumnNameArraySupported to false when getGeneratedKeysSupported is false, since it can't be supported without having generated keys supported. This change only affects logging messages.

Issue: SPR-9006
2012-02-09 17:55:04 -05:00
Thomas Risberg f6c7d99ba4 Improvements for registering custom SQL exception translators in app contexts.
Adding a static CustomSQLExceptionTranslatorRegistry and a CustomSQLExceptionTranslatorRegistrar that can be used to register custom SQLExceptionTranslator implementations for specific databases from any application context.

This can be used in application contexts like this:

  <bean class="org.springframework.jdbc.support.CustomSQLExceptionTranslatorRegistrar">
    <property name="sqlExceptionTranslators">
      <map>
        <entry key="H2">
          <bean class="com.yourcompany.data.CustomSqlExceptionTranslator"/>
        </entry>
      </map>
    </property>
  </bean>

Issue: SPR-7675
2012-02-09 17:43:05 -05:00
Thomas Risberg e202d89c29 SPR-7680 Adding QueryTimeoutException to the DataAccessException hierarchy 2012-02-09 17:18:38 -05:00
Rossen Stoyanchev 21aed042ea Minor polish in WebMvcConfigurationSupport 2012-02-09 16:54:55 -05:00
Chris Beams f1ecd1ca2a Detect overridden boolean getters in ExtendedBeanInfo
Prior to this commit, and due to idiosyncracies of
java.beans.Introspector, overridden boolean getter methods were not
detected by Spring's ExtendedBeanInfo, which relied on too-strict
Method equality checks when selecting read and write methods.

Now ExtendedBeanInfo uses Spring's ClassUtils#getMostSpecificMethod
against the methods returned from java.beans.Introspector in order
to ensure that subsequent equality checks are reasonable to make.

Issue: SPR-8949
2012-02-09 22:23:57 +01:00
Chris Beams c1df51a3b4 Polish ExtendedBeanInfoTests
Clean up ignored test, consolidate and document tests cornering
covariant return type edge cases.

Issue: SPR-8079, SPR-8806
2012-02-09 22:23:57 +01:00
Arjen Poutsma edc80ffa95 Use request contentType/encoding in ServletServetHttpRequest/Response
ServletServerHttpRequest now falls back on the contentType and the
the characterEncoding of the ServletRequest, if the headers of the
incoming request don't specify one. Similary ServletServerHttpResponse
sets the contentType and the characterEncoding of the ServletResponse
if not already set.

This allows using the CharacterEncodingFilter to set a character
encoding where the request doesn't specify one and have it be used
in HttpMessageConverter's.

SPR-9096
2012-02-09 12:34:27 -05:00
Chris Beams ff44c9132c Upgrade Hibernate from 4.0.0.CR7=>4.1.0.Final
spring-orm now successfully builds against Hibernate 4.1.0.Final

Issue: SPR-9082
2012-02-09 12:35:58 +01:00
Juergen Hoeller 0db257cbe3 restored preference for covariant return type if applicable 2012-02-09 12:24:13 +01:00
Chris Beams 3eff364529 Upgrade Hibernate from 4.0.0.CR7=>4.1.0.Final
spring-orm now successfully builds against hibernate-core and
hibernate-entitymanager 4.1.0.Final

Issue: SPR-9082
2012-02-09 12:19:21 +01:00
Juergen Hoeller 35c2869875 INSTANCE constant should be marked as final (SPR-9101) 2012-02-09 11:56:06 +01:00
Juergen Hoeller c931eaa436 documentation fixes (SPR-9025, SPR-9027) 2012-02-08 18:35:57 +01:00
Juergen Hoeller 357a5193b7 added reference documentation to IntelliJ project 2012-02-08 18:34:44 +01:00
Juergen Hoeller e4f2cfe39e Provider injection etc 2012-02-08 17:53:15 +01:00
Juergen Hoeller 4aa8b96687 write method parameter type preferred over read method parameter type for property conversion (fixing regression; SPR-8964) 2012-02-08 17:51:06 +01:00
Juergen Hoeller 17bbc623c1 optimized converter lookup to avoid contention in JDK proxy check (SPR-9084) 2012-02-08 17:08:57 +01:00
Juergen Hoeller c55362c35e Provider injection works with generically typed collections of beans as well (SPR-9030) 2012-02-08 16:29:00 +01:00
Chris Beams 27b8c5d71a Resolve build script plugins via http vs https
The build script should work against http anyway; use of https here was
an oversight. Changing it now is in response to the following build
failure experienced by a user on his initial attempt to build from
source (with --info output):

  09:02:09.437 [ERROR] [org.gradle.BuildExceptionReporter] Caused
  by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
  ...
  Cause: Could not GET
  https://repo.springsource.org/plugins-snapshot/org/springframework/
  build/gradle/docbook-reference-plugin/0.1.2-SNAPSHOT/maven-metadata.xml

The actual cause is unknown at this time, but worth noting that upon
switching the url to http, the following log message was issued:

  Forcing close on abandoned resource: Http GET Resource:
  http://repo.springsource.org/plugins-snapshot/org/springframework/
  build/gradle/docbook-reference-plugin/0.1.2-SNAPSHOT/maven-metadata.xml
2012-02-08 16:23:23 +01:00
Juergen Hoeller 9a61f36d3d removed optional javax.validation.spi dependency (SPR-8973) 2012-02-08 12:52:51 +01:00
Juergen Hoeller 95e3f486b5 fixed SpringValidatorAdapter regression to return correct error codes for class-level constraints (SPR-8958) 2012-02-08 12:46:05 +01:00
Juergen Hoeller 2a0714b41c converted EmptyResultDataAccessException preserves JPA NoResultException as root cause (SPR-9041) 2012-02-08 12:23:15 +01:00
Juergen Hoeller efd2783dd1 restored JBossLoadTimeWeaver compability with JBoss AS 5.1 (SPR-9065) 2012-02-08 12:14:58 +01:00
jhoeller 5b18fc44ce Merge pull request #16 from cbeams/SPR-8954
Check original beanClass in #isFactoryBean calls
2012-02-08 02:58:19 -08:00
Rossen Stoyanchev 4f4a2e7fc7 Update documentation with regards to differences between @MVC 3.0/3.1
Although the reference documentation listed the new @MVC support
classes and their benefits, it did not explicitly mention a few
use cases that are no longer supported. There is now a specific
section on the new support classes listing exactly what is not
supported.

Similary the @RequestMapping annotation never refered explicitly
to the existence of old and new support and never made it clear
exactly what the differences are.

Both have not been corrected.

SPR-9063, SPR-9042
2012-02-07 19:49:44 -05:00
Chris Beams bf541db5b0 Refactor to consistent use of AnnotationAttributes
Uses of AnnotationMetadata#getAnnotationAttributes throughout the
framework have been updated to use the new AnnotationAttributes API in
order to take advantage of the more concise, expressive and type-safe
methods there.

All changes are binary compatible to the 3.1.0 public API, save
the exception below.

A minor binary compatibility issue has been introduced in
AbstractCachingConfiguration, AbstractAsyncConfiguration and
AbstractTransactionManagementConfiguration when updating their
protected Map<String, Object> fields representing annotation attributes
to use the new AnnotationAttributes API. This is a negligible breakage,
however, as the likelilhood of users subclassing these types is very
low, the classes have only been in existence for a short time (further
reducing the likelihood), and it is a source-compatible change given
that AnnotationAttributes is assignable to Map<String, Object>.
2012-02-07 21:57:49 +01:00
Chris Beams d9f7fdd120 Support reading nested annotations via ASM
Background

  Spring 3.1 introduced the @ComponentScan annotation, which can accept
  an optional array of include and/or exclude @Filter annotations, e.g.

     @ComponentScan(
         basePackages = "com.acme.app",
         includeFilters = { @Filter(MyStereotype.class), ... }
     )
     @Configuration
     public class AppConfig { ... }

  @ComponentScan and other annotations related to @Configuration class
  processing such as @Import, @ImportResource and the @Enable*
  annotations are parsed using reflection in certain code paths, e.g.
  when registered directly against AnnotationConfigApplicationContext,
  and via ASM in other code paths, e.g. when a @Configuration class is
  discovered via an XML bean definition or when included via the
  @Import annotation.

  The ASM-based approach is designed to avoid premature classloading of
  user types and is instrumental in providing tooling support (STS, etc).

  Prior to this commit, the ASM-based routines for reading annotation
  attributes were unable to recurse into nested annotations, such as in
  the @Filter example above. Prior to Spring 3.1 this was not a problem,
  because prior to @ComponentScan, there were no cases of nested
  annotations in the framework.

  This limitation manifested itself in cases where users encounter
  the ASM-based annotation parsing code paths AND declare
  @ComponentScan annotations with explicit nested @Filter annotations.
  In these cases, the 'includeFilters' and 'excludeFilters' attributes
  are simply empty where they should be populated, causing the framework
  to ignore the filter directives and provide incorrect results from
  component scanning.

  The purpose of this change then, is to introduce the capability on the
  ASM side to recurse into nested annotations and annotation arrays. The
  challenge in doing so is that the nested annotations themselves cannot
  be realized as annotation instances, so must be represented as a
  nested Map (or, as described below, the new AnnotationAttributes type).

  Furthermore, the reflection-based annotation parsing must also be
  updated to treat nested annotations in a similar fashion; even though
  the reflection-based approach has no problem accessing nested
  annotations (it just works out of the box), for substitutability
  against the AnnotationMetadata SPI, both ASM- and reflection-based
  implementations should return the same results in any case. Therefore,
  the reflection-based StandardAnnotationMetadata has also been updated
  with an optional 'nestedAnnotationsAsMap' constructor argument that is
  false by default to preserve compatibility in the rare case that
  StandardAnnotationMetadata is being used outside the core framework.
  Within the framework, all uses of StandardAnnotationMetadata have been
  updated to set this new flag to true, meaning that nested annotation
  results will be consistent regardless the parsing approach used.

  Spr9031Tests corners this bug and demonstrates that nested @Filter
  annotations can be parsed and read in both the ASM- and
  reflection-based paths.

Major changes

 - AnnotationAttributes has been introduced as a concrete
   LinkedHashMap<String, Object> to be used anywhere annotation
   attributes are accessed, providing error reporting on attribute
   lookup and convenient type-safe access to common annotation types
   such as String, String[], boolean, int, and nested annotation and
   annotation arrays, with the latter two also returned as
   AnnotationAttributes instances.

 - AnnotationUtils#getAnnotationAttributes methods now return
   AnnotationAttributes instances, even though for binary compatibility
   the signatures of these methods have been preserved as returning
   Map<String, Object>.

 - AnnotationAttributes#forMap provides a convenient mechanism for
   adapting any Map<String, Object> into an AnnotationAttributes
   instance. In the case that the Map is already actually of
   type AnnotationAttributes, it is simply casted and returned.
   Otherwise, the map is supplied to the AnnotationAttributes(Map)
   constructor and wrapped in common collections style.

 - The protected MetadataUtils#attributesFor(Metadata, Class) provides
   further convenience in the many locations throughout the
   .context.annotation packagage that depend on annotation attribute
   introspection.

 - ASM-based core.type.classreading package reworked

   Specifically, AnnotationAttributesReadingVisitor has been enhanced to
   support recursive reading of annotations and annotation arrays, for
   example in @ComponentScan's nested array of @Filter annotations,
   ensuring that nested AnnotationAttributes objects are populated as
   described above.

   AnnotationAttributesReadingVisitor has also been refactored for
   clarity, being broken up into several additional ASM
   AnnotationVisitor implementations. Given that all types are
   package-private here, these changes represent no risk to binary
   compatibility.

 - Reflection-based StandardAnnotationMetadata updated

   As described above, the 'nestedAnnotationsAsMap' constructor argument
   has been added, and all framework-internal uses of this class have
   been updated to set this flag to true.

Issue: SPR-7979, SPR-8719, SPR-9031
2012-02-07 21:57:49 +01:00
Juergen Hoeller 905d17d444 LocalContainerEntityManagerFactoryBean etc 2012-02-07 21:00:14 +01:00
Juergen Hoeller 62e5b9da04 LocalContainerEntityManagerFactoryBean's "persistenceUnitName" applies to "packagesToScan" as well; DefaultPersistenceUnitManager uses containing jar as persistence unit root URL for default unit (SPR-8832) 2012-02-07 20:59:48 +01:00
Juergen Hoeller f367619b0c added "durability" and "description" properties to JobDetailFactoryBean (SPR-9080) 2012-02-07 15:54:18 +01:00
Juergen Hoeller afa4bb3f1b fixed javadoc link (SPR-9089) 2012-02-07 15:54:17 +01:00