org.apache.ibatis.executor.ErrorContext类的使用及代码示例

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

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

ErrorContext介绍

暂无

代码示例

代码示例来源: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: 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) {
          value = parameterObject;
        } else {
          MetaObject metaObject = configuration.newMetaObject(parameterObject);
          value = metaObject.getValue(propertyName);
        JdbcType jdbcType = parameterMapping.getJdbcType();
        if (value == null && jdbcType == null) {
          jdbcType = configuration.getJdbcTypeForNull();

代码示例来源: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: 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: org.alfresco/alfresco-repository

throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
} finally {
  ErrorContext.instance().reset();
  this.logger.debug("Property 'configLocation' not specified, using default MyBatis Configuration");
configuration = new Configuration();
configuration.setVariables(this.configurationProperties);
configuration.setObjectFactory(this.objectFactory);
  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: 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: 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: camunda/camunda-bpm-platform

private XMLConfigBuilder(XPathParser parser, String environment, Properties props) {
 super(new Configuration());
 ErrorContext.instance().resource("SQL Mapper Configuration");
 this.configuration.setVariables(props);
 this.parsed = false;
 this.environment = environment;
 this.parser = parser;
}

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

/**
 * 使用DataSource初始化SqlSessionFactory
 * @param ds 数据源
 */
public static void initialize(DataSource ds) {
  TransactionFactory transactionFactory = new MybatisTransactionFactory();
  Environment environment = new Environment("snaker", transactionFactory, ds);
  Configuration configuration = new Configuration(environment);
  configuration.getTypeAliasRegistry().registerAliases(SCAN_PACKAGE, Object.class);
  if (log.isInfoEnabled()) {
    Map<String, Class<?>> typeAliases = configuration.getTypeAliasRegistry().getTypeAliases();
    for(Entry<String, Class<?>> entry : typeAliases.entrySet()) {
      log.info("Scanned class:[name=" + entry.getKey() + ",class=" + entry.getValue().getName() + "]");
    }
  }
  try {
    for(String resource : resources) {
      InputStream in = Resources.getResourceAsStream(resource);
      XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, resource, configuration.getSqlFragments());
      xmlMapperBuilder.parse();
    }
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    ErrorContext.instance().reset();
  }
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}

代码示例来源: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);
}

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

loadedResourcesField.setAccessible(true);
  Set loadedResourcesSet = ((Set) loadedResourcesField.get(configuration));
  XPathParser xPathParser = new XPathParser(resource.getInputStream(), true, configuration.getVariables(),
    new XMLMapperEntityResolver());
  XNode context = xPathParser.evalNode("/mapper");
  Field field = MapperRegistry.class.getDeclaredField("knownMappers");
  field.setAccessible(true);
  Map mapConfig = (Map) field.get(configuration.getMapperRegistry());
  mapConfig.remove(Resources.classForName(namespace));
  loadedResourcesSet.remove(resource.toString());
  configuration.getCacheNames().remove(namespace);
  cleanParameterMap(context.evalNodes("/mapper/parameterMap"), namespace);
  cleanResultMap(context.evalNodes("/mapper/resultMap"), namespace);
  logger.error("Refresh IOException :" + e.getMessage());
} finally {
  ErrorContext.instance().reset();

代码示例来源:origin: com.github.monee1988/mybatis-page

public void reloadXML() throws Exception {
  Configuration configuration = sqlSession.getConfiguration();
  // 移除加载项
  removeConfig(configuration);
  // 重新扫描加载
  for (String mapperLocation : mapperLocations) {
    Resource[] resources = getResource(mapperLocation);
    if (resources != null) {
      for (int i = 0; i < resources.length; i++) {
        if (resources[i] == null) {
          continue;
        }
        try {
          XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resources[i].getInputStream(),
              configuration, resources[i].toString(), configuration.getSqlFragments());
          xmlMapperBuilder.parse();
        } catch (Exception e) {
          throw new NestedIOException("Failed to parse mapping resource: '" + resources[i] + "'", e);
        } finally {
          ErrorContext.instance().reset();
        }
      }
    }
    // }
  }
}

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

@Override
public List<Object> handleResultSets(Statement stmt) throws SQLException {
 ErrorContext.instance().activity("handling results").object(mappedStatement.getId());
   if (parentMapping != null) {
    String nestedResultMapId = parentMapping.getNestedResultMapId();
    ResultMap resultMap = configuration.getResultMap(nestedResultMapId);
    handleResultSet(rsw, resultMap, null, parentMapping);

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

@Override
public <E> Cursor<E> handleCursorResultSets(Statement stmt) throws SQLException {
 ErrorContext.instance().activity("handling cursor results").object(mappedStatement.getId());
 ResultSetWrapper rsw = getFirstResultSet(stmt);
 List<ResultMap> resultMaps = mappedStatement.getResultMaps();
 int resultMapCount = resultMaps.size();
 validateResultMapsCount(rsw, resultMapCount);
 if (resultMapCount != 1) {
  throw new ExecutorException("Cursor results cannot be mapped to multiple resultMaps");
 }
 ResultMap resultMap = resultMaps.get(0);
 return new DefaultCursor<E>(this, resultMap, rsw, rowBounds);
}

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

private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings) throws Exception {
 ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
 String id = resultMapNode.getStringAttribute("id",
   resultMapNode.getValueBasedIdentifier());
  return resultMapResolver.resolve();
 } catch (IncompleteElementException  e) {
  configuration.addIncompleteResultMap(resultMapResolver);
  throw e;

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

public static RuntimeException wrapException(String message, Exception e) {
 return new PersistenceException(ErrorContext.instance().message(message).cause(e).toString(), e);
}

代码示例来源: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: org.apache.ibatis/ibatis-core

private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings) throws Exception {
 ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
 String id = resultMapNode.getStringAttribute("id",
   resultMapNode.getValueBasedIdentifier());
 String type = resultMapNode.getStringAttribute("type",
   resultMapNode.getStringAttribute("ofType",
     resultMapNode.getStringAttribute("resultType",
       resultMapNode.getStringAttribute("javaType"))));
 String extend = resultMapNode.getStringAttribute("extends");
 Class typeClass = resolveClass(type);
 Discriminator discriminator = null;
 List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
 resultMappings.addAll(additionalResultMappings);
 List<XNode> resultChildren = resultMapNode.getChildren();
 for (XNode resultChild : resultChildren) {
  if ("constructor".equals(resultChild.getName())) {
   processConstructorElement(resultChild, typeClass, resultMappings);
  } else if ("discriminator".equals(resultChild.getName())) {
   discriminator = processDiscriminatorElement(resultChild, typeClass, resultMappings);
  } else {
   ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
   if ("id".equals(resultChild.getName())) {
    flags.add(ResultFlag.ID);
   }
   resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
  }
 }
 return builderAssistant.addResultMap(id, typeClass, extend, discriminator, resultMappings);
}

相关文章