Commit Graph

137 Commits

Author SHA1 Message Date
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
Mark Paluch
4aa083377b DATACMNS-1101 - Iterate with BasicPersistentEntity.doWithProperties(…) over precomputed properties. 2017-07-04 14:30:42 +02:00
Roman Rodov
cabfa287cb DATACMNS-1082 - Skip synthetic constructors.
Constructor discovery no longer considers synthetic constructors for preferred constructor.

Original pull request: #225
2017-06-07 08:45:28 +02:00
Mark Paluch
11c1ad8025 DATACMNS-1079 - Polishing.
Remove javadoc params without documentation. Reorder methods in the order they are called. Rename arePropertyHashCodesUnique to hasUniquePropertyHashCodes. Add author tag. Formatting.

Original pull request: #224.
2017-06-02 16:55:00 +02:00
Jens Schauder
497dc08a7c DATACMNS-1079 - Polishing.
Refactored all the checks done to check if ClassGeneratingPropertyAccessorFactory works into separate methods, so the body of isSupported becomes nice and readable.

Original pull request: #224.
2017-06-02 16:53:10 +02:00
Jens Schauder
59f52a9e35 DATACMNS-1079 - Disable generated property accessors if ClassLoader is encapsulated.
ClassGeneratingPropertyAccessorFactory does not work with Java 9 (encapsulated modules, without --permit-illegal-access), because making ClassLoader.defineClass accessible fails.

Therefore this change moves call to setAccessible to the check that ensures availability of the method so isSupported(…) returns false.

Original pull request: #224.
2017-06-02 16:52:59 +02:00
Oliver Gierke
5dba2f4c59 DATACMNS-1066 - Polishing.
Formatting and removal of obsolete methods.
2017-05-16 19:11:38 +02:00
Oliver Gierke
5f9d90ee3e DATACMNS-1066 - ClassGeneratingPropertyAccessorFactory now opts out on failed access to ClassLoader.
We now eagerly check the accessibility of the defineClass(…) method on the class loader to be used for a PersistentEntity. This will then cause the clients to use a different PropertyAccessorFactory (as things stand today: the one using reflection) and not fail to create the class later on.
2017-05-16 19:11:12 +02:00
Oliver Gierke
233fde36b5 DATACMNS-1035 - Moved CustomConversions to Spring Data Commons.
Extracted CustomConversions — whose code has largely been duplicated between the MongoDB, Couchbase and Cassandra modules — into Spring Data Commons. Store-specific extensions can now be contributed via a StoreConversions value type that carries both, store-specific default converters as well as a store-specific SimpleTypeHolder to augment the default list of simple types.

Removed SimpleTypeHolders public default constructor in favour of a protected one and a static DEFAULT instance for plain references.

Original pull request: #210.
2017-04-21 16:49:00 +02:00
Oliver Gierke
6b5b65804e DATACMNS-1015 - Introduced IdentifierAccessor.getRequiredIdentifier().
The new method allows to look up identifiers and immediately fail in the case of absence. Introduced the method as default method but also a new base type TargetAwareIdentifierAccessor to throw an exception with more context, i.e. the actual target bean we try to look up the identifier on.
2017-03-24 11:57:57 +01:00
Oliver Gierke
5f117a00a3 DATACMNS-867 - Polishing of Property value type in mapping package. 2017-03-24 08:00:48 +01:00
Oliver Gierke
7ac12c3c3d DATACMNS-867 - BasicPersistentEntity now rejects null Association.
Related ticket: DATACMNS-934.
2017-03-24 08:00:47 +01:00
Oliver Gierke
7c33bcf98a DATACMNS-867 - Let lookups for a property's component and map value type use Optional. 2017-03-24 08:00:46 +01:00
Oliver Gierke
1c45fcfcdc DATACMNS-867 - Lazify lookups in AbstractPersistentProperty. 2017-03-24 08:00:46 +01:00
Oliver Gierke
082c4157d1 DATACMNS-867 - Less Optional for auditing subsystem.
Removed Optional<Object> parameters in favor of plain Object and clients that avoid calling methods for absent values in the first place.
2017-03-24 08:00:45 +01:00
Oliver Gierke
5f7d1ae2f2 DATACMNS-867 - Overhaul of PersistentEntity API.
Moved getRequired…(…) methods from implementations into interfaces so that implementations inherit them by default.

Expanded generics declaration in PersistentEntities so that PerisistentProperty instances can be properly access from the PersistentEntity instances returned.
2017-03-24 08:00:45 +01:00
Oliver Gierke
c84e6c8427 DATACMNS-867 - More required metadata lookup.
Introduced overloads to lookup required RepositoryInformation and PersistentEntity instances to Repositories and PersistentEntities.
2017-03-24 08:00:44 +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
aa4c51e1ea DATACMNS-867 - Cache constructors in ClassGeneratingPropertyAccesssorFactory.
Fix hotspot in constructor lookup - in particular the propertyAccessorClass.getConstructors() call.
Additionally fix another minor issue in assertion message creation.
2017-03-24 08:00:43 +01:00