org.apache.ibatis.session.Configuration.getSqlFragments()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中org.apache.ibatis.session.Configuration.getSqlFragments()方法的一些代码示例,展示了Configuration.getSqlFragments()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getSqlFragments()方法的具体详情如下:
包路径:org.apache.ibatis.session.Configuration
类名称:Configuration
方法名:getSqlFragments

Configuration.getSqlFragments介绍

暂无

代码示例

代码示例来源:origin: baomidou/mybatis-plus

/**
   * 清理sql节点缓存
   *
   * @param list ignore
   * @param namespace ignore
   */
  private void cleanSqlElement(List<XNode> list, String namespace) {
    for (XNode context : list) {
      String id = context.getStringAttribute("id");
      configuration.getSqlFragments().remove(id);
      configuration.getSqlFragments().remove(namespace + StringPool.DOT + id);
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

void loadMapper(Class mapperClass) {
 String configFile = configFilePath(mapperClass);
 InputStream input = null;
 try {
  input = mapperClass.getResourceAsStream(configFile);
  checkArgument(input != null, format("Can not find mapper XML file %s", configFile));
  new SQXMLMapperBuilder(mapperClass, input, conf, conf.getSqlFragments()).parse();
  loadAndConfigureLogger(mapperClass.getName());
 } catch (Exception e) {
  throw new IllegalArgumentException("Unable to load mapper " + mapperClass, e);
 } finally {
  Closeables.closeQuietly(input);
 }
}

代码示例来源:origin: baomidou/mybatis-plus

private void loadXmlResource() {
  // Spring may not know the real resource name so we check a flag
  // to prevent loading again a resource twice
  // this flag is set at XMLMapperBuilder#bindMapperForNamespace
  if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
    String xmlResource = type.getName().replace('.', '/') + ".xml";
    // #1347
    InputStream inputStream = type.getResourceAsStream("/" + xmlResource);
    if (inputStream == null) {
      // Search XML mapper that is not in the module but in the classpath.
      try {
        inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
      } catch (IOException e2) {
        // ignore, resource is not required
      }
    }
    if (inputStream != null) {
      XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
      xmlParser.parse();
    }
  }
}

代码示例来源:origin: Activiti/Activiti

public Configuration parseCustomMybatisXMLMappers(Configuration configuration) {
 if (getCustomMybatisXMLMappers() != null)
  // see XMLConfigBuilder.mapperElement()
  for (String resource : getCustomMybatisXMLMappers()) {
   XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments());
   mapperParser.parse();
  }
 return configuration;
}

代码示例来源:origin: baomidou/mybatis-plus

XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(),
  sqlSessionFactory.getConfiguration(),
  resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments());
xmlMapperBuilder.parse();
logger.debug("refresh: '" + resource + "', success!");

代码示例来源:origin: baomidou/mybatis-plus

private void mapperElement(XNode parent) throws Exception {
  /*
   * 定义集合 用来分类放置mybatis的Mapper与XML 按顺序依次遍历
   */
  if (parent != null) {
    //指定在classpath中的mapper文件
    Set<String> resources = new HashSet<>();
    //指向一个mapper接口
    Set<Class<?>> mapperClasses = new HashSet<>();
    setResource(parent, resources, mapperClasses);
    // 依次遍历 首先 resource 然后 mapper
    for (String resource : resources) {
      ErrorContext.instance().resource(resource);
      InputStream inputStream = Resources.getResourceAsStream(resource);
      //TODO
      XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource,
        configuration.getSqlFragments());
      mapperParser.parse();
    }
    for (Class<?> mapper : mapperClasses) {
      //TODO
      configuration.addMapper(mapper);
    }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

private void loadXmlResource() {
 // Spring may not know the real resource name so we check a flag
 // to prevent loading again a resource twice
 // this flag is set at XMLMapperBuilder#bindMapperForNamespace
 if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
  String xmlResource = type.getName().replace('.', '/') + ".xml";
  InputStream inputStream = null;
  try {
   inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
  } catch (IOException e) {
   // ignore, resource is not required
  }
  if (inputStream != null) {
   XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
   xmlParser.parse();
  }
 }
}

代码示例来源:origin: org.mybatis/mybatis

