Commit Graph

47 Commits

Author SHA1 Message Date
Mark Paluch
2b14d1ea54 DATACMNS-899 - Fix recursion in ParameterizedTypeInformation.getMapValueType().
Previously, calls to ParameterizedTypeInformation.getMapValueType() caused an infinite recursion when invoked on a type information that was not a map type. This lead to a StackOverflowError.

We now call the super method doGetMapValueType() instead of calling the entry super method getMapValueType() and return by that null in case the map value type is not resolvable.

Original pull request: #176.
2016-09-01 17:28:10 +02:00
Oliver Gierke
4fa84fc983 DATACMNS-896 - Improved detection of type variable mappings in recursively nested generics.
If the same generic type was used on recursively nested generics declarations, like this:

class GenericType<T> {}

class Nested extends GenericType<String> {}

class Concrete extends GenericType<Nested> {}

our traversal of the generics discovered T bound to String in Nested and as that is extending GenericType as well, the T detected here is the same instance as the T within the map discovered for Concrete. As we previously added the nested types after we added the original entry, the nested discovery overwrote the more local one.

We now make sure the detected nested type variable mappings don't overwrite already existing ones.
2016-08-19 19:49:24 +02:00
Pascal Grün
ce2e788374 DATACMNS-869 - Fix Javadoc for parametric types of Pair.
Original pull request: #164.
2016-06-11 18:21:20 +02:00
Oliver Gierke
65bfd5b33a DATACMNS-743 - Optimizations in TypeDiscoverer getProperty(…) in case if invalid property names.
We now also cache a failed property lookup so that we can return null on a subsequent call for the same invalid property name right away and don't have to reattempt the lookup unnecessarily.
2016-06-01 18:38:58 +02:00
Oliver Gierke
fa7ab50c5f DATACMNS-855 - Fixed generic type lookup in SyntheticParamterizedType.
The translation of the list of actual type parameters into an array now uses the loop index correctly. Previously, it always used the first type parameter.
2016-05-13 11:32:31 +02:00
Oliver Gierke
9db6278e77 DATACMNS-855 - Prevent memory leak in SyntheticParameterizedType.
Added proper equals(…) and hashCode() methods to SyntheticParameterizedType to make sure instances created for the same type information and type parameters are considered equal.
2016-05-12 16:48:01 +02:00
Oliver Gierke
137d7cc544 DATACMNS-818 - Renamed Tuple to Pair.
Got rid off manual implementation code in favor of Lombok annotations.
2016-03-18 09:54:29 +01:00
Christoph Strobl
a40e247c25 DATACMNS-825 - Allow usage of composed annotations using @AliasFor.
We now resolve composed annotation values using @AliasFor within AnnotationBasedPersistentProperty and BasicPersistentEntity. Nevertheless it is up to the individual store implementation to make use of this.

Original pull request: #156.
2016-03-13 16:30:03 +00:00
Oliver Gierke
dbe79f89a9 DATACMNS-89 - Infrastructure for projections on repository queries.
QueryMethods now expose a ResourceProcessor which is exposes information about the final to be created object types which can either be DTOs containing a persistence constructor (see @PersistenceConstructor) or projection interfaces. The former are analyzed for constructor properties so that store implementations can use that information to create projected queries that return exactly the fields required for that DTO.

Projection interfaces are inspected, their properties are considered input properties and the same projection queries can be issued against the data store. If a projection contains dynamically calculated properties (i.e. it uses SpEL expressions via @Value) the original entities have to be queried and can be projected during post processing.

ProjectionFactory now exposes a more advanced ProjectionInformation that has additional meta information about the projection type. ProxyProjectionFactory now refers to the BeanClassLoader instead of the ResourceLoader.

RepositoryFactory(Bean)Support now also implement BeanFactoryAware to forward the BeanFactory to the SpelAwareProxyProjectionFactory which in turn now gets handed into the QueryLookupStrategy as well as the QueryMethod.

Parameter now knows about a dynamic projection type, which is a query method parameter of type Class bound to a generic method parameter and will be used to determine the projection to be used on a per call basis.

Original pull request: #150.
2015-12-14 19:31:33 +01:00
Oliver Gierke
b0f81ef80a DATACMNS-790 - Added Tuple value type.
Related pull request: https://github.com/spring-projects/spring-data-mongodb/pull/327.
2015-11-26 16:14:56 +01:00
Oliver Gierke
d2737983c3 DATACMNS-783 - DefaultTypeMapper now specializes raw generic types.
If the type lookup from the store source returns a raw generic type (e.g. resolving the value of a generic property against a value of that generic type - i.e. not a more concrete type binding the generic information) in the context of a generic property, we previously did not apply the generics information of the contextual instance to that very raw type.

We now expose a TypeInformation.specialize(ClassTypeInformation) which applies the current generics context to the given raw type and basically creates a synthetic parameterized TypeInformation instance.

