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