Search in sources :

Example 16 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, 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)

Example 17 with XNode

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

the class XMLMapperBuilder method processConstructorElement.

private void processConstructorElement(XNode resultChild, Class<?> resultType, List<ResultMapping> resultMappings) {
    List<XNode> argChildren = resultChild.getChildren();
    for (XNode argChild : argChildren) {
        List<ResultFlag> flags = new ArrayList<>();
        flags.add(ResultFlag.CONSTRUCTOR);
        if ("idArg".equals(argChild.getName())) {
            flags.add(ResultFlag.ID);
        }
        resultMappings.add(buildResultMappingFromContext(argChild, resultType, flags));
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList) ResultFlag(org.apache.ibatis.mapping.ResultFlag)

Example 18 with XNode

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

the class XMLMapperBuilder method parameterMapElement.

private void parameterMapElement(List<XNode> list) {
    for (XNode parameterMapNode : list) {
        String id = parameterMapNode.getStringAttribute("id");
        String type = parameterMapNode.getStringAttribute("type");
        Class<?> parameterClass = resolveClass(type);
        List<XNode> parameterNodes = parameterMapNode.evalNodes("parameter");
        List<ParameterMapping> parameterMappings = new ArrayList<>();
        for (XNode parameterNode : parameterNodes) {
            String property = parameterNode.getStringAttribute("property");
            String javaType = parameterNode.getStringAttribute("javaType");
            String jdbcType = parameterNode.getStringAttribute("jdbcType");
            String resultMap = parameterNode.getStringAttribute("resultMap");
            String mode = parameterNode.getStringAttribute("mode");
            String typeHandler = parameterNode.getStringAttribute("typeHandler");
            Integer numericScale = parameterNode.getIntAttribute("numericScale");
            ParameterMode modeEnum = resolveParameterMode(mode);
            Class<?> javaTypeClass = resolveClass(javaType);
            JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
            Class<? extends TypeHandler<?>> typeHandlerClass = resolveClass(typeHandler);
            ParameterMapping parameterMapping = builderAssistant.buildParameterMapping(parameterClass, property, javaTypeClass, jdbcTypeEnum, resultMap, modeEnum, typeHandlerClass, numericScale);
            parameterMappings.add(parameterMapping);
        }
        builderAssistant.addParameterMap(id, parameterClass, parameterMappings);
    }
}
Also used : ParameterMode(org.apache.ibatis.mapping.ParameterMode) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList) JdbcType(org.apache.ibatis.type.JdbcType)

Example 19 with XNode

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

the class XMLStatementBuilder method parseSelectKeyNodes.

private void parseSelectKeyNodes(String parentId, List<XNode> list, Class<?> parameterTypeClass, LanguageDriver langDriver, String skRequiredDatabaseId) {
    for (XNode nodeToHandle : list) {
        String id = parentId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
        String databaseId = nodeToHandle.getStringAttribute("databaseId");
        if (databaseIdMatchesCurrent(id, databaseId, skRequiredDatabaseId)) {
            parseSelectKeyNode(id, nodeToHandle, parameterTypeClass, langDriver, databaseId);
        }
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode)

Example 20 with XNode

use of org.apache.ibatis.parsing.XNode in project alfresco-repository by Alfresco.

the class HierarchicalXMLConfigBuilder method typeHandlerElement.

private void typeHandlerElement(XNode parent) throws Exception {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            if ("package".equals(child.getName())) {
                String typeHandlerPackage = child.getStringAttribute("name");
                typeHandlerRegistry.register(typeHandlerPackage);
            } else {
                String javaTypeName = child.getStringAttribute("javaType");
                String jdbcTypeName = child.getStringAttribute("jdbcType");
                String handlerTypeName = child.getStringAttribute("handler");
                Class<?> javaTypeClass = resolveClass(javaTypeName);
                JdbcType jdbcType = resolveJdbcType(jdbcTypeName);
                Class<?> typeHandlerClass = resolveClass(handlerTypeName);
                if (javaTypeClass != null) {
                    if (jdbcType == null) {
                        typeHandlerRegistry.register(javaTypeClass, typeHandlerClass);
                    } else {
                        typeHandlerRegistry.register(javaTypeClass, jdbcType, typeHandlerClass);
                    }
                } else {
                    typeHandlerRegistry.register(typeHandlerClass);
                }
            }
        }
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) JdbcType(org.apache.ibatis.type.JdbcType)

Aggregations

XNode (org.apache.ibatis.parsing.XNode)22 ArrayList (java.util.ArrayList)5 BuilderException (org.apache.ibatis.builder.BuilderException)5 JdbcType (org.apache.ibatis.type.JdbcType)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)3 List (java.util.List)2 Properties (java.util.Properties)2 DataSource (javax.sql.DataSource)2 BaseBuilder (org.apache.ibatis.builder.BaseBuilder)2 ResultMapResolver (org.apache.ibatis.builder.ResultMapResolver)2 XMLMapperBuilder (org.apache.ibatis.builder.xml.XMLMapperBuilder)2 DataSourceFactory (org.apache.ibatis.datasource.DataSourceFactory)2 Discriminator (org.apache.ibatis.mapping.Discriminator)2 Environment (org.apache.ibatis.mapping.Environment)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