private void loadXmlResource() {
 // Spring may not know the real resource name so we check a flag
 // to prevent loading again a resource twice
 // this flag is set at XMLMapperBuilder#bindMapperForNamespace
 if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
  String xmlResource = type.getName().replace('.', '/') + ".xml";
  // #1347
  InputStream inputStream = type.getResourceAsStream("/" + xmlResource);
  if (inputStream == null) {
   // Search XML mapper that is not in the module but in the classpath.
   try {
    inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
   } catch (IOException e2) {
    // ignore, resource is not required
   }
  }
  if (inputStream != null) {
   XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
   xmlParser.parse();
  }
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

private Node findSqlFragment(String refid, Properties variables) {
 refid = PropertyParser.parse(refid, variables);
 refid = builderAssistant.applyCurrentNamespace(refid, true);
 try {
  XNode nodeToInclude = configuration.getSqlFragments().get(refid);
  return nodeToInclude.getNode().cloneNode(true);
 } catch (IllegalArgumentException e) {
  throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
 }
}

代码示例来源:origin: org.mybatis/mybatis

private Node findSqlFragment(String refid, Properties variables) {
 refid = PropertyParser.parse(refid, variables);
 refid = builderAssistant.applyCurrentNamespace(refid, true);
 try {
  XNode nodeToInclude = configuration.getSqlFragments().get(refid);
  return nodeToInclude.getNode().cloneNode(true);
 } catch (IllegalArgumentException e) {
  throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

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.");
    }
   }
  }
 }
}

代码示例来源:origin: org.mybatis/mybatis

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.");
    }
   }
  }
 }
}

代码示例来源:origin: com.baomidou/mybatis-plus-extension

/**
   * 清理sql节点缓存
   *
   * @param list
   * @param namespace
   */
  private void cleanSqlElement(List<XNode> list, String namespace) {
    for (XNode context : list) {
      String id = context.getStringAttribute("id");
      configuration.getSqlFragments().remove(id);
      configuration.getSqlFragments().remove(namespace + StringPool.DOT + id);
    }
  }
}

代码示例来源:origin: mybatis-book/book

public static void main(String[] args) throws IOException {
  UnpooledDataSource dataSource = new UnpooledDataSource(
      "com.mysql.jdbc.Driver", 
      "jdbc:mysql://localhost:3306/mybatis", 
      "root", 
      "");
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Java", transactionFactory, dataSource);
  
  Configuration configuration = new Configuration(environment);
  configuration.getTypeAliasRegistry().registerAliases("tk.mybatis.simple.model");
  configuration.setLogImpl(Log4jImpl.class);
  
  InputStream inputStream = Resources.getResourceAsStream("tk/mybatis/simple/mapper/CountryMapper.xml");
  XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, "tk/mybatis/simple/mapper/CountryMapper.xml", configuration.getSqlFragments());
  mapperParser.parse();
  
  SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    List<Country> countryList = sqlSession.selectList("selectAll");
    printCountryList(countryList);
  } finally {
    sqlSession.close();
  }
}

代码示例来源:origin: youtongluan/sumk

SqlSessionFactory sqlParse() throws Exception {
  Map<String, InputStream> sqls = MybatisSqlXmlUtils.openInputs(db);
  Set<Map.Entry<String, InputStream>> entries = sqls.entrySet();
  for (Map.Entry<String, InputStream> entry : entries) {
    InputStream in = entry.getValue();
    XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, entry.getKey(),
        configuration.getSqlFragments());
    xmlMapperBuilder.parse();
    in.close();
  }
  return this;
}

代码示例来源:origin: org.flowable/flowable-engine-common

protected void parseMybatisXmlMapping(Configuration configuration, String resource) {
  // see XMLConfigBuilder.mapperElement()
  XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments());
  mapperParser.parse();
}

代码示例来源:origin: org.ow2.petals.flowable/flowable-engine-common

protected void parseMybatisXmlMapping(Configuration configuration, String resource) {
  // see XMLConfigBuilder.mapperElement()
  XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments());
  mapperParser.parse();
}

代码示例来源:origin: io.github.itfinally/mybatis-jpa

@Override
  public ResultMap call() throws Exception {
    if ( !configuration.hasResultMap( token.getResultMapId() ) ) {
      try ( InputStream in = new ByteArrayInputStream( ResultMapBuilder
          .build( token, metadata ).getBytes() ) ) {
        new XMLMapperBuilder( in, configuration, token.getResultMapId(), configuration.getSqlFragments() ).parse();
      }
    }
    return configuration.getResultMap( token.getResultMapId() );
  }
} );

代码示例来源:origin: org.activiti/activiti-engine

public Configuration parseCustomMybatisXMLMappers(Configuration configuration) {
 if (getCustomMybatisXMLMappers() != null)
  // see XMLConfigBuilder.mapperElement()
  for (String resource : getCustomMybatisXMLMappers()) {
   XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource), configuration, resource, configuration.getSqlFragments());
   mapperParser.parse();
  }
 return configuration;
}

代码示例来源:origin: org.flowable/flowable5-engine

protected Configuration parseCustomMybatisXMLMappers(Configuration configuration) {
  if (getCustomMybatisXMLMappers() != null)
    // see XMLConfigBuilder.mapperElement()
    for (String resource : getCustomMybatisXMLMappers()) {
      XMLMapperBuilder mapperParser = new XMLMapperBuilder(getResourceAsStream(resource),
          configuration, resource, configuration.getSqlFragments());
      mapperParser.parse();
    }
  return configuration;
}

相关文章

Configuration类方法