当前位置: 首页>>代码示例>>Java>>正文


Java ErrorContext类代码示例

本文整理汇总了Java中org.apache.ibatis.executor.ErrorContext的典型用法代码示例。如果您正苦于以下问题:Java ErrorContext类的具体用法?Java ErrorContext怎么用?Java ErrorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErrorContext类属于org.apache.ibatis.executor包,在下文中一共展示了ErrorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapperElement

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
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
            MybatisXMLMapperBuilder mapperParser = new MybatisXMLMapperBuilder(inputStream, configuration, resource,
                    configuration.getSqlFragments());
            mapperParser.parse();
        }
        for (Class<?> mapper : mapperClasses) {
            //TODO
            configuration.addMapper(mapper);
        }
    }
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:26,代码来源:MybatisXMLConfigBuilder.java

示例2: handleCursorResultSets

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
@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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:DefaultResultSetHandler.java

示例3: openSessionFromDataSource

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:21,代码来源:DynamicSqlSessionFactory.java

示例4: openSessionFromDataSource

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
   * 源码解析: 从数据源创建会话
   *
   * @param execType 执行类型
   * @param level 数据库隔离级别
   * @param autoCommit 是否自动提交
   * @return
   */
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
  Transaction tx = null;
  try {
    // 源码解析: 获取环境
    final Environment environment = configuration.getEnvironment();
    // 源码解析: 获取事务工厂
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    // 源码解析: 创建一个新的事务
    tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
    // 源码解析: 创建执行器
    final Executor executor = configuration.newExecutor(tx, execType);
    // 源码解析: 创建一个新的sql会话
    return new DefaultSqlSession(configuration, 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();
  }
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:31,代码来源:DefaultSqlSessionFactory.java

示例5: refresh

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * TODO 刷新
 * 
 * @param inputStream
 * @param resource
 * @param configuration
 * @throws NestedIOException
 */
public static void refresh(java.io.InputStream inputStream,
		String resource, Configuration configuration)
		throws NestedIOException {

	try {
		XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(
				inputStream, configuration, resource,
				configuration.getSqlFragments());
		xmlMapperBuilder.parse1();
	} catch (Exception e) {
		throw new NestedIOException("Failed to parse mapping resource: '"
				+ resource + "'", e);
	} finally {
		ErrorContext.instance().reset();
	}

}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:26,代码来源:SqlSessionFactoryBean.java

示例6: mapperElement

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:26,代码来源:MybatisXMLConfigBuilder.java

示例7: checkDaoConfig

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * {@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();
		}
	}
}
 
开发者ID:dianping,项目名称:zebra,代码行数:22,代码来源:ZebraMapperFactoryBean.java

示例8: refresh

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * TODO 刷新
 *
 * @param inputStream
 * @param resource
 * @param configuration
 * @throws NestedIOException
 */
public static void refresh(java.io.InputStream inputStream,
						   String resource, Configuration configuration)
		throws NestedIOException {

	try {
		XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(
				inputStream, configuration, resource,
				configuration.getSqlFragments());
		xmlMapperBuilder.parse();
	} catch (Exception e) {
		throw new NestedIOException("Failed to parse mapping resource: '"
				+ resource + "'", e);
	} finally {
		ErrorContext.instance().reset();
	}

}
 
开发者ID:whatlookingfor,项目名称:spring-boot-sample,代码行数:26,代码来源:SqlSessionFactoryBean.java

示例9: openSessionFromDataSource

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
  Transaction tx = null;
  try {
    final Environment environment = configuration.getEnvironment();
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    //通过事务工厂来产生一个事务
    tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
    //生成一个执行器(事务包含在执行器里)
    final Executor executor = configuration.newExecutor(tx, execType);
    //然后产生一个DefaultSqlSession
    return new DefaultSqlSession(configuration, 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();
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:21,代码来源:DefaultSqlSessionFactory.java

示例10: checkDaoConfig

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * {@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();
    }
  }
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:22,代码来源:MapperFactoryBean.java

示例11: checkDaoConfig

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * {@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();
    }
  }
}
 
开发者ID:colin-lee,项目名称:mybatis-spring-support,代码行数:21,代码来源:MapperFactoryBean.java

示例12: initialize

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * 使用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);
}
 
开发者ID:snakerflow,项目名称:snakerflow,代码行数:29,代码来源:MybatisHelper.java

示例13: checkDaoConfig

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * {@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();
    }
  }
}
 
开发者ID:zyong2004,项目名称:mybatis-spring,代码行数:22,代码来源:MapperFactoryBean.java

示例14: refresh

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
/**
 * 刷新mapper
 *
 * @throws Exception
 */
@SuppressWarnings("rawtypes")
private void refresh(Resource resource) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    this.configuration = sqlSessionFactory.getConfiguration();
    boolean isSupper = configuration.getClass().getSuperclass() == Configuration.class;
    try {
        Field loadedResourcesField = isSupper ? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
                : configuration.getClass().getDeclaredField("loadedResources");
        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");
        String namespace = context.getStringAttribute("namespace");
        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);
        cleanKeyGenerators(context.evalNodes("insert|update"), namespace);
        cleanSqlElement(context.evalNodes("/mapper/sql"), namespace);
        XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(),
                sqlSessionFactory.getConfiguration(), // 注入的sql先不进行处理了
                resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments());
        xmlMapperBuilder.parse();
        logger.debug("refresh: '" + resource + "', success!");
    } catch (IOException e) {
        logger.error("Refresh IOException :" + e.getMessage());
    } finally {
        ErrorContext.instance().reset();
    }
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:40,代码来源:MybatisMapperRefresh.java

示例15: resultMapElement

import org.apache.ibatis.executor.ErrorContext; //导入依赖的package包/类
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");
    Boolean autoMapping = resultMapNode.getBooleanAttribute("autoMapping");
    Class<?> typeClass = resolveClass(type);
    Discriminator discriminator = null;
    List<ResultMapping> resultMappings = new ArrayList<>();
    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 {
            List<ResultFlag> flags = new ArrayList<>();
            if ("id".equals(resultChild.getName())) {
                flags.add(ResultFlag.ID);
            }
            resultMappings.add(buildResultMappingFromContext(resultChild, typeClass, flags));
        }
    }
    ResultMapResolver resultMapResolver = new ResultMapResolver(builderAssistant, id, typeClass, extend, discriminator, resultMappings, autoMapping);
    try {
        return resultMapResolver.resolve();
    } catch (IncompleteElementException e) {
        configuration.addIncompleteResultMap(resultMapResolver);
        throw e;
    }
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:34,代码来源:MybatisXMLMapperBuilder.java


注:本文中的org.apache.ibatis.executor.ErrorContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。