Commit Graph

234 Commits

Author SHA1 Message Date
Oliver Gierke
4c1a187dd4 DATACMNS-599 - Introduced IdentifierAccessor API.
PersistentEntity now exposes an getIdentifierAccessor(…)-method that allows obtaining the identifier of an entity without using a PersistentProperty instance. This allows advanced scenarios (like multi-property identifiers). Also we can use store specific means to optimize id lookups to e.g. avoid proxy initialization for lazy loading proxies.
2014-11-24 13:01:23 +01:00
Oliver Gierke
2388b6fa90 DATACMNS-597 - Fixed to strict consistency check in PersistentPropertyAccessor lookup.
BasicpersistentEntity now allows subtypes to be handed into the PersistentPropertyAccessor lookup to support inheritance hierarchies as well as interface based PersistentEntity scenarios.
2014-11-19 17:05:50 +01:00
Oliver Gierke
3446c457d5 DATACMNS-596 - Polishing.
PersistentEntityInformation now falls back to null values for PersistentEntity instances that don't expose an identifier property.
2014-11-18 16:46:18 +01:00
Oliver Gierke
6a849bc8ef DATACMNS-596 - Introduced PersistentPropertyAccessor.
To be able to customize the lookup of bean properties by persistent store we now expose a getPropertyAccessor(Object entity) method on PersistentEntity. It returns a PersistentPropertyAccessor which is basically an interface with a simplified API of BeanWrapper.

Reduced the plain BeanWrapper to not perform any type conversion to be able to drop the ConversionService dependency. To compensate for that we introduced a ConvertingPropertyAccessor that takes a ConversionService and delegates to a standard PersistentPropertyAccessor and applies conversions if necessary.

Refactored client APIs to use the PersistentPropertyAccessor instead of referring to BeanWrapper directly. Deprecated BeanWrapper.create(…) for removal in RC1.
2014-11-18 12:29:30 +01:00
Oliver Gierke
93dbc26969 DATACMNS-589 - Polishing.
Made DefaultCrudMethods public to support better testing. Components that are based on CrudMethods can be tested easier if DefaultCrudMethods is public, so that an instance can easily be set up by using a DefaultRepositoryMetadata instance.

Polished JavaDoc and copyright headers.
2014-11-14 16:53:17 +01:00
Oliver Gierke
c5721cfc0c DATACMNS-594 - Fixed creation of type variable map to extend into detected bounds.
The initial setup of the type variable map now unfolds the detected types in the map to make sure we detect all type variables present in the current scope.

Added caching of component and map value TypeInformation instances to avoid repeated creation.
2014-11-14 16:34:31 +01:00
Oliver Gierke
eac6fcaa8e DATACMNS-589 - Integrated RepositoryInvoker abstraction from Spring Data REST.
Replaced CrudInvoker with the more sophisticated and flexible RepositoryInvoker originating from Spring Data REST. Slightly refined the API and added a lot more unit tests. Refactored usage of CrudInvoker to use a DefaultRepositoryInvokerFactory and create RepositoryInvokers for the domain types.
2014-11-14 15:45:42 +01:00
Oliver Gierke
ac73720668 DATACMNS-590 - Fixed calculation of nested generics in ParentTypeAwareTypeInformation.
So far, the lookup of the type variable map was preferring the type variable maps detected on parent types in nested structures. This caused the concrete type variables in nested types not being considered correctly which caused the type resolution to fall back to the generic bounds.

We now accumulate the type variable maps to avoid having to lookup a certain map in the nesting hierarchy. The core fix is in ParentTypeAwareTypeInformation's constructor and mergeMaps(…) respectively. Simplified the handling of type variable maps and made proper use of generics throughout the class hierarchy.
2014-11-12 14:30:34 +01:00
Thomas Darimont
dec5cadce9 DATACMNS-581 - Add support for NotContaining keyword for derived repository queries.
We now support the keyword NotContaining in query methods for repositories. This is achieved by adding NOT_CONTAINING to the Part.Type enum with the variants 'IsNotContaining', 'NotContaining', 'NotContains'. Added a dedicated toString() method to ease debugging to Part.Type.

Original pull request: #100.
2014-10-29 09:50:02 +01:00
Thomas Darimont
c898f1ec7b DATACMNS-583 - DomainClassConverter returns input if given types are the same.
DomainClassConverter now returns input when the source type is identical to the target type. Previously we erroneously tried to convert the sourceType to the idType of the targetType's backing repository. As a side effect we also avoid performing some unnecessary converter hops.

