Java Code Examples for org.apache.ibatis.parsing.XNode

The following examples show how to use org.apache.ibatis.parsing.XNode. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void parseConfiguration(XNode root) {
    try {
        //issue #117 read properties first
        propertiesElement(root.evalNode("properties")); 
        typeAliasesElement(root.evalNode("typeAliases"));
        pluginElement(root.evalNode("plugins"));
        objectFactoryElement(root.evalNode("objectFactory"));
        objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
        reflectionFactoryElement(root.evalNode("reflectionFactory"));
        settingsElement(root.evalNode("settings"));
        // read it after objectFactory and objectWrapperFactory issue #631
        environmentsElement(root.evalNode("environments")); 
        databaseIdProviderElement(root.evalNode("databaseIdProvider"));
        typeHandlerElement(root.evalNode("typeHandlers"));
        mapperElement(root.evalNode("mappers"));
    } catch (Exception e) {
        throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
    }
}
 
Example 2
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);
                }
            }
        }
    }
}
 
Example 3
Source Project: mybatis   Source File: XMLMapperBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private ResultMapping buildResultMappingFromContext(XNode context, Class<?> resultType, List<ResultFlag> flags) throws Exception {
//<id property="id" column="author_id"/>
//<result property="username" column="author_username"/>
   String property = context.getStringAttribute("property");
   String column = context.getStringAttribute("column");
   String javaType = context.getStringAttribute("javaType");
   String jdbcType = context.getStringAttribute("jdbcType");
   String nestedSelect = context.getStringAttribute("select");
   //处理嵌套的result map
   String nestedResultMap = context.getStringAttribute("resultMap",
       processNestedResultMappings(context, Collections.<ResultMapping> emptyList()));
   String notNullColumn = context.getStringAttribute("notNullColumn");
   String columnPrefix = context.getStringAttribute("columnPrefix");
   String typeHandler = context.getStringAttribute("typeHandler");
   String resulSet = context.getStringAttribute("resultSet");
   String foreignColumn = context.getStringAttribute("foreignColumn");
   boolean lazy = "lazy".equals(context.getStringAttribute("fetchType", configuration.isLazyLoadingEnabled() ? "lazy" : "eager"));
   Class<?> javaTypeClass = resolveClass(javaType);
   @SuppressWarnings("unchecked")
   Class<? extends TypeHandler<?>> typeHandlerClass = (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
   JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
   //又去调builderAssistant.buildResultMapping
   return builderAssistant.buildResultMapping(resultType, property, column, javaTypeClass, jdbcTypeEnum, nestedSelect, nestedResultMap, notNullColumn, columnPrefix, typeHandlerClass, flags, resulSet, foreignColumn, lazy);
 }
 
Example 4
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);
                }
            }
        }
    }
}
 
Example 5
Source Project: mybatis   Source File: XMLConfigBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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");
//循环比较id是否就是指定的environment
      if (isSpecifiedEnvironment(id)) {
        //7.1事务管理器
        TransactionFactory txFactory = transactionManagerElement(child.evalNode("transactionManager"));
        //7.2数据源
        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());
      }
    }
  }
}
 
Example 6
Source Project: Shop-for-JavaWeb   Source File: XMLMapperBuilder.java    License: MIT License 6 votes vote down vote up
private void cacheElement(XNode context) throws Exception {
	if (context != null) {
		String type = context.getStringAttribute("type", "PERPETUAL");
		Class<? extends Cache> typeClass = typeAliasRegistry
				.resolveAlias(type);
		String eviction = context.getStringAttribute("eviction", "LRU");
		Class<? extends Cache> evictionClass = typeAliasRegistry
				.resolveAlias(eviction);
		Long flushInterval = context.getLongAttribute("flushInterval");
		Integer size = context.getIntAttribute("size");
		boolean readWrite = !context.getBooleanAttribute("readOnly", false);
		Properties props = context.getChildrenAsProperties();
		builderAssistant.useNewCache(typeClass, evictionClass,
				flushInterval, size, readWrite, props);
	}
}
 
Example 7
Source Project: mybatis   Source File: XMLMapperBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void configurationElement(XNode context) {
  try {
    //1.配置namespace
    String namespace = context.getStringAttribute("namespace");
    if (namespace.equals("")) {
      throw new BuilderException("Mapper's namespace cannot be empty");
    }
    builderAssistant.setCurrentNamespace(namespace);
    //2.配置cache-ref
    cacheRefElement(context.evalNode("cache-ref"));
    //3.配置cache
    cacheElement(context.evalNode("cache"));
    //4.配置parameterMap(已经废弃,老式风格的参数映射)
    parameterMapElement(context.evalNodes("/mapper/parameterMap"));
    //5.配置resultMap(高级功能)
    resultMapElements(context.evalNodes("/mapper/resultMap"));
    //6.配置sql(定义可重用的 SQL 代码段)
    sqlElement(context.evalNodes("/mapper/sql"));
    //7.配置select|insert|update|delete TODO
    buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
  } catch (Exception e) {
    throw new BuilderException("Error parsing Mapper XML. Cause: " + e, e);
  }
}
 
