org.apache.ibatis.executor.ErrorContext.instance()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(73)

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

ErrorContext.instance介绍

暂无

代码示例

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

/**
 * 使用自己的 MybatisConfiguration
 */
private MybatisXMLConfigBuilder(XPathParser parser, String environment, Properties props) {
  super(new MybatisConfiguration());
  ErrorContext.instance().resource("SQL Mapper Configuration");
  this.configuration.setVariables(props);
  this.parsed = false;
  this.environment = environment;
  this.parser = parser;
}

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

logger.error("Refresh IOException :" + e.getMessage());
} finally {
  ErrorContext.instance().reset();

代码示例来源: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: hs-web/hsweb-framework

private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) {
  try {
    boolean autoCommit;
    try {
      autoCommit = connection.getAutoCommit();
    } catch (SQLException e) {
      // Failover to true, as most poor drivers
      // or databases won't support transactions
      autoCommit = true;
    }
    final Environment environment = configuration.getEnvironment();
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    final Transaction tx = transactionFactory.newTransaction(connection);
    final Executor executor = configuration.newExecutor(tx, execType);
    return new DefaultSqlSession(configuration, executor, autoCommit);
  } catch (Exception e) {
    throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
  } finally {
    ErrorContext.instance().reset();
  }
}

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

throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
} finally {
  ErrorContext.instance().reset();
    throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
  } finally {
    ErrorContext.instance().reset();

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

@Override
@SuppressWarnings("unchecked")
public void setParameters(PreparedStatement ps) {
  ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
  List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
  if (parameterMappings != null) {

代码示例来源:origin: hs-web/hsweb-framework

@SuppressWarnings("all")
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
  Transaction tx = null;
  try {
    final Environment environment = getConfiguration().getEnvironment();
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    DataSource ds = DataSourceHolder.currentDataSource().getNative();
    if (ds == null) {
      ds = environment.getDataSource();
    }
    tx = transactionFactory.newTransaction(ds, level, autoCommit);
    final Executor executor = getConfiguration().newExecutor(tx, execType);
    return new DefaultSqlSession(getConfiguration(), executor, autoCommit);
  } catch (Exception e) {
    closeTransaction(tx); // may have fetched a connection so lets call close()
    throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
  } finally {
    ErrorContext.instance().reset();
  }
}

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

public MapperBuilderAssistant(Configuration configuration, String resource) {
 super(configuration);
 ErrorContext.instance().resource(resource);
 this.resource = resource;
}

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

protected void generateKeys(Object parameter) {
 KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
 ErrorContext.instance().store();
 keyGenerator.processBefore(executor, mappedStatement, null, parameter);
 ErrorContext.instance().recall();
}

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

@Override
public List<BatchResult> flushStatements() {
 try {
  return executor.flushStatements();
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error flushing statements.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void commit(boolean force) {
 try {
  executor.commit(isCommitOrRollbackRequired(force));
  dirty = false;
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error committing transaction.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void close() {
 try {
  executor.close(isCommitOrRollbackRequired(false));
  closeCursors();
  dirty = false;
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void rollback(boolean force) {
 try {
  executor.rollback(isCommitOrRollbackRequired(force));
  dirty = false;
 } catch (Exception e) {
  throw ExceptionFactory.wrapException("Error rolling back transaction.  Cause: " + e, e);
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public void close() {
 try {
  executor.close(isCommitOrRollbackRequired(false));
  closeCursors();
  dirty = false;
 } finally {
  ErrorContext.instance().reset();
 }
}

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

@Override
public int update(MappedStatement ms, Object parameter) throws SQLException {
 ErrorContext.instance().resource(ms.getResource()).activity("executing an update").object(ms.getId());
 if (closed) {
  throw new ExecutorException("Executor was closed.");
 }
 clearLocalCache();
 return doUpdate(ms, parameter);
}

相关文章