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

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

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

Configuration.addMappedStatement介绍

暂无

代码示例

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

@Override
public void addMappedStatement(MappedStatement ms) {
  try {
    super.addMappedStatement(ms);
    //没有任何配置时,使用默认配置
    if (this.mapperHelper == null) {
      this.mapperHelper = new MapperHelper();
    }
    this.mapperHelper.processMappedStatement(ms);
  } catch (IllegalArgumentException e) {
    //这里的异常是导致 Spring 启动死循环的关键位置,为了避免后续会吞异常,这里直接输出
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}

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

@Override
public void addMappedStatement(MappedStatement ms) {
  try {
    super.addMappedStatement(ms);
    //没有任何配置时,使用默认配置
    if (this.mapperHelper == null) {
      this.mapperHelper = new MapperHelper();
    }
    this.mapperHelper.processMappedStatement(ms);
  } catch (IllegalArgumentException e) {
    //这里的异常是导致 Spring 启动死循环的关键位置,为了避免后续会吞异常,这里直接输出
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}

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

/**
 * 创建一个MappedStatement
 *
 * @param mappedStatement
 * @param sqlSource       执行的sqlSource
 * @param sqlCommandType  执行的sqlCommandType
 */
@SuppressWarnings("serial")
private void createUpdateMappedStatement(String mappedStatement, SqlSource sqlSource, SqlCommandType sqlCommandType) {
  MappedStatement ms = new MappedStatement.Builder(configuration, mappedStatement, sqlSource, sqlCommandType).resultMaps(
    new ArrayList<ResultMap>() {
      {
        add(new ResultMap.Builder(configuration, "defaultResultMap", int.class, new ArrayList<>(0))
          .build());
      }
    }).build();
  // 缓存
  configuration.addMappedStatement(ms);
}

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

/**
 * 创建查询MappedStatement
 *
 * @param mappedStatement
 * @param sqlSource       执行的sqlSource
 * @param resultType      返回的结果类型
 */
@SuppressWarnings("serial")
private void createSelectMappedStatement(String mappedStatement, SqlSource sqlSource, final Class<?> resultType) {
  MappedStatement ms = new MappedStatement.Builder(configuration, mappedStatement, sqlSource, SqlCommandType.SELECT)
    .resultMaps(new ArrayList<ResultMap>() {
      {
        add(new ResultMap.Builder(configuration, "defaultResultMap", resultType, new ArrayList<>(0))
          .build());
      }
    }).build();
  // 缓存
  configuration.addMappedStatement(ms);
}

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

/**
 * MybatisPlus 加载 SQL 顺序:
 * <p>1、加载XML中的SQL</p>
 * <p>2、加载sqlProvider中的SQL</p>
 * <p>3、xmlSql 与 sqlProvider不能包含相同的SQL</p>
 * <p>调整后的SQL优先级:xmlSql > sqlProvider > curdSql</p>
 */
@Override
public void addMappedStatement(MappedStatement ms) {
  logger.debug("addMappedStatement: " + ms.getId());
  if (GlobalConfigUtils.isRefresh(ms.getConfiguration())) {
    /*
     * 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
     */
    mappedStatements.remove(ms.getId());
  } else {
    if (mappedStatements.containsKey(ms.getId())) {
      /*
       * 说明已加载了xml中的节点; 忽略mapper中的SqlProvider数据
       */
      logger.error("mapper[" + ms.getId() + "] is ignored, because it exists, maybe from xml file");
      return;
    }
  }
  super.addMappedStatement(ms);
}

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

configuration.addMappedStatement(statement);
} catch (Exception e) {

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

configuration.addMappedStatement(statement);
} catch (Exception e) {

代码示例来源:origin: com.gitee.zhaohuihua/bdp-general-svc

public static void addMappedStatement(Configuration conf, MappedStatement ms) {
  try {
    conf.addMappedStatement(ms);
  } catch (Exception e) {
  }
}

代码示例来源:origin: tk.mybatis/mapper-core

@Override
public void addMappedStatement(MappedStatement ms) {
  try {
    super.addMappedStatement(ms);
    //没有任何配置时,使用默认配置
    if (this.mapperHelper == null) {
      this.mapperHelper = new MapperHelper();
    }
    this.mapperHelper.processMappedStatement(ms);
  } catch (IllegalArgumentException e) {
    //这里的异常是导致 Spring 启动死循环的关键位置,为了避免后续会吞异常,这里直接输出
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.github.yangziwen/quick-dao-mybatis

private void newSelectMappedStatement(String id, SqlSource sqlSource, final Class<?> resultType) {
  List<ResultMap> resultMaps = new ArrayList<>();
  resultMaps.add(new ResultMap.Builder(configuration, "defaultResultMap", resultType, new ArrayList<ResultMapping>(0)).build());
  MappedStatement mappedStatement = new MappedStatement.Builder(configuration, id, sqlSource, SqlCommandType.SELECT)
      .resultMaps(resultMaps)
      .build();
  configuration.addMappedStatement(mappedStatement);
}

代码示例来源:origin: io.github.yangziwen/quick-dao-mybatis

private void newUpdateMappedStatement(String id, SqlSource sqlSource, SqlCommandType sqlCommandType) {
  List<ResultMap> resultMaps = new ArrayList<>();
  resultMaps.add(new ResultMap.Builder(configuration, "defaultResultMap", int.class, new ArrayList<ResultMapping>(0)).build());
  MappedStatement mappedStatement = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType)
      .resultMaps(resultMaps)
      .build();
  configuration.addMappedStatement(mappedStatement);
}

代码示例来源:origin: io.github.yangziwen/quick-dao-mybatis

private void newInsertMappedStatement(String id, SqlSource sqlSource, String keyProperty) {
  List<ResultMap> resultMaps = new ArrayList<>();
  resultMaps.add(new ResultMap.Builder(configuration, "defaultResultMap", int.class, new ArrayList<ResultMapping>(0)).build());
  MappedStatement.Builder builder = new MappedStatement.Builder(configuration, id, sqlSource, SqlCommandType.INSERT)
      .resultMaps(resultMaps);
  if (StringUtils.isNotBlank(keyProperty)) {
    builder.keyGenerator(Jdbc3KeyGenerator.INSTANCE).keyProperty(keyProperty);
  }
  MappedStatement mappedStatement = builder.build();
  configuration.addMappedStatement(mappedStatement);
}

代码示例来源:origin: svili365/mybatis-jpa

@Override
public void parseStatement(Method method) {
 if (!configuration.isResourceLoaded(method.getDeclaringClass().toString())) {
  configuration.addLoadedResource(method.getDeclaringClass().toString());
 }
 LanguageDriver languageDriver = configuration.getDefaultScriptingLanuageInstance();
 SqlSource sqlSource = languageDriver
   .createSqlSource(configuration, parseSQL(method), Object.class);
 String statementId = method.getDeclaringClass().getName() + "." + method.getName();
 MappedStatement.Builder builder = new MappedStatement.Builder(configuration, statementId,
   sqlSource, recognizeSqlCommandType(method));
 String resource = recognizeResource(method);
 builder.resource(resource).lang(languageDriver).statementType(StatementType.PREPARED);
 MappedStatement statement = builder.build();
 configuration.addMappedStatement(statement);
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration,LanguageDriver languageDriver, EntityInfo entity) {
  String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
  for (String name : names) {			
    String msId = entity.getMapperClass().getName() + "." + name;
    
    EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
    
    String sql = buildUpdateSql(entityMapper,name.endsWith("Selective"));
    
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
    
    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource,SqlCommandType.UPDATE);
    
    MappedStatement statement = statementBuilder.build();
    
    configuration.addMappedStatement(statement);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration,LanguageDriver languageDriver, EntityInfo entity) {
  String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();
  // 从参数对象里提取注解信息
  EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
  // 生成sql
  String sql = buildDeleteSql(entityMapper);
  
  SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
  
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource,SqlCommandType.DELETE);
  MappedStatement statement = statementBuilder.build();
  configuration.addMappedStatement(statement);
}

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

configuration.addMappedStatement(statement);
return statement;

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

configuration.addMappedStatement(statement);
return statement;

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,EntityInfo entity) {
  String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.selectAllName();
  EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
  String sql = buildSelectAllSql(entityMapper);
  SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
  
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource,SqlCommandType.SELECT);
  // 将返回值修改为实体类型
  MappedStatement statement = statementBuilder.build();
  setResultType(configuration, statement, entity.getEntityClass());
  
  configuration.addMappedStatement(statement);
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,EntityInfo entity) {
  String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.selectName();
  EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
  String sql = buildGetByIdSql(entityMapper);
  SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
  
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource,SqlCommandType.SELECT);
  // 将返回值修改为实体类型
  MappedStatement statement = statementBuilder.build();
  setResultType(configuration, statement, entity.getEntityClass());
  
  configuration.addMappedStatement(statement);
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,EntityInfo entity) {
  
  
  String msId = entity.getMapperClass().getName() + ".insertList";
  
  // 从参数对象里提取注解信息
  EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
  // 生成sql
  String sql = buildBatchInsertSql(entityMapper);
  
  SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
  
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource,SqlCommandType.INSERT);
  
  KeyGenerator keyGenerator = entityMapper.autoId() ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
  statementBuilder.keyGenerator(keyGenerator)//
          .keyProperty(entityMapper.getIdColumn().getProperty())//
          .keyColumn(entityMapper.getIdColumn().getColumn());
  
  MappedStatement statement = statementBuilder.build();
  
  configuration.addMappedStatement(statement);

  
}

相关文章

微信公众号

最新文章

更多

Configuration类方法