Commit Graph

256 Commits

Author SHA1 Message Date
Mark Paluch
40222d6d8c Polishing.
Skip shadowed properties that are not assignable to their shadowing type.

Extend tests. Document property overrides.

Original pull request: #390.
See #1911.
2021-04-21 09:29:37 +02:00
Christoph Strobl
85578b5cb1 Ignore override properties when creating PersistentEntity.
Original pull request: #390.
Closes #1911.
2021-04-21 09:29:37 +02:00
Oliver Drotbohm
c643d2d90f AbstractPersistentProperty now considers association target type for ….getPersistentEntityTypes().
Prior to this commit, the lookup of types to be added as persistent entities for a given PersistentProperty used the actual property type which did not consider the association target type at all. Removed the usage of Optional for the entity type information and switched to use TypeInformation for the raw association target type so that it can be considered in ….getActualType().
2021-04-07 15:31:43 +02:00
Mark Paluch
8adfe47efa Improve ClassGeneratingEntityInstantiator error message if the to be instantiated type is abstract.
We now throw MappingInstantiationException with a nested BeanInstantiationException in alignment to ReflectionEntityInstantiator when attempting to create a new instance of an abstract class.

Closes #2348.
2021-04-06 14:15:16 +02:00
Oliver Drotbohm
23ebf3164f Support for association target type detection for jMolecules.
We now detect the component type of jMolecules' Association as association target type in AbstractPersistentProperty. AnnotationBasedPersistentProperty keeps the lookup of the explicit @Reference around but falls back to the Association analysis for that.

@Reference is now only considered by AnnotationBasedPersistentProperty. It was previously also (erroneously) considered by AbstractPersistentProperty.

It was also changed to return `null` in case no association target type could be looked up instead of returning the sole property's type in case that is an entity. This was done to satisfy the behavior documented on the interface but also to avoid the call to isEntity() during the calculation which might use association information in turn and thus lead to a stack overflow. Reworded the contract of PersistentProperty.getAssociationTargetType() to emphasize the symmetry with ….isAssociation() in implementation classes.

Closes: #2344.
2021-03-31 15:07:25 +02:00
Mark Paluch
79ed0a75c7 Support @Value meta-annotations and expose MergedAnnotations on PreferredConstructor parameters.
We now support composed annotation that are annotated with `@Value`. we also expose MergedAnnotations through PreferredConstructor.Parameter for further use by store modules that want to inspect constructor argument annotations.

Closes: #2332
Original Pull Request: #2333
2021-03-30 12:06:03 +02:00
Mark Paluch
1eeef23fd9 Fix Kotlin copy method assignability check.
We now resolve only the raw class when checking if a primary constructor argument is assignable to method parameters of the synthetic copy method.
Previously we used ResolvableType's assignability check which considered generic type arguments. As the type resolution between the KType and copy method type is not symmetric, the check only succeeded in cases where both types could be resolved to the same type/assignable type. Using projections or Any caused asymmetric resolution and therefor the assignability check returned non-assignable.

Closes #2336.
2021-03-22 10:06:08 +01:00
Mark Paluch
08cb9e848d Polishing.
Use ResolvableType for type assignability check when resolving Type from a KType.

See #2324.
2021-03-12 16:56:10 +01:00
Mark Paluch
0065c17cca Use primary copy method for Kotlin data classes.
We now resolve the copy method for Kotlin data classes that match the primary constructor. Previously, copy method resolution could find a secondary copy method as we didn't check for the primary constructor structure (parameter names and types).

Closes #2324.
2021-03-12 11:30:10 +01:00
Oliver Drotbohm
d03bfb877a Introduce PersistentEntity.doWithAll(…).
To let a PropertyHandler operate on all properties *and* the inverse property of associations.

Fixes #2325.
2021-03-11 10:38:44 +01:00
Oliver Drotbohm
6b0292cc66 Support for jMolecules' Association type.
We no recognize properties of type org.jmolecules.ddd.types.Association as associations in our PersistentProperty model.

Also, we now register JMolecules Converter implementations for Association and Identifier in CustomConversions so that they can persisted like their embedded primitive value out of the box.

