当前位置: 首页>>代码示例>>Java>>正文


Java Transaction类代码示例

本文整理汇总了Java中org.apache.ibatis.transaction.Transaction的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Transaction类属于org.apache.ibatis.transaction包,在下文中一共展示了Transaction类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCount

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
/**
 * 查询总纪录数
 *
 * @param mappedStatement mapped
 * @param parameterObject 参数
 * @param boundSql        boundSql
 * @param dialect         database dialect
 * @return 总记录数
 * @throws java.sql.SQLException sql查询错误
 */
public static int getCount(
                           final MappedStatement mappedStatement, final Transaction transaction, final Object parameterObject,
                           final BoundSql boundSql, Dialect dialect) throws SQLException {
    final String count_sql = dialect.getCountSQL();
    logger.debug("Total count SQL [{}] ", count_sql);
    logger.debug("Total count Parameters: {} ", parameterObject);

    Connection connection = transaction.getConnection();
    PreparedStatement countStmt = connection.prepareStatement(count_sql);
    DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement,parameterObject,boundSql);
    handler.setParameters(countStmt);

    ResultSet rs = countStmt.executeQuery();
    int count = 0;
    if (rs.next()) {
        count = rs.getInt(1);
    }
    logger.debug("Total count: {}", count);
    return count;

}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:32,代码来源:SQLHelp.java

示例2: openSessionFromDataSource

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例3: openSessionFromDataSource

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例4: openSessionFromDataSource

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例5: newTransaction

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  // Silently ignores autocommit and isolation level, as managed transactions are entirely
  // controlled by an external manager.  It's silently ignored so that
  // code remains portable between managed and unmanaged configurations.
  return new ManagedTransaction(ds, level, closeConnection);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:ManagedTransactionFactory.java

示例6: openSessionFromDataSource

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例7: closeTransaction

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
private void closeTransaction(Transaction tx) {
  if (tx != null) {
    try {
      tx.close();
    } catch (SQLException ignore) {
      // Intentionally ignore. Prefer previous error.
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:10,代码来源:DefaultSqlSessionFactory.java

示例8: BaseExecutor

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
protected BaseExecutor(Configuration configuration, Transaction transaction) {
  this.transaction = transaction;
  this.deferredLoads = new ConcurrentLinkedQueue<DeferredLoad>();
  this.localCache = new PerpetualCache("LocalCache");
  this.localOutputParameterCache = new PerpetualCache("LocalOutputParameterCache");
  this.closed = false;
  this.configuration = configuration;
  this.wrapper = this;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:10,代码来源:BaseExecutor.java

示例9: getTransaction

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
@Override
public Transaction getTransaction() {
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  return transaction;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:BaseExecutor.java

示例10: newExecutor

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例11: shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例12: shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection

import org.apache.ibatis.transaction.Transaction; //导入依赖的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

示例13: closeTransaction

import org.apache.ibatis.transaction.Transaction; //导入依赖的package包/类
private void closeTransaction(Transaction tx) {
    if (tx != null) {
        try {
            tx.close();
        } catch (SQLException ignore) {
            // Intentionally ignore. Prefer previous error.
        }
    }
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:10,代码来源:DynamicSqlSessionFactory.java

示例14: newExecutor

import org.apache.ibatis.transaction.Transaction; //导入依赖的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.Transaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。