Original pull request: #101.
2014-10-29 09:41:14 +01:00
Oliver Gierke
28b7e0439d DATACMNS-578 - Polishing.
Added some JavaDoc where missing. Better variable names and slightly parameter ordering changes. Formatting in the unit tests and reference to the original ticket.

Original pull request: #98.
2014-10-21 12:18:01 +02:00
Thomas Darimont
1b9cdc941f DATACMNS-578 - Speed up instance creation by generating factory classes with ASM.
Introduced BytecodeGeneratingEntityInstantiator which dynamically generates classes to speed up the dynamic instantiation of objects. Since we cannot support every use case with byte code generation we gracefully fallback to the ReflectiveEntityInstantiator.

BytecodeGeneratingEntityInstantiator has support for unboxing of constructor parameters and more robust handling for cases where we cannot generate a custom ObjectInstantiator.

Original pull request: #98.
2014-10-21 12:18:01 +02:00
Thomas Darimont
48966b50d6 DATACMNS-577 - Improved JavaDoc on QueryDslPredicateExecutor.
Clarified return values if predicates don't match or return multiple results (for the findOne(…) method). Copied summary to the @return tag.

Original pull request: #96.
2014-10-08 06:46:55 +02:00
Thomas Darimont
ad7a87403d DATACMNS-530 - Improve JavaDoc for RepositoryConfigurationSourceSupport.
Removed misleading JavaDoc.

Original pull request: #97.
2014-10-07 15:01:30 +02:00
Mark Paluch
6cc9e33359 DATACMNS-565 - Improved detection of custom implementations for CDI repositories.
The detection of the custom implementation has now been moved into the Bean base class to avoid calls to BeanManager.getBeans(…) (which are necessary to pick up the configuration class defining postfixes and the like) happen to early in the CDI container lifecycle.

Related ticket: DATACMNS-557.
2014-09-01 12:46:12 +02:00
Thomas Darimont
9fc57ea3bf DATACMNS-566 - Allow sorting by QueryDsl operator expressions.
Previously we only allowed to sort by QueryDsl path expressions. With this change we now also support ordering by operator expressions, e.g. yearMonth() on a date property.

Original pull request: #94.
2014-08-26 13:56:17 +02:00
Oliver Gierke
c9dd679cd1 DATACMNS-562 - AbstractPersistentProperty doesn't consider maps and collections entities anymore.
The type detection for entity candidates of PersistentProperty instances now consistently handles collection types even if they're used als collection or map values.
2014-08-19 17:53:51 +02:00
Oliver Gierke
5352701374 DATACMNS-556 - Make annotation validation in AnnotationBasedPersistentProperty more lenient.
Annotations used on both fields and accessors are now only rejected if they're Spring Data annotations (i.e. from the org.springframework.data namespace) and the configurations of these annotations differ.
2014-08-10 13:15:39 +02:00
Oliver Gierke
3660676338 DATACMNS-558 - Some code cleanups according to the Sonar report. 2014-08-10 12:51:28 +02:00
Oliver Gierke
756c951112 DATACMNS-557 - Polishing.
Renamed CdiRepositoryConfigurationSource to CdiRepositoryConfiguration. Turned anonymous inner default implementation into dedicated enum to avoid repeated instantiation.

Changed the CdiRepositoryBean to rather take a Bean instance of the custom implementation instead of the resolved object to make sure both instances (the custom implementation and the repository proxy) are instantiated at the same time.

Fixed imports. Some early returns to avoid unnecessary nesting.

Adapted architecture description to allow CDI module accessing the configuration module.

Related pull request: #92.
2014-08-07 12:33:29 +02:00
Mark Paluch
1f0260e48d DATACMNS-557 - Added support for custom implementations to CDI infrastructure.
The CDI extension now discovers a custom implementation class similarly to the detection when using Spring Data in a Spring container. Extracted the custom implementation detection for re-use. The CDI extension discovers the potentially available bean and hands it to the CdiRepositoryBean for further usage.

Implementations should implement the extended variant of the create(…) method we introduce with this commit to be able to forward the resolved custom implementation bean.

