Example usage for org.apache.ibatis.transaction TransactionFactory newTransaction

List of usage examples for org.apache.ibatis.transaction TransactionFactory newTransaction

Introduction

In this page you can find the example usage for org.apache.ibatis.transaction TransactionFactory newTransaction.

Prototype

Transaction newTransaction(Connection conn);

Source Link

Document

Creates a Transaction out of an existing connection.

Usage

From source file:org.activiti.MultiTenantSqlSessionFactory.java

License:Apache License

private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) {
    try {//from  w  ww  . jav a 2  s  .  c om
        final Environment environment = getConfiguration().getEnvironment();
        final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
        final Transaction tx = transactionFactory.newTransaction(connection);
        final Executor executor = getConfiguration().newExecutor(tx, execType, connection.getAutoCommit());
        return new DefaultSqlSession(getConfiguration(), executor);
    } catch (Exception e) {
        throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
        ErrorContext.instance().reset();
    }
}

From source file:org.hsweb.web.mybatis.dynamic.DynamicSqlSessionFactory.java

License:Apache License

private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) {
    try {/*from w ww  . jav  a 2 s . com*/
        boolean autoCommit;
        try {
            autoCommit = connection.getAutoCommit();
        } catch (SQLException e) {
            // Failover to true, as most poor drivers
            // or databases won't support transactions
            autoCommit = true;
        }
        final Environment environment = configuration.getEnvironment();
        final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
        final Transaction tx = transactionFactory.newTransaction(connection);
        final Executor executor = configuration.newExecutor(tx, execType);
        return new DefaultSqlSession(configuration, executor, autoCommit);
    } catch (Exception e) {
        throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
        ErrorContext.instance().reset();
    }
}