Fixes #2315.
Original pull request: #2316.
2021-03-01 15:20:26 +01:00
Christoph Strobl
67ee745374 Use NativeDetector.inNativeImage() instead of manual property check.
Closes: #2298
Original pull request: #2299.
Relates to: spring-projects/spring-framework#25795
2021-02-17 09:14:02 +01:00
Christoph Strobl
b51bee7a0b Use contextual information when creating PersistentPropertyPaths.
In oder to preserve contextual information the PersistentPropertyPathFactory now obtains EntityInformation for properties from the MappingContext via their PersistentProperty representation instead of plain the TypeInformation as the former contains more information about the actual type and signatures.

Closes #2293.
Original pull request: #2294.
2021-02-16 10:50:16 +01:00
Mark Paluch
ed34f2aef8 Add negative-caching in PreferredConstructor.isConstructorParameter(…).
We now cache the negative outcome of PreferredConstructor.isConstructorParameter(…) to avoid iterations and iterator allocations which roughly improves typical converter usage by roughly 32%.

Before:
Benchmark                                                               Mode  Cnt        Score        Error  Units
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField  thrpt   10  6848447,474 ± 554354,377  ops/s

After
Benchmark                                                               Mode  Cnt        Score         Error  Units
TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField  thrpt   10  9071099,879 ± 1423166,087  ops/s

Closes #2295.
2021-02-09 11:44:16 +01:00
Mark Paluch
ce4558fc4b Fix constructor resolution for Kotlin classes using unsigned types.
We now leniently skip parameter name resolution for types using unsigned types. The issue is caused by Kotlin's DefaultConstructorMarker that doesn't report a parameter name.

Closes #2215
2021-01-18 13:46:31 +01:00
Mark Paluch
8bd2f9bf34 Update copyright year to 2021.
Closes #2268.
2021-01-07 13:42:27 +01:00
Mark Paluch
71b92bc3f9 DATACMNS-1838 - Accept ExpressionDependencies in BasicPersistentEntity.getEvaluationContext(…).
Allow obtaining an EvaluationContext with a reduced set of extensions that are required for ExpressionDependencies instead of initializing all extensions.
2020-12-07 11:26:58 +01:00
Christoph Strobl
f261220372 DATACMNS-1762 - Polishing.
Update JavaDoc, remove unused imports and reduce method visibility.

Original Pull Request: #459
2020-09-25 08:00:29 +02:00
Mark Paluch
d840057b0c DATACMNS-1783 - Simplify null check in PersistentEntityIsNewStrategy.
Switch from Number.class.isInstance(…) method call to instanceof check.
2020-08-11 10:16:28 +02:00
Oliver Drotbohm
c99f2c9459 DATACMNS-1296 - PersistentPropertyPathAccessor now properly handles intermediate nulls when setting values.
We now use a dedicated GetOptions instance for the lookup of the parent path in case SetOptions is defined to skip nulls so that the lookup does not fail if the parent path contains a null value.
2020-08-06 08:50:20 +02:00
Mark Paluch
cdd8359103 DATACMNS-1781 - Reinstantate PersistentPropertyPathAccessor.setProperty(…).
Reintroduce method that was earlier removed as part of deprecation cleanup.
2020-08-05 08:58:35 +02:00
Mark Paluch
7b26fd199f DATACMNS-1780 - Polishing.
Consistently use MappingException when a required PersistentEntity cannot be obtained.
2020-08-04 15:25:34 +02:00
Mark Paluch
2aae23763b DATACMNS-1780 - Polishing.
Refine Javaoc. Eagerly react to availability of a single MappingContext.

Original pull request: #462.
2020-08-04 14:39:17 +02:00
Christoph Strobl
fd15c099e9 DATACMNS-1780 - PersistentEntities allows in flight metadata creation if the associated mapping context can be identified.
Use a more lenient approach, that allows metadata creation, when looking up persistent entities. This allows eg. a configured AuditingHandler to kick in without having to register an initial entity set in first place.

Original pull request: #462.
2020-08-04 14:39:05 +02:00
Mark Paluch
a600d8160c DATACMNS-1781 - Move off deprecated Spring Framework API.
Use KotlinDetector instead of ReflectionUtils.isKotlinClass(…). Use replacement MethodParameter(…).withContainingClass(…) instead of GenericTypeResolver.resolveParameterType(…). Use MergedAnnotations.from(…).isPresent(…) instead of AnnotationUtils.isAnnotationMetaPresent(…).
2020-08-04 12:16:55 +02:00
Mark Paluch
bb4d621a32 DATACMNS-1779 - Consider kotlin.Unit a simple type.
kotlin.Unit is now considered a simple type to avoid PersistentEntity creation.

