Commit Graph

477 Commits

Author SHA1 Message Date
Oliver Gierke
cccfa5e5c5 DATACMNS-669 - Polishing.
Javadoc on MultiValueBinding. Hide QuerydslBindings.bind(…), ….include(…) and ….exclude(…) methods that take String arguments to reduce the probability of no query class being present.

Refined the value handling for empty request values which are represented as String[] containing an empty String. We now massage those into an empty Collection for MultiValueBindings and a null value for SingleValueInvocations.

We currently skip property values that match this pattern entirely but are prepared to allow a configuration flip switch to handle those scenarios in the future. We currently stick to skipping those values to prevent the bindings from having to deal with null values.

We now also allow the bindings to return null to indicate they don't want to get applied in the resulting predicate at all.

Switched to interface based customization to make it easier to use customizations with Spring Data REST. Added Querydsl-specific adapter of RepositoryInvoker to allow Spring Data REST to hook in the execution of the predicate obtained from request parameters.

Original pull request: #132.
2015-07-20 08:12:11 +02:00
Christoph Strobl
dc49101850 DATACMNS-669 - Ignore non-reachable paths for Querydsl parameter binding.
We now ignore invalid PropertyPaths on property binding to Querydsl Predicates. Those may occur since the request also holds non-property-related arguments, such as pagination parameters.

Fixed two potential NullPointerExceptions along the way since we no longer depend on the presence of @QuerydslPredicate.

Original pull request: #132.
2015-07-20 08:11:47 +02:00
Oliver Gierke
5db3def79b DATACMNS-669 - Polishing.
QuerydslBindings now uses a builder style pattern to define custom bindings. This allows to define the same binding for multiple properties of the same type in one configuration call.

Introduced MultiValueBinding to be able to register a binding for multiple source values (i.e. if multiple values are provided for the same parameter). The previously named QuerydslBinding is now a SingleValueBinding which gets adapted to by extracting the first element of the values provided considered as collection.

Slightly refined the generics signature in QuerydslBinding for better type derivation in Lambdas. Removed the need for QuerydslBindingContext by moving a few properties around. The ConversionService instance is now piped into the QuerydslPredicateBuilder directly.

Added a bit of sample data to the Users test domain type to be able to execute the generated Predicates in tests to validate their correctness.

Original pull request: #132.
2015-07-20 08:11:28 +02:00
Christoph Strobl
e645501174 DATACMNS-669 - Added support to bind Querydsl Predicates to Spring MVC controllers.
Adding @QuerydslPredicate to a parameter within SpringMVC Controller when having registered the QueryDslPredicateArgumentResolver allows to generate a Querydsl Predicate based on the request parameters.

Parameters will be converted into their corresponding property types before using the as predicate value. Given more than one attribute will connect those using 'and'. Collections of values will force usage of 'in' while single values on collection like properties result in 'contains'.

The base type for building the Querydsl Path is extracted from the methods return type. In case of non domain type return values it can optionally be specified via @QueydslPredicate(root = …). Specific Predicate conversions can be registered via '@QuerydslSpecification'.

This allows to sneak in specific property path handlings more easily.

new QueryDslPredicateSpecification() {
  {
    define(new StringPath("address.city"), (path, value) -> path.like(value.toString()));
  }
};

Renamed resolver, accessor etc. to express operation of binding properties to a resolved path and introduced explicit binding context which allows reuse of predicate builder within the ArgumentResolver.

Added registration of QuerydslPredicateArgumentResolver directly in SpringDataWebConfiguration reusing the provided ConversionService.

Added Javadoc and changed visibility of non public API and types.

