Search in sources :

Example 1 with XNode

use of org.apache.ibatis.parsing.XNode 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 XNode

use of org.apache.ibatis.parsing.XNode in project mybatis-3 by mybatis.

the class XMLConfigBuilder method pluginElement.

private void pluginElement(XNode parent) throws Exception {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            String interceptor = child.getStringAttribute("interceptor");
            Properties properties = child.getChildrenAsProperties();
            Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).getDeclaredConstructor().newInstance();
            interceptorInstance.setProperties(properties);
            configuration.addInterceptor(interceptorInstance);
        }
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) Properties(java.util.Properties) Interceptor(org.apache.ibatis.plugin.Interceptor)

Example 3 with XNode

use of org.apache.ibatis.parsing.XNode in project mybatis-3 by mybatis.

the class XMLMapperBuilder method sqlElement.

private void sqlElement(List<XNode> list, String requiredDatabaseId) {
    for (XNode context : list) {
        String databaseId = context.getStringAttribute("databaseId");
        String id = context.getStringAttribute("id");
        id = builderAssistant.applyCurrentNamespace(id, false);
        if (databaseIdMatchesCurrent(id, databaseId, requiredDatabaseId)) {
            sqlFragments.put(id, context);
        }
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode)

Example 4 with XNode

use of org.apache.ibatis.parsing.XNode in project mybatis-3 by mybatis.

the class XMLIncludeTransformer method findSqlFragment.

private Node findSqlFragment(String refid, Properties variables) {
    refid = PropertyParser.parse(refid, variables);
    refid = builderAssistant.applyCurrentNamespace(refid, true);
    try {
        XNode nodeToInclude = configuration.getSqlFragments().get(refid);
        return nodeToInclude.getNode().cloneNode(true);
    } catch (IllegalArgumentException e) {
        throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException)

Example 5 with XNode

use of org.apache.ibatis.parsing.XNode in project mybatis-3 by mybatis.

the class XMLScriptBuilder method parseDynamicTags.

protected MixedSqlNode parseDynamicTags(XNode node) {
    List<SqlNode> contents = new ArrayList<>();
    NodeList children = node.getNode().getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        XNode child = node.newXNode(children.item(i));
        if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {
            String data = child.getStringBody("");
            TextSqlNode textSqlNode = new TextSqlNode(data);
            if (textSqlNode.isDynamic()) {
                contents.add(textSqlNode);
                isDynamic = true;
            } else {
                contents.add(new StaticTextSqlNode(data));
            }
        } else if (child.getNode().getNodeType() == Node.ELEMENT_NODE) {
            // issue #628
            String nodeName = child.getNode().getNodeName();
            NodeHandler handler = nodeHandlerMap.get(nodeName);
            if (handler == null) {
                throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");
            }
            handler.handleNode(child, contents);
            isDynamic = true;
        }
    }
    return new MixedSqlNode(contents);
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) NodeList(org.w3c.dom.NodeList) XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList)

Aggregations

XNode (org.apache.ibatis.parsing.XNode)17 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 BuilderException (org.apache.ibatis.builder.BuilderException)3 IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)3 JdbcType (org.apache.ibatis.type.JdbcType)3 InputStream (java.io.InputStream)2 List (java.util.List)2 ResultMapResolver (org.apache.ibatis.builder.ResultMapResolver)2 Discriminator (org.apache.ibatis.mapping.Discriminator)2 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)2 ResultFlag (org.apache.ibatis.mapping.ResultFlag)2 ResultMapping (org.apache.ibatis.mapping.ResultMapping)2 XPathParser (org.apache.ibatis.parsing.XPathParser)2 NodeList (org.w3c.dom.NodeList)2 Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 BaseBuilder (org.apache.ibatis.builder.BaseBuilder)1 MapperBuilderAssistant (org.apache.ibatis.builder.MapperBuilderAssistant)1 XMLMapperEntityResolver (org.apache.ibatis.builder.xml.XMLMapperEntityResolver)1