Commit Graph

901 Commits

Author SHA1 Message Date
Mark Paluch
cc0ab54c38 DATACMNS-1171 - Do not create PersistentEntity for unsupported Kotlin classes.
We now reject unsupported Kotlin classes from the MappingContext by default by not creating persistent entities.

Original pull request: #245.
2017-09-25 12:23:35 +02:00
Mark Paluch
d9d0d594e5 DATACMNS-1171 - Limit Kotlin reflection support to regular classes.
We now only inspect regular Kotlin classes with inspection to adapt Kotlin-specific behavior. Multipart-, synthetic and unknown classes are not supported. In such cases we fall back to the JVM reflection mechanism.

Non-regular classes are typically synthetic stubs, lambdas and SAM conversion which do not represent typical domain objects but rather technical bridge code.

Original pull request: #245.
2017-09-25 12:23:30 +02:00
Oliver Gierke
65e21344ac DATACMNS-1173 - Fixed value lookup of AnnotationRevisionMetadata.
Fixed handling of absent values. Minor refactorings. More unit tests.
2017-09-25 09:56:31 +02:00
Mark Paluch
041c18bef9 DATACMNS-1170 - Fallback to default constructor discovery for Kotlin classes without primary constructor.
We now fall back to default preferred constructor discovery if a Kotlin class has no primary constructor and no preferred constructor is resolved. Previously, primary constructor resolution yielded no result (returned null) which caused the subsequent Java constructor lookup to fail.

Original pull request: #244.
2017-09-22 12:11:04 +02:00
Oliver Gierke
d9860f2d20 DATACMNS-1161 - Polishing.
Typo in JavaDoc.

Original pull request: #243.
2017-09-21 18:14:57 +02:00
Jens Schauder
ea03388a7c DATACMNS-1161 - Renamed PersistentProperty.getPersitentEntityType(…) to ….getPersitentEntityTypes(…).
The new name currently delegates to old version, so classes only implementing the old method still work. Old name is deprecated.

Original pull request: #243.
2017-09-21 17:46:28 +02:00
Oliver Gierke
404610ebb4 DATACMNS-1168 - QuerydslPredicateBuilder now returns empty predicate by default. 2017-09-21 16:23:40 +02:00
Mark Paluch
fcf97e1e71 DATACMNS-1157 - Enforce nullable/non-null API constraints on repository query methods.
We now validate query method invocations to check method parameters whether they accept null values and reject execution if null values are not supported. We derive nullability support from repository interfaces declared using Kotlin and Spring's NonNullApi/Nullable annotations.

We also check whether a query method can return null. If a query method returns null which isn't supposed to do so, then we throw EmptyResultDataAccessException to prevent null return values.

interface UserRepository extends Repository<User, String> {

  List<User> findByLastname(@Nullable String firstname);

  @Nullable
  User findByFirstnameAndLastname(String firstname, String lastname);
}

interface UserRepository : Repository<User, String> {

  fun findByLastname(username: String?): List<User>

  fun findByFirstnameAndLastname(firstname: String, lastname: String): User?
}

