Commit Graph

201 Commits

Author SHA1 Message Date
Oliver Drotbohm
ced3dde2a4 DATACMNS-1609, DATACMNS-1438 - Skip collection path segments for auditing properties.
We now skip PersistentPropertyPath instances pointing to auditing properties for which the path contains a collection or map path segment as the PersistentPropertyAccessor currently cannot handle those. A more extensive fix for that will be put in place for Moore but requires more extensive API changes which we don't want to ship in a Lovelace maintenance release.

Related tickets: DATACMNS-1461.
2019-11-11 10:45:18 +01:00
Oliver Drotbohm
9e4d490137 DATACMNS-1602 - Avoid attempts to recreate the same property accessor class.
PropertyAccessorClassGenerator now tries to look up the class to be generated first to potentially reuse an already existing one and avoid the recreation and registration of a same class which would trigger a Linkage error as a classloader cannot hold two classes with the same name.

The root of the problem is in the fact that the accessor instances are held in per instance caches in EntityInstantiators, so that multiple of those might try to create the same accessor class for a given domain type.
2019-10-30 15:04:12 +01:00
Oliver Drotbohm
c42f5efe01 DATACMNS-1547 - Properly remove partially populated PersistentEntity instances from cache.
We now remove partially populated PersistentEntity instances from the cache held in AbstractMappingContext as the creation could fail for other RuntimeExceptions other than a MappingException and we wouldn't want to keep the instances around in any case.

Slight refactorings in the unit tests so that we can easily create MappingContext instances that reject certain types with certain exceptions.
2019-08-30 12:11:55 +02:00
Oliver Drotbohm
e0f2d65d73 DATACMNS-1555 - Support for extracting properties during a PersistentPropertyPath traversal.
PersistentPropertyAccessor now has an overloaded method to pass in a TraversalContext that can be prepared to property handlers for PersistentProperties. During the traversal, the handler is called with the value for the property so that it can e.g. extract list elements, map values etc.
2019-07-22 10:56:07 +02:00
Mark Paluch
687222d1fa DATACMNS-1467 - Polishing.
Tweak docs.

Original Pull Request: #332
2019-06-07 14:30:00 +02:00
Christoph Strobl
dde9a651ba DATACMNS-1467 - Decouple sync and reactive bits.
Add dedicated interfaces for sync and reactive usage.
Hide default implementation and use reflective callback method lookup.
Update documentation and add initial reference documentation snippet for store specific modules.

Original Pull Request: #332
2019-06-07 14:29:00 +02:00
Mark Paluch
52724cd5dd DATACMNS-1467 - Entity Callback API draft.
This is a draft for a possible Entity Callback API heavily inspired by Spring Framework's Application Event listeners. Entity callbacks are callbacks for entities that allow for entity modification at certain check points such as before saving an entity or after loading it.

Entity callbacks consist of a marker-interface for all entity callback types and the EntityCallbacks API to dispatch callbacks.

Entity callbacks are picked up from the ApplicationContext and invoked sequentially according to their ordering.

Usage example:

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);

SimpleEntityCallbacks callbacks = new SimpleEntityCallbacks(ctx);

PersonDocument personDocument = new PersonDocument(null, "Walter", null);
PersonDocument afterCallback = callbacks.callback(personDocument, BeforeSaveCallback.class,
		BeforeSaveCallback::onBeforeSave);

Mono<PersonDocument> afterCallback = callbacks.callbackLater(personDocument, ReactiveBeforeSaveCallback.class,
		ReactiveBeforeSaveCallback::onBeforeSave);

@Configuration
static class MyConfig {

	@Bean
	BeforeSaveCallback<Person> personCallback() {
		return object -> {
			object.setSsn(object.getFirstName().length());
			return object;
		};
	}

	@Bean
	MyReactiveBeforeSaveCallback callback() {
		return new MyReactiveBeforeSaveCallback();
	}

}

class MyReactiveBeforeSaveCallback implements ReactiveBeforeSaveCallback<Person> {

	@Override
	public Mono<Person> onBeforeSave(Person object) {

		PersonDocument result = new PersonDocument(object.getFirstName().length(), object.getFirstName(),
				object.getLastName());

		return Mono.just(result);
	}
}

Original Pull Request: #332
2019-06-07 14:26:38 +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
Oliver Drotbohm
0bf160eb97 DATACMNS-1496 - Removed deprecations at least introduced in Lovelace. 2019-03-13 18:29:08 +01:00
Mark Paluch
aa39b9ba3a DATACMNS-1451 - Consider more than 16 immutable Kotlin properties in generated PropertyAccessor.
We now consider more than 16 immutable and nullable Kotlin properties per bucket in generated PropertyAccessors.

Previously only the first 16 properties were considered due to truncation of the defaulting bitmap. We used SIPUSH to render the defaulting mask in bytecode which is intended for 16 bit integers (short). Migrating to LDC (runtime constants) preserves the actual constant value of 32 bits and so we're considering now full buckets.
2019-02-13 12:01:22 +01:00
Oliver Drotbohm
fe1ccd50be DATACMNS-1466 - Polishing. 2019-01-11 11:48:26 +01:00
Oliver Drotbohm
e0c08e64e8 DATACMNS-1466 - Fixed potential ArrayIndexOutOfBoundsException in DefaultPersistentPropertyPath.
Introduced explicit content checks in ….getLeafProperty() and ….getBaseProperty().
2019-01-11 11:48:23 +01:00
Mark Paluch
1969f4bcdc DATACMNS-1459 - Update copyright years to 2019. 2019-01-02 12:12:19 +01:00
Mark Paluch
596b0d8177 DATACMNS-1422 - Fall back to reflection-based PropertyAccessor/EntityInstantiator on inaccessible framework types.
We now fall back to reflection-based PropertyAccessor/EntityInstantiator strategies when framework types are not visible by the entity's ClassLoader.

