Commit Graph

155 Commits

Author SHA1 Message Date
Oliver Gierke
0f174f6867 DATACMNS-1278 - Make sure that SimpleTypeHolder always treats enums as simple.
We now explicitly check for an enum type in SimpleTypeHolder.isSimpleType(…) and resort to true immediately. Before that an enum implementing an interface could have seen a false for the actual enum type in case the interface type had been checked first and (correctly) produced a false. In the check for the actual enum type, depending on the iteration order through the cached values we could've hit the cached false for the interface or the cached true value for Enum.
2018-03-12 10:47:26 +01:00
Mark Paluch
c068ab679c DATACMNS-1271 - Polishing.
Use ConcurrentHashMap in AnnotationBasedPersistentProperty for thread-safe annotation caching. Reintroduce eager cache check to prevent lambda instances on positive cache hits.
2018-03-01 16:25:06 +01:00
Oliver Gierke
32ea1f77c0 DATACMNS-1271 - Streamlined implementation of AnnotationBasedPersistentProperty to avoid NullPointerExceptions.
We now use the annotation cache's ….computeIfAbsent(…) to avoid inconsistencies between ….contains(…) and ….get(…) in multi-threaded scenarios.
2018-03-01 16:25:06 +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
Oliver Gierke
e2bac30be4 DATACMNS-1214 - Fixed AbstractMappingContext.getPersistentEntity(PersistentProperty) to now return null for non-entities.
Previously, a call to AbstractMappingContext.getPersistentEntity(PersistentProperty) would've added potentially leniently added the type of the given PersistentProperty, no matter whether it's actually considered to be an entity in the first place. We now defensively check for whether the given property is to be considered an entity (taking potentially registered converters into account) before the potentially entity-creating by-type lookup.
2017-11-16 16:36:27 +01:00
Oliver Gierke
24c1b823c6 DATACMNS-1210 - Polishing.
More fixes of imports. Removed obsolete generics in constructor expressions. Removed a couple of compiler warnings in test cases. Removed assumption for test case to only run on JDK 9.

Original pull request: #259.
2017-11-14 17:59:43 +01:00
Christoph Strobl
309cdc5e43 DATACMNS-1210 - Fix concurrency issue in BasicPersitentEntity.
Make sure to use concurrent collection implementations for properties holding mutable state. Especially the ones making use of computeIfAbsent(…).

Usage of ConcurrentReferenceHashMap allows us to move on without additional changes as it allows to store null values, whereas ConcurrentHashMap would require us to store explicit NullValue placeholders for such cases, potentially causing trouble in downstream store specific projects.

JMH Benchmarks done with the Spring Data MongoDB mapping layer showed a potential performance loss of up to 5%. However a comparison between ConcurrentReferenceHashMap and ConcurrentHashMap did not show any significant difference in performance.

Original pull request: #259.
2017-11-14 17:59:16 +01:00
Oliver Gierke
d8cea8ba1c DATACMNS-1208 - AbstractMappingContext.hasPersistentEntityFor(…) now properly considers cached absence.
AbstractMappingContext.hasPersistentEntityFor(…) now also properly consideres the empty Optional as non-presence as that is held to allow to distinguish between a type completely unkown to the context, or already known but not considered a persistent entity.

Related pull request: #258.
2017-11-14 10:01:32 +01:00
Oliver Gierke
baee26e5e7 DATACMNS-1180 - Fixed accessor lookup for generic properties.
In AbstractPersistentProperty, we now resolve the potentially generic return and parameter types of getters and setters. To achieve that Property has now been made aware of the actual owning type.
2017-10-27 10:40:38 +02:00
Mark Paluch
a13fc238d3 DATACMNS-1201 - Support generated property accessors for types in default packages.
We now support generated property accessors for types that reside in the default package.

Original pull request: #256.
2017-10-24 22:34:30 +02:00
Oliver Gierke
4bd8a3cfc3 DATACMNS-1199 - Added PropertyPath.nested(…).
This allows to obtain a nested property path based on a currently available one.
2017-10-19 12:40:53 +02:00
Oliver Gierke
b3e1601bc6 DATACMNS-1198 - Added PropertyPath.getLeafType() to expose leaf-property type. 2017-10-19 12:25:00 +02:00
Mark Paluch
506fe37aea DATACMNS-1200 - Polishing.
Throw MappingInstantiationException from KotlinClassGeneratingEntityInstantiator if instantiation fails to align behavior with ClassGeneratingEntityInstantiator. Report Kotlin constructor instead of Java constructor if available.

