Commit Graph

1229 Commits

Author SHA1 Message Date
Oliver Gierke
14c2b5b766 DATACMNS-1375 - AnnotationRepositoryMetadata now exposes the offending repository name. 2018-08-16 14:06:01 +02:00
Oliver Gierke
22a6870d5c DATACMNS-1367 - Improved repository bootstrap logging.
Core information about the bootstrap mode, timing and number of repositories created is now logged in info. Individual repository registration is logged in trace now.

Related tickets: DATACMNS-1368.
2018-08-16 14:03:47 +02:00
Oliver Gierke
5da6cf20a2 DATACMNS-1368 - Add support for deferred repository initialization.
Both the XML and annotation based configuration sources now support a bootstrap mode configuration property that allow to configure whether repositories are eagerly initialized unless declared as lazy, initialized in a deferred way (just before the application context finishs bootstrapping) or entirely lazy (upon first usage, i.e. a method invocation).

We now register a custom AutowireCandidateResolver that will consider all injection points of lazy repositories lazy too. This will prevent them to accidentally trigger downstream infrastructure initialization.
2018-08-16 12:16:40 +02:00
Oliver Gierke
60bbc59054 DATACMNS-1366 - Performance improvements in CustomConversions.
Removed Optional wrapping for ConcurrentHashMap values in favor of using Void.class as null object. Avoid use streams and removed (repeated) non-null assertions in private methods. Benchmark numbers for calling ….hasCustomReadTarget(…) when non actually exists showing a 5 to 10% increase in performance:

Before:

Iteration   1: 41433276.537 ops/s
Iteration   2: 43991315.457 ops/s
Iteration   3: 45322063.260 ops/s
Iteration   4: 44906183.709 ops/s
Iteration   5: 45378084.579 ops/s
Iteration   6: 44912727.364 ops/s
Iteration   7: 45588155.896 ops/s
Iteration   8: 45453353.185 ops/s
Iteration   9: 45558273.633 ops/s
Iteration  10: 45473310.099 ops/s

After:

Iteration   1: 48979746.822 ops/s
Iteration   2: 48438497.338 ops/s
Iteration   3: 48627686.004 ops/s
Iteration   4: 48815459.842 ops/s
Iteration   5: 48004993.191 ops/s
Iteration   6: 48566871.366 ops/s
Iteration   7: 48604435.350 ops/s
Iteration   8: 47543377.257 ops/s
Iteration   9: 48250165.369 ops/s
Iteration  10: 47845463.861 ops/s
2018-08-16 08:58:07 +02:00
Mark Paluch
4600190d01 DATACMNS-1366 - Performance improvements in mapping subsystem
We now use a presized HashMap and Weak references in BasicPersistentEntity to improve memory and CPU profile and and avoid unmodifiable collection creation in BasicPersistentEntity.iterator(). Refactored ClassTypeInformation.from(…) lambda to method reference and predefined collection size for the cache. Reduced object instantiations during TypeDiscoverer.equals(…) by checking for type variable map emptiness to avoid Map iterator creation in Map.equals(…).

Original pull request: #305.
2018-08-15 15:13:41 +02:00
Mark Paluch
e50e013964 DATACMNS-1364 - Polishing.
Use weak references in annotation and property annotation cache to retain references until the last GC root is cleared. Remove trailing whitespaces. Reformat.

Original pull request: #304.
2018-08-15 09:51:17 +02:00
Mark Paluch
7d3222320c DATACMNS-1364 - Store persistent properties in HashMap.
We now use HashMap to store persistent properties of a PersistentEntity. An entity is built in a single thread so no concurrent modification happens. Concurrent reads may happen during entity usage which is fine as the PersistentEntity is not changed anymore. Previously, we used ConcurrentReferenceHashMap defaulting to soft references. Soft references can be cleared at the discretion of the GC in response to memory demand. So a default ConcurrentReferenceHashMap is memory-sensitive and acts like a cache with memory-based eviction rules.

Persistent properties are not subject to be cached but elements of a PersistentEntity and cannot be recovered once cleared.

