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

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

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

Configuration.addMapper介绍

暂无

代码示例

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

private void retryBindMapperForNamespace() {
  if (!configuration.hasMapper(mapperType)) {
   // Spring may not know the real resource name so we set a flag
   // to prevent loading again this resource from the mapper interface
   // look at MapperAnnotationBuilder#loadXmlResource
   configuration.addLoadedResource("namespace:" + mapperType.getName());
   configuration.addMapper(mapperType);
  }
 }
}

代码示例来源: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: Activiti/Activiti

public void initCustomMybatisMappers(Configuration configuration) {
 if (getCustomMybatisMappers() != null) {
  for (Class<?> clazz : getCustomMybatisMappers()) {
   configuration.addMapper(clazz);
  }
 }
}

代码示例来源: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: 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: abel533/Mapper

/**
 * {@inheritDoc}
 */
@Override
protected void checkDaoConfig() {
  super.checkDaoConfig();
  notNull(this.mapperInterface, "Property 'mapperInterface' is required");
  Configuration configuration = getSqlSession().getConfiguration();
  if (this.addToConfig && !configuration.hasMapper(this.mapperInterface)) {
    try {
      configuration.addMapper(this.mapperInterface);
    } catch (Exception e) {
      logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", e);
      throw new IllegalArgumentException(e);
    } finally {
      ErrorContext.instance().reset();
    }
  }
  //直接针对接口处理通用接口方法对应的 MappedStatement 是安全的,通用方法不会出现 IncompleteElementException 的情况
  if (configuration.hasMapper(this.mapperInterface) && mapperHelper != null && mapperHelper.isExtendCommonMapper(this.mapperInterface)) {
    mapperHelper.processConfiguration(getSqlSession().getConfiguration(), this.mapperInterface);
  }
}

代码示例来源:origin: abel533/Mapper

/**
 * {@inheritDoc}
 */
@Override
protected void checkDaoConfig() {
  super.checkDaoConfig();
  notNull(this.mapperInterface, "Property 'mapperInterface' is required");
  Configuration configuration = getSqlSession().getConfiguration();
  if (this.addToConfig && !configuration.hasMapper(this.mapperInterface)) {
    try {
      configuration.addMapper(this.mapperInterface);
    } catch (Exception e) {
      logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", e);
      throw new IllegalArgumentException(e);
    } finally {
      ErrorContext.instance().reset();
    }
  }
  //直接针对接口处理通用接口方法对应的 MappedStatement 是安全的,通用方法不会出现 IncompleteElementException 的情况
  if (configuration.hasMapper(this.mapperInterface) && mapperHelper != null && mapperHelper.isExtendCommonMapper(this.mapperInterface)) {
    mapperHelper.processConfiguration(getSqlSession().getConfiguration(), this.mapperInterface);
  }
}

代码示例来源:origin: Meituan-Dianping/Zebra

/**
 * {@inheritDoc}
 */
@Override
protected void checkDaoConfig() {
  super.checkDaoConfig();
  notNull(this.mapperInterface, "Property 'mapperInterface' is required");
  Configuration configuration = getSqlSession().getConfiguration();
  if (this.addToConfig && !configuration.hasMapper(this.mapperInterface)) {
    try {
      configuration.addMapper(this.mapperInterface);
    } catch (Throwable t) {
      logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", t);
      throw new IllegalArgumentException(t);
    } finally {
      ErrorContext.instance().reset();
    }
  }
}

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

private void bindMapperForNamespace() {
 String namespace = builderAssistant.getCurrentNamespace();
 if (namespace != null) {
  Class<?> boundType = null;
  try {
   boundType = Resources.classForName(namespace);
  } catch (ClassNotFoundException e) {
   //ignore, bound type is not required
  }
  if (boundType != null) {
   if (!configuration.hasMapper(boundType)) {
    // Spring may not know the real resource name so we set a flag
    // to prevent loading again this resource from the mapper interface
    // look at MapperAnnotationBuilder#loadXmlResource
    configuration.addLoadedResource("namespace:" + namespace);
    configuration.addMapper(boundType);
   }
  }
 }
}

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

