org.apache.ibatis.builder.IncompleteElementException Java Examples

The following examples show how to use org.apache.ibatis.builder.IncompleteElementException. 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
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
private void parsePendingStatements() {
	Collection<XMLStatementBuilder> incompleteStatements = configuration
			.getIncompleteStatements();
	synchronized (incompleteStatements) {
		Iterator<XMLStatementBuilder> iter = incompleteStatements
				.iterator();
		while (iter.hasNext()) {
			try {
				iter.next().parseStatementNode();
				iter.remove();
			} catch (IncompleteElementException e) {
				// Statement is still missing a resource...
			}
		}
	}
}
 
Example #2
Source File: MapperAnnotationBuilder.java    From mybaties with Apache License 2.0 6 votes vote down vote up
public void parse() {
  String resource = type.toString();
  if (!configuration.isResourceLoaded(resource)) {
    loadXmlResource();
    configuration.addLoadedResource(resource);
    assistant.setCurrentNamespace(type.getName());
    parseCache();
    parseCacheRef();
    Method[] methods = type.getMethods();
    for (Method method : methods) {
      try {
        // issue #237
        if (!method.isBridge()) {
          parseStatement(method);
        }
      } catch (IncompleteElementException e) {
        configuration.addIncompleteMethod(new MethodResolver(this, method));
      }
    }
  }
  parsePendingMethods();
}
 
Example #3
Source File: MapperAnnotationBuilder.java    From mybatis with Apache License 2.0 6 votes vote down vote up
public void parse() {
  String resource = type.toString();
  if (!configuration.isResourceLoaded(resource)) {
    loadXmlResource();
    configuration.addLoadedResource(resource);
    assistant.setCurrentNamespace(type.getName());
    parseCache();
    parseCacheRef();
    Method[] methods = type.getMethods();
    for (Method method : methods) {
      try {
        // issue #237
        if (!method.isBridge()) {
          parseStatement(method);
        }
      } catch (IncompleteElementException e) {
        configuration.addIncompleteMethod(new MethodResolver(this, method));
      }
    }
  }
  parsePendingMethods();
}
 
Example #4
Source File: XMLMapperBuilder.java    From mybaties with 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 #5
Source File: XMLIncludeTransformer.java    From mybatis with 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 #6
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void resultMapElements(List<XNode> list) throws Exception {
    //基本上就是循环把resultMap加入到Configuration里去,保持2份,一份缩略,一分全名
  for (XNode resultMapNode : list) {
    try {
        //循环调resultMapElement
      resultMapElement(resultMapNode);
    } catch (IncompleteElementException e) {
      // ignore, it will be retried
    }
  }
}
 
Example #7
Source File: XMLMapperBuilder.java    From mybatis with 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 #8
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void parsePendingStatements() {
  Collection<XMLStatementBuilder> incompleteStatements = configuration.getIncompleteStatements();
  synchronized (incompleteStatements) {
    Iterator<XMLStatementBuilder> iter = incompleteStatements.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().parseStatementNode();
        iter.remove();
      } catch (IncompleteElementException e) {
        // Statement is still missing a resource...
      }
    }
  }
}
 
Example #9
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void parsePendingChacheRefs() {
  Collection<CacheRefResolver> incompleteCacheRefs = configuration.getIncompleteCacheRefs();
  synchronized (incompleteCacheRefs) {
    Iterator<CacheRefResolver> iter = incompleteCacheRefs.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolveCacheRef();
        iter.remove();
      } catch (IncompleteElementException e) {
        // Cache ref is still missing a resource...
      }
    }
  }
}
 
Example #10
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void parsePendingResultMaps() {
  Collection<ResultMapResolver> incompleteResultMaps = configuration.getIncompleteResultMaps();
  synchronized (incompleteResultMaps) {
    Iterator<ResultMapResolver> iter = incompleteResultMaps.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolve();
        iter.remove();
      } catch (IncompleteElementException e) {
        // ResultMap is still missing a resource...
      }
    }
  }
}
 
Example #11
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) {
  for (XNode context : list) {
    //构建所有语句,一个mapper下可以有很多select
    //语句比较复杂,核心都在这里面,所以调用XMLStatementBuilder
    final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId);
    try {
        //核心XMLStatementBuilder.parseStatementNode
      statementParser.parseStatementNode();
    } catch (IncompleteElementException e) {
        //如果出现SQL语句不完整,把它记下来,塞到configuration去
      configuration.addIncompleteStatement(statementParser);
    }
  }
}
 