Original pull request: #304.
2018-08-15 09:50:48 +02:00
Oliver Gierke
13b115068d DATACMNS-1371 - Improvements to custom implementation scanning.
CustomRepositoryImplementationDetector now works in two differend modes. If initialized with an ImplementationDetectionConfiguration, it will trigger a canonical, cached component scan for implementation types matching the configured name pattern. Individual custom implementation lookups will then select from this initially scanned set of bean definitions to pick the matching implementation class and potentially resolve ambiguities.
2018-08-14 15:25:30 +02:00
Oliver Gierke
3f613ff13f DATACMNS-1370 - Avoid superflous, regex-based type check while scanning for custom implementations. 2018-08-09 13:05:44 +02:00
Oliver Gierke
084b46036a DATACMNS-1369 - RepositoryFactoryBeanSupport now adds the aggregate root type to the MappingContext.
We now eagerly look up the aggregate root type of a repository in the MappingContext. Some implementations might not have pre-populated the context with all entities and we need to make sure it knows about the aggregate root as other clients (e.g. the auditing subsystem) might only defensively access the entities via PersistentEntities which is not adding new entities to avoid store clashes.
2018-08-09 12:09:54 +02:00
Oliver Gierke
1984fbdb56 DATACMNS-1367 - Improved debug logging to better identify scanning and initialization of repositories.
Added debug logging in RepositoryFactorySupport and RepositoryConfigurationDelegate so that the scanning and the instantiation of repositories can be a lot easier identified in the logs.
2018-08-09 08:14:11 +02:00
Oliver Gierke
f72b446361 DATACMNS-1366 - Polishing. 2018-08-08 13:16:06 +02:00
Oliver Gierke
14fbc11f00 DATACMNS-1366 - Introduce PersistentEntity.requiresPropertyPopulation().
The newly introduced method indicates whether any properties have to be populated to create instances of the entity. This is useful for objects that are completely initialized through their constructors as converters then can avoid iterating over all properties just to find out none of them have to be populated.
2018-08-08 13:16:05 +02:00
Oliver Gierke
57d0b322e6 DATACMNS-1359 - Improved exception message for missing accessors and getters.
The exception messages used in the PersistentProperty.getRequired(Getter|Setter|Wither|Field)(…) now mention the name of the property that's offending.
2018-08-06 12:45:43 +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
Oliver Gierke
31a08254a7 DATACMNS-1354 - BasicPersistentEntity now exposes means to override the fallback IsNewStrategy.
This is useful in case a particular store implementation needs to customize the default is new detection.
2018-07-12 12:18:29 +02:00
Oliver Gierke
3c2522df9a DATACMNS-1322 - Added @Immutable to allow users to express a persistent entity to be considered immutable.
This is needed for downstream projects that attempt to merge persistent entity instances and previously didn't have a chance to detect that an object had to be set as-is instead of being merged recursively.
2018-07-12 10:26:16 +02:00
Oliver Gierke
1f4d494f83 DATACMNS-1322 - Generified PersistentPropertyAccessor API.
PersistentPropertyAccessor is now generic to be able to retain the type information about the object it was created for and the return type of ….getBean(). Adapted client APIs.
2018-07-12 10:23:17 +02:00
Oliver Gierke
d1ebfcfc5e DATACMNS-1322 - Add support for immutable entities in PersistentPropertyAccessor.setProperty(PersistentPropertyPath, Object).
As setting a PersistentProperty can actually change the object that the property is changed on, we now recursively traverse property paths up as longs as the setting of the property results in the bean not being replaced.
2018-07-04 16:59:51 +02:00
Oliver Gierke
6cb3587ba3 DATACMNS-1322 - Adapt auditing handler API to support immutable entities.
We've changed the APIs in the auditing subsystem so that we support immutable entities, mostly through MappingAuditableBeanWrapperFactory that uses a PersistentPropertyAccessor.
2018-07-04 16:59:51 +02:00
Mark Paluch
85b507ce10 DATACMNS-1322 - Cleanup refactorings.
Add missing since tags. Extract methods to maintain single abstraction level per method. Move visitDefaultValue from ClassGeneratingPropertyAccessorFactory to BytecodeUtil. Extend Javadoc.
2018-07-04 16:59:51 +02:00
Mark Paluch
79119000bb DATACMNS-1322 - Add support for Kotlin's copy(…) method.
We now support updating of immutable Kotlin data objects by creating new copies through Kotlin's copy method that is generated along with data classes and immutable properties.

data class DataClassKt(val id: String) {
}

data class ExtendedDataClassKt(val id: String, val name: String) {
}
2018-07-04 16:59:51 +02:00
Mark Paluch
80db17d6ba DATACMNS-1322 - Polishing.
Extract utility methods to BytecodeUtil.
2018-07-04 16:59:51 +02:00
Mark Paluch
1ea65f3130 DATACMNS-1322 - Detect wither methods.
We now detect withher methods (withId(…)) that create a new object instance that contains the new property value. We support those wither methods to create new object instances from property updates. Classes following a wither pattern declare a withXXX(…) method that accepts the property value and return a new, instance of its own type associated with the property value. Along with this change we removed the ability to update final fields that worked by accident using reflection.

class ValueClass {
	@Wither String id;
}

class ValueClass {
	final String id;

	ValueClass withId(String id) {
		return new ValueClass(id);
	}
}
2018-07-04 16:59:51 +02:00
Oliver Gierke
6951d8b711 DATACMNS-1345 - RepositoryFactoryBeanSupport now properly reports missing MappingContext. 2018-06-21 08:55:45 +02:00
Oliver Gierke
d570f4d79e DATACMNS-1342 - TypeInformation.isCollectionLike() considers Streamable now. 2018-06-14 12:18:41 +02:00
Oliver Gierke
37ab0a5d8f DATACMNS-1341 - ProxyUtils now detects JDK proxy target classes. 2018-06-14 11:51:15 +02:00
Mark Paluch
53560e0979 DATACMNS-1338 - Calculate defaulting mask count in Kotlin default constructor resolution.
We now calculate the number of expected default masks to filter synthetic constructors that do not match the expected parameter count. A Kotlin constructor with argument defaulting generates a synthetic integer argument for every 32 constructor arguments. This is independent of the number of actual optional arguments.

Previously, we used an non-exact check to consider constructors as default ones if they had at least two additional arguments. This caused the wrong constructor being used if the non-synthetic types matched the types of the default constructor.
2018-06-10 17:22:17 +02:00
Oliver Gierke
0341f60c7c DATACMNS-1336 - Avoid warning logs for JodaTime and ThreeTenBP converter registrations.
Removed the explicit registration for JodaTime and ThreeTenBP to JSR-310 converters (originally introduced to support the unifying lookup of the last modified date in the auditing subsystem) as reading converters. This avoids the warning reporting that the source types (JodaTime and ThreeTenBP LocalDateTime) not being store-native types (which usually indicates a superfluous converter registration).

Updated the test cases to make sure these warnings aren't trigger due to test setups causing the same issue.
2018-06-06 14:05:06 +02:00
Oliver Gierke
5f87c67668 DATACMNS-1304 - Polishing.
Moved test cases into PropertyPathUnit test so that they're closer to the implementation. Switched to Introspector.decapitalize(…) to follow the Java Beans Specification regarding the handling of all-uppercase properties.

Original pull request: #289.
2018-06-05 18:34:12 +02:00
Mariusz Mączkowski
1da969db0a DATACMNS-1304 - PropertyPath now supports properties with all uppercase endings.
Original pull request: #289.
2018-06-05 17:29:21 +02:00
Oliver Gierke
fc2135df3d DATACMNS-1333 - Unified is-new-detection in PersistentEntity.isNew(…).
PersistentEntity now exposes an ….isNew(…) method that exposes the same detection algorithm previously exposed through MappingContextIsNewStrategyFactory (Persistable in favor of the version property in favor of an identifier lookup). MappingContextIsNewStrategyFactory  has been refactored to return an ad-hoc strategy to delegate to the newly introduced method.

