Package org.apache.ibatis.builder
Class ResultMappingConstructorResolver
java.lang.Object
org.apache.ibatis.builder.ResultMappingConstructorResolver
-
Constructor Summary
ConstructorsConstructorDescriptionResultMappingConstructorResolver(Configuration configuration, List<ResultMapping> constructorResultMappings, Class<?> resultType, String resultMapId) -
Method Summary
Modifier and TypeMethodDescriptionAttempts to find a matching constructor for the suppliedresultTypeand (possibly unordered mappings) by: Finding constructors with the same amount of arguments Rejecting candidates which have different argument names than our mappings Ensuring the type of each mapping matches the resolved constructor Rebuilding and sorting the mappings according to the found constructor
-
Constructor Details
-
ResultMappingConstructorResolver
public ResultMappingConstructorResolver(Configuration configuration, List<ResultMapping> constructorResultMappings, Class<?> resultType, String resultMapId) - Parameters:
configuration- the global configuration objectconstructorResultMappings- the current mappings as resolved from xml or annotationsresultType- the result type of the object to be built
-
-
Method Details
-
resolveWithConstructor
Attempts to find a matching constructor for the suppliedresultTypeand (possibly unordered mappings) by:- Finding constructors with the same amount of arguments
- Rejecting candidates which have different argument names than our mappings
- Ensuring the type of each mapping matches the resolved constructor
- Rebuilding and sorting the mappings according to the found constructor
Note that if there are multiple constructors which match,
javaTypeis the only way to differentiate between them. i.e. if there is only one constructor, all types could be missing, however if there is more than one with the same amount of arguments, we need type on at least a few mappings to differentiate and select the correct constructor.Argument order can only be derived if all mappings have a
namespecified, as this is the only way we order against the constructor reliably, i.e. we cannot orderX(String, String, String)based on types alone.- Returns:
- ordered mappings based on the resolved constructor, original mappings if none were found, or original mappings if they did not have property names and a constructor could not be resolved
- Throws:
BuilderException- when a constructor could not be resolved- See Also:
-