示例#1
0
 private String processNestedResultMappings(XNode context, List<ResultMapping> resultMappings)
     throws Exception {
   if ("association".equals(context.getName())
       || "collection".equals(context.getName())
       || "case".equals(context.getName())) {
     if (context.getStringAttribute("select") == null) {
       ResultMap resultMap = resultMapElement(context, resultMappings);
       return resultMap.getId();
     }
   }
   return null;
 }
 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.");
         }
       }
     }
   }
 }
 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);
         }
       }
     }
   }
 }
示例#4
0
 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;
   }
 }
示例#5
0
 private void processConstructorElement(
     XNode resultChild, Class<?> resultType, List<ResultMapping> resultMappings) throws Exception {
   List<XNode> argChildren = resultChild.getChildren();
   for (XNode argChild : argChildren) {
     ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
     flags.add(ResultFlag.CONSTRUCTOR);
     if ("idArg".equals(argChild.getName())) {
       flags.add(ResultFlag.ID);
     }
     resultMappings.add(buildResultMappingFromContext(argChild, resultType, flags));
   }
 }
 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);
         }
       }
     }
   }
 }