ReflectionUtils.isVoid(…) now encapsulates the check so that calling code doesn't need to check if Kotlin is on the class path.
2020-07-31 10:57:56 +02:00
Mark Paluch
0c37484b19 DATACMNS-1768 - Polishing.
Reduce test visibility. Remove forEach detour through stream().
2020-07-14 09:50:40 +02:00
Mark Paluch
ebcea509b8 DATACMNS-1768 - Reuse bean state in InstantiationAwarePropertyAccessor when setting multiple properties.
We now reuse the new bean in InstantiationAwarePropertyAccessor when setting properties. Previously, we used the initial bean state as the bean was held by a delegate PersistentPropertyAccessor which caused only the last set property to be visible.
2020-07-14 09:50:40 +02:00
Mark Paluch
00d77d03cd DATACMNS-1767 - Polishing.
Reformat code. Use reflection for property access when running within a native image.

Original pull request: #456.
2020-07-13 14:25:59 +02:00
Christoph Strobl
ff0a8f77e8 DATACMNS-1767 - Disable ClassGeneratingEntityInstantiator when running native-image.
Always fall back to reflection when the system property for org.graalvm.nativeimage.imagecode is set.
This is required because on the fly code generation is not supported in this case.

Original pull request: #456.
2020-07-13 14:25:48 +02:00
Mark Paluch
e19bdb8fc4 DATACMNS-1758 - Revert optimizations from DATACMNS-1698.
We ensure that each EntityCallback retrieval operates on its own List to not share the retrieved callback list with other threads.
2020-07-09 14:15:30 +02:00
Phillip Webb
d72ccdacf6 DATACMNS-1755 - Fix malformed copyright headers.
Fix a few copyright headers that had formatting or date issues.

Original pull request: #448.
2020-06-25 11:20:41 +02:00
Phillip Webb
86bda64daa DATACMNS-1755 - Declare each variable in its own statement.
Update classes so that each member is declared on its own line. This
help to make them slightly easier to see when not using an IDE.

Original pull request: #448.
2020-06-25 11:20:28 +02:00
Phillip Webb
67442077b7 DATACMNS-1755 - Consistently use commons-logging.
Replace the few occurrences where SLF4J was being used directly so that
all logging now happens via commons-logging. The log patterns used in
SLF4J messages have been replaced with `LogMessage` which was introduced
in Spring Framework 5.2.

Original pull request: #448.
2020-06-25 11:20:24 +02:00
Phillip Webb
32826eec05 DATACMNS-1755 - Replace anonymous class with static initializer.
Replace the use of an anonymous class with a static initializer block.
This update also changes the constant to an unmodifiable variant.

Original pull request: #448.
2020-06-25 11:20:03 +02:00
Phillip Webb
b42cdb6568 DATACMNS-1755 - Use method references in favor of lambdas.
Simplify several lambda expressions in the codebase by using
method references.

Original pull request: #448.
2020-06-25 11:19:52 +02:00
Phillip Webb
cb8443e299 DATACMNS-1755 - Rename uppercase 'CACHE' static finals.
Rename static final `CACHE` members to use the lowercase form. Although
the caches are static final, they are not constant values.

Original pull request: #448.
2020-06-25 11:19:44 +02:00
Phillip Webb
ea263b233b Rename uppercase 'LOGGER' static finals
Rename static final `LOGGER` members to use the lowercase form.
Although the loggers are static final, they are not constant values.
2020-06-25 11:09:16 +02:00
Mark Paluch
fbe51ef1bb DATACMNS-1735 - Polishing.
Use mutated object as guard for synchronization. Copy discovered callbacks to cached callbacks.

Reduce concurrency in unit test to reduce test load. Guard synchronization with timeouts.

Original pull request: #446.
2020-05-27 09:53:52 +02:00
mhyeon-lee
d9969cb7d4 DATACMNS-1735 - Fix ConcurrencyModificationException in EntityCallbackDiscoverer.
We now guard modifications of the cached entity callbacks list with a synchronization block.

Original pull request: #446.
2020-05-27 09:32:24 +02:00
Mark Paluch
ce7928b28b DATACMNS-1706 - Polishing.
Improve Javadoc.

Original pull request: #437.
2020-05-26 09:06:26 +02:00
mhyeon-lee
9d482b0e35 DATACMNS-1706 - Improve locking in PreferredConstructor#isConstructorParameter.
Switch property parameter cache from HashMap and external locks to ConcurrentHashMap to improve multi-threaded locking behavior during isConstructorParameter(…) initialization.