Original pull request: #92.
2014-08-07 12:05:09 +02:00
Oliver Gierke
85157b6644 DATACMNS-526 - Added type matching to strict repository scanning.
Repository interfaces are now also considered strict matches if they are assignable to one of the types returned by getIdentifyingTypes().
2014-07-31 12:54:08 +02:00
Oliver Gierke
81af5ee730 DATACMNS-526 - Improved configuration behavior in multi-store scenarios.
We now apply a stricter repository interface selection if we detect multiple Spring Data modules to be in the classpath to avoid the repository scanning accidentally overriding each others definitions or even picking up interfaces they weren't intended to manage.

The detection is based on a type scan in dedicated base package where subtypes of RepositoryFactorySupport usually reside. If more than one type is found, we activate strict scanning.

The strict check is actually implemented in RepositoryConfigurationExtensionSupport to be accessible for store implementations. By default we try to load the repository candidate interface and inspect the managed domain types for a collection of annotations (see RepositoryConfigurationExtensionSupport.getIdentifyingAnnotations()). Implementors still have the chance to customize the behavior by overriding isStrictRepositoryCandidate(…).

We also introduced a getModuleName() to be able to create better logging output in terms of repository registration. Moved registration of RepositoryConfigurationExtension as Spring bean into the base types for XML and annotation configuration support to make sure they only kick in if explicit configuration is used.
2014-07-28 19:56:40 +02:00
Oliver Gierke
3bcf6f3f27 DATACMNS-547 - @TypeAlias is now @Persistent.
For @TypeAlias annotated types being picked up using entity scanning, the annotation is now @Persistent.

Related tickets: DATAMONGO-992.
2014-07-24 14:13:10 +02:00
Oliver Gierke
ba70380555 DATACMNS-546 - PropertyPath has better exception messages now.
PropertyPath now exposes the complete property named the resolution failed for in case it can't resolve a source String. It will expose the part of the Path from the deepest successful resolution result.

Changed the resolution algorithm to use a List instead of a Stack and a fresh instance of the former so that the nested recursion steps keep track of the correct resolution depths.
2014-07-21 18:11:12 +02:00
Oliver Gierke
5bc89af4e7 DATACMNS-544 - Indicate repository configuration has been active.
RepositoryConfigurationDelegate now registers the store-specific RepositoryConfigurationExtension as lazy-init BeanDefinition so that other parties can detect that definition.
2014-07-18 20:02:49 +02:00
Oliver Gierke
5aa5b9e1aa DATACMNS-543 - Avoid duplicate repository bean registration in XML namespace.
We're now firing the component registration event manually in RepositoryBeanDefinitionParser as ParserContext.registerBeanComponent(…) registers the given BeanComponentDefinition with the registry. As we do that manually before this previously resulted in the BeanDefinition overriding the very same one and container warnings in turn.
2014-07-18 12:21:35 +02:00
Oliver Gierke
ed0f7c51f8 DATACMNS-469 - Removed deprecations. 2014-07-16 11:53:20 +02:00
Oliver Gierke
789f620af1 DATACMNS-539 - DefaultCrudMethods now detects delete(T t) methods.
The CRUD method detection now also discovers delete methods taking the domain type as argument.

Related ticket: DATAREST-319.
2014-07-15 10:37:29 +02:00
Oliver Gierke
94436dd609 DATACMNS-533 - Implemented handling of root objects.
Refactored the implementation of the dynamic lookup of properties and functions on EvaluationContextExtensions. All the reflective lookup logic has moved into an EvaluationContextExtensionAdapter.

