Search in sources :

Example 1 with ResultMapResolver

use of org.apache.ibatis.builder.ResultMapResolver in project mybatis-3 by mybatis.

the class XMLMapperBuilder method resultMapElement.

private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings) throws Exception {
    ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
    String id = resultMapNode.getStringAttribute("id", resultMapNode.getValueBasedIdentifier());
    String type = resultMapNode.getStringAttribute("type", resultMapNode.getStringAttribute("ofType", resultMapNode.getStringAttribute("resultType", resultMapNode.getStringAttribute("javaType"))));
    String extend = resultMapNode.getStringAttribute("extends");
    Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping");
    Class<?> typeClass = resolveClass(type);
    Discriminator discriminator = null;
    List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
    resultMappings.addAll(additionalResultMappings);
    List<XNode> resultChildren = resultMapNode.getChildren();
    for (XNode resultChild : resultChildren) {
        if ("constructor".equals(resultChild.getName())) {
            processConstructorElement(resultChild, typeClass, resultMappings);
        } else if ("discriminator".equals(resultChild.getName())) {
            discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
        } else {
            List<ResultFlag> flags = new ArrayList<ResultFlag>();
            if ("id".equals(resultChild.getName())) {
                flags.add(ResultFlag.ID);
            }
            resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
        }
    }
    ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
    try {
        return resultMapResolver.resolve();
    } catch (IncompleteElementException e) {
        configuration.addIncompleteResultMap(resultMapResolver);
        throw e;
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList) Discriminator(org.apache.ibatis.mapping.Discriminator) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException) ResultMapping(org.apache.ibatis.mapping.ResultMapping) ArrayList(java.util.ArrayList) List(java.util.List) ResultFlag(org.apache.ibatis.mapping.ResultFlag) ResultMapResolver(org.apache.ibatis.builder.ResultMapResolver)

Example 2 with ResultMapResolver

use of org.apache.ibatis.builder.ResultMapResolver in project mybatis-3 by mybatis.

the class Configuration method parsePendingResultMaps.

private void parsePendingResultMaps() {
    if (incompleteResultMaps.isEmpty()) {
        return;
    }
    synchronized (incompleteResultMaps) {
        boolean resolved;
        IncompleteElementException ex = null;
        do {
            resolved = false;
            Iterator<ResultMapResolver> iterator = incompleteResultMaps.iterator();
            while (iterator.hasNext()) {
                try {
                    iterator.next().resolve();
                    iterator.remove();
                    resolved = true;
                } catch (IncompleteElementException e) {
                    ex = e;
                }
            }
        } while (resolved);
        if (!incompleteResultMaps.isEmpty() && ex != null) {
            // At least one result map is unresolvable.
            throw ex;
        }
    }
}
Also used : ResultMapResolver(org.apache.ibatis.builder.ResultMapResolver) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException)

Example 3 with ResultMapResolver

use of org.apache.ibatis.builder.ResultMapResolver in project mybatis-3 by mybatis.

the class XMLMapperBuilder method resultMapElement.

private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings, Class<?> enclosingType) {
    ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
    String type = resultMapNode.getStringAttribute("type", resultMapNode.getStringAttribute("ofType", resultMapNode.getStringAttribute("resultType", resultMapNode.getStringAttribute("javaType"))));
    Class<?> typeClass = resolveClass(type);
    if (typeClass == null) {
        typeClass = inheritEnclosingType(resultMapNode, enclosingType);
    }
    Discriminator discriminator = null;
    List<ResultMapping> resultMappings = new ArrayList<>(additionalResultMappings);
    List<XNode> resultChildren = resultMapNode.getChildren();
    for (XNode resultChild : resultChildren) {
        if ("constructor".equals(resultChild.getName())) {
            processConstructorElement(resultChild, typeClass, resultMappings);
        } else if ("discriminator".equals(resultChild.getName())) {
            discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
        } else {
            List<ResultFlag> flags = new ArrayList<>();
            if ("id".equals(resultChild.getName())) {
                flags.add(ResultFlag.ID);
            }
            resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
        }
    }
    String id = resultMapNode.getStringAttribute("id", resultMapNode.getValueBasedIdentifier());
    String extend = resultMapNode.getStringAttribute("extends");
    Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping");
    ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
    try {
        return resultMapResolver.resolve();
    } catch (IncompleteElementException e) {
        configuration.addIncompleteResultMap(resultMapResolver);
        throw e;
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList) Discriminator(org.apache.ibatis.mapping.Discriminator) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException) ResultMapping(org.apache.ibatis.mapping.ResultMapping) ArrayList(java.util.ArrayList) List(java.util.List) ResultMapResolver(org.apache.ibatis.builder.ResultMapResolver)

Aggregations

IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)3 ResultMapResolver (org.apache.ibatis.builder.ResultMapResolver)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Discriminator (org.apache.ibatis.mapping.Discriminator)2 ResultMapping (org.apache.ibatis.mapping.ResultMapping)2 XNode (org.apache.ibatis.parsing.XNode)2 ResultFlag (org.apache.ibatis.mapping.ResultFlag)1