The core message to implementing modules is that they should now prefer PersistentEntityInformation within their RepositoryFactorySupport implementation and move all customizations made in the store-specific EntityInformation implementation in PersistentEntity.
2018-06-01 13:50:28 +02:00
Alex Bondarev
b7da49f97a DATACMNS-1327 - Prevent int overflow in AbstractPageRequest#getOffset().
Original pull request: #291.
2018-06-01 13:50:24 +02:00
Oliver Gierke
96c5ff87ef DATACMNS-1328 - DefaultRepositoryInvokerFactory now uses a ConcurrentHashMap.
We now use ConcurrentHashMap to prevent ConcurrentModificationExceptions in multithreaded access to repository invokers.
2018-05-31 10:26:32 +02:00
Oliver Gierke
0f9e88fcaf DATACMNS-983 - Added support for Javaslang and Vavr Try as method return types.
We now support the use of Vavr's Try as repository method return type so that exceptions caused by the repository method execution are wrapped into a Failure. Introduced a return type specific indirection of the execution. We now also recursively handle wrapper types so that Try<Option<…>> is valid, too.

Added support for Javaslang's Try, too.
2018-05-30 22:51:11 +02:00
Oliver Gierke
7ab2c84ea8 DATACMNS-1318 - Polishing.
Moved to newly introduced varargs-based factory method for PersistentEntities where applicable.
2018-05-30 21:39:56 +02:00
Oliver Gierke
61e489b67e DATACMNS-1318 - Allow inspection of a reference's ultimate target entity.
We now expose what type or PersistentEntity an association points to by trying to match the association's type to identifier types to entities. In case multiple matches are found, we require the user to explicitly declare the target type via @Reference.

Introduced PersistentEntities.of(…) for convenience.
2018-05-30 21:39:54 +02:00
Oliver Gierke
7d8539d83c DATACMNS-1326 - PersistentPropertyInspectingIsNewStrategy now considers primitive type's defaults.
PersistentPropertyInspectingIsNewStrategy now considers entities with primitive default identifier values new.
2018-05-18 23:46:48 +02:00
Oliver Gierke
865163d466 DATACMNS-1325 - Added dedicated identifier accessor for Persistable entities.
BasicPersistentEntity now returns a dedicated IdentifierAccessor that uses Persistable.getId() in case the entity implements Persistable.
2018-05-18 23:46:48 +02:00
Oliver Gierke
d73e0a1f8f DATACMNS-1324 - Introduced extensible proxy detection infrastructure.
Introduced ProxyUtils.getUserClass(…) that by default is basically a facade for Spring's ClassUtils.getUserClass(…) but allows the registration of ProxyDetector implementations via Spring's SpringFactoriesLoader mechanism.

Moved all existing usages of ClassUtils.getUserClass(…) to ProxyUtils.
2018-05-17 16:20:11 +02:00
Oliver Gierke
495b1f30bb DATACMNS-1258 - Polishing.
Moved newly introduced types into the ….data.repository.query package as the parser one contains types that parses queries from method names. Simplified the API surface by hiding SpelExtractor completely and making the API on SpelQueryContext more convenient to directly create a SpelEvaluator.
2018-05-15 18:11:41 +02:00
Jens Schauder
1fdf77aed7 DATACMNS-1258 - Added infrastructure for SpEL handling in queries.
The goal is to extract the parts of query parsing that are generic into commons in order to avoid slightly different behavior in modules. 

Extracted the QuotationMap from Spring Data JPA as well as the part of the parser that deals with extracting SpEL expressions.
Added the SpelEvaluator for evaluating the SpEL expressions.

Added enough configurability to satisfy the needs of Neo4j and JPA.
Mainly to support the different formats for bind parameter :name vs {name}.
2018-05-15 16:16:28 +02:00
Oliver Gierke
a6215fbe0f DATACMNS-1260 - Extract EvaluationContextProvider and corresponding SPIs into dedicated package.
We now have a refined replica of the EvaluationContextProvider API and SPIs in the org.springframework.data.spel package. It has seen a bit of a Java 8 overhaul by removing the SPI support class in favor of turning most methods in EvaluationContextExtension into default ones.