Example #12
Source File: MapperAnnotationBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void parsePendingMethods() {
  Collection<MethodResolver> incompleteMethods = configuration.getIncompleteMethods();
  synchronized (incompleteMethods) {
    Iterator<MethodResolver> iter = incompleteMethods.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolve();
        iter.remove();
      } catch (IncompleteElementException e) {
        // This method is still missing a resource
      }
    }
  }
}
 
Example #13
Source File: XMLIncludeTransformer.java    From mybaties with 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 #14
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void resultMapElements(List<XNode> list) throws Exception {
    //基本上就是循环把resultMap加入到Configuration里去,保持2份,一份缩略,一分全名
  for (XNode resultMapNode : list) {
    try {
        //循环调resultMapElement
      resultMapElement(resultMapNode);
    } catch (IncompleteElementException e) {
      // ignore, it will be retried
    }
  }
}
 
Example #15
Source File: AnnotationStatementScanner.java    From mybatis-jpa with Apache License 2.0 5 votes vote down vote up
private void parsePendingMethods() {
  Collection<MethodResolver> incompleteMethods = configuration.getIncompleteMethods();
  synchronized (incompleteMethods) {
    Iterator<MethodResolver> iter = incompleteMethods.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolve();
        iter.remove();
      } catch (IncompleteElementException e) {
        // This method is still missing a resource
      }
    }
  }
}
 
Example #16
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void parsePendingStatements() {
  Collection<XMLStatementBuilder> incompleteStatements = configuration.getIncompleteStatements();
  synchronized (incompleteStatements) {
    Iterator<XMLStatementBuilder> iter = incompleteStatements.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().parseStatementNode();
        iter.remove();
      } catch (IncompleteElementException e) {
        // Statement is still missing a resource...
      }
    }
  }
}
 
Example #17
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void parsePendingChacheRefs() {
  Collection<CacheRefResolver> incompleteCacheRefs = configuration.getIncompleteCacheRefs();
  synchronized (incompleteCacheRefs) {
    Iterator<CacheRefResolver> iter = incompleteCacheRefs.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolveCacheRef();
        iter.remove();
      } catch (IncompleteElementException e) {
        // Cache ref is still missing a resource...
      }
    }
  }
}
 
Example #18
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void parsePendingResultMaps() {
  Collection<ResultMapResolver> incompleteResultMaps = configuration.getIncompleteResultMaps();
  synchronized (incompleteResultMaps) {
    Iterator<ResultMapResolver> iter = incompleteResultMaps.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolve();
        iter.remove();
      } catch (IncompleteElementException e) {
        // ResultMap is still missing a resource...
      }
    }
  }
}
 
Example #19
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) {
  for (XNode context : list) {
    //构建所有语句,一个mapper下可以有很多select
    //语句比较复杂,核心都在这里面,所以调用XMLStatementBuilder
    final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId);
    try {
        //核心XMLStatementBuilder.parseStatementNode
      statementParser.parseStatementNode();
    } catch (IncompleteElementException e) {
        //如果出现SQL语句不完整,把它记下来,塞到configuration去
      configuration.addIncompleteStatement(statementParser);
    }
  }
}
 
Example #20
Source File: MapperAnnotationBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void parsePendingMethods() {
  Collection<MethodResolver> incompleteMethods = configuration.getIncompleteMethods();
  synchronized (incompleteMethods) {
    Iterator<MethodResolver> iter = incompleteMethods.iterator();
    while (iter.hasNext()) {
      try {
        iter.next().resolve();
        iter.remove();
      } catch (IncompleteElementException e) {
        // This method is still missing a resource
      }
    }
  }
}
 
Example #21
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
private void resultMapElements(List<XNode> list) throws Exception {
	for (XNode resultMapNode : list) {
		try {
			resultMapElement(resultMapNode);
		} catch (IncompleteElementException e) {
			// ignore, it will be retried
		}
	}
}
 