Original pull request: #437.
2020-05-26 09:05:00 +02:00
Mark Paluch
4be5aae181 DATACMNS-1726 - Delombok source files. 2020-05-15 08:46:58 +02:00
Christoph Strobl
7c883acece DATACMNS-1721 - Lazily evaluate potential property matches in PropertyReferenceException.
Original pull request: #443.
2020-05-12 09:43:35 +02:00
Mark Paluch
d2d07fbec5 DATACMNS-1710 - Polishing.
Reformat code. Skip parameter inspection if constructor has no parameters.

Original pull request: #440.
2020-04-27 15:20:37 +02:00
Christoph Strobl
03832c36a4 DATACMNS-1710 - Avoid potentially expensive constructor parameter creation where possible.
Reorder constructor filtering with the goal to delay/avoid potentially expensive PersistenceConstructor creation with parameter lookup as much as possible.

The lookup is (in a default setup) only done once per domain type, but depending on the number of entities to inspect the change can help save some cycles for larger domains.

Before:
Benchmark                                  Mode  Cnt         Score         Error  Units
EntityMetadataBenchmark.alwaysNew         thrpt   10    224318,163 ±   42542,453  ops/s

After:
Benchmark                                  Mode  Cnt         Score         Error  Units
EtityMetadataBenchmark.alwaysNew         	thrpt   10    420053,505 ±    9288,093  ops/s

public class DomainType {

	private String id;
	private @Id String theId;

	private String firstname, lastname;
	private Integer age;

	public DomainType(String id, String theId, String firstname, String lastname, Integer age) {
		this.id = id;
		this.theId = theId;
		this.firstname = firstname;
		this.lastname = lastname;
		this.age = age;
	}

	@PersistenceConstructor
	public DomainType(String firstname, String lastname) {

		this.firstname = firstname;
		this.lastname = lastname;
	}
}

Original pull request: #440.
2020-04-27 15:20:30 +02:00
Mark Paluch
461647403d DATACMNS-1698 - Reduce allocations in EntityCallbackDiscoverer.
We now detect whether callbacks are present before we create result lists instead of always allocating a Collection. CallbackRetriever now also returns a cached variant of its list of callbacks instead of always allocating a new ArrayList.
2020-04-06 14:34:18 +02:00
SergiiTsypanov
eaaa37d4ff DATACMNS-1673 - Polishing.
Use method references where possible. Cleanup generics. Omit superfluous calls.

Original pull request: #426.
2020-02-25 09:39:17 +01:00
Oliver Drotbohm
d5786edec7 DATACMNS-1610 - Polishing. 2020-02-03 13:53:17 +01:00
Oliver Drotbohm
5cdb3139a4 DATACMNS-1610 - Improved property path access.
We now expose a dedicated PersistentPropertyPathAccessor and optionally take options for both the read and write access to properties. On read, clients can define to eagerly receive null in case one of the path segments is null. By default, we reject those as it indicates that there might be an issue with the backing object if the client assumes it can look up the more deeply nested path to receive a result.

On write access clients can define to either reject, skip or log intermediate null segments where skip means, that the setting is just silently aborted. Clients can also control how to deal with collection and map intermediates. By default we now propagate the attempt to set a value to all collection or map items respectively. This could be potentially extended to provide a filter receiving both the property and property value to selectively propagate those calls in the future.

The separation of these APIs (PersistentPropertyAccessor and PersistentPropertyPathAccessor) is introduced as the latter can be implemented on top of the former and the former potentially being dynamically generated. The logic of the latter can then be clearly separated from the actual individual property lookup. ConvertingPropertyAccessor is now a PersistentPropertyPathAccessor, too, and overrides SimplePersistentPropertyPathAccessor.getTypedProperty(…) to plug in conversion logic. This allows custom collection types being used if the ConversionService backing the accessor can convert from and to Collection or Map respectively.

Deprecated all PersistentPropertyPath-related methods on PersistentPropertyAccessor for removal in 2.3.

MappingAuditableBeanWrapperFactory now uses these new settings to skip both null values as well as collection and map values when setting auditing metadata.

Related tickets: DATACMNS-1438, DATACMNS-1461, DATACMNS-1609.
2020-02-03 13:11:44 +01:00