DefaultTypeMapper applies this specialization by default now with ClassTypeInformation simply returning the given type as is so that we don't create any resolution overhead in case no generics are involved in the first place.
2015-11-13 17:16:47 +01: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
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
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
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
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
Oliver Gierke
2d75cf2c43 DATACMNS-651 - Introduced a Range value type.
Primarily intended to be used with Distance instances, we introduce a Range value type. Distance now has factory methods to create Range instances between two distances. To support this, Distance now implements comparable based on the normalized value of it.

Tiny refactoring in TypeDiscoverer to avoid code duplication between the lookup of parameter type information for constructors and methods.
2015-03-04 17:34:32 +01:00
Oliver Gierke
186cb25605 DATACMNS-650 - Polishing.
Added stream to the list of supported query method prefixes. Allow Stream to be used as return type for paginating queries, too.

Renamed Java8StreamUtils to StreamUtils. Some additional JavaDoc.

Original pull request: #116.
2015-03-03 18:10:40 +01:00
Thomas Darimont
e92c235fdf DATACMNS-650 - Introduced CloseableIterator abstraction as a foundation for streaming of results.
A CloseableIterator abstracts the underlying result with support for releasing the associated resources via close() which can be transparently be used with try-with-resources in Java 7 since Closeable implements AutoCloseable from Java 7 on upwards. Added detector methods to QueryMethod to check whether the current method returns a Stream. 

Introduced ReflectionUtils.isJava8StreamType to safely detect whether the given type is assignable to a Java 8 Stream. Introduced CloseableIteratorDisposingRunnable that can be registered as a cleanup action on a Stream.

Original pull request: #116.
2015-03-03 16:08:00 +01:00
Oliver Gierke
df9f8c417e DATACMNS-637 - Performance improvements.
Made ObjectInstantiator interface public as otherwise the generated class to implement it cannot access it and thus the usage of the ByteCodeGeneratingEntityInstantiator fails completely.

PreferredConstructor.isEnclosingClassParameter(…) now eagerly returns if the parameter itself is not an enclosing one and thus avoids a collection lookup and equals check. Moved equals check for the type to the very end of the equals check to increase the chances that other inequality guards kick in earlier.

AbstractMappingContext now leaves the non-null-check for getPersistentEntity(…) to the factory method of ClassTypeInformation.

We now pre-calculate the hash codes for TypeInformation implementations as far as possible as the instances are used as cache keys quite a lot. The same applies to AbstractPersistentProperty.

BasicPersistentEntity now uses an ArrayList we sort during the verify() phase to mimic the previous behavior wich was implemented using a TreeSet as ArrayLists are way more performant when iterating over all elements which doWithProperties(…) is doing which is used quite a lot.

BeanWrapper now avoids the getter lookup if field access is used.

SimpleTypeHolder now uses a CopyOnWriteArrySet to leniently add types detected to be simple to the set of simple types to avoid ongoing checks against the inheritance hierarchy.
2015-01-25 17:43:59 +01:00
Oliver Gierke
013f97899e DATACMNS-616 - Fixed field value lookup for private fields in AnnotationDetectionFieldCallback.
We now make the field detected by the callback accessible so that the value lookup doesn't fail for private fields. Added a few more unit tests to verify behavior.
2014-12-17 17:38:04 +01:00
Oliver Gierke
e1b38faee9 DATACMNS-601 - Fixes for most of the SonarQube warnings. 2014-11-26 09:25:14 +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
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
Oliver Gierke
3660676338 DATACMNS-558 - Some code cleanups according to the Sonar report. 2014-08-10 12:51:28 +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
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
5791e9b201 DATACMNS-495 - Prepare 1.8.0.RC1.
Removed compiler warnings (obsolete @SuppressWarnings and obsolete code). Upgraded to Spring HATEOAS 0.11.0.
2014-05-01 20:23:58 +02:00
Christoph Strobl
57271baf54 DATACMNS-496 - Version.parse(…) now drops non-numeric artifacts.
Version parsing failed when given version contained non-numeric parts (like 2.0.0-rc1). We now strip everything after the first non numeric part to create a logical version equivalent of the source String.

Original pull request: #81.
2014-04-29 16:02:10 +02:00
Oliver Gierke
165c0595e3 DATACMNS-485 - API improvements to in TypeInformationMapper area.
The default implementations of the TypeInformation Mapper interfaces now work with ClassTypeInformation where possible to express they only map raw types effectively.

Added TypeInformation.getRawTypeInformation() to easily turn whatever TypeInformation into the raw type representation. Changed ClassTypeInformation.from(…) to return ClassTypeInformations directly.
2014-04-15 07:49:46 +02:00
Oliver Gierke
e13fc294bb DATACMNS-486 - Added ParsingUtils helper class to easily transform camel case Strings.
Refactored XmlRepositoryConfigurationSource to use the newly introduced type.
2014-04-10 18:35:36 +02:00
Oliver Gierke
f52635da13 DATACMNS-485 - Fixed bug in ParameterizedTypeInformation.hashCode().
Previously, ParameterizedTypeInformation.hashCode() had been inconsistent to equals in case of a fully resolved parameterized type. This is now fixed by not including the parent reference in case a parameterized type is resolved completely.