Typically, we use class generation to create and load PropertyAccessor and EntityInstantiator classes to bypass reflection. Generated types are injected into the ClassLoader that has loaded the actual entity. Generated classes implement framework types such as ObjectInstantiator and these interfaces must be visible to the ClassLoader that hosts the generated class. Some arrangements, such as OSGi isolate class repositories so the OSGi class loader cannot load our own types which prevents loading the generated class.

Original pull request: #324.
2018-11-23 15:19:54 +01:00
Oliver Drotbohm
9791bb9354 DATACMNS-1421 - Polishing.
Extracted method filter into dedicated method. Changed method order according to conventions.

Original pull request: #323.
2018-11-19 19:46:03 +01:00
Mark Paluch
5bbb458dc5 DATACMNS-1421 - Lookup most specific wither method for a property.
We now inspect all methods that match the wither method pattern (name, accepting a single argument) to find the most specific method returning the actual entity type.

Previously, we attempted to find a method only considering name and argument properties and not the return type. This lookup strategy could find a method returning the entity super type that isn't assignable to the entity type.

Original pull request: #323.
2018-11-19 19:46:03 +01:00
Mark Paluch
2c6831948f DATACMNS-1401 - Provide context class on runtime class definition.
We now provide the context class for private MethodHandle lookup in the context of the actual entity class to properly use MethodHandles.defineClass(…) and to avoid illegal access warnings caused by reflective access to the defineClass(…) method on class loaders.

Also, we now use the internal type name without adding the reference type decorator when casting the result of a wither invocation. CHECKCAST allowed on earlier Java runtimes (version 8 and earlier) to use the reference decorator (L…;) around the type name. Java 9 and newer reject this format with a ClassFormatError.

Original pull request: #318.
2018-10-08 13:53:18 +02:00
Mark Paluch
fc4b2d1deb DATACMNS-1402 - Fix invocation of default Kotlin constructor.
We now correctly calculate the number of defaulting masks used to represent constructor arguments. Previously, we've been one off which caused that Kotlin classes with 32/33 parameters weren't able to be instantiated.

We also now reuse KotlinDefaultMask to apply defaulting calculation and removed code duplicates.
2018-10-04 14:38:28 +02:00
Mark Paluch
42ee9448d9 DATACMNS-1400 - Do not consider bridge modifier in Kotlin default-method discovery.
We now no longer consider bridge modifiers when looking up Kotlin default methods. We previously included checks whether a synthetic default method is also a bridge method to take all specifics of synthetic methods into account. With Kotlin 1.3, the compiler no longer sets the bridge flag. This behavior change would previously prevent usage of the copy method with classes compiled with Kotlin 1.3.

Default method discovery is still guesswork and Kotlin compiler reverse engineering as there is no documentation on how to look up this kind of methods.

Further references:
* https://youtrack.jetbrains.net/issue/KT-24415 - Remove bridge flag from default methods.
* https://youtrack.jetbrains.net/issue/KT-27317 - No documented rules for discoverability of generated methods.
2018-10-04 10:59:23 +02:00
Mark Paluch
7eacab6a34 DATACMNS-1391 - Use prefered constructors to discover Kotlin's copy method.
We now use the primary constructor of Kotlin classes to discover the copy method. We use the primary constructor args to compare signatures and only use the copy method that takes all parameters in the constructor args order. This allows to find the appropriate copy method in case the class declares multiple copy methods.

We now also cache the copy method (KCallable) to reduce lookups in BeanWrapper.

Original pull request: #312.
2018-09-18 18:34:57 +02:00
Oliver Gierke
b0eb0c47d2 DATACMNS-1377 - ConvertingPropertyAccessor now properly coverts values for property paths.
Previously, ConvertingPropertyAccessor did not override PersistentPropertyAccessor.setProperty(PersistentPropertyPath, Object), so that the target value had to be of the leaf property's type. We now implement that method and convert it into that type before invoking the super method.
2018-08-17 11:47:31 +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
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
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
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
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
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
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
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
Oliver Gierke
ac324b22a5 DATACMNS-1275 - Introduced MappingContext.findPersistentPropertyPaths(Class<?>, Predicate<P>).
MappingContext now exposes a method to detect all property paths pointing to properties matching a given predicate.

Extracted PersistentPropertyPath creation into a dedicated factory class so that it can be tested individually. DefaultPersistentPropertyPath now exposes a ….containsPropertyOfType(…) to detect whether we've already processed a particular type in the path. Also applied a bit of Java 8 and Lombok polish.

InvalidPersistentPropertyPath now collects suggested alternatives to create a better exception message. PersistentEntities now allows to map over a MappingContext and PersistentEntity that a given type is corresponding to. Streamable now exposes an ….isEmpty(). Removed references to equivalent methods implemented in subtypes.
2018-04-09 14:31:20 +02:00
Oliver Gierke
06b0dab536 DATACMNS-1285 - PropertyPath now limits the depth of its parsing to 1000 segments. 2018-04-03 19:27:16 +02:00
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