本文整理匯總了Java中org.apache.ibatis.transaction.TransactionFactory.newTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Java TransactionFactory.newTransaction方法的具體用法?Java TransactionFactory.newTransaction怎麽用?Java TransactionFactory.newTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ibatis.transaction.TransactionFactory
的用法示例。
在下文中一共展示了TransactionFactory.newTransaction方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openSessionFromDataSource
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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: openSessionFromDataSource
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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();
}
}
示例3: openSessionFromDataSource
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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();
}
}
示例4: openSessionFromDataSource
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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);
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: newExecutor
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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);
}
示例6: shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的package包/類
@Test
public void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections() throws Exception {
TransactionFactory tf = new ManagedTransactionFactory();
tf.setProperties(new Properties());
Transaction tx = tf.newTransaction(conn);
assertEquals(conn, tx.getConnection());
tx.commit();
tx.rollback();
tx.close();
verify(conn).close();
}
示例7: shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的package包/類
@Test
public void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection() throws Exception {
TransactionFactory tf = new ManagedTransactionFactory();
Properties props = new Properties();
props.setProperty("closeConnection", "false");
tf.setProperties(props);
Transaction tx = tf.newTransaction(conn);
assertEquals(conn, tx.getConnection());
tx.commit();
tx.rollback();
tx.close();
verifyNoMoreInteractions(conn);
}
示例8: newExecutor
import org.apache.ibatis.transaction.TransactionFactory; //導入方法依賴的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);
}