Commit Graph

54 Commits

Author SHA1 Message Date
Christoph Strobl
f261220372 DATACMNS-1762 - Polishing.
Update JavaDoc, remove unused imports and reduce method visibility.

Original Pull Request: #459
2020-09-25 08:00:29 +02:00
Mark Paluch
bd3992dfc5 DATACMNS-1762 - Support Optional wrapping for projection getters.
We now support nullable wrappers for projection interfaces. Getters are inspected whether their return type is a supported nullable wrapper. If so, then the value can be wrapped into that type. Null values default in that case to their corresponding empty wrapper representation.

Original Pull Request: #459
2020-09-25 07:59:02 +02:00
Phillip Webb
67442077b7 DATACMNS-1755 - Consistently use commons-logging.
Replace the few occurrences where SLF4J was being used directly so that
all logging now happens via commons-logging. The log patterns used in
SLF4J messages have been replaced with `LogMessage` which was introduced
in Spring Framework 5.2.

Original pull request: #448.
2020-06-25 11:20:24 +02:00
Phillip Webb
ea263b233b Rename uppercase 'LOGGER' static finals
Rename static final `LOGGER` members to use the lowercase form.
Although the loggers are static final, they are not constant values.
2020-06-25 11:09:16 +02:00
Mark Paluch
4be5aae181 DATACMNS-1726 - Delombok source files. 2020-05-15 08:46:58 +02:00
Mark Paluch
eed7658ce5 DATACMNS-1643 - Update copyright years to 2020. 2020-01-07 08:32:25 +01:00
Mark Paluch
cace881a13 DATACMNS-1598 - Polishing.
Add unit tests to back change. Guard invocations against null dereference.
Join assertions.

Original pull request: #409.
2019-10-28 08:54:17 +01:00
Wilds
36b95d39ce DATACMNS-1598 - Fix interface projection returning EnumSet.
EnumSet's are now constructed with a proper component type.

Original pull request: #409.
2019-10-28 08:48:58 +01:00
Mark Paluch
972449ef2d DATACMNS-1556 - Limit default method invocation only to interfaces that actually declare default methods. 2019-07-25 14:12:11 +02:00
Spring Operator
48c9297118 DATACMNS-1500 - URL Cleanup.
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* [ ] http://www.apache.org/licenses/ with 1 occurrences migrated to:
  https://www.apache.org/licenses/ ([https](https://www.apache.org/licenses/) result 200).
* [ ] http://www.apache.org/licenses/LICENSE-2.0 with 701 occurrences migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).

Original Pull Request: #387
2019-03-22 11:00:44 +01:00
Mark Paluch
1969f4bcdc DATACMNS-1459 - Update copyright years to 2019. 2019-01-02 12:12:19 +01:00
Mark Paluch
caaec1b862 DATACMNS-1415 - Use thread-safe caching in SpelAwareProxyProjectionFactory.
We now use ConcurrentHashMap as type instead of HashMap to properly synchronize concurrent updates to missing cache elements.

The previously used HashMap was not thread-safe so concurrent modifications resulted in ConcurrentModificationException.
2018-11-12 16:01:21 +01:00
Mark Paluch
0d39693c94 DATACMNS-1376 - Fix illegal access warning in DefaultMethodInvokingMethodInterceptor on Java 9 and higher.
We now attempt to use private MethodHandles lookup as the first mechanism to resolve a MethodHandle for default interface methods and fall back to reflection-based Lookup construction if private lookup is not available. Reflective availability is checked lazily to prevent illegal access on enum constant construction. This approach prevents an illegal access which was logged by attempting a reflection-based lookup first.

We also introduced a FALLBACK mechanism to split encapsulated access from a fallback mechanism.

Original pull request: #307.
2018-08-17 13:08:30 +02:00
Mark Paluch
ea8cf8c629 DATACMNS-1357 - Use shared DefaultConversionService in ProxyProjectionFactory and ResultProcessor.
ProxyProjectionFactory and ResultProcessor require a DefaultConversionService to convert values for projection proxies and to post-process query method results. Creating instances of these types requires an instance of the conversion service which previously created a DefaultConversionService instance (along all converter registrations) upon ProxyProjection/ResultProcessor instantiation.

