org.apache.ibatis.session.TransactionIsolationLevel Java Examples

The following examples show how to use org.apache.ibatis.session.TransactionIsolationLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSqlSessionFactory.java    From mybatis with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example #2
Source File: DefaultSqlSessionFactory.java    From mybaties with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example #3
Source File: ManagedTransactionFactory.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: ManagedTransactionFactory.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: MybatisTransactionFactory.java    From snakerflow with Apache License 2.0 4 votes vote down vote up
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
	return new MybatisTransaction(dataSource);
}
 
Example #6
Source File: DelegatingSqlSessionFactory.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return wrappedSessionFactory.openSession(execType, level);
}
 
Example #7
Source File: DelegatingSqlSessionFactory.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public SqlSession openSession(TransactionIsolationLevel level) {
  return wrappedSessionFactory.openSession(level);
}
 
Example #8
Source File: DefaultSqlSessionFactory.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
 
Example #9
Source File: DefaultSqlSessionFactory.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
 
Example #10
Source File: ManagedTransaction.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
 
Example #11
Source File: JdbcTransactionFactory.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  return new JdbcTransaction(ds, level, autoCommit);
}
 
Example #12
Source File: JdbcTransaction.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
 
Example #13
Source File: RountingManagedTransactionFactory.java    From easyooo-framework with Apache License 2.0 4 votes vote down vote up
@Override
public Transaction newTransaction(DataSource dataSource,
		TransactionIsolationLevel level, boolean autoCommit) {
	return new RoutingSpringManagedTransaction(dataSource);
}
 
Example #14
Source File: MultiDataSourceTransactionFactory.java    From Milkomeda with MIT License 4 votes vote down vote up
@Override
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
    return new MultiDataSourceTransaction(dataSource);
}
 
Example #15
Source File: DefaultSqlSessionFactory.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) {
  return openSessionFromDataSource(execType, level, false);
}
 
Example #16
Source File: DefaultSqlSessionFactory.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSession openSession(TransactionIsolationLevel level) {
  return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false);
}
 
Example #17
Source File: ManagedTransaction.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public ManagedTransaction(DataSource ds, TransactionIsolationLevel level, boolean closeConnection) {
  this.dataSource = ds;
  this.level = level;
  this.closeConnection = closeConnection;
}
 
Example #18
Source File: JdbcTransactionFactory.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
  return new JdbcTransaction(ds, level, autoCommit);
}
 
Example #19
Source File: JdbcTransaction.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public JdbcTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
  dataSource = ds;
  level = desiredLevel;
  autoCommmit = desiredAutoCommit;
}
 
Example #20
Source File: ActivitiTransactionFactory.java    From my_curd with Apache License 2.0 4 votes vote down vote up
@Override
public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
    return new ActivitiTransaction(ds, level, autoCommit);
}
 
Example #21
Source File: ActivitiTransaction.java    From my_curd with Apache License 2.0 4 votes vote down vote up
ActivitiTransaction(DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit) {
    dataSource = ds;
    level = desiredLevel;
    autoCommit = desiredAutoCommit;
}
 
Example #22
Source File: AlfrescoDefaultSqlSessionFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level)
{
    SqlSession sqlSession = super.openSession(execType, level);
    return buildSqlSessionMetricsWrapper(sqlSession);
}
 
Example #23
Source File: AlfrescoDefaultSqlSessionFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public SqlSession openSession(TransactionIsolationLevel level)
{
    SqlSession sqlSession = super.openSession(level);
    return buildSqlSessionMetricsWrapper(sqlSession);
}
 
Example #24
Source File: JxSqlSessionFactory.java    From sinavi-jfw with Apache License 2.0 2 votes vote down vote up
/**
 * このメソッドは委譲先ファクトリが返却したSqlSessionをラップして返却します。
 * @param level トランザクションの分離レベル
 * @return SqlSessionのインスタンス
 */
public SqlSession openSession(TransactionIsolationLevel level) {
    return wrap(delegate.openSession(level));
}
 
Example #25
Source File: JxSqlSessionFactory.java    From sinavi-jfw with Apache License 2.0 2 votes vote down vote up
/**
 * このメソッドは委譲先ファクトリが返却したSqlSessionをラップして返却します。
 * @param execType 実行タイプ
 * @param level トランザクションの分離レベル
 * @return SqlSessionのインスタンス
 */
public SqlSession openSession(ExecutorType execType,
        TransactionIsolationLevel level) {
    return wrap(delegate.openSession(execType, level));
}
 
Example #26
Source File: TransactionFactory.java    From mybatis with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link Transaction} out of a datasource.
 * @param dataSource DataSource to take the connection from
 * @param level Desired isolation level
 * @param autoCommit Desired autocommit
 * @return Transaction
 * @since 3.1.0
 */
//根据数据源和事务隔离级别创建Transaction
Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);
 
Example #27
Source File: TransactionFactory.java    From mybaties with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link Transaction} out of a datasource.
 * @param dataSource DataSource to take the connection from
 * @param level Desired isolation level
 * @param autoCommit Desired autocommit
 * @return Transaction
 * @since 3.1.0
 */
//根据数据源和事务隔离级别创建Transaction
Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);