private void bindMapperForNamespace() {
 String namespace = builderAssistant.getCurrentNamespace();
 if (namespace != null) {
  Class<?> boundType = null;
  try {
   boundType = Resources.classForName(namespace);
  } catch (ClassNotFoundException e) {
   //ignore, bound type is not required
  }
  if (boundType != null) {
   if (!configuration.hasMapper(boundType)) {
    // Spring may not know the real resource name so we set a flag
    // to prevent loading again this resource from the mapper interface
    // look at MapperAnnotationBuilder#loadXmlResource
    configuration.addLoadedResource("namespace:" + namespace);
    configuration.addMapper(boundType);
   }
  }
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

private void retryBindMapperForNamespace() {
  if (!configuration.hasMapper(mapperType)) {
   // Spring may not know the real resource name so we set a flag
   // to prevent loading again this resource from the mapper interface
   // look at MapperAnnotationBuilder#loadXmlResource
   configuration.addLoadedResource("namespace:" + mapperType.getName());
   configuration.addMapper(mapperType);
  }
 }
}

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

public void initCustomMybatisMappers(Configuration configuration) {
 if (getCustomMybatisMappers() != null) {
  for (Class<?> clazz : getCustomMybatisMappers()) {
   configuration.addMapper(clazz);
  }
 }
}

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

public void initCustomMybatisMappers(Configuration configuration) {
  if (getCustomMybatisMappers() != null) {
    for (Class<?> clazz : getCustomMybatisMappers()) {
      configuration.addMapper(clazz);
    }
  }
}

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

protected void initCustomMybatisMappers(Configuration configuration) {
  if (getCustomMybatisMappers() != null) {
    for (Class<?> clazz : getCustomMybatisMappers()) {
      configuration.addMapper(clazz);
    }
  }
}

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

public void initCustomMybatisMappers(Configuration configuration) {
  if (getCustomMybatisMappers() != null) {
    for (Class<?> clazz : getCustomMybatisMappers()) {
      configuration.addMapper(clazz);
    }
  }
}

代码示例来源:origin: org.apache.ibatis/ibatis-core

private void bindMapperForNamespace() {
 String namespace = builderAssistant.getCurrentNamespace();
 if (namespace != null) {
  Class boundType = null;
  try {
   boundType = Resources.classForName(namespace);
  } catch (ClassNotFoundException e) {
   //ignore, bound type is not required
  }
  if (boundType != null) {
   if (!configuration.hasMapper(boundType)) {
    configuration.addMapper(boundType);
   }
  }
 }
}

代码示例来源:origin: org.codehaus.griffon.plugins/griffon-mybatis-core

@Nonnull
@SuppressWarnings("ConstantConditions")
private SqlSessionFactory createSqlSessionFactory(@Nonnull Map<String, Object> config, @Nonnull String dataSourceName) {
  DataSource dataSource = getDataSource(dataSourceName);
  Environment environment = new Environment(dataSourceName, new JdbcTransactionFactory(), dataSource);
  Configuration configuration = new Configuration(environment);
  Map<String, Object> copyOfConfig = new LinkedHashMap<>(config);
  copyOfConfig.remove("connect_on_startup");
  GriffonClassUtils.setProperties(configuration, copyOfConfig);
  if (mappers.isEmpty()) {
    readMappers();
  }
  for (Class<?> mapper : mappers) {
    configuration.addMapper(mapper);
  }
  return new RecordingSqlSessionFactory(new SqlSessionFactoryBuilder().build(configuration));
}

代码示例来源:origin: Meituan-Dianping/Leaf

public IDAllocDaoImpl(DataSource dataSource) {
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("development", transactionFactory, dataSource);
  Configuration configuration = new Configuration(environment);
  configuration.addMapper(IDAllocMapper.class);
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}

代码示例来源:origin: jneat/mybatis-types

static synchronized void setupSessionFactoryBuilder(DataSource ds) {
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("jneat", transactionFactory, ds);
  Configuration configuration = new Configuration(environment);
  configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis");
  configuration.setMapUnderscoreToCamelCase(true);
  // Add Mappers
  configuration.addMapper(TypesMapper.class);
  configuration.addMapper(ArraysMapper.class);
  configuration.addMapper(TimeMapper.class);
  ssf = new SqlSessionFactoryBuilder().build(configuration);
}

代码示例来源:origin: jneat/mybatis-jackson

protected static SqlSessionFactory setUpDb(DataSource ds, String initSql) throws SQLException, IOException {
    try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) {
      st.execute(getResourceAsString(initSql));
    }

    // Init mybatis
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("jneat", transactionFactory, ds);
    Configuration configuration = new Configuration(environment);
    configuration.getTypeHandlerRegistry().register("com.github.jneat.mybatis");
    configuration.addMapper(JsonMapper.class);

    return new SqlSessionFactoryBuilder().build(configuration);
  }
}

相关文章

微信公众号

最新文章

更多

Configuration类方法