The already existing API has been renamed to QueryMethodEvaluationContextProvider to indicate it's working with additional semantics specific to query methods (i.e. the Parameters metadata). The internals have been refactored to use the new API but still detect implementations of the old EvaluationContextExtension interface. The implementations get wrapped into an adapting proxy to satisfy the new API so that the actual inspection and usage of the extension is now already done using the new APIs.

The repository configuration has slightly change so that the creation of the EvaluationContextProvider is now taking place within RepositoryFactoryBeanSupport's implementation of BeanFactoryAware.

AbstractMappingContext is now ApplicationContextAware and holds an ExtensionAwareEvaluationContextProvider using the configured ApplicationContext. That EvaluationContextProvider is forwarded to all MutablePersistentEntity instances. BasicPersistentEntity now exposes getEvaluationContext(…) to subclasses to easily create an EvaluationContext using the extension aware infrastructure.

Removed DefaultEvaluationContextProvider in favor of a simple constant in QueryMethodEvaluationContextProvider.

Related tickets: DATACMNS-1258, DATACMNS-1108.
2018-05-14 16:50:04 +02:00
Oliver Gierke
b8974a292a DATACMNS-1292 - Improved default setup of XMLBeam.
We now explicitly disable entity expansion in the DocumentBuilderFactory used by XMLBeam.

Introduced constructor in XmlBeamHttpMessageConverter to allow dedicated configuration of an XBProjector instance in case the defaults need tweaking and augmented the web configuration setup to automatically pick up a custom XmlBeamHttpMessageConverter bean instead of our own default if present.
2018-05-08 09:52:35 +02:00
Mark Paluch
4a7bb4853b DATACMNS-1294 - Enforce JSR-310 type mapping to java.util.Date.
After considering JSR-310 types to be simple we map these types primarily to java.util.Date as the majority of stores does not natively support JSR-310 types. Converters referencing JSR-310 types are now properly annotated with Reading/WritingConverter annotations to distinguish between reading and writing intents.

Othwerise, converters between JSR-310/java.util types and Joda/ThreeTenBackport to JSR-310 types interfere with conversion as regular java.util.Date types would convert to e.g. LocalDateTime.
2018-04-19 09:56:14 +02:00
Mark Paluch
2d24acf9de DATACMNS-1294 - Consider java.time types simple ones.
We now consider all types in the java.time package as simple types to prevent deep reflective access. We are already excluding java.lang types for the same reason.

Original pull request: #286.
2018-04-18 18:53:59 +02:00
Mark Paluch
d85e9e117e DATACMNS-1299 - Polishing.
Consider GeoResults as native wrapper to properly unwrap its component type.
2018-04-17 09:58:41 +02:00
Oliver Gierke
3676ae0c87 DATACMNS-1300 - Improved collection query detection for Iterables.
Previously a custom Iterable implementation would've caused QueryMethod.isCollectionQuery() to return true. We now solely rely on TypeInformation.isCollectionLike() (which checks for exact Iterable, Collection assignability and arrays) after handling potential wrapper types.
2018-04-16 16:19:58 +02:00
Oliver Gierke
5986b4b7af DATACMNS-1299 - QueryExecutionsConverters now don't unwrap custom Iterable implementations.
Instead of a simple check for assignability from Iterable, we now properly use TypeInformation.isCollectionLike(), which checks for Iterable equality or assignability of collections or arrays as well as an explicit check for Slice as that is needed to properly unwrap Page instances and Slices themselves. That prevents custom domain types implementing Iterable from being unwrapped into their element types.
2018-04-16 16:11:01 +02:00
Mark Paluch
666447a4c8 DATACMNS-1293 - Polishing.
Fix leftovers pointing to legacy Querydsl packages in Javadoc. Reformat code.

Original pull request: #284.
2018-04-12 14:34:24 +02:00