We now use the shared instance that is initialized once and shared across all ProxyProjection/ResultProcessor instances to reduce garbage and improve the CPU profile.
2018-07-25 15:31:45 +02:00
Mark Paluch
06116b7726 DATACMNS-1206 - Polishing.
Convert type array to string to construct the exception message. Slight Javadoc tweaks. Reduce method visibility. Simplify hasDefaultGetter check. Remove superfluous throws declaration. Strip trailing whitespaces. Ignore property descriptors without getter (e.g. indexed properties).

Original pull request: #263.
2018-01-12 12:28:38 +01:00
Oliver Gierke
5eb10a0817 DATACMNS-1206 - Polishing.
Moved PropertyDescriptor lookup into dedicated subclass to group functionality around the type and MethodsMetadata instances. Extracted individual stream handling steps into dedicated methods for better understandability.

Moved MethodsMetadataReader into classreading package for symmetry with Spring Framework's metadata arrangement. Removed manually declared getters in DefaultMethodsMetadataReader in favor of Lombok getters. Inlined MethodsMetadataReadingVisitor into DefaultMethodsMetadataReader as it's only used there.

Original pull request: #263.
2018-01-12 11:04:49 +01:00
Mark Paluch
9e013d3c14 DATACMNS-1206 - Add API to read methods in declaration order.
We now provide MethodsMetadataReader to read method metadata from a class file. MethodMetadata is read for all user-declared methods except for constructors (which are technically methods, too).

MethodsMetadataReaderFactory factory = new MethodsMetadataReaderFactory();
MethodsMetadataReader metadataReader = factory.getMetadataReader("com.acme.Foo");
MethodsMetadata metadata = metadataReader.getMethodsMetadata();

This new API is now used by DefaultProjectionInformation to make sure the order of input properties is based on the declaration order in the projection interfaces. Previously that order could not be guaranteed to be stable.

Original pull request: #263.
2018-01-12 11:04:31 +01:00
Mark Paluch
51e7e1b7f5 DATACMNS-1240 - Update copyright years to 2018.
Also, remove some trailing whitespaces and align outdated license header format.
2018-01-08 16:04:34 +01:00
Oliver Gierke
34cadd0b9b DATACMNS-1224 - Polishing of nullability annotations.
Refactored code to properly check for null fields in Eclipse. Added warning suppressions where suitable.
2017-11-30 00:29:32 +01:00
Jens Schauder
300f3cfd66 DATACMNS-1158 - ProjectionFactory is now configurable by module implementations.
Introduced RepositoryFactorySupport.getProjectionFactory(…) to create a ProjectionFactory to be used for repository instances created. The default implementation uses the SpelAwareProxyProjectionFactory.

The ProjectionInformation implementation is now a named class so it can be used for more specialized implementations.

Original pull request: #243.
Related issue: DATAJPA-1173.
2017-11-24 11:05:17 +01:00
Mark Paluch
11458c9dcf DATACMNS-1181 - Polishing.
Use Spring Framework's Nullable annotation instead the JSR-305 one.

Original pull request: #251.
2017-10-02 10:41:30 +02:00
Mark Paluch
b18989786f DATACMNS-1181 - Adapt MethodHandle lookup of default methods in package-scoped interfaces to changes in Java 9.
We now attempt MethodHandle lookup with deep reflection capabilities via MethodHandles.privateLookupIn(…) to properly resolve default interface methods on interfaces with package-protected visibility. This API is only available in Java 9 so we need to rely on reflection.

Original pull request: #251.
2017-10-02 10:41:17 +02:00
Oliver Gierke
4b323eca11 DATACMNS-1150 - Projection methods with SpEL expressions can now use method parameters.
We now forward method parameters of methods on projection interfaces to the expression evaluation. The parameters are exposed via an array named "args".
2017-09-04 19:15:04 +02:00
Oliver Gierke
049970874d DATACMNS-1114 - Introduced usage of nullable annotations for API validation.
Marked all packages with Spring Frameworks @NonNullApi. Added Spring's @Nullable to methods, parameters and fields that take or produce null values. Adapted using code to make sure the IDE can evaluate the null flow properly. Fixed Javadoc in places where an invalid null handling policy was advertised. Strengthened null requirements for types that expose null-instances.