Original pull request: #241.
2017-09-21 10:23:47 +02:00
Oliver Gierke
e7ae4a8bb8 DATACMNS-1165 - Added support for Streamable as repository return type.
We now allow users to use our own Streamable interface as query method return types to easily invoke ….stream() on everything that returns an Iterable using non-parallel streaming by default.
2017-09-20 16:31:29 +02:00
Oliver Gierke
1a199847cd DATACMNS-1162 - Improved support for immutable aggregates.
AbstractAggregateRoot is now generified to be able to use its concrete type on methods returning an instance of itself. Added new methods andEvent(…) and andEventsFrom(…) to easily transfer events from another aggregate instance. Added unit tests for fundamental functionality of the base class.
2017-09-20 11:45:37 +02:00
Oliver Gierke
72b927ea2c DATACMNS-1163 - EventPublishingInterceptor now prefers arguments over return values for event publication.
We now prefer to inspect the arguments handed to save(…) methods over inspecting the return value as the invocation of the actual method is free to exchange the instance handed into it and return a completely new one with the events contained in the parameter completely wiped.
2017-09-20 11:09:25 +02:00
Johnny Lim
fb19d84c75 DATACMNS-1153 - Removed unreachable assertion in XmlRepositoryConfigurationSource.
Original pull request: #236.
2017-09-07 15:22:35 +02:00
Oliver Gierke
2cfd6b8966 DATACMNS-1152 - Setup of ProjectingJackson2HttpMessageConverter now tries to use unique ObjectMapper from ApplicationContext.
We're now trying to look up a uniquely available ObjectMapper instance from the application context falling back to a simple new instance in case none can be found.
2017-09-06 17:11:51 +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
Mark Paluch
c091d4db56 DATACMNS-1148 - Return primitive boolean in PartTree.isExistsProjection(…).
Declare primitive return type to avoid nullable return values.
2017-08-28 15:52:26 +02:00
Mark Paluch
67f52d5d70 DATACMNS-1141 - Polishing.
Remove superfluous null checks in places where state cannot be null. Add nullable annotations to nullable variables. Remove whitespaces.
2017-08-28 15:52:25 +02:00
Christoph Strobl
0669632a61 DATACMNS-1141 - Add missing NonNullApi and Nullable annotations. 2017-08-28 13:32:47 +02:00
Mark Paluch
1e134cbd33 DATACMNS-1141 - Fix line endings. 2017-08-28 13:32:47 +02:00
Mark Paluch
3a2b6b601b DATACMNS-1141 - Add missing NonNullApi and Nullable annotations.
Add Nullable annotation to ParsingUtils, Sort.Order and PropertyValueProvider.

Add getRequiredAnnotation(…) to PersistentEntity and PersistentProperty to provide methods returning required, non-null annotations.
2017-08-28 13:32:15 +02:00
Mark Paluch
d657b17e74 DATACMNS-1147 - Do not consider @NoRepositoryBean interfaces as fragment interfaces.
We filter interfaces annotated with @NoRepositoryBean from fragment interface candidates and not longer scan for implementations of these.

Extending a base repository usually requires an interface which is used as base interface instead of Repository/CrudRepository in user repositories. If the naming scheme of the extended interface and the implementation fits to fragment interfaces, then we previously registered the class additionally as fragment implementation. The bean registration caused container startup failures because of unsatisfied dependencies or would shadow the base repository implementation.

Original pull request #239.
2017-08-28 12:54:17 +02:00
Oliver Gierke
22b6971318 DATACMNS-1126 - Polishing.
Moved PreferredConstructorDiscoverers into PreferredConstructorDiscoverer to hide more API. Renamed ClassGeneratingKotlinEntityInstantiator to KotlinClassGeneratingEntityInstantiator.

Use org.springframework.util.Assert instead of com.mysema.commons.lang.Assert.

Original pull request: #233.
2017-08-25 15:00:45 +02:00
Mark Paluch
b05c4e74fb DATACMNS-1126 - Polishing.
Trailing whitespace in ReflectionUtils.

Original pull request: #233.
2017-08-25 13:04:28 +02:00
Mark Paluch
22b37800ec DATACMNS-1126 - Add class-generating entity instantiation support for Kotlin.
We now discover Kotlin constructors and apply parameter defaulting to allow construction of immutable value objects. Constructor discovery uses primary constructors by default and considers PersistenceConstructor annotations.

KotlinClassGeneratingEntityInstantiator can instantiate Kotlin classes with default parameters by resolving the synthetic constructor. Null values translate to parameter defaults.

class Person(val firstname: String = "Walter") {
}

class Address(val street: String, val city: String) {

	@PersistenceConstructor
	constructor(street: String = "Unknown", city: String = "Unknown", country: String) : this(street, city)
}

Original pull request: #233.
2017-08-25 13:04:28 +02:00
Mark Paluch
e4e677d6b1 DATACMNS-1140 - Polishing.
Extend javadoc. Remove trailing whitespaces.

