Search in sources :

Example 11 with XNode

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

the class XMLConfigBuilder method environmentsElement.

private void environmentsElement(XNode context) throws Exception {
    if (context != null) {
        if (environment == null) {
            environment = context.getStringAttribute("default");
        }
        for (XNode child : context.getChildren()) {
            String id = child.getStringAttribute("id");
            if (isSpecifiedEnvironment(id)) {
                TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
                DataSourceFactory dsFactory = dataSourceElement(child.evalNode("dataSource"));
                DataSource dataSource = dsFactory.getDataSource();
                Environment.Builder environmentBuilder = new Environment.Builder(id).transactionFactory(txFactory).dataSource(dataSource);
                configuration.setEnvironment(environmentBuilder.build());
            }
        }
    }
}
Also used : DataSourceFactory(org.apache.ibatis.datasource.DataSourceFactory) XNode(org.apache.ibatis.parsing.XNode) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) BaseBuilder(org.apache.ibatis.builder.BaseBuilder) Environment(org.apache.ibatis.mapping.Environment) DataSource(javax.sql.DataSource)

Example 12 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) throws Exception {
    List<XNode> argChildren = resultChild.getChildren();
    for (XNode argChild : argChildren) {
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        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 13 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) throws Exception {
    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<ParameterMapping>();
        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);
            @SuppressWarnings("unchecked") Class<? extends TypeHandler<?>> typeHandlerClass = (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
            ParameterMapping parameterMapping = builderAssistant.buildParameterMapping(parameterClass, property, javaTypeClass, jdbcTypeEnum, resultMap, modeEnum, typeHandlerClass, numericScale);
            parameterMappings.add(parameterMapping);
        }
        builderAssistant.addParameterMap(id, parameterClass, parameterMappings);
    }
}
Also used : XNode(org.apache.ibatis.parsing.XNode) ArrayList(java.util.ArrayList) JdbcType(org.apache.ibatis.type.JdbcType) ParameterMode(org.apache.ibatis.mapping.ParameterMode) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) TypeHandler(org.apache.ibatis.type.TypeHandler)

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