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

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

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

Configuration.getMappedStatement介绍

暂无

代码示例

代码示例来源:origin: pagehelper/Mybatis-PageHelper

/**
 * 尝试获取已经存在的在 MS,提供对手写count和page的支持
 *
 * @param configuration
 * @param msId
 * @return
 */
public static MappedStatement getExistedMappedStatement(Configuration configuration, String msId) {
  MappedStatement mappedStatement = null;
  try {
    mappedStatement = configuration.getMappedStatement(msId, false);
  } catch (Throwable t) {
    //ignore
  }
  return mappedStatement;
}

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

private void makeSureGeneratedKeysAreNotUsedInBatchInserts(String statement) {
 Configuration configuration = super.getConfiguration();
 if (null != configuration) {
  MappedStatement mappedStatement = configuration.getMappedStatement(statement);
  if (null != mappedStatement) {
   KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
   if (keyGenerator instanceof Jdbc3KeyGenerator) {
    throw new IllegalStateException("Batch inserts cannot use generated keys");
   }
  }
 }
}

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

private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String methodName,
                          Class<?> declaringClass, Configuration configuration) {
    String statementId = mapperInterface.getName() + "." + methodName;
    if (configuration.hasStatement(statementId)) {
      return configuration.getMappedStatement(statementId);
    } else if (mapperInterface.equals(declaringClass)) {
      return null;
    }
    for (Class<?> superInterface : mapperInterface.getInterfaces()) {
      if (declaringClass.isAssignableFrom(superInterface)) {
        MappedStatement ms = resolveMappedStatement(superInterface, methodName,
          declaringClass, configuration);
        if (ms != null) {
          return ms;
        }
      }
    }
    return null;
  }
}

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

private String translateStatementName(String statementName) {
  return translatedStatementNames.computeIfAbsent(statementName, statementName1 -> {
    if (systemEnvironment.isDefaultDbProvider()) {
      return statementName1;
    }
    String forExternalDb = String.format("%s-%s", statementName1, database.getType());
    MappedStatement statement;
    try {
      statement = delegate.getConfiguration().getMappedStatement(forExternalDb);
    } catch (Exception e) {
      statement = null;
    }
    return statement != null ? forExternalDb : statementName1;
  });
}

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

private void executeWithResultHandler(SqlSession sqlSession, Object[] args) {
  MappedStatement ms = sqlSession.getConfiguration().getMappedStatement(command.getName());
  if (!StatementType.CALLABLE.equals(ms.getStatementType())
    && void.class.equals(ms.getResultMaps().get(0).getType())) {
    throw new BindingException("method " + command.getName()
      + " needs either a @ResultMap annotation, a @ResultType annotation,"
      + " or a resultType attribute in XML so a ResultHandler can be used as a parameter.");
  }
  Object param = method.convertArgsToSqlCommandParam(args);
  if (method.hasRowBounds()) {
    RowBounds rowBounds = method.extractRowBounds(args);
    sqlSession.select(command.getName(), param, rowBounds, method.extractResultHandler(args));
  } else {
    sqlSession.select(command.getName(), param, method.extractResultHandler(args));
  }
}

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

public MappedStatement getMappedStatement(String id) {
 return this.getMappedStatement(id, true);
}

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

MappedStatement keyStatement = configuration.getMappedStatement(id, false);
SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
configuration.addKeyGenerator(id, answer);

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

/**
   * 自定义 KEY 生成器
   */
  public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
                        String baseStatementId, LanguageDriver languageDriver) {
    IKeyGenerator keyGenerator = GlobalConfigUtils.getKeyGenerator(builderAssistant.getConfiguration());
    if (null == keyGenerator) {
      throw new IllegalArgumentException("not configure IKeyGenerator implementation class.");
    }
    String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    Class<?> resultTypeClass = tableInfo.getKeySequence().clazz();
    StatementType statementType = StatementType.PREPARED;
    String keyProperty = tableInfo.getKeyProperty();
    String keyColumn = tableInfo.getKeyColumn();
    SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(),
      keyGenerator.executeSql(tableInfo.getKeySequence().value()), null);
    builderAssistant.addMappedStatement(id, sqlSource, statementType, SqlCommandType.SELECT, null, null, null,
      null, null, resultTypeClass, null, false, false, false,
      new NoKeyGenerator(), keyProperty, keyColumn, null, languageDriver, null);
    id = builderAssistant.applyCurrentNamespace(id, false);
    MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false);
    SelectKeyGenerator selectKeyGenerator = new SelectKeyGenerator(keyStatement, true);
    builderAssistant.getConfiguration().addKeyGenerator(id, selectKeyGenerator);
    return selectKeyGenerator;
  }
}

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

MappedStatement keyStatement = configuration.getMappedStatement(keyId, false);

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

MappedStatement keyStatement = configuration.getMappedStatement(keyId, false);

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

@Override
public int executeNonEmptyUpdateStmt(String updateStmt, Object parameter) {
 updateStmt = dbSqlSessionFactory.mapStatement(updateStmt);
 //if mapped statement is empty, which can happens for some databases, we have no need to execute it
 MappedStatement mappedStatement = sqlSession.getConfiguration().getMappedStatement(updateStmt);
 if (mappedStatement.getBoundSql(parameter).getSql().isEmpty())
  return 0;
 return sqlSession.update(updateStmt, parameter);
}

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

@Override
public int executeNonEmptyUpdateStmt(String updateStmt, Object parameter) {
 updateStmt = dbSqlSessionFactory.mapStatement(updateStmt);
 //if mapped statement is empty, which can happens for some databases, we have no need to execute it
 MappedStatement mappedStatement = sqlSession.getConfiguration().getMappedStatement(updateStmt);
 if (mappedStatement.getBoundSql(parameter).getSql().isEmpty())
  return 0;
 return sqlSession.update(updateStmt, parameter);
}

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

@Override
public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER);
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  executor.query(ms, wrapCollection(parameter), rowBounds, handler);
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public int update(String statement, Object parameter) {
 try {
  dirty = true;
  MappedStatement ms = configuration.getMappedStatement(statement);
  return executor.update(ms, wrapCollection(parameter));
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error updating database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER);
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public int update(String statement, Object parameter) {
 try {
  dirty = true;
  MappedStatement ms = configuration.getMappedStatement(statement);
  return executor.update(ms, wrapCollection(parameter));
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error updating database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  executor.query(ms, wrapCollection(parameter), rowBounds, handler);
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public <T> Cursor<T> selectCursor(String statement, Object parameter, RowBounds rowBounds) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  Cursor<T> cursor = executor.queryCursor(ms, wrapCollection(parameter), rowBounds);
  registerCursor(cursor);
  return cursor;
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public <T> Cursor<T> selectCursor(String statement, Object parameter, RowBounds rowBounds) {
 try {
  MappedStatement ms = configuration.getMappedStatement(statement);
  Cursor<T> cursor = executor.queryCursor(ms, wrapCollection(parameter), rowBounds);
  registerCursor(cursor);
  return cursor;
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

相关文章

Configuration类方法