Original pull request: #238.
2017-08-25 09:31:04 +02:00
Christoph Strobl
0ff4961853 DATACMNS-1140 - Open up Query by Example to allow extension in module implementations.
We turned Example and ExampleMatcher into interfaces with default implementations created via the static of methods. The default ExampleMatcher has strongly typed default implementation. This change allows store implementations to create their very own flavor of Example and ExampleMatcher allowing eg. non typed ones.

Original pull request: #238.
2017-08-25 09:28:54 +02:00
Oliver Gierke
d018757995 DATACMNS-1144 - @JsonPath now supports multiple path expressions.
Path expressions are now evaluated one by one with the first one actually available in the payload being used for value lookup. Also tweaked the default behavior to return null in case of an single, invalid path.
2017-08-24 12:56:19 +02:00
Oliver Gierke
ce7a2e8ea5 DATACMNS-1143 - Improve design of AbstractAggregateRoot.
Methods for domain event registration and access are now not following bean semantics anymore to avoid those accidentally leaking into formats that use the bean spec (e.g. Jackson to produce JSON).
2017-08-23 15:47:50 +02:00
Oliver Gierke
fb9d38d79c DATACMNS-1139 - AbstractPersistentProperty.getRawType() now correctly resolves generics.
We're now favoring the generic TypeInformation over trying to resolve the property type via field or PropertyDescriptor as only the former does proper generic type resolution.
2017-08-14 14:06:16 +02:00
Oliver Gierke
fab854c906 DATACMNS-1138 - TypeInformation.specialize(…) now only specializes unresolved parameterized types.
Type specialization - i.e. enrichment of a raw type with a current generic context - is now only done if the current type is not yet resolved completely. This allows wildcarded target references to just fall back to the type to specialize, which will then by definition carry more generics information than the one to be specialized.
2017-08-11 16:15:54 +02:00
Oliver Gierke
756396a065 DATACMNS-1135 - Fixed generics lookup for recursively nested container references.
Revert the merging of a parent type's type variable map and only apply the locally available declared generics in case of parameterized types. Moved that augmentation into ParameterizedTypeInformation.
2017-08-03 15:39:54 +02:00
Mark Paluch
0ff80930a3 DATACMNS-1080 - Inject generated property accessor classes via ReflectUtils.defineClass(…).
We now use CGLibs ReflectUtils.defineClass(…) to inject classes into the entity's class loader instead of our own code. ReflectUtils itself discovers whether the class loader is encapsulated and falls back to Unsafe for class definition. We no longer require our own code so the evil class was removed.

Original pull request: #234.
2017-07-27 08:43:09 +02:00
Mark Paluch
3c66ce423f DATACMNS-1077 - Remove RxJava1CrudRepository and RxJava1SortingRepository interfaces.
RxJava 1 development is phased out over time (Feature freeze in June 2017, EOL in March 2018) and we don't want to ship newly developed first-class support for libraries known to be no longer maintained. RxJava 1 type adoption support is not affected. Single and Observable can be still used in user-space code declaration, also copies of RxJava1CrudRepository (in user-space code) remain working.
2017-07-26 14:36:54 +02:00
Oliver Gierke
7960786083 DATACMNS-1129 - A PartTree is now an empty iterable if no predicate is given. 2017-07-25 13:52:16 +02:00
Oliver Gierke
beebcf1f7c DATACMNS-1114 - Updated Javadoc of Sort.and(…) to match nullability requirements. 2017-07-24 23:03:58 +02:00
Oliver Gierke
af56889e72 DATACMNS-1123 - Upgraded to XmlBeam 1.4.12 and tweaked HttpMessageConverter implementation.
XmlBeam 1.4.11 accidentally removed ProjectionFactory as public interface. Adapted our HttpMessageConverter implementation to make sure we still work on those versions.