We now also distinguish between the meta-information that can be looked up once and cached (so that we avoid reflection overhead for subsequent context creations).

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:21:12 +02:00
Thomas Darimont
1e489bbd6d DATACMNS-533 - Added test cases for root object integration in SpEL extension API.
Changed SPI to expose a Function type rather than plain methods as well as an arbitrary root object.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:20:59 +02:00
Oliver Gierke
39f028bb6c DATACMNS-533 - Polishing of special parameter handling.
Collapsed variable gathering methods into one, make sure we expose all values (also null ones). Renamed unit test for ExtensionAwareEvaluationContextProvider according to the class name. Some further cleanups in the test case.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:20:49 +02:00
Thomas Darimont
31848f87eb DATACMNS-533 - Expose special parameters in SpEL expressions.
We now expose special parameters like Pageable and Sort to be used in SpEL expressions if they don't collide with existing named parameters.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:20:33 +02:00
Thomas Darimont
1ff4961cbc DATACMNS-533 - Discover declared properties on EvaluationContextExtension.
We new automatically register public static fields declared on classes extending EvaluationContextExtensionSupport as properties to be used within SpEL expressions.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:20:11 +02:00
Thomas Darimont
9ab9467386 DATACMNS-533 - Discover declared functions on EvaluationContextExtension.
We new automatically register public static methods declared on classes extending EvaluationContextExtensionSupport as functions to be used within SpEL expressions.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:19:58 +02:00
Oliver Gierke
d303f6ac37 DATACMNS-533 - Infrastructure support for SpEL expressions in manually defined queries.
Extracted SPI build for DATAJPA-564 into Spring Data Commons. Simplified the configuration setup code and removed the ability to define a custom EvaluationContextProvider for now. We directly declare a bean definition which automatically picks up EvaluationContextExtensions.

RepositoryFactory(Bean)Support is now aware of the EvaluationContextProvider to hand it to the template method that creates the QueryLookupStrategy. Deprecated the previously existing template method in favor of an extended one.

Removed variable declarations from the extension interface for now as usually properties serve the same purposes as variables which makes the latter superfluous for now. Applied some JavaDoc and API signature polish. Added unit tests for ExtensionAwareEvaluationContextProvider.

Related pull request: spring-projects/spring-data-jpa#101
Related ticket: DATAJPA-564
2014-07-10 12:19:48 +02:00
Christoph Strobl
acd3a9b6fd DATACMNS-534 - Add support to mark a persistent property as read only.
This commit introduces @ReadOnlyProperty to mark properties as not to be persisted. That trait is exposed via the newly added PersistentProperty.isWritable() which supersedes shallBePersisted(). Currently all non-transient property that are not annotated with @ReadOnlyProperty are considered writable.

Original pull request: #88.
2014-07-09 14:41:31 +02:00
Oliver Gierke
15597d35dc DATACMNS-532 - Added support for default methods on repository interfaces.
DefaultRepositoryInformation now excludes default methods from the query methods it detects. RepositoryFactorySupport adds a special MethodInterceptor to the proxy which handles the invocation of default methods.

Related tickets: DATACMNS-535.
2014-07-07 17:26:06 +02:00
Oliver Gierke
0841c7dc43 DATACMNS-529 - Removed reflective lookup of DefaultParameterNameDiscoverer.
As we build against Spring 4 now, we can replace the reflective lookup of DefaultParameterNameDiscoverer to a simple instantiation.
2014-07-02 08:52:54 +02:00
Thomas Darimont
2586344218 DATACMNS-518 - Avoid potential infinite loops in PreferredConstructor.
We now synchronize the (seldom) writes to the isPropertyParameterCache HashMap in PreferredConstructor via a ReadWriteLock. We could as well have used a ConcurrentHashMap here without the need for manual locking but this would potentially waste memory for a mostly read-only data structure. We also anticipate potential multiple writes for the same property.

Original pull request: #86.
2014-06-26 14:07:31 +02:00
Oliver Gierke
a885b57dbf DATACMNS-523 - Pulled up FieldNamingStrategy SPI from Spring Data MongoDB.
Pulled up the SPI for field naming from Spring Data MongoDB for reuse in other Spring Data modules.
2014-06-20 21:22:21 +02:00
Oliver Gierke
aa8d5987d9 DATACMNS-520 - Fixed @Param validation in Parameters.
Parameters erroneously rejected @Param annotated query method parameters that were preceded by a non-bindable type (like Pageable or Sort) as it checked for a 0 index of the parameter. We now manually keep an index in the check itself and have removed the Parameter.isFirst() method as it's not used anywhere else.
2014-06-12 15:59:57 +02:00
Oliver Gierke
28b3221bcf DATACMNS-519 - PagedResourcesAssembler now keeps template variables of base link.
Significant overhaul of the link creation in PagedResourcesAssembler.
2014-06-11 15:30:23 +02:00
Thomas Darimont
1697c77f31 DATACMNS-516 - Add support for limiting the query result in the query derivation mechanism.
We can now detect whether a given query method wants to limit the query results based on two new supported prefixes (findFirstBy…(…) and findFirstKBy…(…)) where "First" part can also be replaced by "Top" and an following optional K (which must be a decimal int) that denotes the maximal number of result rows to be retuned by the query.

