Commit Graph

112 Commits

Author SHA1 Message Date
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
Christoph Strobl
47e2e61ff5 DATACMNS-867 - Preserve underscores when resolving PropertyPath for PersistentProperties.
Preserve underscores in variable names (eg. String foo_bar) when resolving the actual type information for the property via PropertyPath by quoting (Pattern#quote) the property name.
2017-03-24 08:00:43 +01:00
Mark Paluch
2da5acc553 DATACMNS-981 - Consider merged annotations when populating for annotation cache.
We now consider property annotations as merged annotations when initially scanning for annotations in a property declaration. Composed annotations such as declared outside our code are captured correctly because they use an own type that is not queried by users of PersistentProperty. Own, revised annotations, using @AliasFor providing an alias for annotation values require merged annotation processing.

Previously, annotations were cached as-is without resolving @AliasFor. This caused a later lookup via findAnnotation(…) to return the cached annotation without aliasing. Because the annotation was cached, no further lookup via AnnotatedElementUtils.findMergedAnnotation(…) was attempted.

@Retention(RetentionPolicy.RUNTIME)
@Target(value = { FIELD, METHOD })
public @interface RevisedAnnnotationWithAliasFor {

	@AliasFor("value")
	String name() default "";

	@AliasFor("name")
	String value() default "";
}

public class Person {
	@RevisedAnnnotationWithAliasFor(value = "spring")
	String firstname;
}

PersistentProperty firstname = …

property.findAnnotation(…) returned previously @RevisedAnnnotationWithAliasFor(value = "spring", name = "")

now we return @RevisedAnnnotationWithAliasFor(value = "spring", name = "spring")
2017-03-24 08:00:43 +01:00
Oliver Gierke
d7340e391c DATACMNS-867 - Further fixes. 2017-03-24 08:00:25 +01:00
Oliver Gierke
8268373d11 DATACMNS-867 - Further polishing in MappingContext APIs. 2017-03-24 08:00:25 +01:00
Oliver Gierke
49575fd4ce DATACMNS-867 - Introduced Stream-based alternatives for PersistentEntity.doWith… methods. 2017-03-24 08:00:24 +01:00
Oliver Gierke
db4bf10ebb DATACMNS-867 - Introduced PersistentEntity.getRequiredPersistentProperty(). 2017-03-24 08:00:24 +01:00
Oliver Gierke
d4811e29d9 DATACMNS-867 - Second draft. 2017-03-24 08:00:23 +01:00
Mark Paluch
57ed50a730 DATACMNS-867 - Adopt Optional<T> in ASM generated property accessor factories. 2017-03-24 08:00:23 +01:00
Oliver Gierke
cc63e5b7a4 DATACMNS-867 - First draft. 2017-03-24 08:00:23 +01:00
Oliver Gierke
642e92b2eb DATACMNS-1006 - SimpleTypeHolder now considers java.lang types simple ones.
This prevents AbstractMappingContext from adding them as entities.

Related tickets: DATAREST-1018.
2017-03-07 13:44:44 +01:00
Christoph Strobl
aaf4ccc69c DATACMNS-999 - Improve resource extensive error message concatenation.
We now use Assert.isTrue(…) taking a Supplier to avoid unnecessary String concatenation.

Original pull request: #198.
2017-02-28 19:03:51 +01:00
Christoph Strobl
3e048a6dca DATACMNS-985 - Remove references to single-argument assertion methods. 2017-01-31 18:10:40 +01:00
Oliver Gierke
d3f235872c DATACMNS-934 - BasicPersistentEntity.addAssociation(…) drops null values now.
Previously a null value was added to the list of associations if it was handed to BasicaPersistentEntity.addAssociation(…). We now drop those null values and log a warning as it usually indicates a MappingContext implementation identifying a property as association but subsequently failing to look it up.
2016-12-05 16:39:58 +01:00
Oliver Gierke
7d901d2005 DATACMNS-916 - Polishing.
Minor formatting changes.

Original pull request: #178.
2016-09-23 14:53:26 +02:00
Mark Paluch
0e29af3a15 DATACMNS-916 - Fix setter lookup in ClassGeneratingPropertyAccessorFactory.
Previously, ClassGeneratingPropertyAccessorFactory uses boxed types for primitive type setters. This threw NoSuchMethodExceptions and caused ExceptionInInitializerError as the generated class could not be initialized. We now use the appropriate argument type to look up setters.

Also, we now only generate accessor usage if the property is configured to use property access in the first place.

Original pull request: #178.
2016-09-23 14:53:26 +02:00
Oliver Gierke
d4c0aa70ba DATACMNS-866 - Improved error message in invalid invocations of BasicPersistentEntity.getPropertyAccessor(…).
We now explicitly report the given object's type and the one expected in case of a mismatch when BasicPersistentEntity.getPropertyAccessor(…) is invoked.
2016-06-08 16:10:25 +02:00
Oliver Gierke
5b5daaf397 DATACMNS-831 - Polishing.
Formatting. Fixed copyright header and author. Added missing assertions in AbstractMappingContext.addPersistentEntity(…).

Original pull request: #157.
2016-05-31 18:52:36 +02:00
Mikael Klamra
046f0408d1 DATACMNS-831 - AbstractMappingContext.addPersistentEntity(…) now acquires necessary read lock.
The lookup for already available PersistentEntity instances now acquires a read lock to shield the execution from partially equipped PersistentEntity instances currently in creation from another thread.

Original pull request: #157.
2016-05-31 18:50:59 +02:00
Oliver Gierke
f29cbf5752 DATACMNS-853 - Polishing.
Simplified test case. Formatting in ClassGeneratingPropertyAccessorFactory.

Related tickets: DATACMNS-809.
Original pull request: #161.
Related pull request: #160.
2016-05-12 15:45:05 +02:00
Mark Paluch
db5259292c DATACMNS-853 - Support interface entity types using generated property accessors.
Property accessors (getter and setter) defined on an interface require a different instruction opcode for invoking methods. We now distinguish whether a property accessor is defined on an interface and use either INVOKEINTERFACE or INVOKEVIRTUAL otherwise.

Related tickets: DATACMNS-809.
Original pull request: #161.
Related pull request: #160.
2016-05-12 15:31:09 +02:00
Oliver Gierke
38a41139fc DATACMNS-809 - Polishing.
Removed DefaultPersistentPropertyAccessorFactory as it only delegates to the class generating one. Tweaked AbstractMappingContext to actually use the latter in the first place. Introduced BeanWrapperPropertyAccessorFactory to implement the default behavior of using a BeanWrapper and initialize BasicPersistentEntity to avoid a null clause in getPersistentPropertyAccessor(…).

Removed getPersistentPropertyAccessorFactory and rather rely on ReflectionTestUtils in tests to avoid additional API being exposed.

Original pull request: #159.
2016-05-03 16:47:54 +02:00
Mark Paluch
defc3c7874 DATACMNS-809 - Refactor BasicPersistentEntity to set PersistentPropertyAccessorFactory.
PersistentPropertyAccessorFactory can be set on a BasicPersistentEntity. This is done by AbstractMappingContext once the entity is verified. This change reduces the count of PersistentPropertyAccessorFactory instances and performs the isSupported check only once, when initializing the entity.

Original pull request: #159.
2016-05-03 16:47:54 +02:00
Oliver Gierke
41fe89743b DATACMNS-809 - Polishing.
Made as many methods in ClassGeneratingPropertyAccessorFactory static as possible. Some code formatting. Some warning suppressions where needed.

Original pull request: #159.
2016-05-03 16:47:54 +02:00
Mark Paluch
899a98c83e DATACMNS-809 - Add Class-generating property accessor factory.
We now support generated PersistentPropertyAccessors when using Java 7 and if property/association name hashCodes are unique within a PersistentEntity.
Generated PersistentPropertyAccessors provide optimized access to properties. They use either MethodHandles or direct property/field access, depending on the visibility/final modifiers of the entity type and its members. A generated PersistentPropertyAccessor is injected into the originating class loader of the entity class to enable optimizations for package-default/protected member access.

Original pull request: #159.
2016-05-03 16:47:53 +02:00
Oliver Gierke
f0f9d5bc20 DATACMNS-825 - Polishing.
Tweaked annotation cache usage in BasicPersistentEntity.findAnnotation(…).

Original pull request: #156.
2016-03-15 13:20:20 +01:00