Original pull request: #132.
2015-07-20 08:11:04 +02:00
Oliver Gierke
30b4cf53fc DATACMNS-715 - Introduced support for JTA 2.1 @Transactional.
Refreshed the copy of AnnotationTransactionAttributeSource to pull in the JTA 2.1 support introduced in the Spring Framework class. Opened up a ticket [0] to improve Spring Framework to eventually be able to ditch the copies to prevent such scenarios in the future (the missing feature introduced that is).
2015-07-17 09:43:24 +02:00
Oliver Gierke
174e9a6e93 DATACMNS-731 - Parameter now exposes whether it's named explicitly.
Parameter now has a isExplicitlyNamed() to indicate whether the user explicitly assigned a name to it in contrast to an implicitly discovered parameter name.
2015-07-15 16:18:37 +02:00
Oliver Gierke
cd6b2c09c6 DATACMNS-542 - Be more lenient about simplified way to customize repository base classes.
We now leniently return null for the repository base class name from the AnnotationRepositoryConfigurationSource to make sure Spring Data modules compile against Spring Data Commons 1.10 continue to work on 1.11 without having the annotation attribute added.
2015-07-13 17:39:49 +02:00
Oliver Gierke
709bb5c4b1 DATACMNS-727 - Improved error handling in MappingContext.getPersistentPropertyPath(…).
A failure to resolve a property path into a PersistentPropertyPath now causes an InvalidPropertyPath exception being thrown. It captures the context of the failure like the resolved path, the offending segment. Added getPersistentPropertyPath(InvalidPropertyPath) that resolves the resolvable part for further use downstream.

Added null-checking assertions to AbstractMappingContext.getPersistentPropertyPath(…) variants. Improved DefaultPersistentPropertyPath to be able to append properties while building and to allow representing an empty path.
2015-07-09 14:10:26 +02:00
Oliver Gierke
d859540f92 DATACMNS-703 - PropertyReferenceException now exposes potential matches.
We now use Spring's PropertyMatches to build up the exception message and include a list of potentially meant properties.

Removed unused config file for tests along the way.

Original pull request: #125.
2015-07-06 12:44:13 +02:00
Oliver Gierke
bad0edef06 DATACMNS-722 - ProxyProjectionFactory now deals with arrays.
We now handle primitive and non-primitive arrays in ProxyProjectionFactory. WE basically skip element projections for the former and correctly implement exactly that for the latter.
2015-06-25 14:04:28 +02:00
Oliver Gierke
ac2faab0d2 DATACMNS-720 - Improved disabling of default transactions.
When default transactions get disabled, we now still configure a TransactionInterceptor to make sure explicitly defined transactions are still applied. Previously the interceptor was not registered at all if default transactions were configured to be turned off and thus even explicitly declared transaction configuration was not considered.

Related tickets: DATACMNS-656.
2015-06-22 17:06:41 +02:00
Oliver Gierke
e0dafd29f4 DATACMNS-714 - Improved test cases for CompletableFuture support.
We now make sure the converter for CompletableFuture is only registered if Spring 4.2 or better is on the classpath. Adapted test cases to only run tests for CompletableFuture support in the very same scenario.
2015-06-22 11:33:31 +02:00
Oliver Gierke
6da31347b8 DATACMNS-719 - Version now parses strings with non-numeric suffixes correctly.
Extended Version value object to correctly dump a non-numeric last segment of a version string to parse. Incorrect source version strings now raise an IllegalArgumentException better explaining the cause.

Related tickets: DATACMNS-496.
2015-06-22 11:25:52 +02:00
Oliver Gierke
3a2dc3d1d4 DATACMNS-713 - Disabled total adaption in PageImpl for empty pages.
The newly introduced adaption of the total in PageImpl must only be applied if the page accessed is not empty.
2015-06-19 15:26:40 +02:00
Oliver Gierke
c49f8357b6 DATACMNS-718 - Class loader improvements in ProxyProjectionFactory.
ProxyProjectionFactory now implements ResourceLoaderAware to be able to use the class loader used by the framework. SpringDataWebConfiguration now forwards the Application context as ResourceLoader through ProxyingHandlerMethodArgumentResolver into the target factory.
2015-06-19 13:05:56 +02:00
Oliver Gierke
26e398e553 DATACMNS-717 - AnnotatedTypeScanner now uses Environment and ResourceLoader configured.
We now implement EnvironmentAware and ResourceLoaderAware to respect the current environment setup when scanning for types. We use the ResourceLoader's ClassLoader if configured but indicate to fall back to the default one if none configured.
2015-06-18 17:44:05 +02:00
Thomas Darimont
7adb67351b DATACMNS-716 - Allow collection executions with wrapper types as return values.
We now support collection executions in query derivation in combination with wrapper types like (Future, Optional, CompletableFuture, ListenableFuture) that wrap a collection, e.g. Future<List<User>>. Previously we used the "raw" return type which tricked our detection for Collection / Page / Slice executions.