This can be used by the stores to allow queries like:

- T findFirstBy…OrderBy…Asc -> smallest
- T findFirstBy…OrderBy…Desc -> greatest
- T findTopBy…OrderBy…Desc -> greatest
- T findFirstBy…(Sort sort) -> general purpose
- T findTopBy…(Sort sort) -> general purpose
- List<T> findFirstKBy…OrderBy…Asc -> smallest K
- List<T> findFirstKBy…OrderBy…Desc -> biggest K
- List<T> findFirstKBy…(Sort sort) -> general purpose TOP K
- List<T> findTopKBy…(Sort sort) -> general purpose TOP K

The limiting expressions also support the Distinct expression. Also, for the queries limiting the result set to one instance, wrapping the result into an Optional is supported.

If pagination or slicing is applied to a limiting query pagination (and the calculation of the number of pages available) is happening within the limited result.

Original pull request: #85.
2014-06-06 15:20:37 +02:00
Oliver Gierke
d41da583e9 DATACMNS-513 - PagedResourcesAssemblerArgumentResolver now correctly resolves mappings for sub-class invocations.
We're now using the newly introduced method on ControllerLinkBuilderFactory that takes both a type and a method to forward the method the invocation is happening on independently from the method being invoked.
2014-06-05 17:16:16 +02:00
Oliver Gierke
fd4121e03e DATACMNS-511 - Improve equals(…) and hashCode() in TypeVariableTypeInformation.
The equals(…) and hashCode() methods of TypeVariableTypeInformation previously tried to evaluate the unresolved context of the type variable. This can cause issues in recursive type definitions as set up in the according test case. We now implement the methods based on the resolved type to makes sure we break the recursive lookup of PersistentEntity instances in AbstractMappingContext. 

The erroneous lookup was actually caused by unresolved base types being added to the mapping context within the JPA project as the JPA meta-model also returns those types as managed types.

Related pull request: #84.
2014-05-28 15:40:21 +02:00
Oliver Gierke
b94d1fac8e DATACMNS-494 - Removed the defaulting of the environment in RepositoryBeanDefinitionRegistrarSupport.
As SPR-11744 got fixed recently and will be available in Spring 3.2.9, we removed the guard in RepositoryBeanDefinitionRegistrarSupport which defaulted the environment in case it was not set by the container.

Related tickets: SPR-11744.
2014-05-20 16:36:17 +02:00
Oliver Gierke
5541989058 DATACMNS-509 - Fixed non-NullableWrapper conversion.
In case the repository method execution returns a collection that needs to be converted into a different collection (e.g. List -> Set) we erroneously ran into a NullableWrapper conversion. This was due to the fact that we only used the raw method return type, which caused the ObjectToCollectionConverter to kick in (as the target type's component type falls back to Object if we use raw types).

We're now using Spring's MethodParameter abstraction to create a TypeDescriptor for the method's return type which fully supports generics, so that the conversion check for NullableWrapper -> target type does not match the ObjectToCollectionWrapper.

Prepared the QueryExecutionConverters to be able to support recursive type conversion once we move to Spring 4 as TypeDescriptor exposes the ResolvedType as of this version so that we can inspect the type parameter of the wrapper type to invoke a nested conversion (e.g. Integer -> Optional<String> requires NullableWrapperTo(Guava|Jdk)OptionalConverter being invoked and in turn recursively convert the Integer to String).
2014-05-20 08:46:08 +02:00
Oliver Gierke
8164426981 DATACMNS-506 - PreferredConstructorDiscoverer now uses Spring 4's ParameterNameDiscoverer if present.
We now also reflectively check for the presence of DefaultParameterNameDiscoverer. This allows the usage of the new reflection methods introduced in Java 8 if the user code is running on Spring 4.

Changed the name of the constant for the ParameterNameDiscoverer in Parameters to meet conventions for constants.
2014-05-19 08:48:05 +02:00
Oliver Gierke
28f7630acc DATACMNS-502 - Prevent IndexOutOfBoundException in AnnotationRepositoryConfigurationSource.
If a configuration class resides in the default package and no base package is defined in the @Enable…Repositories annotation we previously failed in extracting the package from the class name (as there is none).

We now use Spring's ClassUtils that correctly handles this case and returns an empty String for the default package.
2014-05-08 12:11:21 +02:00