Example 8
Source Project: Shop-for-JavaWeb   Source File: XMLMapperBuilder.java    License: MIT License 6 votes vote down vote up
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);
}
 
Example 9
Source Project: mybatis   Source File: XMLMapperBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 10
Source Project: Shop-for-JavaWeb   Source File: XMLMapperBuilder.java    License: MIT License 6 votes vote down vote up
private boolean databaseIdMatchesCurrent(String id, String databaseId,
		String requiredDatabaseId) {
	if (requiredDatabaseId != null) {
		if (!requiredDatabaseId.equals(databaseId)) {
			return false;
		}
	} else {
		if (databaseId != null) {
			return false;
		}
		// skip this fragment if there is a previous one with a not null
		// databaseId
		if (this.sqlFragments.containsKey(id)) {
			XNode context = this.sqlFragments.get(id);
			if (context.getStringAttribute("databaseId") != null) {
				return false;
			}
		}
	}
	return true;
}
 
Example 11
Source Project: mybaties   Source File: XMLScriptBuilder.java    License: Apache License 2.0 6 votes vote down vote up
List<SqlNode> parseDynamicTags(XNode node) {
  List<SqlNode> contents = new ArrayList<SqlNode>();
  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 = nodeHandlers(nodeName);
      if (handler == null) {
        throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");
      }
      handler.handleNode(child, contents);
      isDynamic = true;
    }
  }
  return contents;
}
 
Example 12
Source Project: mybatis   Source File: XMLScriptBuilder.java    License: Apache License 2.0 6 votes vote down vote up
List<SqlNode> parseDynamicTags(XNode node) {
  List<SqlNode> contents = new ArrayList<SqlNode>();
  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 = nodeHandlers(nodeName);
      if (handler == null) {
        throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");
      }
      handler.handleNode(child, contents);
      isDynamic = true;
    }
  }
  return contents;
}
 
Example 13
Source Project: mybaties   Source File: XMLMapperBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) {
  if (requiredDatabaseId != null) {
    if (!requiredDatabaseId.equals(databaseId)) {
      return false;
    }
  } else {
    if (databaseId != null) {
      return false;
    }
    // skip this fragment if there is a previous one with a not null databaseId
    //如果有重名的id了
    //<sql id="userColumns"> id,username,password </sql>
    if (this.sqlFragments.containsKey(id)) {
      XNode context = this.sqlFragments.get(id);
      //如果之前那个重名的sql id有databaseId,则false,否则难道true?这样新的sql覆盖老的sql???
      if (context.getStringAttribute("databaseId") != null) {
        return false;
      }
    }
  }
  return true;
}
 
Example 14
Source Project: mybaties   Source File: XMLMapperBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private void configurationElement(XNode context) {
  try {
    //1.配置namespace
    String namespace = context.getStringAttribute("namespace");
    if (namespace.equals("")) {
      throw new BuilderException("Mapper's namespace cannot be empty");
    }
    builderAssistant.setCurrentNamespace(namespace);
    //2.配置cache-ref
    cacheRefElement(context.evalNode("cache-ref"));
    //3.配置cache
    cacheElement(context.evalNode("cache"));
    //4.配置parameterMap(已经废弃,老式风格的参数映射)
    parameterMapElement(context.evalNodes("/mapper/parameterMap"));
    //5.配置resultMap(高级功能)
    resultMapElements(context.evalNodes("/mapper/resultMap"));
    //6.配置sql(定义可重用的 SQL 代码段)
    sqlElement(context.evalNodes("/mapper/sql"));
    //7.配置select|insert|update|delete TODO
    buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
  } catch (Exception e) {
    throw new BuilderException("Error parsing Mapper XML. Cause: " + e, e);
  }
}
 
Example 15
Source Project: mybatis   Source File: XMLIncludeTransformer.java    License: Apache License 2.0 5 votes vote down vote up
private Node findSqlFragment(String refid) {
  refid = PropertyParser.parse(refid, configuration.getVariables());
  refid = builderAssistant.applyCurrentNamespace(refid, true);
  try {
    //去之前存到内存map的SQL片段中寻找
    XNode nodeToInclude = configuration.getSqlFragments().get(refid);
    //clone一下,以防改写?
    return nodeToInclude.getNode().cloneNode(true);
  } catch (IllegalArgumentException e) {
    throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
  }
}
 
Example 16
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).newInstance();
            interceptorInstance.setProperties(properties);
            configuration.addInterceptor(interceptorInstance);
        }
    }
}
 
Example 17
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 18
private void objectWrapperFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    ObjectWrapperFactory factory = (ObjectWrapperFactory) resolveClass(type).newInstance();
    configuration.setObjectWrapperFactory(factory);
  }
}
 
Example 19
private void reflectionFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance();
    configuration.setReflectorFactory(factory);
  }
}
 
Example 20
Source Project: mybaties   Source File: XMLStatementBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void processSelectKeyNodes(String id, Class<?> parameterTypeClass, LanguageDriver langDriver) {
  List<XNode> selectKeyNodes = context.evalNodes("selectKey");
  if (configuration.getDatabaseId() != null) {
    parseSelectKeyNodes(id, selectKeyNodes, parameterTypeClass, langDriver, configuration.getDatabaseId());
  }
  parseSelectKeyNodes(id, selectKeyNodes, parameterTypeClass, langDriver, null);
  removeSelectKeyNodes(selectKeyNodes);
}
 