Example #22
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
private void cacheRefElement(XNode context) {
	if (context != null) {
		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 #23
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
private void parsePendingChacheRefs() {
	Collection<CacheRefResolver> incompleteCacheRefs = configuration
			.getIncompleteCacheRefs();
	synchronized (incompleteCacheRefs) {
		Iterator<CacheRefResolver> iter = incompleteCacheRefs.iterator();
		while (iter.hasNext()) {
			try {
				iter.next().resolveCacheRef();
				iter.remove();
			} catch (IncompleteElementException e) {
				// Cache ref is still missing a resource...
			}
		}
	}
}
 
Example #24
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
private void parsePendingResultMaps() {
	Collection<ResultMapResolver> incompleteResultMaps = configuration
			.getIncompleteResultMaps();
	synchronized (incompleteResultMaps) {
		Iterator<ResultMapResolver> iter = incompleteResultMaps.iterator();
		while (iter.hasNext()) {
			try {
				iter.next().resolve();
				iter.remove();
			} catch (IncompleteElementException e) {
				// ResultMap is still missing a resource...
			}
		}
	}
}
 
Example #25
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
private void buildStatementFromContext(List<XNode> list,
		String requiredDatabaseId) {
	for (XNode context : list) {
		final XMLStatementBuilder statementParser = new XMLStatementBuilder(
				configuration, builderAssistant, context,
				requiredDatabaseId);
		try {
			statementParser.parseStatementNode();
		} catch (IncompleteElementException e) {
			configuration.addIncompleteStatement(statementParser);
		}
	}
}
 
Example #26
Source File: XMLMapperBuilder.java    From mybaties with Apache License 2.0 4 votes vote down vote up
private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings) throws Exception {
    //错误上下文
//取得标示符   ("resultMap[userResultMap]")
//    <resultMap id="userResultMap" type="User">
//      <id property="id" column="user_id" />
//      <result property="username" column="username"/>
//      <result property="password" column="password"/>
//    </resultMap>
    ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
    String id = resultMapNode.getStringAttribute("id",
        resultMapNode.getValueBasedIdentifier());
    //一般拿type就可以了,后面3个难道是兼容老的代码?
    String type = resultMapNode.getStringAttribute("type",
        resultMapNode.getStringAttribute("ofType",
            resultMapNode.getStringAttribute("resultType",
                resultMapNode.getStringAttribute("javaType"))));
    //高级功能,还支持继承?
//  <resultMap id="carResult" type="Car" extends="vehicleResult">
//    <result property="doorCount" column="door_count" />
//  </resultMap>
    String extend = resultMapNode.getStringAttribute("extends");
    //autoMapping
    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())) {
        //解析result map的constructor
        processConstructorElement(resultChild, typeClass, resultMappings);
      } else if ("discriminator".equals(resultChild.getName())) {
        //解析result map的discriminator
        discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
      } else {
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        if ("id".equals(resultChild.getName())) {
          flags.add(ResultFlag.ID);
        }
        //调5.1.1 buildResultMappingFromContext,得到ResultMapping
        resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
      }
    }
    //最后再调ResultMapResolver得到ResultMap
    ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
    try {
      return resultMapResolver.resolve();
    } catch (IncompleteElementException  e) {
      configuration.addIncompleteResultMap(resultMapResolver);
      throw e;
    }
  }
 
Example #27
Source File: XMLMapperBuilder.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
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 {
			ArrayList<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;
	}
}
 
Example #28
Source File: XMLMapperBuilder.java    From mybatis with Apache License 2.0 4 votes vote down vote up
private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings) throws Exception {
    //错误上下文
//取得标示符   ("resultMap[userResultMap]")
//    <resultMap id="userResultMap" type="User">
//      <id property="id" column="user_id" />
//      <result property="username" column="username"/>
//      <result property="password" column="password"/>
//    </resultMap>
    ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
    String id = resultMapNode.getStringAttribute("id",
        resultMapNode.getValueBasedIdentifier());
    //一般拿type就可以了,后面3个难道是兼容老的代码?
    String type = resultMapNode.getStringAttribute("type",
        resultMapNode.getStringAttribute("ofType",
            resultMapNode.getStringAttribute("resultType",
                resultMapNode.getStringAttribute("javaType"))));
    //高级功能,还支持继承?
//  <resultMap id="carResult" type="Car" extends="vehicleResult">
//    <result property="doorCount" column="door_count" />
//  </resultMap>
    String extend = resultMapNode.getStringAttribute("extends");
    //autoMapping
    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())) {
        //解析result map的constructor
        processConstructorElement(resultChild, typeClass, resultMappings);
      } else if ("discriminator".equals(resultChild.getName())) {
        //解析result map的discriminator
        discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
      } else {
        List<ResultFlag> flags = new ArrayList<ResultFlag>();
        if ("id".equals(resultChild.getName())) {
          flags.add(ResultFlag.ID);
        }
        //调5.1.1 buildResultMappingFromContext,得到ResultMapping
        resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
      }
    }
    //最后再调ResultMapResolver得到ResultMap
    ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
    try {
      return resultMapResolver.resolve();
    } catch (IncompleteElementException  e) {
      configuration.addIncompleteResultMap(resultMapResolver);
      throw e;
    }
  }