當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。