當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionFactory.newTransaction方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:21,代碼來源:DynamicSqlSessionFactory.java

示例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();
  }
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:31,代碼來源:DefaultSqlSessionFactory.java

示例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();
  }
}
 
開發者ID:shurun19851206,項目名稱:mybaties,代碼行數:21,代碼來源:DefaultSqlSessionFactory.java

示例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();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:16,代碼來源:DefaultSqlSessionFactory.java

示例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);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:14,代碼來源:ResultLoader.java

示例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();
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:12,代碼來源:ManagedTransactionFactoryTest.java

示例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);
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:14,代碼來源:ManagedTransactionFactoryTest.java

示例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);
}
 
開發者ID:shurun19851206,項目名稱:mybaties,代碼行數:15,代碼來源:ResultLoader.java


注:本文中的org.apache.ibatis.transaction.TransactionFactory.newTransaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。