Removed null handling from converters for JodaTime and ThreeTenBP. Introduced factory methods Page.empty() and Page.empty(Pageable). Introduced default methods getRequiredGetter(), …Setter() and …Field() on PersistentProperty to allow non-nullable lookups of members. The same for TypeInformation.getrequiredActualType(), …SuperTypeInformation().

Tweaked PersistentPropertyCreator.addPropertiesForRemainingDescriptors() to filter unsuitable PropertyDescriptors before actually trying to create a Property instance from them as the new stronger nullability requirements would cause exceptions downstream.

Lazy.get() now expects a non-null return value. Clients being able to cope with null need to call ….orElse(…).

Original pull request: #232.
2017-07-24 10:47:28 +02:00
Oliver Gierke
51f099306d DATACMNS-1121 - ProxyProjectionFactory now returns instance as is if it implements the target.
If you previously asked ProxyProjectionFactory for a proxy of an interface which the target instance already implements, it created a proxy although it could've returned the instance as is. It's now actually doing that avoiding superfluous proxy creation.
2017-07-20 14:29:54 +02:00
Oliver Gierke
b724797dc6 DATACMNS-1107 - Polishing.
Moved methods around in ProjectionFactory implementations to follow the coding guidelines.
2017-07-11 11:23:37 +02:00
Oliver Gierke
6e09c09afa DATACMNS-1107 - ProxyProjectionFactory now caches ProjectionInformation instances.
To avoid the repeated scanning of projection interfaces for property descriptors we now cache the ProjectionInformation instances created via ProjectionFactory.getProjectionInformation(…). Adapted SpelAwareProxyProjectionFactory to now apply its customizations in newly introduced createProjectionInformation(…).
2017-07-11 11:23:05 +02:00
Oliver Gierke
8026e9ff72 DATACMNS-1106 - Removed deprecations in ProjectionFactory.
Removed the deprecated implementation of ResourceLoaderAware in favor of BeanClassLoaderAware. Removed deprecated ProjectionFactory.getInputProperties() in favor of ….getProjectionInformation(). Removed the Java conditional to add a MethodInterceptor for default methods. Adapted test cases.
2017-07-11 11:18:18 +02:00
Oliver Gierke
f44255b9a8 DATACMNS-1102 - Reuse ConversionService in ProjectingMethodInterceptors created by ProxyProjectionFactory.
Applied the same to internals of MapDataBinder.
2017-07-05 09:41:21 +02:00
Oliver Gierke
976aeaf34c DATACMNS-1074 - Polishing.
Java-8-ification.

Original pull request: #221.
2017-06-07 10:45:04 +02:00
Oliver Gierke
83d9c56eb4 DATACMNS-1074 - Polishing.
Enum names in all caps.

Original pull request: #221.
2017-06-07 10:45:04 +02:00
Mark Paluch
9038e6894c DATACMNS-1074 - Cache MethodHandles of default methods after lookup.
We now cache method handles after lookup on a best-effort basis to reuse them and prevent subsequent lookups as a MethodHandle lookup is expensive, in particular the lookup uses exceptions as control flow [0] during speculative lookup [1].

