本文整理汇总了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);
}
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
}
示例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();
}
}
示例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;
}
}