Original pull request: #255.
2017-10-19 12:01:28 +02:00
Oliver Gierke
370b37fbfd DATACMNS-901 - AbstractMappingContext publishes entity added events outside the write lock.
Previously, the publication of the event that indicated a PersistentEntity having been added to it took place before the write lock over the entities had been released. We now keep the lock smaller and publish the addition event *after* the lock has been released.
2017-10-10 16:10:41 +02:00
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
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
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
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
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
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
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
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
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
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
5e4cac308e DATACMNS-1120 - Introduced caching of PropertyPath instances. 2017-07-20 13:38:43 +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
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
Christoph Strobl
f6a6565638 DATACMNS-1101 - Remove getPersistentProperties/Associations from PersistentEntity.
Remove lately introduced getPersistentProperties / getAssociations and rather extend Iterable<? extends PersistentProperty<P>>
2017-07-04 14:30:45 +02:00
Christoph Strobl
88ac1fc165 DATACMNS-1101 - Polishing.
Move MappingException from o.s.d.mapping.model to o.s.d.mapping package and use it for getRequired* methods in MappingContext instead of throwing IllegalArgumentException. Further on we’ve consolidated usage of IllegalArgumentException and IllegalStateException. Along that IllegalMappingException was removed in favor or MappingException.

BasicPersistentEntity now looks up all properties by annotation instead of just returning the first one found. We’ve kept the original methods behavior and updated the comment as well as introduced getPersistentProperties returning all matching properties.
2017-07-04 14:30:45 +02:00
Oliver Gierke
f78793ceeb DATACMNS-1101 - User method invocation over reference to avoid compiler error in Eclipse. 2017-07-04 14:30:45 +02:00
Mark Paluch
4a04251a81 DATACMNS-1101 - Reinstantiate assertions using Supplier. 2017-07-04 14:30:44 +02:00
Mark Paluch
5015b34a58 DATACMNS-1101 - Add caching for annotation-based property lookup. 2017-07-04 14:30:44 +02:00
Mark Paluch
0493d131e0 DATACMNS-1101 - Remove Optional from TypeDiscoverer API. 2017-07-04 14:30:44 +02:00
Mark Paluch
2064c72a85 DATACMNS-1101 - Remove Optional from PersistentProperty.getComponentType(…)/getMapValueType(…). 2017-07-04 14:30:44 +02:00
Mark Paluch
eb9854f18f DATACMNS-1101 - Cache positive and negative simple type hits. 2017-07-04 14:30:44 +02:00
Oliver Gierke
0e86470e36 DATACMNS-1101 - Remove Alias.ofOptional(…).
Refactored type alias detection invocation in BasicPersistentEntity into separate method and avoid the factory method Alias.ofOptional(…) so that it can be removed.
2017-07-04 14:30:44 +02:00
Mark Paluch
8c499122c7 DATACMNS-1101 - Alias is no longer based on Optional.
Remove internal Optional usage from Alias so it's a pure value object that does not create Optional instances during its usage.
2017-07-04 14:30:43 +02:00
Mark Paluch
78e8327d2d DATACMNS-1101 - Replace Stream usage in SimpleTypeHolder with loops.
Use loops to prevent Stream allocation in isSimpleType(…). Use WeakHashMap for type caching for improved contains(…) performance and GC behavior.
2017-07-04 14:30:43 +02:00
Mark Paluch
773fb80263 DATACMNS-1101 - Apply caching to frequently used flags in AnnotationBasedPersistentProperty. 2017-07-04 14:30:43 +02:00
Mark Paluch
17b82cfe37 DATACMNS-1101 - Use construction object array pooling.
Use a thread-local object pool for constructor arguments to reduce object allocations.
2017-07-04 14:30:43 +02:00
Mark Paluch
6495a50df7 DATACMNS-1101 - Replace ArrayList indirections in ReflectionEntityInstantiator/PreferredConstructor.
Iterate over simple ArrayList and construct array of params instead of copying elements between multiple Lists.
2017-07-04 14:30:43 +02:00
Mark Paluch
ce9aae49c8 DATACMNS-1101 - Use non-capturing lambdas in CustomConversions for conversion lookup. 2017-07-04 14:30:43 +02:00
Oliver Gierke
38d9b08132 DATACMNS-1101 - Ternary value assignment in AnnotationBasedPersistentProperty. 2017-07-04 14:30:43 +02:00
Mark Paluch
a15b25c9ef DATACMNS-1101 - Cache Value annotation value eagerly. 2017-07-04 14:30:42 +02:00
Mark Paluch
6c65c02e78 DATACMNS-1101 - Remove Optional from mapping/convert use except for caching of absence and computations that are used to populate caches. 2017-07-04 14:30:42 +02:00
Mark Paluch
74fbe13f54 DATACMNS-1101 - Reduce Optional usage in convert/mapping packages.
Reducing Optional usage that lies on hot code paths for object mapping.
2017-07-04 14:30:42 +02:00