Also, TypeDiscoverer.getActualType() does not return the component type for non-collection/non-maps anymore to make sure we don't accidentally unwrap parameterized types.
2014-04-02 09:59:44 +02:00
Oliver Gierke
08d5f936c8 DATACMNS-452 - Added constructor to DirectFieldAccessFallbackBeanWrapper. 2014-03-06 19:27:53 +01:00
Oliver Gierke
6408e16faf DATACMNS-452 - Added some helper types to simplify the implementations in store modules.
Added AnnotatedTypeScanner to easily scan for annotated types within a set of base packages. Picks up interfaces by default which had to be customized when using ClassPathScanningCanidateComponentProvider.

Added DirectFieldAccessFallbackBeanWrapper that will use direct field access for beans in case no accessor method can be found. This allows to easily implement bean property values through accessors first but using the field directly if the accessors aren't available.

Introduced AnnotationDetectionMethodCallback to easily find methods equipped with a given annotation.
2014-02-27 08:36:00 +01:00
Oliver Gierke
ab37869a1a DATACMNS-446 - Added toString() methods to TypeInformation types. 2014-02-23 13:51:41 +01:00
Oliver Gierke
931a697ec5 DATACMNS-440 - Fixed map value type resolving for Map value types.
Previously the map value type resolving algorithm checked the value type to be of type Map again to shortcut the resolution. We now weakened this to an assignment check and eagerly resolve the generic type if its bound on exactly that level already. If no concrete type argument can be found, we fall back to the general generics resolution mechanism.
2014-02-13 12:06:26 +01:00
Oliver Gierke
1f172725f0 DATACMNS-422 - Mitigate semantic changes in Spring 4.0's GenericTypeResolver.
In case of an unresolvable generic parameter in TypeDiscoverer's getTypeArgument(…) we check for a generic super type for the given bound and fall back to Object in case we find a parameterized type.
2014-01-19 15:37:44 +01:00
Oliver Gierke
c0fc0f905a DATACMNS-401 - Some cleanups regarding generics and deprecations.
Suppress deprecation warnings for GenericTypeResolver for now. Added Simple(Property|Association)Handler to ease working with untyped PersistentProperty instances without having to fall back to raw types. Polished Sonargraph architecture description.
2013-11-14 09:28:11 +00:00
Oliver Gierke
057c2e9bf8 DATACMNS-384 - Polished toString() representation of Version.
Trailing zeros now get removed up until the minor version number.
2013-11-04 11:02:50 +01:00
Oliver Gierke
ae9ee5b428 DATACMNS-387 - Improvements in null handling in PartTree area.
We're now rejecting invalid constructor arguments handed to ClassTypeInformation, Part, PartTree and PropertyPath. Beyond that we skip the creation of a Part for an empty path segment, so that you don't end up with an invalid Part instance for a findAllByOrderByFooAsc.
2013-10-27 16:34:26 +01:00
Oliver Gierke
06df973c54 DATACMNS-384 - Introduced value object for Version. 2013-10-17 10:29:33 +02:00
Oliver Gierke
541ef648f1 DATACMNS-356 - Parameters now uses DefaultParameterNameDiscoverer if present.
We now leniently try to lookup DefaultParameterNameDiscoverer and create an instance of it to make use of Spring 4's improved parameter name capabilities on Java 8. We fall back on a LocalVariableTableParameterNameDiscoverer if on Spring versions prior to 4.
2013-08-07 14:39:37 +02:00
Oliver Gierke
cd2ea03928 DATACMNS-332 - Further performance improvements.
Reverted from ConcurrentHashMap to plain HashMap where concurrency wasn't an issue and profiling showed performance hotspots. Introduced caches for ParameterizedTypeInformation.getComponentType() and the resolved raw type in TypeDiscoverer.
2013-05-23 18:57:48 +02:00
Oliver Gierke
8d69459f74 DATACMNS-311 - TypeDiscoverer now also finds properties in type hierarchy.
We now also inspect the entire type hierarchy to lookup a property descriptor to inspect for read methods in case no field is found for a property.
2013-04-12 16:41:39 +02:00
Oliver Gierke
a7820c8cc6 DATACMNS-309 - Fixed lookup of nested properties on TypeDiscoverer.
So far the property lookup of a nested property path (e.g. "foo.bar") failed in cases the head property was not cached already. We now recursively resolve the type information even for an unpopulated cache.
2013-04-05 20:44:27 +02:00
Oliver Gierke
6b49eb4ca5 DATACMNS-276 - Added hashCode() to ParameterizedTypeInformation.
Implemented hashCode() to be as close as possible to the equals(…) implementation.
2013-01-29 13:07:44 +01:00
Oliver Gierke
ac256f9921 DATACMNS-266 - Use new common Maven build infrastructure.
Simplified project setup to be a single module build again. Using Spring Data Build parent POM to simplify project setup. See https://github.com/SpringSource/spring-data-build#spring-data-build-infrastructure
2013-01-16 15:15:24 +01:00