[0] http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/5b86f66575b7/src/share/classes/java/lang/invoke/MemberName.java#l978
[1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-August/042770.html

Original pull request: #221.
2017-06-07 10:45:04 +02:00
Mark Paluch
2e532b3d21 DATACMNS-991 - Polishing.
Refactor conditional lookup strategies into enum instances reflecting the open/encapsulated lookup strategy.

Original pull request: #223.
2017-05-31 15:56:50 +02:00
Jens Schauder
6a39937d51 DATACMNS-991 - Support Java 9 compatible MethodHandle lookup.
DefaultMethodInvokingMethodInterceptor now contains two alternative implementations, one compatible to Java 8, one for Java 9.

Original pull request: #223.
2017-05-31 15:55:49 +02:00
Oliver Gierke
1c60ea8d36 DATACMNS-867 - Rework utility classes.
Removed the additional methods that reflectively checked for the Stream type and whether a Method instance is a default method. Turned utility classes into interfaces where possible. Make use of Lombok's @UtilityClass where not.

Removed obsolete implementation class in StreamUtils in favor of a lambda.
2017-03-24 08:00:45 +01:00
Christoph Strobl
be347eaaab DATACMNS-867 - Additional Java 8 language feature cleanup.
Make use of lambdas and method references though out the codebase. Remove no longer required generic type parameters.
Additionally remove unused imports and replace single element list initialization with dedicated singletonList.
Use Assertion overloads taking Supplier for dynamic assertion error messages.
2017-03-24 08:00:43 +01:00
Christoph Strobl
8bcd8cb3da DATACMNS-867 - Fixed glitch causing failure in PropertyDescriptor lookup for ProjectionInformation.
Re added PropertyDescriptor collection. Looks like the method got dropped during one of the rebase operations.
Additionally make use of .distinct() name collection in tests as descriptors might appear multiple times for the same property name.
2017-03-24 08:00:43 +01:00
Oliver Gierke
d4811e29d9 DATACMNS-867 - Second draft. 2017-03-24 08:00:23 +01:00
Oliver Gierke
cc63e5b7a4 DATACMNS-867 - First draft. 2017-03-24 08:00:23 +01:00
Oliver Gierke
a946d651ff DATACMNS-967 - Getters that are default methods are not considered projection input properties anymore.
We now exclude getter methods that are default methods from the consideration which properties of a projection interface are considered input properties in the first place.

Some additional Java 8 polish in DefaultProjectionInformation.
2016-12-23 13:06:34 +01:00
Oliver Gierke
8ed2bca557 DATACMNS-909 - Mask getDecoratedClass() of Spring 4.3's DecoratingProxy.
The proxies created for projections now defensively mask getDecoratedClass(), a method declared on DecoratingProxy, an interface that JDK proxies on Spring 4.3 will implement.
2016-09-09 21:59:55 +02:00
Oliver Gierke
eec2b43fd0 DATACMNS-885 - Support for binding JSON payloads to projection interfaces.
Projection types annotated with @ProjectedPayload can now be used as parameters for @RequestBody annotated Spring MVC controller method parameters.

Accessor methods will be translated into JSON path property expressions which can be customized by using the @JsonPath annotation. The methods are allowed to return simple types, nested projection interfaces or complex classes which will will be mapped using a Jackson ObjectMapper.
2016-07-25 17:26:32 +02:00
Oliver Gierke
a8db5e3d23 DATACMNS-829 - Fixed handling of Map null values in ProxyProjectionFactory.
We now eagerly return null values in attempts to project Map values.
2016-03-15 15:46:56 +01:00
Oliver Gierke
d3e6ad104c DATACMNS-820 - Polishing.
Fixed indentation to use tabs instead of spaces. Tweaked structure of if-clauses in PropertyAccessingMethodInterceptor to reduce nesting. Made helper method static. 

Restructured test cases slightly and used ExpectedException rule to verify exceptions. Moved newly introduced test methods more to the end of the file (new tests last).

Added author and copyright year extensions where necessary.

Original pull request: #155.
2016-02-20 20:33:14 +01:00
Mark Paluch
e868577def DATACMNS-820 - Allow setter invocations in projections backed by beans.
Invocations to setter methods are now passed to the backing bean.

Original pull request: #155.
2016-02-20 20:33:13 +01: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
0d6476c642 DATACMNS-782 - ProxyProjectionFactory now converts primitive attribute values.
The ProjectingMethodInterceptor now uses a default ConversionService instance to try to convert a potentially not matching result of the target invocation into the type the projection requires before the attempt to create nested projection.
2015-11-12 11:17:43 +01: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
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
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