Class ResultMappingConstructorResolver

java.lang.Object
org.apache.ibatis.builder.ResultMappingConstructorResolver

public class ResultMappingConstructorResolver extends Object
  • Constructor Details

    • ResultMappingConstructorResolver

      public ResultMappingConstructorResolver(Configuration configuration, List<ResultMapping> constructorResultMappings, Class<?> resultType, String resultMapId)
      Parameters:
      configuration - the global configuration object
      constructorResultMappings - the current mappings as resolved from xml or annotations
      resultType - the result type of the object to be built
  • Method Details

    • resolveWithConstructor

      public List<ResultMapping> resolveWithConstructor()
      Attempts to find a matching constructor for the supplied resultType and (possibly unordered mappings) by:
      1. Finding constructors with the same amount of arguments
      2. Rejecting candidates which have different argument names than our mappings
      3. Ensuring the type of each mapping matches the resolved constructor
      4. Rebuilding and sorting the mappings according to the found constructor

      Note that if there are multiple constructors which match, javaType is 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 name specified, as this is the only way we order against the constructor reliably, i.e. we cannot order X(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: