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