Original pull request: #130.
2015-06-17 17:39:31 +02:00
Oliver Gierke
9eb4603503 DATACMNS-715 - Repository factory now adds TransactionProxy interface if available.
We now leniently add the TransactionProxy marker interface to the repository proxy to opt-out of any further transaction handling potentially applied through @EnableTransactionManagement or its XML equivalent.

The interface will be introduced in Spring 4.1.7 / 4.2 RC2 so we're reflectively adding it if present. Might be something we can think of making less indirect for Fowler once 4.1.7 has been released.
2015-06-17 15:44:26 +02:00
Oliver Gierke
b294bfce3b DATACMNS-714 - Added support for CompletableFuture and ListenableFuture for query methods.
Spring Framework 4.2 is going to introduce support for CompletableFuture as return type for @Async methods. Support for Spring's ListenableFuture has already been supported in the framework 4.1. We've added the necessary infrastructure to  allow these types as return types on repository methods, too.

Related tickets: SPR-13128.
2015-06-16 14:35:21 +02:00
Oliver Gierke
a8b64c3828 DATACMNS-710 - Polishing.
Some additional JavaDoc, deprecations, copyright headers.

Original pull request: #128.
2015-06-15 22:16:46 +02:00
Phillip Webb
8156c2a151 DATACMNS-710 - Replace ObjectInstantiatorClassGenerator
Deprecate ObjectInstantiatorClassGenerator and provide a replacement
ClassGeneratingEntityInstantiator which doesn't retain a reference to
the context class loader.

Original pull request: #128.
2015-06-15 22:16:43 +02:00
Oliver Gierke
b60f5d84ec DATACMNS-648 - Parameters now holds a non-static ParameterNameDiscoverer.
Turned the previously static ParameterNameDiscoverer into an instance variable to make sure the instance can be GCed correctly.
2015-06-15 18:01:42 +02:00
Oliver Gierke
de4f1ffb7b DATACMNS-713 - PageImpl now adapts total if necessary.
On a last page the total handed into a PageImpl constructor might not necessarily fit the content as there's the change of an insertion or deletion between the calculated count and the retrieval of the content. We now leniently mitigate those differences if the page created is the last page of the result.

