Search in sources :

Example 6 with XNode

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

the class XMLConfigBuilder method typeAliasesElement.

private void typeAliasesElement(XNode parent) {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            if ("package".equals(child.getName())) {
                String typeAliasPackage = child.getStringAttribute("name");
                configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
            } else {
                String alias = child.getStringAttribute("alias");
                String type = child.getStringAttribute("type");
                try {
                    Class<?> clazz = Resources.classForName(type);
                    if (alias == null) {
                        typeAliasRegistry.registerAlias(clazz);
                    } else {
                        typeAliasRegistry.registerAlias(alias, clazz);
                    }
                } catch (ClassNotFoundException e) {
                    throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
                }
            }
        }
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) XNode(org.apache.ibatis.parsing.XNode)

Example 7 with XNode

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

the class XMLMapperBuilder method processDiscriminatorElement.

private Discriminator processDiscriminatorElement(XNode context, Class<?> resultType, List<ResultMapping> resultMappings) throws Exception {
    String column = context.getStringAttribute("column");
    String javaType = context.getStringAttribute("javaType");
    String jdbcType = context.getStringAttribute("jdbcType");
    String typeHandler = context.getStringAttribute("typeHandler");
    Class<?> javaTypeClass = resolveClass(javaType);
    @SuppressWarnings("unchecked") Class<? extends TypeHandler<?>> typeHandlerClass = (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
    JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
    Map<String, String> discriminatorMap = new HashMap<String, String>();
    for (XNode caseChild : context.getChildren()) {
        String value = caseChild.getStringAttribute("value");
        String resultMap = caseChild.getStringAttribute("resultMap", processNestedResultMappings(caseChild, resultMappings));
        discriminatorMap.put(value, resultMap);
    }
    return builderAssistant.buildDiscriminator(resultType, column, javaTypeClass, jdbcTypeEnum, typeHandlerClass, discriminatorMap);
}
Also used : HashMap(java.util.HashMap) XNode(org.apache.ibatis.parsing.XNode) JdbcType(org.apache.ibatis.type.JdbcType) TypeHandler(org.apache.ibatis.type.TypeHandler)

Example 8 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 9 with XNode

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

the class XMLConfigBuilder 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)

Example 10 with XNode

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

the class XMLConfigBuilder method mapperElement.

private void mapperElement(XNode parent) throws Exception {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            if ("package".equals(child.getName())) {
                String mapperPackage = child.getStringAttribute("name");
                configuration.addMappers(mapperPackage);
            } else {
                String resource = child.getStringAttribute("resource");
                String url = child.getStringAttribute("url");
                String mapperClass = child.getStringAttribute("class");
                if (resource != null && url == null && mapperClass == null) {
                    ErrorContext.instance().resource(resource);
                    InputStream inputStream = Resources.getResourceAsStream(resource);
                    XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
                    mapperParser.parse();
                } else if (resource == null && url != null && mapperClass == null) {
                    ErrorContext.instance().resource(url);
                    InputStream inputStream = Resources.getUrlAsStream(url);
                    XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments());
                    mapperParser.parse();
                } else if (resource == null && url == null && mapperClass != null) {
                    Class<?> mapperInterface = Resources.classForName(mapperClass);
                    configuration.addMapper(mapperInterface);
                } else {
                    throw new BuilderException("A mapper element may only specify a url, resource or class, but not more than one.");
                }
            }
        }
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) InputStream(java.io.InputStream) XNode(org.apache.ibatis.parsing.XNode)

Aggregations

XNode (org.apache.ibatis.parsing.XNode)13 ArrayList (java.util.ArrayList)4 BuilderException (org.apache.ibatis.builder.BuilderException)3 JdbcType (org.apache.ibatis.type.JdbcType)3 IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)2 ResultFlag (org.apache.ibatis.mapping.ResultFlag)2 TypeHandler (org.apache.ibatis.type.TypeHandler)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 BaseBuilder (org.apache.ibatis.builder.BaseBuilder)1 ResultMapResolver (org.apache.ibatis.builder.ResultMapResolver)1 DataSourceFactory (org.apache.ibatis.datasource.DataSourceFactory)1 Discriminator (org.apache.ibatis.mapping.Discriminator)1 Environment (org.apache.ibatis.mapping.Environment)1 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)1 ParameterMode (org.apache.ibatis.mapping.ParameterMode)1 ResultMapping (org.apache.ibatis.mapping.ResultMapping)1