Java 类org.apache.ibatis.session.TransactionIsolationLevel 实例源码

项目:mybatis    文件:DefaultSqlSessionFactory.java   
/**
   * 源码解析: 从数据源创建会话
   *
   * @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();
  }
}
项目:mybaties    文件:DefaultSqlSessionFactory.java   
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();
  }
}
项目:bpm-adapter    文件:BpmBaseDao.java   
protected int batchUpdate(List<T> updateObjects , String statement , Integer batchSize){
    SqlSession sqlSession = this.sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH , TransactionIsolationLevel.NONE);
    if (batchSize == null || batchSize == 0){
        batchSize = BATCH_SIZE ;
    }
    int execCount = 0;
    for (int i = 0 , size = updateObjects.size(); i < size ; i++){
        sqlSession.update(statement, updateObjects);
        if ((i != 0 && i % batchSize == 0) || i == size -1){
            List<BatchResult> batchResults = sqlSession.flushStatements();
            execCount = batchResults.size() ;
            sqlSession.commit();
            sqlSession.clearCache();
            LOGGER.debug("batch insert , current commit size : {} " , execCount );
        }
    }
    sqlSession.close();
    return execCount;
}
项目:bpm-adapter    文件:BpmBaseDao.java   
protected int batchDelete(List<T> delObjects , String statement , Integer batchSize){
    SqlSession sqlSession = this.sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH , TransactionIsolationLevel.NONE);
    if (batchSize == null || batchSize == 0){
        batchSize = BATCH_SIZE ;
    }
    int execCount = 0;
    for (int i = 0 , size = delObjects.size(); i < size ; i++){
        sqlSession.delete(statement, delObjects);
        if ((i != 0 && i % batchSize == 0) || i == size -1){
            List<BatchResult> batchResults = sqlSession.flushStatements();
            execCount = batchResults.size() ;
            sqlSession.commit();
            sqlSession.clearCache();
            LOGGER.debug("batch insert , current commit size : {} " , execCount );
        }
    }
    sqlSession.close();
    return execCount;
}
项目:brigen-base    文件:InjectorFactory.java   
@Override
public void verify() {
    SqlSessionManager sqlSessionManager = getInjector().getInstance(SqlSessionManager.class);
    if (sqlSessionManager != null) {
        try (SqlSessionManager ssm = sqlSessionManager) {
            if (!ssm.isManagedSessionStarted()) {
                ssm.startManagedSession(ExecutorType.SIMPLE, (TransactionIsolationLevel) null);
            }
            Connection connection = ssm.getConnection();
            if (connection != null) {
                try (Connection conn = connection) {
                    DatabaseMetaData dmd = conn.getMetaData();
                    if (dmd != null) {
                        if (!compareBeanToTable(dmd, getBeanClasses(getConfig()))) {
                            throw new IllegalStateException("compareBeanToTable returns false.");
                        }
                    }
                    ssm.rollback(true);
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
项目:MybatisCode    文件:ManagedTransactionFactory.java   
@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);
}
项目:MybatisCode    文件:DefaultSqlSessionFactory.java   
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();
  }
}
项目:mybatis    文件:ManagedTransactionFactory.java   
@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);
}
项目:mybaties    文件:ManagedTransactionFactory.java   
@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);
}
项目:play    文件:ManagedTransactionFactory.java   
@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);
}
项目:play    文件:DefaultSqlSessionFactory.java   
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();
  }
}
项目:checklistbank    文件:UsageSyncServiceMyBatis.java   
@Transactional(
    executorType = ExecutorType.BATCH,
    isolationLevel = TransactionIsolationLevel.READ_UNCOMMITTED,
    exceptionMessage = "Something went wrong while inserting nub relations batch for dataset {0}"
)
private void insertNubRelationBatch(UUID datasetKey, Map<Integer, Integer> relations, Iterable<Integer> usageKeyBatch) {
  for (Integer usageKey : usageKeyBatch) {
    Set<NameUsageIssue> issues = nameUsageMapper.getIssues(usageKey).getIssues();
    if (relations.get(usageKey) == null) {
      // no match, add issue if not existing yet
      if (!issues.contains(NameUsageIssue.BACKBONE_MATCH_NONE)) {
        issues.add(NameUsageIssue.BACKBONE_MATCH_NONE);
        nameUsageMapper.updateIssues(usageKey, issues);
      }

    } else {
      if (issues.remove(NameUsageIssue.BACKBONE_MATCH_NONE) || issues.remove(NameUsageIssue.BACKBONE_MATCH_FUZZY)) {
        nameUsageMapper.updateIssues(usageKey, issues);
      }
      nubRelMapper.insert(datasetKey, usageKey, relations.get(usageKey));
      // for CoL with its instable ids update source key
      if (Constants.COL_DATASET_KEY.equals(datasetKey)) {
        usageMapper.updateSourceTaxonKey(relations.get(usageKey), usageKey);
      }
    }
  }
}
项目:brigen-base    文件:TransactionalMethodInterceptor.java   
@Override
public TransactionIsolationLevel isolationLevel() {
    TransactionIsolationLevel ret = null;
    if (particular != null) {
        ret = particular.isolationLevel();
    }
    if ((ret == null) && (setting != null)) {
        ret = setting.isolationLevel();
    }
    if (ret == null) {
        ret = def.isolationLevel();
    }
    return ret;
}
项目:mybatis-3    文件:ManagedTransactionFactory.java   
@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);
}
项目:mybatis-3    文件:DefaultSqlSessionFactory.java   
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();
  }
}
项目:MybatisCode    文件:JdbcTransaction.java   
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
项目:MybatisCode    文件:JdbcTransactionFactory.java   
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  return new JdbcTransaction(ds, level, autoCommit);
}
项目:MybatisCode    文件:ManagedTransaction.java   
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
项目:MybatisCode    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
项目:MybatisCode    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
项目:spring-data-mybatis    文件:ReadWriteManagedTransactionFactory.java   
@Override
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
    return new ReadWriteManagedTransaction(dataSource);
}
项目:mybatis    文件:JdbcTransaction.java   
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
项目:mybatis    文件:JdbcTransactionFactory.java   
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  // 源码解析: 返回JDBC事务
  return new JdbcTransaction(ds, level, autoCommit);
}
项目:mybatis    文件:ManagedTransaction.java   
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
项目:mybatis    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
项目:mybatis    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
项目:mybaties    文件:JdbcTransaction.java   
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
项目:mybaties    文件:JdbcTransactionFactory.java   
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  return new JdbcTransaction(ds, level, autoCommit);
}
项目:mybaties    文件:ManagedTransaction.java   
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
项目:mybaties    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
项目:mybaties    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
项目:mybatis-spring-1.2.2    文件:SpringManagedTransactionFactory.java   
/**
 * {@inheritDoc}
 */
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
  return new SpringManagedTransaction(dataSource);
}
项目:play    文件:JdbcTransaction.java   
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
项目:play    文件:JdbcTransactionFactory.java   
/**
 * 根据DataSource、隔离级别和是否自动提交创建Transacion
 */
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  return new JdbcTransaction(ds, level, autoCommit);
}
项目:play    文件:ManagedTransaction.java   
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
项目:play    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
项目:play    文件:DefaultSqlSessionFactory.java   
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
项目:snakerflow    文件:MybatisTransactionFactory.java   
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
    return new MybatisTransaction(dataSource);
}
项目:mybatis-spring    文件:SpringManagedTransactionFactory.java   
/**
 * {@inheritDoc}
 */
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
  return new SpringManagedTransaction(dataSource);
}
项目:easyooo-framework    文件:RountingManagedTransactionFactory.java   
@Override
public Transaction newTransaction(DataSource dataSource,
        TransactionIsolationLevel level, boolean autoCommit) {
    return new RoutingSpringManagedTransaction(dataSource);
}