Class PreferredConstructorDiscoverer<T>
- Type Parameters:
T- target DTO type
- Direct Known Subclasses:
CachedPreferredConstructorDiscoverer
Tuple.
Constructor discovery is based entirely on the tuple's positional shape. Parameter names, tuple aliases, and property names are not consulted.
A constructor is considered suitable when all of the following are true:
- it is not synthetic
- its parameter count exactly matches the tuple element count
- for each position, the constructor parameter type is assignable from the tuple element Java type after primitive types are boxed
The implementation iterates over Class.getDeclaredConstructors(),
keeps track of the latest suitable constructor it has seen, and stops early
if it encounters a suitable constructor annotated with
PersistenceCreator. Because Java reflection does not guarantee a
stable ordering for declared constructors, constructor selection is
unpredictable when multiple suitable constructors are present.
To keep selection deterministic, DTOs should ideally expose only one
suitable constructor. If PersistenceCreator is used, it is strongly
recommended that at most one suitable constructor be annotated with it.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondiscover(@NonNull jakarta.persistence.Tuple tuple) Finds a constructor whose parameter list is compatible with the supplied tuple and makes it accessible for later invocation.Returns the DTO type whose constructors this discoverer inspects.protected Class<?>Converts primitive types to their boxed equivalents before assignability checks are performed.
-
Field Details
-
clazz
DTO type whose constructors are inspected.
-
-
Constructor Details
-
PreferredConstructorDiscoverer
public PreferredConstructorDiscoverer()
-
-
Method Details
-
getTargetClass
Returns the DTO type whose constructors this discoverer inspects.- Returns:
- target DTO type
-
discover
Finds a constructor whose parameter list is compatible with the supplied tuple and makes it accessible for later invocation.Matching is performed position by position. For each tuple element, the constructor parameter at the same index must be assignable from the tuple element Java type, with primitive parameter types first converted to their boxed equivalents. Tuple aliases are ignored.
If several suitable constructors exist, the outcome depends on the order returned by
Class.getDeclaredConstructors(). A suitable constructor annotated withPersistenceCreatorwins immediately when encountered. Otherwise, the last suitable constructor encountered is selected.- Parameters:
tuple- tuple whose values will be passed to the constructor- Returns:
- matching constructor made accessible for invocation
- Throws:
QueryConfigurationException- if no suitable constructor can be found for the tuple shape
-
wrap
Converts primitive types to their boxed equivalents before assignability checks are performed.
-