Related ticket: https://github.com/SvenEwald/xmlbeam/issues/45
2017-07-24 14:17:36 +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
d9b16d8a27 DATACMNS-1085 - Fixed typos in Javadoc.
Original pull request: #229.
2017-07-24 10:32:19 +02:00
Mark Paluch
86945f81d1 DATACMNS-1122 - Improve message for absent required property in PersistentEntity.getRequiredPersistentProperty(…).
Exception message now contains the property name.
2017-07-21 08:54:39 +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
5e4cac308e DATACMNS-1120 - Introduced caching of PropertyPath instances. 2017-07-20 13:38:43 +02:00
Oliver Gierke
75ac90150f DATACMNS-1119 - Cache for ClassTypeInformation is now a ConcurrentReferenceHashMap. 2017-07-20 12:56:11 +02:00
Oliver Gierke
7ee5ae446b DATACMNS-1117 - Fixed creation of RepositoryInformation in RepositoryFactoryBeanSupport.
RepositoryFactoryBeanSupport.getRepositoryInformation() previously didn't consider any store-specific compositions (incl. store-specific fragments like the Querydsl support) as it just handed a fragment with the custom implementation to RepositoryFactorySupport.

This is now fixed by improving the API in RepositoryFactorySupport which now exposes a getRepositoryInformation(RepositoryMetadata, RepositoryFragments) which creates a fresh RepositoryComposition from the given RepositoryMetadata. Intermediate setup methods are still kept around but private as RepositoryFactorySupport.getRepository(…) still needs to forward the base RepositoryComposition to method interceptors for query result mapping.
2017-07-20 10:14:57 +02:00
Oliver Gierke
dfcb9f77a4 DATACMNS-1116 - AbstractMappingContext now caches PersistentPropertyPaths.
As the calculation of a PersistentPropertyPath instances is rather expensive and they're heavily used in downstream mapping operations (e.g. query and fields mapping in MongoDB) we now cache the instances created per base type and property path.
2017-07-19 13:45:41 +02:00
Oliver Gierke
d692702663 DATACMNS-1115 - Improve RepositoryBeanNameGenerator to properly resolve bean names for indexed BeanDefinitions.
Previously, RepositoryBeanNameGenerator applied the custom bean name lookup if the BeanDefinition given was not a ScannedGenericBeanDefinition. That in turn had been the case for custom implementation classes that were obtained through classpath scanning. With Spring 5 an index file can be used by the scanner, which in turn will cause AnnotatedGenericBeanDefinition instances being returned. That caused the code path to lookup the first constructor argument to kick in (usually used to obtain the repository interface from repository factory beans) and cause a NullPointerException.

We now forward AnnotatedBeanDefinitions as is and only apply the custom lookup for everything else, i.e. the bean definitions used for the factories.
2017-07-19 01:28:58 +02:00
Oliver Gierke
d5728b6e3f DATACMNS-1113 - Deprecated MappingContext.getPersistentPropertyPath(InvalidPersistentPropertyPath).
Deprecated the additional method in favor if a lookup via MappingContext.getPersistentPropertyPath(PropertyPath) using the resolvable PropertyPath exposed by InvalidPersistentPropertyPath.
2017-07-17 16:09:28 +02:00
Oliver Gierke
6a6d995eab DATACMNS-1109 - Reinstantiate support for all date/time APIs in auditing.
Re-enabled test cases for handling of different date/time APIs in auditing. Tweaked the lookup of the last modified value to try to convert to LocalDateTime as well in case it's a subtype of the type requested. In combination with two newly introduced converters for local date type times in JodaTime and ThreeTenBP, this allows us to still convert legacy JodaTime and ThreeTenBP types to be used as well.
2017-07-12 19:17:23 +02:00
Oliver Gierke
d4b79ea8f2 DATACMNS-1112 - Cache instances of ReturnedType to avoid repeated reflection inspection.
We now keep instances of ReturnedType around to avoid the repeated reflection inspection for constructor and parameter name detection for class types and projection information for interfaces.
2017-07-12 17:09:39 +02:00
Oliver Gierke
4d2cc9ab8e DATACMNS-1110 - Introduced StreamUtils.createStreamFromIterator(CloseableIterator).
This is an overload for the already existing method taking a plain Iterator so that we only apply the close callback to the Stream in the newly introduced one.
2017-07-12 10:54:11 +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