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


Java Environment.getDataSource方法代码示例

本文整理汇总了Java中org.apache.ibatis.mapping.Environment.getDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.getDataSource方法的具体用法?Java Environment.getDataSource怎么用?Java Environment.getDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.mapping.Environment的用法示例。


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

示例1: openSessionFromDataSource

import org.apache.ibatis.mapping.Environment; //导入方法依赖的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

示例2: openCommitOnCloseSession

import org.apache.ibatis.mapping.Environment; //导入方法依赖的package包/类
private CommitOnCloseSession openCommitOnCloseSession(boolean batch){
	
	ExecutorType executorType = batch? ExecutorType.BATCH : ExecutorType.SIMPLE;
	if( ! isSingleTxMode()){
		return new CommitOnCloseSession(sessionFactory.openSession(executorType));
	}

	//SINGLE CONN MODE
	Environment env = sessionFactory.getConfiguration().getEnvironment();
	DataSource ds = env.getDataSource();
	
	Connection conn = null;
	try {
		conn = getSingleOrNewConnection(ds);
	}catch (Exception e) {
		throw new IllegalStateException("can't get conneciton", e);
	}
	
	return new CommitOnCloseSession(sessionFactory.openSession(executorType, conn));


}
 
开发者ID:edolganov,项目名称:live-chat-engine,代码行数:23,代码来源:BaseDb.java

示例3: beginTrace

import org.apache.ibatis.mapping.Environment; //导入方法依赖的package包/类
private void beginTrace(String sql, Environment environment) throws Exception {
    if (!(environment.getDataSource() instanceof DataSourceAdapter)) {
        throw new IllegalDataSourceException("datasource must be DataSourceAdapter");
    }
    DataSourceAdapter dataSource = (DataSourceAdapter) environment.getDataSource();
    statementTracer.beginTrace(sql, dataSource.getUrl());
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:8,代码来源:MybatisTracingInterceptor.java

示例4: newExecutor

import org.apache.ibatis.mapping.Environment; //导入方法依赖的package包/类
private Executor newExecutor() {
  final Environment environment = configuration.getEnvironment();
  if (environment == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  Environment was not configured.");
  }
  final DataSource ds = environment.getDataSource();
  if (ds == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  DataSource was not configured.");
  }
  final TransactionFactory transactionFactory = environment.getTransactionFactory();
  final Transaction tx = transactionFactory.newTransaction(ds, null, false);
  return configuration.newExecutor(tx, ExecutorType.SIMPLE);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:14,代码来源:ResultLoader.java

示例5: newExecutor

import org.apache.ibatis.mapping.Environment; //导入方法依赖的package包/类
private Executor newExecutor() {
  final Environment environment = configuration.getEnvironment();
  if (environment == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  Environment was not configured.");
  }
  final DataSource ds = environment.getDataSource();
  if (ds == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  DataSource was not configured.");
  }
  final TransactionFactory transactionFactory = environment.getTransactionFactory();
  final Transaction tx = transactionFactory.newTransaction(ds, null, false);
  //如果executor已经被关闭了,则创建一个新的SimpleExecutor
  return configuration.newExecutor(tx, ExecutorType.SIMPLE);
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:15,代码来源:ResultLoader.java


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