Related tickets: DATAJPA-728, DATACMNS-615.
2015-06-15 14:24:03 +02:00
Oliver Gierke
7107a599bb DATACMNS-710 - ObjectInstantiatorClassGenerator now uses default class loader.
We're now using ClassUtils.getDefaultClassloader() to make sure we adhere to any class loading tricks the framework might impose for domain type instantiation.
2015-06-09 22:01:25 +02:00
阮杰锋
a57bac07e2 DATACMNS-707 - Fixed typo in JavaDoc of CrudRepository
Changed from ( to { in JavaDoc of file CrudRepository.

Original pull request: #127.
2015-06-09 11:33:41 +02:00
Oliver Gierke
501f0c8493 DATACMNS-700 - ReflectionRepositoryInvoker now captures context for failed parameter conversions.
Introduced QueryMethodParameterConversionException to capture the context of a failed ConversionException to allow better error reporting.

Cleaned up test cases to not use deprecated API anymore.
2015-05-22 10:29:19 +02:00
Oliver Gierke
1fb7466065 DATACMNS-701 - First and last links are now always rendered for navigable PagedResources.
We now always render both first and last links in case the page returned is navigable, which essentially means: whenever the result spans across more than one page. I.e. whenever either a next or prev link will be rendered, both first and last links are rendered, too.

Clients can still reason about the fact whether they're on the first or last page by the non-presence of prev (indicates you're on the first page) or next (indicates you're on the last page).
2015-05-20 13:33:53 +02:00
Oliver Gierke
62170ab767 DATACMNS-701 - PagedResourcesAssembler now adds first and last links.
We now add first and last links to the PagedResources created in line with the appearance of the prev and next links. The PagedResourcesAssembler can be configured to enforce the rendering using setForceFirstAndLastRels(…).
2015-05-20 13:30:41 +02:00
Oliver Gierke
c5aaebd0e4 DATACMNS-699 - PagedResourcesAssembler now allows to create empty Page with type information. 2015-05-18 16:19:14 +02:00
Oliver Gierke
65104a4a3a DATACMNS-697 - TypeDiscoverer now considers field-local generics information.
In case we create a ParameterizedTypeInformation for a property we now also analyze the field-local generics information and add the discovered type mappings to the type variable map.
2015-05-16 18:55:47 +02:00
Oliver Gierke
6ebb05e606 DATACMNS-515 - Links for PagedResources should be canonical.
PagedResourcesAssembler now creates the self, prev and next links for a PagedResource to be canonical and not contain any template parameters. This is to make sure a client can not actually tweak the links and follow a link that's not strictly conforming to semantics of the rel.
2015-05-14 14:06:35 +02:00
Oliver Gierke
5b60d487e1 DATACMNS-695 - Fixed potential NullPointerException in AbstractMappingContext.getPersistentPropertyPath(…).
When traversing nested property paths, AbstractMappingContext.getPersistentPropertyPath(…) previously used the raw actual property type. If the property path contains a reference to a generically typed property, this causes the deeper paths not being resolved correctly.

We now explicitly use the TypeInformation of the property to retain generics information while traversing the path.
2015-05-13 18:33:58 +02:00
Oliver Gierke
9230b5f30f DATACMNS-692 - Fixed web parameter range handling for Pageables.
In case the PageableHandlerMethodArgumentResolver was configured to use one-indexed parameters, it wasn't defaulting the lower bounds for the page number. This caused indexes out of the allowed bound submitted causing an invalid index handed tor PageRequest. We now apply better range shifting before the bounds are applied.
2015-05-13 18:00:19 +02:00
Tomasz Wysocki
024dd50d92 DATACMNS-693 - AbstractMappingContext now uses Spring's BeanUtils to lookup PropertyDescriptors.
Instead of manually using Introspector.getBeanInfo(…) we now use Spring's BeanUtils.getPropertyDescriptors(…) to benefit from some caching of descriptor instances as well as advanced support for fluent setters, default methods etc.

Original pull request: #122.
2015-05-13 13:22:57 +02:00
Oliver Gierke
2d62c149bb DATACMNS-542 - Simplified way to customize repository base class.
RepositoryFactorySupport now exposes a setRepositoryBaseClass(…) to take a custom type that instances will be created reflectively for. This removes the need for a boilerplate repository factory and FactoryBean implementation to hook custom repository base class implementations into the infrastructure.

RepositoryFactorySupport now exposes a getTargetRepositoryViaReflection(…) method to allow sub-classes to create repository instances and consider customized repository base classes nonetheless. getTargetRepository(…) needs a tiny signature change which unfortunately requires imple

Fixed schema registration for version 1.8 schema. Added new XSD containing a base-class attribute on the <repositories /> element to customize the repository base class via XML.

Removed outdated section of how to create a custom base repository class from the reference documentation and replaced it with new simplified instructions.

Deprecated usage of factory-class attribute in configuration. Point users to newly introduced way of configuring a base class directly to avoid the need for a boilerplate repository factory and factory bean implementation.

DefaultRepositoryInformation now makes target class methods assignable before caching and returning them, so that they can always be invoked reflectively. Made this aspect part of the contract of RepositoryInformation.getTargetClassMethod(…).
2015-05-04 14:31:59 +02:00
Oliver Gierke
cb78260322 DATAREST-684 - ProxyProjectionFactory now exposes target instance on proxy.
Changed TargetClassAware to TargetAware and expose the actual proxy target for framework purposes.
2015-04-15 20:42:34 +02:00
Oliver Gierke
9977c61667 DATACMNS-683 - Tweaked the matching algorithm for DomainClassConverter.
DomainClassConverter as well as its internal ToEntity- and ToIdConverter implementations now actively refrain from matching if the source type is assignable to the target one to prevent unnecessary conversion attempts if the source value already actually is assignable to the target type.

Related ticket: DATACMNS-583.
2015-04-13 17:40:40 +02:00
Oliver Gierke
d48fddf9e6 DATACMNS-681 - Removed some compiler warnings.
Removed unused constants. Removed usage of deprecated method in RepositoryBeanDefinitionParser.
2015-04-13 13:04:59 +02:00
Oliver Gierke
e3df8907fb DATACMNS-678 - Improved RepositoryInvoker.invokeQueryMethod(…).
Introduced a new overload for invokeQueryMethod(…) that uses a MultiValueMap with effective values of type Object so that clients can hand non-String values to the invocation. This is particularly useful if certain values shall trigger dedicated Converters registered in the ConversionService of ReflectionRepositoryInvoker.

Related tickets: DATAREST-502.
2015-04-07 16:43:01 +02:00
Oliver Gierke
b0211911b5 DATACMNS-677 - AnnotationBasedPersistentProperty now caches absence of annotations on accessor-only properties.
AnnotationBasedPersistentProperty now also caches the absence of properties that are expressed through accessors only. Previously the absence of a field caused us to skip the registration of the absence in the cache.
2015-04-07 08:44:30 +02:00
Oliver Gierke
ffbaeddedb DATACMNS-613 - Removed custom CollectionFactory after upgrade to Spring 4.1. 2015-03-31 17:13:37 +02:00
Oliver Gierke
1c175ef59b DATACMNS-673 - Enhanced RepositoryMetadata to allow returning alternative domain types.
In case a RepositoryMetadata implementation alters the domain type the repository is actually handling, we still have to be able to find the repository based on the type originally declared in the repository.

The newly introduced getAlternativeDomainTypes() is now used by Repositories to register a repository for all types returned by that method, too, so that this reverse lookup still works.
2015-03-31 16:30:39 +02:00
Oliver Gierke
53d19c72c3 DATACMNS-663 - Fixed typo in BytecodeGeneratingEntityInstantiator. 2015-03-27 12:33:13 +01:00
Thomas Darimont
6f7d8489bf DATACMNS-654 - Polishing.
Added missing documentation for geospatial return types.
Fixed typo in GeoResult JavaDoc.
2015-03-23 11:13:36 +01:00
Oliver Gierke
5487395397 DATACMNS-661 - Polishing.
Removed the ability to configure a custom SpElExpressionParser for now as it's not really part of the performance optimization. Polished assertions in SpelEvaluatingMethodInterceptor.

Original pull request: #118.
2015-03-19 18:57:20 +01:00
Thomas Darimont
0cf395c1b1 DATACMNS-661 - Improvements in SpelAwareProxyProjectionFactory.
We now allow a SpelExpressionParser to be configured on the SpelAwareProxyProjectionFactory. This parser is then passed on to SpelEvaluatingMethodInterceptor. We also now eagerly pre-parse any SpEL expression in @Value annotations on methods of the projection interface. This avoids repeated evaluations during the actual method invocations.

Original pull request: #118.
2015-03-19 18:57:19 +01:00
Oliver Gierke
537fc430a9 DATACMNS-660 - Web configuration support now picks up configuration annotated with @SpringDataWebConfigurationMixing.
Introduced @SpringDataWebConfigurationMixing that can be used on configuration classes that are supposed to contribute components to the Application context when @EnableSpringDataWebSupport is used.

SpringDataWebConfigurationImportSelector scans the org.springframework.data package for classes annotated with that annotation and adds them to the classes to be considered config classes.
2015-03-17 17:08:31 +01:00
Oliver Gierke
d7adfbd859 DATACMNS-656 - Make application of default transactions configurable on TrasnactionalRepositoryFactoryBeanSupport.
TrasnactionalRepositoryFactoryBeanSupport now exposes a setEnableDefaultTransactions(…) which, if disabled, causes the TransactionalRepositoryProxyPostProcessor not to be registered and thus no default transactions to be applied.

Related tickets: DATAJPA-685.
2015-03-10 19:18:28 +01:00
Oliver Gierke
57180568c5 DATACMNS-655 - Invoking default methods on projection proxies now works.
Extracted DefaultMethodInvokingMethodInterceptor from RepositoryFactorySupport and register it within ProxyProjectionFactory if the code is running on Java 8.

Original pull request: #117.
2015-03-10 11:47:12 +01:00
Oliver Gierke
e2a7057af9 DATACMNS-652 - Removed JDK 8 reference from TypeDiscoverer.
Removed accidentally introduced reference to JDK 8's Executable as common super type of Constructor and Method.
2015-03-05 17:14:27 +01:00