Example 21
private void settingsElement(XNode context) throws Exception {
    if (context != null) {
        Properties props = context.getChildrenAsProperties();
        // Check that all settings are known to the configuration class
        MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);
        for (Object key : props.keySet()) {
            if (!metaConfig.hasSetter(String.valueOf(key))) {
                throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
            }
        }
        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
        configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
        configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
        configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
        configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
        configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
        configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
        configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
        configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
        configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
        configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
        configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
        configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
        configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
        configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
        configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
        configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
        configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
        configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
        configuration.setLogPrefix(props.getProperty("logPrefix"));
        configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    }
}
 
Example 22
Source Project: mybaties   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void objectFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties properties = context.getChildrenAsProperties();
    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
    factory.setProperties(properties);
    configuration.setObjectFactory(factory);
  }
}
 
Example 23
Source Project: mybatis   Source File: XMLMapperBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private XMLMapperBuilder(XPathParser parser, Configuration configuration, String resource, Map<String, XNode> sqlFragments) {
  super(configuration);
  this.builderAssistant = new MapperBuilderAssistant(configuration, resource);
  this.parser = parser;
  this.sqlFragments = sqlFragments;
  this.resource = resource;
}
 
Example 24
Source Project: mumu   Source File: MapperScanApplication.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 加载别名
 * @param configuration
 */
private void handleTypeAlias(Configuration configuration, XNode root) {
	log.info("load alias message...........................");
	TypeAliasRegistry typeAliasRegistry = configuration.getTypeAliasRegistry();
	XNode parent = root.evalNode("typeAliases");
	if(parent!=null){
		for (XNode child : parent.getChildren()) {
			if ("package".equals(child.getName())) {
				String typeAliasPackage = child.getStringAttribute("name");
				configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
				log.info("package:"+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);
					}
					log.info("alias:"+alias+"   type:"+clazz);
				} catch (ClassNotFoundException e) {
					throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
				}
			}
		}
	}
}
 
Example 25
Source Project: QuickProject   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void objectWrapperFactoryElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    ObjectWrapperFactory factory = (ObjectWrapperFactory) resolveClass(type).newInstance();
    configuration.setObjectWrapperFactory(factory);
  }
}
 
Example 26
Source Project: mybatis   Source File: XMLMapperBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void cacheRefElement(XNode context) {
  if (context != null) {
    //增加cache-ref
    configuration.addCacheRef(builderAssistant.getCurrentNamespace(), context.getStringAttribute("namespace"));
    CacheRefResolver cacheRefResolver = new CacheRefResolver(builderAssistant, context.getStringAttribute("namespace"));
    try {
      cacheRefResolver.resolveCacheRef();
    } catch (IncompleteElementException e) {
      configuration.addIncompleteCacheRef(cacheRefResolver);
    }
  }
}
 
Example 27
Source Project: mybaties   Source File: XMLConfigBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private TransactionFactory transactionManagerElement(XNode context) throws Exception {
  if (context != null) {
    String type = context.getStringAttribute("type");
    Properties props = context.getChildrenAsProperties();
//根据type="JDBC"解析返回适当的TransactionFactory
    TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance();
    factory.setProperties(props);
    return factory;
  }
  throw new BuilderException("Environment declaration requires a TransactionFactory.");
}
 
Example 28
Source Project: Shop-for-JavaWeb   Source File: XMLMapperBuilder.java    License: MIT License 5 votes vote down vote up
@Deprecated
public XMLMapperBuilder(Reader reader, Configuration configuration,
		String resource, Map<String, XNode> sqlFragments) {
	this(new XPathParser(reader, true, configuration.getVariables(),
			new XMLMapperEntityResolver()), configuration, resource,
			sqlFragments);
}
 
Example 29
Source Project: mybatis   Source File: XMLScriptBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private void handleWhenOtherwiseNodes(XNode chooseSqlNode, List<SqlNode> ifSqlNodes, List<SqlNode> defaultSqlNodes) {
  List<XNode> children = chooseSqlNode.getChildren();
  for (XNode child : children) {
    String nodeName = child.getNode().getNodeName();
    NodeHandler handler = nodeHandlers(nodeName);
    if (handler instanceof IfHandler) {
      handler.handleNode(child, ifSqlNodes);
    } else if (handler instanceof OtherwiseHandler) {
      handler.handleNode(child, defaultSqlNodes);
    }
  }
}
 
Example 30
Source Project: Shop-for-JavaWeb   Source File: XMLMapperBuilder.java    License: MIT License 5 votes vote down vote up
private XMLMapperBuilder(XPathParser parser, Configuration configuration,
		String resource, Map<String, XNode> sqlFragments) {
	super(configuration);
	this.builderAssistant = new MapperBuilderAssistant(configuration,
			resource);
	this.parser = parser;
	this.sqlFragments = sqlFragments;
	this.resource = resource;
}